Author: chris.laprun(a)jboss.com
Date: 2010-09-13 04:56:44 -0400 (Mon, 13 Sep 2010)
New Revision: 4165
Added:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/migration/BaseMigrationInfo.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/migration/ImportInfo.java
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/migration/ExportInfo.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerRegistry.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/migration/MigrationServiceTestCase.java
Log:
- Started implementing importPortlets on the consumer.
- Added injection of MigrationService on ConsumerRegistry.
- Added export context support on ExportInfo.
- Added BaseMigrationInfo and ImportInfo classes.
- Mostly synchronization commit.
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java 2010-09-13
08:08:14 UTC (rev 4164)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java 2010-09-13
08:56:44 UTC (rev 4165)
@@ -50,6 +50,7 @@
import org.gatein.wsrp.consumer.handlers.ProducerSessionInformation;
import org.gatein.wsrp.consumer.handlers.SessionHandler;
import org.gatein.wsrp.consumer.migration.ExportInfo;
+import org.gatein.wsrp.consumer.migration.ImportInfo;
import org.gatein.wsrp.consumer.migration.MigrationService;
import org.gatein.wsrp.consumer.portlet.WSRPPortlet;
import org.gatein.wsrp.consumer.portlet.info.WSRPPortletInfo;
@@ -61,6 +62,9 @@
import org.oasis.wsrp.v2.ExportedPortlet;
import org.oasis.wsrp.v2.Extension;
import org.oasis.wsrp.v2.FailedPortlets;
+import org.oasis.wsrp.v2.ImportPortlet;
+import org.oasis.wsrp.v2.ImportPortletsFailed;
+import org.oasis.wsrp.v2.ImportedPortlet;
import org.oasis.wsrp.v2.InconsistentParameters;
import org.oasis.wsrp.v2.InvalidHandle;
import org.oasis.wsrp.v2.Lifetime;
@@ -107,6 +111,8 @@
private ProducerInfo producerInfo;
+ private transient MigrationService migrationService;
+
/** A registration data element used to indicate when no registration was required by
the producer */
private final static RegistrationData REGISTRATION_NOT_NEEDED =
WSRPTypeFactory.createDefaultRegistrationData();
@@ -130,14 +136,13 @@
/** The set of supported user scopes */
private Set supportedUserScopes = WSRP_DEFAULT_USER_SCOPE; // todo: make it possible
to support different user scopes
private transient boolean started;
- private MigrationService migrationService;
public WSRPConsumerImpl()
{
- this(new ProducerInfo());
+ this(new ProducerInfo(), new MigrationService());
}
- public WSRPConsumerImpl(ProducerInfo info)
+ public WSRPConsumerImpl(ProducerInfo info, MigrationService migrationService)
{
ParameterValidation.throwIllegalArgExceptionIfNull(info,
"ProducerInfo");
@@ -145,7 +150,7 @@
sessionHandler = new SessionHandler(this);
dispatcher = new InvocationDispatcher(this);
- migrationService = new MigrationService(); // todo: inject this
+ this.migrationService = migrationService;
}
public ProducerInfo getProducerInfo()
@@ -822,7 +827,7 @@
XMLGregorianCalendar terminationTime = lifetime.getTerminationTime();
}
- ExportInfo exportInfo = new ExportInfo(System.currentTimeMillis(),
handleToState, errorCodeToHandle);
+ ExportInfo exportInfo = new ExportInfo(System.currentTimeMillis(),
errorCodeToHandle, handleToState, exportContextHolder.value);
migrationService.add(exportInfo);
return exportInfo;
}
@@ -883,6 +888,110 @@
}
}
+ public ImportInfo importPortlets(ExportInfo exportInfo, List<String> portlets)
throws PortletInvokerException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(exportInfo, "ExportInfo to
import from");
+
+ if (ParameterValidation.existsAndIsNotEmpty(portlets))
+ {
+ try
+ {
+ List<ImportPortlet> importPortlets = new
ArrayList<ImportPortlet>(portlets.size());
+ for (String portlet : portlets)
+ {
+ // todo: check semantics
+ importPortlets.add(WSRPTypeFactory.createImportPortlet(portlet,
exportInfo.getPortletStateFor(portlet)));
+ }
+
+ Holder<List<ImportedPortlet>> importedPortletsHolder = new
Holder<List<ImportedPortlet>>();
+ Holder<List<ImportPortletsFailed>> failedPortletsHolder = new
Holder<List<ImportPortletsFailed>>();
+ Holder<ResourceList> resourceListHolder = new
Holder<ResourceList>();
+ getPortletManagementService().importPortlets(getRegistrationContext(),
exportInfo.getExportContext(),
+ importPortlets, UserAccess.getUserContext(), null, importedPortletsHolder,
failedPortletsHolder,
+ resourceListHolder, new Holder<List<Extension>>());
+
+ List<ImportedPortlet> importedPortlets = importedPortletsHolder.value;
+ SortedMap<String, PortletContext> importIdToPortletContext = null;
+ if (ParameterValidation.existsAndIsNotEmpty(importedPortlets))
+ {
+ for (ImportedPortlet importedPortlet : importedPortlets)
+ {
+ org.oasis.wsrp.v2.PortletContext portletContext =
importedPortlet.getNewPortletContext();
+ importIdToPortletContext.put(importedPortlet.getImportID(),
+
PortletContext.createPortletContext(portletContext.getPortletHandle(),
portletContext.getPortletState()));
+ }
+ }
+
+ SortedMap<QName, List<String>> errorCodeToHandle = null;
+ List<ImportPortletsFailed> failedPortlets =
failedPortletsHolder.value;
+ if (ParameterValidation.existsAndIsNotEmpty(failedPortlets))
+ {
+ errorCodeToHandle = new TreeMap<QName, List<String>>();
+ for (ImportPortletsFailed failedPortletsForReason : failedPortlets)
+ {
+ errorCodeToHandle.put(failedPortletsForReason.getErrorCode(),
failedPortletsForReason.getImportID());
+ }
+ }
+
+ return new ImportInfo(System.currentTimeMillis(), errorCodeToHandle,
importIdToPortletContext);
+ }
+ catch (OperationNotSupported operationNotSupported)
+ {
+ throw new UnsupportedOperationException(operationNotSupported);
+ }
+ catch (InconsistentParameters inconsistentParameters)
+ {
+ throw new IllegalArgumentException(inconsistentParameters);
+ }
+ /*
+ // GTNWSRP-62
+ catch (AccessDenied accessDenied)
+ {
+ accessDenied.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
+ }
+ catch (ExportByValueNotSupported exportByValueNotSupported)
+ {
+ exportByValueNotSupported.printStackTrace(); //To change body of catch
statement use File | Settings | File Templates.
+ }
+ catch (InvalidHandle invalidHandle)
+ {
+ invalidHandle.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
+ }
+ catch (InvalidRegistration invalidRegistration)
+ {
+ invalidRegistration.printStackTrace(); //To change body of catch statement
use File | Settings | File Templates.
+ }
+ catch (InvalidUserCategory invalidUserCategory)
+ {
+ invalidUserCategory.printStackTrace(); //To change body of catch statement
use File | Settings | File Templates.
+ }
+ catch (MissingParameters missingParameters)
+ {
+ missingParameters.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
+ }
+ catch (ModifyRegistrationRequired modifyRegistrationRequired)
+ {
+ modifyRegistrationRequired.printStackTrace(); //To change body of catch
statement use File | Settings | File Templates.
+ }
+ catch (OperationFailed operationFailed)
+ {
+ operationFailed.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
+ }
+ catch (ResourceSuspended resourceSuspended)
+ {
+ resourceSuspended.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
+ }*/
+ catch (Exception e)
+ {
+ throw new PortletInvokerException(e);
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException("Must provide a non-null, non-empty list
of portlet handles.");
+ }
+ }
+
public MigrationService getMigrationService()
{
return migrationService;
Added:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/migration/BaseMigrationInfo.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/migration/BaseMigrationInfo.java
(rev 0)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/migration/BaseMigrationInfo.java 2010-09-13
08:56:44 UTC (rev 4165)
@@ -0,0 +1,82 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, 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.wsrp.consumer.migration;
+
+import org.gatein.common.util.ParameterValidation;
+
+import javax.xml.namespace.QName;
+import java.text.DateFormat;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class BaseMigrationInfo
+{
+ protected final static SortedMap<QName, List<String>> EMPTY_FAILED = new
TreeMap<QName, List<String>>();
+ protected final SortedMap<QName, List<String>> errorCodeToHandles;
+ protected final long exportTime;
+
+ public BaseMigrationInfo(long exportTime, SortedMap<QName, List<String>>
errorCodeToHandles)
+ {
+ if (ParameterValidation.existsAndIsNotEmpty(errorCodeToHandles))
+ {
+ this.errorCodeToHandles = errorCodeToHandles;
+ }
+ else
+ {
+ this.errorCodeToHandles = EMPTY_FAILED;
+ }
+ this.exportTime = exportTime;
+ }
+
+ public SortedMap<QName, List<String>>
getErrorCodesToFailedPortletHandlesMapping()
+ {
+ return Collections.unmodifiableSortedMap(errorCodeToHandles);
+ }
+
+ public long getExportTime()
+ {
+ return exportTime;
+ }
+
+ public String getHumanReadableExportTime(Locale locale)
+ {
+ return getHumanReadableTime(locale, exportTime);
+ }
+
+ protected String getHumanReadableTime(Locale locale, final long time)
+ {
+ if (locale == null)
+ {
+ locale = Locale.getDefault();
+ }
+ return DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL,
locale).format(new Date(time));
+ }
+}
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/migration/ExportInfo.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/migration/ExportInfo.java 2010-09-13
08:08:14 UTC (rev 4164)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/migration/ExportInfo.java 2010-09-13
08:56:44 UTC (rev 4165)
@@ -26,10 +26,7 @@
import org.gatein.common.util.ParameterValidation;
import javax.xml.namespace.QName;
-import java.text.DateFormat;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.SortedMap;
@@ -39,18 +36,17 @@
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision$
*/
-public class ExportInfo
+public class ExportInfo extends BaseMigrationInfo
{
- private final long exportTime;
+ private final byte[] exportContext;
private long expirationTime;
private final SortedMap<String, byte[]> handleToExportedState;
- private final SortedMap<QName, List<String>> errorCodeToHandles;
private final static SortedMap<String, byte[]> EMPTY_EXPORTED = new
TreeMap<String, byte[]>();
- private final static SortedMap<QName, List<String>> EMPTY_FAILED = new
TreeMap<QName, List<String>>();
- public ExportInfo(long exportTime, SortedMap<String, byte[]> handleToState,
SortedMap<QName, List<String>> errorCodeToHandles)
+ public ExportInfo(long exportTime, SortedMap<QName, List<String>>
errorCodeToHandles, SortedMap<String, byte[]> handleToState, byte[] exportContext)
{
- this.exportTime = exportTime;
+ super(exportTime, errorCodeToHandles);
+
if (ParameterValidation.existsAndIsNotEmpty(handleToState))
{
this.handleToExportedState = handleToState;
@@ -60,26 +56,9 @@
handleToExportedState = EMPTY_EXPORTED;
}
- if (ParameterValidation.existsAndIsNotEmpty(errorCodeToHandles))
- {
- this.errorCodeToHandles = errorCodeToHandles;
- }
- else
- {
- this.errorCodeToHandles = EMPTY_FAILED;
- }
+ this.exportContext = exportContext;
}
- public long getExportTime()
- {
- return exportTime;
- }
-
- public String getHumanReadableExportTime(Locale locale)
- {
- return getHumanReadableTime(locale, exportTime);
- }
-
public long getExpirationTime()
{
return expirationTime;
@@ -90,15 +69,6 @@
return getHumanReadableTime(locale, expirationTime);
}
- private String getHumanReadableTime(Locale locale, final long time)
- {
- if(locale == null)
- {
- locale = Locale.getDefault();
- }
- return DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL,
locale).format(new Date(time));
- }
-
public List<String> getExportedPortletHandles()
{
return new ArrayList<String>(handleToExportedState.keySet());
@@ -109,11 +79,6 @@
return handleToExportedState.get(portletHandle);
}
- public SortedMap<QName, List<String>>
getErrorCodesToFailedPortletHandlesMapping()
- {
- return Collections.unmodifiableSortedMap(errorCodeToHandles);
- }
-
@Override
public boolean equals(Object o)
{
@@ -141,4 +106,9 @@
{
return (int)(exportTime ^ (exportTime >>> 32));
}
+
+ public byte[] getExportContext()
+ {
+ return exportContext;
+ }
}
Added:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/migration/ImportInfo.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/migration/ImportInfo.java
(rev 0)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/migration/ImportInfo.java 2010-09-13
08:56:44 UTC (rev 4165)
@@ -0,0 +1,56 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, 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.wsrp.consumer.migration;
+
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.pc.api.PortletContext;
+
+import javax.xml.namespace.QName;
+import java.util.List;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class ImportInfo extends BaseMigrationInfo
+{
+ private final SortedMap<String, PortletContext> importIdToPortletContext;
+ private static final SortedMap<String, PortletContext> EMPTY_IMPORTED = new
TreeMap<String, PortletContext>();
+
+ public ImportInfo(long exportTime, SortedMap<QName, List<String>>
errorCodeToHandles, SortedMap<String, PortletContext> importIdToPortletContext)
+ {
+ super(exportTime, errorCodeToHandles);
+ if (ParameterValidation.existsAndIsNotEmpty(importIdToPortletContext))
+ {
+ this.importIdToPortletContext = importIdToPortletContext;
+ }
+ else
+ {
+ this.importIdToPortletContext = EMPTY_IMPORTED;
+ }
+ }
+
+
+}
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java 2010-09-13
08:08:14 UTC (rev 4164)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java 2010-09-13
08:56:44 UTC (rev 4165)
@@ -33,6 +33,7 @@
import org.gatein.wsrp.consumer.ConsumerException;
import org.gatein.wsrp.consumer.ProducerInfo;
import org.gatein.wsrp.consumer.WSRPConsumerImpl;
+import org.gatein.wsrp.consumer.migration.MigrationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -60,6 +61,7 @@
private Map<String, String> keysToIds;
private SessionEventBroadcaster sessionEventBroadcaster;
+ private MigrationService migrationService;
private static final String CONSUMER_WITH_ID = "Consumer with id '";
private static final String RELEASE_SESSIONS_LISTENER =
"release_sessions_listener_";
@@ -81,6 +83,16 @@
this.sessionEventBroadcaster = sessionEventBroadcaster;
}
+ public MigrationService getMigrationService()
+ {
+ return migrationService;
+ }
+
+ public void setMigrationService(MigrationService migrationService)
+ {
+ this.migrationService = migrationService;
+ }
+
public WSRPConsumer createConsumer(String id, Integer expirationCacheSeconds, String
wsdlURL)
{
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "Consumer
identifier", "Creating a Consumer");
@@ -171,7 +183,7 @@
private WSRPConsumer createConsumerFrom(ProducerInfo producerInfo)
{
- WSRPConsumer consumer = new WSRPConsumerImpl(producerInfo);
+ WSRPConsumer consumer = new WSRPConsumerImpl(producerInfo, migrationService);
add(consumer);
return consumer;
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerRegistry.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerRegistry.java 2010-09-13
08:08:14 UTC (rev 4164)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerRegistry.java 2010-09-13
08:56:44 UTC (rev 4165)
@@ -28,6 +28,7 @@
import org.gatein.wsrp.api.SessionEventBroadcaster;
import org.gatein.wsrp.consumer.ConsumerException;
import org.gatein.wsrp.consumer.ProducerInfo;
+import org.gatein.wsrp.consumer.migration.MigrationService;
import java.util.List;
@@ -76,4 +77,8 @@
void setFederatingPortletInvoker(FederatingPortletInvoker federatingPortletInvoker);
ProducerInfo getProducerInfoByKey(String key);
+
+ MigrationService getMigrationService();
+
+ void setMigrationService(MigrationService migrationService);
}
\ No newline at end of file
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/migration/MigrationServiceTestCase.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/migration/MigrationServiceTestCase.java 2010-09-13
08:08:14 UTC (rev 4164)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/migration/MigrationServiceTestCase.java 2010-09-13
08:56:44 UTC (rev 4165)
@@ -49,7 +49,7 @@
public void testAddExport()
{
- ExportInfo info = new ExportInfo(System.currentTimeMillis(), new TreeMap<String,
byte[]>(), null);
+ ExportInfo info = new ExportInfo(System.currentTimeMillis(), null, new
TreeMap<String, byte[]>(), null);
service.add(info);
List<ExportInfo> exports = service.getAvailableExportInfos();