Author: chris.laprun(a)jboss.com
Date: 2010-09-20 14:13:41 -0400 (Mon, 20 Sep 2010)
New Revision: 4259
Added:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/StoresByPathManager.java
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/JCRMigrationService.java
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/mapping/
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/mapping/ExportErrorMapping.java
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/mapping/ExportInfoMapping.java
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/mapping/ExportInfosMapping.java
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/mapping/ExportedStateMapping.java
portal/branches/wsrp2-integration/web/portal/src/main/webapp/WEB-INF/conf/wsrp/migration-nodetypes.xml
Modified:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/WSRPServiceIntegration.java
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/JCRConsumerRegistry.java
portal/branches/wsrp2-integration/web/portal/src/main/webapp/WEB-INF/conf/jcr/jcr-configuration.xml
Log:
- GTNWSRP-61: First implementation of JCR persistence for export data.
- Added JCRPersister.delete method and used it in JCRConsumerRegistry.
Modified:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/WSRPServiceIntegration.java
===================================================================
---
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/WSRPServiceIntegration.java 2010-09-20
15:19:44 UTC (rev 4258)
+++
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/WSRPServiceIntegration.java 2010-09-20
18:13:41 UTC (rev 4259)
@@ -40,6 +40,7 @@
import org.gatein.pc.portlet.state.producer.PortletStatePersistenceManager;
import org.gatein.pc.portlet.state.producer.ProducerPortletInvoker;
import org.gatein.portal.wsrp.state.consumer.JCRConsumerRegistry;
+import org.gatein.portal.wsrp.state.migration.JCRMigrationService;
import
org.gatein.portal.wsrp.state.producer.configuration.JCRProducerConfigurationService;
import
org.gatein.portal.wsrp.state.producer.registrations.JCRRegistrationPersistenceManager;
import org.gatein.portal.wsrp.state.producer.state.JCRPortletStatePersistenceManager;
@@ -230,7 +231,7 @@
consumerRegistry.setSessionEventBroadcaster(sessionEventBroadcaster);
// migration service
- MigrationService migrationService = new MigrationService();
+ MigrationService migrationService = new JCRMigrationService(container);
migrationService.setStructureProvider(new
MOPPortalStructureProvider(container));
consumerRegistry.setMigrationService(migrationService);
Modified:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java
===================================================================
---
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java 2010-09-20
15:19:44 UTC (rev 4258)
+++
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java 2010-09-20
18:13:41 UTC (rev 4259)
@@ -100,7 +100,26 @@
session.save();
}
+ public <T> boolean delete(T toDelete, StoresByPathManager<T> manager)
+ {
+ ChromatticSession session = getSession();
+ Object old = session.findByPath(toDelete.getClass(),
manager.getChildPath(toDelete));
+
+ if (old != null)
+ {
+ session.remove(old);
+ closeSession(session, true);
+ return true;
+ }
+ else
+ {
+ closeSession(session, false);
+ return false;
+ }
+
+ }
+
public static class WSRPSessionLifeCycle implements SessionLifeCycle
{
private ManageableRepository repository;
@@ -234,12 +253,12 @@
return encode(s);
}
- private String decode(String s)
+ public static String decode(String s)
{
return s.replace(CLOSE_BRACE_REPLACEMENT,
CLOSE_BRACE).replace(OPEN_BRACE_REPLACEMENT, OPEN_BRACE).replace(COLON_REPLACEMENT,
COLON);
}
- private String encode(String s)
+ public static String encode(String s)
{
return s.replace(OPEN_BRACE, OPEN_BRACE_REPLACEMENT).replace(CLOSE_BRACE,
CLOSE_BRACE_REPLACEMENT).replace(COLON, COLON_REPLACEMENT);
}
@@ -252,6 +271,11 @@
public String decodeNodeName(FormatterContext formatterContext, String s)
{
+ return decode(s);
+ }
+
+ public static String decode(String s)
+ {
return s.replace(SLASH_REPLACEMENT, SLASH);
}
Added:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/StoresByPathManager.java
===================================================================
---
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/StoresByPathManager.java
(rev 0)
+++
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/StoresByPathManager.java 2010-09-20
18:13:41 UTC (rev 4259)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.portal.wsrp.state;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public interface StoresByPathManager<C>
+{
+ String getChildPath(C needsComputedPath);
+}
Modified:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/JCRConsumerRegistry.java
===================================================================
---
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/JCRConsumerRegistry.java 2010-09-20
15:19:44 UTC (rev 4258)
+++
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/JCRConsumerRegistry.java 2010-09-20
18:13:41 UTC (rev 4259)
@@ -26,6 +26,7 @@
import org.chromattic.api.ChromatticSession;
import org.exoplatform.container.ExoContainer;
import org.gatein.portal.wsrp.state.JCRPersister;
+import org.gatein.portal.wsrp.state.StoresByPathManager;
import org.gatein.portal.wsrp.state.consumer.mapping.EndpointInfoMapping;
import org.gatein.portal.wsrp.state.consumer.mapping.ProducerInfoMapping;
import org.gatein.portal.wsrp.state.consumer.mapping.ProducerInfosMapping;
@@ -46,7 +47,7 @@
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision$
*/
-public class JCRConsumerRegistry extends AbstractConsumerRegistry
+public class JCRConsumerRegistry extends AbstractConsumerRegistry implements
StoresByPathManager<ProducerInfo>
{
// private NewJCRPersister persister;
private JCRPersister persister;
@@ -89,10 +90,7 @@
@Override
protected void delete(ProducerInfo info)
{
- ChromatticSession session = persister.getSession();
- delete(session, getPathFor(info));
-
- persister.closeSession(session, true);
+ persister.delete(info, this);
}
@Override
@@ -168,14 +166,9 @@
return producerInfosMapping;
}
- private void delete(ChromatticSession session, String path)
+ public String getChildPath(ProducerInfo needsComputedPath)
{
- ProducerInfoMapping old = session.findByPath(ProducerInfoMapping.class, path);
-
- if (old != null)
- {
- session.remove(old);
- }
+ return getPathFor(needsComputedPath);
}
private static String getPathFor(ProducerInfo info)
Added:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/JCRMigrationService.java
===================================================================
---
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/JCRMigrationService.java
(rev 0)
+++
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/JCRMigrationService.java 2010-09-20
18:13:41 UTC (rev 4259)
@@ -0,0 +1,186 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.portal.wsrp.state.migration;
+
+import org.chromattic.api.ChromatticSession;
+import org.exoplatform.container.ExoContainer;
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.portal.wsrp.state.JCRPersister;
+import org.gatein.portal.wsrp.state.StoresByPathManager;
+import org.gatein.portal.wsrp.state.migration.mapping.ExportErrorMapping;
+import org.gatein.portal.wsrp.state.migration.mapping.ExportInfoMapping;
+import org.gatein.portal.wsrp.state.migration.mapping.ExportInfosMapping;
+import org.gatein.portal.wsrp.state.migration.mapping.ExportedStateMapping;
+import org.gatein.wsrp.api.PortalStructureProvider;
+import org.gatein.wsrp.consumer.migration.ExportInfo;
+import org.gatein.wsrp.consumer.migration.MigrationService;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class JCRMigrationService implements MigrationService,
StoresByPathManager<ExportInfo>
+{
+ private PortalStructureProvider structureProvider;
+ private JCRPersister persister;
+ private static final String EXPORT_INFOS_PATH = ExportInfosMapping.NODE_NAME;
+ private int exportInfosCount = -1;
+
+ public JCRMigrationService(ExoContainer container) throws Exception
+ {
+ List<Class> mappingClasses = new ArrayList<Class>(4);
+ Collections.addAll(mappingClasses, ExportInfosMapping.class,
ExportInfoMapping.class, ExportedStateMapping.class,
+ ExportErrorMapping.class);
+
+ persister = new JCRPersister(container, JCRPersister.WSRP_WORKSPACE_NAME);
+ persister.initializeBuilderFor(mappingClasses);
+ }
+
+ public PortalStructureProvider getStructureProvider()
+ {
+ return structureProvider;
+ }
+
+ public void setStructureProvider(PortalStructureProvider structureProvider)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(structureProvider,
"PortalStructureProvider");
+ this.structureProvider = structureProvider;
+ }
+
+ public List<ExportInfo> getAvailableExportInfos()
+ {
+ ChromatticSession session = persister.getSession();
+
+ ExportInfosMapping exportInfosMapping = getExportInfosMapping(session);
+
+ List<ExportInfoMapping> exportInfoMappings =
exportInfosMapping.getExportInfos();
+ List<ExportInfo> exportInfos = new
ArrayList<ExportInfo>(exportInfoMappings.size());
+ for (ExportInfoMapping eim : exportInfoMappings)
+ {
+ exportInfos.add(eim.toExportInfo());
+ }
+
+ persister.closeSession(session, false);
+
+ exportInfosCount = exportInfos.size();
+
+ return exportInfos;
+ }
+
+ private ExportInfosMapping getExportInfosMapping(ChromatticSession session)
+ {
+ ExportInfosMapping exportInfosMapping =
session.findByPath(ExportInfosMapping.class, ExportInfosMapping.NODE_NAME);
+ if(exportInfosMapping == null)
+ {
+ exportInfosMapping = session.insert(ExportInfosMapping.class,
ExportInfosMapping.NODE_NAME);
+ exportInfosCount = 0;
+ }
+
+ return exportInfosMapping;
+ }
+
+ public ExportInfo getExportInfo(long exportTime)
+ {
+ ChromatticSession session = persister.getSession();
+
+ ExportInfoMapping eim = session.findByPath(ExportInfoMapping.class,
getPathFor(exportTime));
+
+ if(eim != null)
+ {
+ return eim.toExportInfo();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public void add(ExportInfo info)
+ {
+ ChromatticSession session = persister.getSession();
+
+ ExportInfoMapping eim = session.findByPath(ExportInfoMapping.class,
getChildPath(info));
+ long exportTime = info.getExportTime();
+ if(eim != null)
+ {
+ throw new IllegalArgumentException("An ExportInfo with export time "
+ + exportTime + " already exists!");
+ }
+ else
+ {
+ ExportInfosMapping exportInfosMapping = getExportInfosMapping(session);
+ String exportTimeAsString = "" + exportTime;
+ ExportInfoMapping exportInfo =
exportInfosMapping.createExportInfo(exportTimeAsString);
+ session.persist(exportInfosMapping, exportInfo, exportTimeAsString);
+ exportInfo.initFrom(info);
+
+ persister.closeSession(session, true);
+ exportInfosCount++;
+ }
+ }
+
+ public ExportInfo remove(ExportInfo info)
+ {
+ if (persister.delete(info, this))
+ {
+ exportInfosCount--;
+ return info;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public boolean isAvailableExportInfosEmpty()
+ {
+ if(exportInfosCount == -1)
+ {
+ ChromatticSession session = persister.getSession();
+ ExportInfosMapping mappings = getExportInfosMapping(session);
+ exportInfosCount = mappings.getExportInfos().size();
+ }
+
+ return exportInfosCount == 0;
+ }
+
+ public String getParentPath()
+ {
+ return EXPORT_INFOS_PATH;
+ }
+
+ public String getChildPath(ExportInfo exportInfo)
+ {
+ return getPathFor(exportInfo.getExportTime());
+ }
+
+ private String getPathFor(final long exportTime)
+ {
+ return getParentPath() + "/" + exportTime;
+ }
+}
Added:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/mapping/ExportErrorMapping.java
===================================================================
---
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/mapping/ExportErrorMapping.java
(rev 0)
+++
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/mapping/ExportErrorMapping.java 2010-09-20
18:13:41 UTC (rev 4259)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.portal.wsrp.state.migration.mapping;
+
+import org.chromattic.api.annotations.PrimaryType;
+import org.chromattic.api.annotations.Property;
+import org.gatein.common.util.ParameterValidation;
+
+import javax.xml.namespace.QName;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = ExportErrorMapping.NODE_NAME)
+public abstract class ExportErrorMapping
+{
+ public static final String NODE_NAME = "wsrp:exporterror";
+ private static final String COMMA = ",";
+
+ @Property(name = "errorcode")
+ public abstract String getCode();
+
+ public abstract void setCode(String code);
+
+ @Property(name = "handles")
+ public abstract String getHandles();
+
+ public abstract void setHandles(String handles);
+
+ public QName getErrorCode()
+ {
+ return QName.valueOf(getCode());
+ }
+
+ public List<String> getPortletHandles()
+ {
+ return Arrays.asList(getHandles().split(COMMA));
+ }
+
+ public void initFrom(QName errorCode, List<String> handles)
+ {
+ setCode(errorCode.toString());
+
+ if (ParameterValidation.existsAndIsNotEmpty(handles))
+ {
+ StringBuilder sb = new StringBuilder();
+ int size = handles.size();
+ int index = 0;
+ for (String handle : handles)
+ {
+ sb.append(handle);
+ if (index++ < size)
+ {
+ sb.append(COMMA);
+ }
+ }
+ setHandles(sb.toString());
+ }
+ }
+}
Added:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/mapping/ExportInfoMapping.java
===================================================================
---
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/mapping/ExportInfoMapping.java
(rev 0)
+++
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/mapping/ExportInfoMapping.java 2010-09-20
18:13:41 UTC (rev 4259)
@@ -0,0 +1,139 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.portal.wsrp.state.migration.mapping;
+
+import org.chromattic.api.annotations.Create;
+import org.chromattic.api.annotations.OneToMany;
+import org.chromattic.api.annotations.PrimaryType;
+import org.chromattic.api.annotations.Property;
+import org.exoplatform.commons.utils.Safe;
+import org.gatein.portal.wsrp.state.JCRPersister;
+import org.gatein.wsrp.consumer.migration.ExportInfo;
+
+import javax.xml.namespace.QName;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = ExportInfoMapping.NODE_NAME)
+public abstract class ExportInfoMapping
+{
+ public static final String NODE_NAME = "wsrp:exportinfo";
+
+ @Property(name = "exporttime")
+ public abstract long getExportTime();
+ public abstract void setExportTime(long exportTime);
+
+ @Property(name = "expirationtime")
+ public abstract long getExpirationTime();
+ public abstract void setExpirationTime(long expirationTime);
+
+ @Property(name = "exportcontext")
+ public abstract InputStream getExportContext();
+ public abstract void setExportContext(InputStream exportContext);
+
+ @OneToMany
+ public abstract List<ExportedStateMapping> getExportedStates();
+
+ @Create
+ public abstract ExportedStateMapping internalCreateExportedState(String
portletHandle);
+
+ public ExportedStateMapping createExportedState(String portletHandle)
+ {
+ return
internalCreateExportedState(JCRPersister.PortletNameFormatter.encode(portletHandle));
+ }
+
+ @OneToMany
+ protected abstract List<ExportErrorMapping> getErrors();
+
+ @Create
+ public abstract ExportErrorMapping internalCreateError(String errorCode);
+
+ public ExportErrorMapping createError(String errorCode)
+ {
+ return internalCreateError(JCRPersister.QNameFormatter.encode(errorCode));
+ }
+
+ public void initFrom(ExportInfo exportInfo)
+ {
+ setExportTime(exportInfo.getExportTime());
+ setExpirationTime(exportInfo.getExpirationTime());
+
+ byte[] exportContext = exportInfo.getExportContext();
+ if(exportContext != null && exportContext.length > 0)
+ {
+ ByteArrayInputStream is = new ByteArrayInputStream(exportContext);
+ setExportContext(is);
+ }
+
+ List<ExportedStateMapping> exportedStates = getExportedStates();
+ exportedStates.clear();
+ for (String handle : exportInfo.getExportedPortletHandles())
+ {
+ ExportedStateMapping exportedState = createExportedState(handle);
+
+ // add then init idiom
+ exportedStates.add(exportedState);
+ exportedState.initFrom(handle, exportInfo.getPortletStateFor(handle));
+ }
+
+ List<ExportErrorMapping> errors = getErrors();
+ errors.clear();
+ for (Map.Entry<QName, List<String>> entry :
exportInfo.getErrorCodesToFailedPortletHandlesMapping().entrySet())
+ {
+ QName errorCode = entry.getKey();
+ ExportErrorMapping error = createError(errorCode.toString());
+
+ // add then init idiom
+ errors.add(error);
+ error.initFrom(errorCode, entry.getValue());
+ }
+ }
+
+ public ExportInfo toExportInfo()
+ {
+ List<ExportedStateMapping> exportedStates = getExportedStates();
+ SortedMap<String, byte[]> states = new TreeMap<String,byte[]>();
+ for (ExportedStateMapping exportedState : exportedStates)
+ {
+ states.put(JCRPersister.PortletNameFormatter.decode(exportedState.getHandle()),
Safe.getBytes(exportedState.getState()));
+ }
+
+ List<ExportErrorMapping> errors = getErrors();
+ SortedMap<QName, List<String>> errorCodesToHandles = new
TreeMap<QName, List<String>>();
+ for (ExportErrorMapping error : errors)
+ {
+ errorCodesToHandles.put(error.getErrorCode(), error.getPortletHandles());
+ }
+
+ return new ExportInfo(getExportTime(), errorCodesToHandles, states,
Safe.getBytes(getExportContext()));
+ }
+}
Added:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/mapping/ExportInfosMapping.java
===================================================================
---
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/mapping/ExportInfosMapping.java
(rev 0)
+++
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/mapping/ExportInfosMapping.java 2010-09-20
18:13:41 UTC (rev 4259)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.portal.wsrp.state.migration.mapping;
+
+import org.chromattic.api.annotations.Create;
+import org.chromattic.api.annotations.OneToMany;
+import org.chromattic.api.annotations.PrimaryType;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = ExportInfosMapping.NODE_NAME)
+public abstract class ExportInfosMapping
+{
+
+ public static final String NODE_NAME = "wsrp:exportinfos";
+
+ @OneToMany
+ public abstract List<ExportInfoMapping> getExportInfos();
+
+ @Create
+ public abstract ExportInfoMapping createExportInfo(String exportTimeAsString);
+}
Added:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/mapping/ExportedStateMapping.java
===================================================================
---
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/mapping/ExportedStateMapping.java
(rev 0)
+++
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/mapping/ExportedStateMapping.java 2010-09-20
18:13:41 UTC (rev 4259)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.portal.wsrp.state.migration.mapping;
+
+import org.chromattic.api.annotations.PrimaryType;
+import org.chromattic.api.annotations.Property;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = ExportedStateMapping.NODE_NAME)
+public abstract class ExportedStateMapping
+{
+ public static final String NODE_NAME = "wsrp:exportedstate";
+
+ @Property(name = "handle")
+ public abstract String getHandle();
+ public abstract void setHandle(String handle);
+
+ @Property(name = "state")
+ public abstract InputStream getState();
+ public abstract void setState(InputStream state);
+
+ public void initFrom(String handle, byte[] state)
+ {
+ setHandle(handle);
+
+ if(state != null && state.length > 0)
+ {
+ ByteArrayInputStream is = new ByteArrayInputStream(state);
+ setState(is);
+ }
+ }
+}
Modified:
portal/branches/wsrp2-integration/web/portal/src/main/webapp/WEB-INF/conf/jcr/jcr-configuration.xml
===================================================================
---
portal/branches/wsrp2-integration/web/portal/src/main/webapp/WEB-INF/conf/jcr/jcr-configuration.xml 2010-09-20
15:19:44 UTC (rev 4258)
+++
portal/branches/wsrp2-integration/web/portal/src/main/webapp/WEB-INF/conf/jcr/jcr-configuration.xml 2010-09-20
18:13:41 UTC (rev 4259)
@@ -123,6 +123,7 @@
<value>war:/conf/wsrp/producer-configuration-nodetypes.xml</value>
<value>war:/conf/wsrp/producer-registrations-nodetypes.xml</value>
<value>war:/conf/wsrp/producer-pc-nodetypes.xml</value>
+ <value>war:/conf/wsrp/migration-nodetypes.xml</value>
</values-param>
</init-params>
</component-plugin>
Added:
portal/branches/wsrp2-integration/web/portal/src/main/webapp/WEB-INF/conf/wsrp/migration-nodetypes.xml
===================================================================
---
portal/branches/wsrp2-integration/web/portal/src/main/webapp/WEB-INF/conf/wsrp/migration-nodetypes.xml
(rev 0)
+++
portal/branches/wsrp2-integration/web/portal/src/main/webapp/WEB-INF/conf/wsrp/migration-nodetypes.xml 2010-09-20
18:13:41 UTC (rev 4259)
@@ -0,0 +1,114 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!--
+ ~ JBoss, a division of Red Hat
+ ~ Copyright 2010, Red Hat Middleware, LLC, and individual
+ ~ contributors as indicated by the @authors tag. See the
+ ~ copyright.txt in the distribution for a full listing of
+ ~ individual contributors.
+ ~
+ ~ This is free software; you can redistribute it and/or modify it
+ ~ under the terms of the GNU Lesser General Public License as
+ ~ published by the Free Software Foundation; either version 2.1 of
+ ~ the License, or (at your option) any later version.
+ ~
+ ~ This software is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ ~ Lesser General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public
+ ~ License along with this software; if not, write to the Free
+ ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ ~ 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ -->
+
+<nodeTypes
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
xmlns:mix="http://www.jcp.org/jcr/mix/1.0"
+
xmlns:jcr="http://www.jcp.org/jcr/1.0">
+
+ <nodeType name="wsrp:exportinfos" isMixin="false"
hasOrderableChildNodes="true" primaryItemName="">
+ <supertypes>
+ <supertype>nt:base</supertype>
+ <supertype>mix:referenceable</supertype>
+ </supertypes>
+ <childNodeDefinitions>
+ <childNodeDefinition name="*"
defaultPrimaryType="wsrp:exportinfo" autoCreated="false"
mandatory="false"
+ onParentVersion="COPY"
protected="false" sameNameSiblings="false">
+ <requiredPrimaryTypes>
+ <requiredPrimaryType>wsrp:exportinfo</requiredPrimaryType>
+ </requiredPrimaryTypes>
+ </childNodeDefinition>
+ </childNodeDefinitions>
+ </nodeType>
+
+ <nodeType name="wsrp:exportinfo" isMixin="false"
hasOrderableChildNodes="true" primaryItemName="">
+ <supertypes>
+ <supertype>nt:base</supertype>
+ <supertype>mix:referenceable</supertype>
+ </supertypes>
+ <propertyDefinitions>
+ <propertyDefinition name="exporttime" requiredType="Long"
autoCreated="false" mandatory="false"
+ onParentVersion="COPY" protected="false"
multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+ <propertyDefinition name="expirationtime"
requiredType="Long" autoCreated="false" mandatory="false"
+ onParentVersion="COPY" protected="false"
multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+ <propertyDefinition name="exportcontext"
requiredType="Binary" autoCreated="false" mandatory="false"
+ onParentVersion="COPY" protected="false"
multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+ </propertyDefinitions>
+ <childNodeDefinitions>
+ <childNodeDefinition name="*"
defaultPrimaryType="wsrp:exportedstate" autoCreated="false"
+ mandatory="false"
+ onParentVersion="COPY"
protected="false" sameNameSiblings="false">
+ <requiredPrimaryTypes>
+ <requiredPrimaryType>wsrp:exportedstate</requiredPrimaryType>
+ </requiredPrimaryTypes>
+ </childNodeDefinition>
+ <childNodeDefinition name="*"
defaultPrimaryType="wsrp:exporterror" autoCreated="false"
+ mandatory="false"
+ onParentVersion="COPY"
protected="false" sameNameSiblings="false">
+ <requiredPrimaryTypes>
+ <requiredPrimaryType>wsrp:exporterror</requiredPrimaryType>
+ </requiredPrimaryTypes>
+ </childNodeDefinition>
+ </childNodeDefinitions>
+ </nodeType>
+
+ <nodeType name="wsrp:exportedstate" isMixin="false"
primaryItemName="">
+ <supertypes>
+ <supertype>nt:base</supertype>
+ <supertype>mix:referenceable</supertype>
+ </supertypes>
+ <propertyDefinitions>
+ <propertyDefinition name="handle" requiredType="String"
autoCreated="false" mandatory="false"
+ onParentVersion="COPY" protected="false"
multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+ <propertyDefinition name="state" requiredType="Binary"
autoCreated="false" mandatory="false"
+ onParentVersion="COPY" protected="false"
multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+ </propertyDefinitions>
+ </nodeType>
+
+ <nodeType name="wsrp:exporterror" isMixin="false"
primaryItemName="">
+ <supertypes>
+ <supertype>nt:base</supertype>
+ <supertype>mix:referenceable</supertype>
+ </supertypes>
+ <propertyDefinitions>
+ <propertyDefinition name="errorcode"
requiredType="String" autoCreated="false" mandatory="false"
+ onParentVersion="COPY" protected="false"
multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+ <propertyDefinition name="handles" requiredType="String"
autoCreated="false" mandatory="false"
+ onParentVersion="COPY" protected="false"
multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+ </propertyDefinitions>
+ </nodeType>
+</nodeTypes>
\ No newline at end of file