Author: mwringe
Date: 2010-09-08 00:25:46 -0400 (Wed, 08 Sep 2010)
New Revision: 4077
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportManager.java
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportPersistenceManager.java
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportContext.java
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/support/TestMockExportPersistenceManager.java
Log:
GTNWSRP-64: remove lifetime class references (WSRP 2.0 specific class) in the export
manager apis. Still need to throw new, non WSRP 2.0 specific exceptions. Ugly right now,
still need to find a better more clean solution.
GTNWSRP-69: Update the persistence manager classes to work a bit better. The
TestMockExportPersistenceManager is very close to being an in memory solution.
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportManager.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportManager.java 2010-09-07
21:59:31 UTC (rev 4076)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportManager.java 2010-09-08
04:25:46 UTC (rev 4077)
@@ -24,7 +24,6 @@
import org.gatein.exports.data.ExportContext;
import org.gatein.exports.data.ExportPortletData;
-import org.oasis.wsrp.v2.Lifetime;
import org.oasis.wsrp.v2.OperationFailed;
import org.oasis.wsrp.v2.OperationNotSupported;
@@ -43,19 +42,19 @@
boolean supportsExportByValue();
- ExportContext createExportContext(boolean exportByValueRequired, Lifetime lifetime)
throws UnsupportedEncodingException;
+ ExportContext createExportContext(boolean exportByValueRequired, long currentTime,
long terminationTime, long refreshDuration) throws UnsupportedEncodingException;
ExportContext createExportContext(byte[] bytes) throws OperationFailed;
ExportPortletData createExportPortletData(ExportContext exportContextData, String
portletHandle, byte[] portletState) throws UnsupportedEncodingException;
- ExportPortletData createExportPortletData(ExportContext exportContext, Lifetime
lifetime, byte[] bytes) throws OperationFailed;
+ ExportPortletData createExportPortletData(ExportContext exportContext, long
currentime, long terminationTime, long refreshDuration, byte[] bytes) throws
OperationFailed;
byte[] encodeExportPortletData(ExportContext exportContextData, ExportPortletData
exportPortletData) throws UnsupportedEncodingException, IOException;
byte[] encodeExportContextData(ExportContext exportContextData) throws
UnsupportedEncodingException, IOException;
- Lifetime setExportLifetime(ExportContext exportContext, Lifetime lifetime) throws
OperationFailed, OperationNotSupported;
+ ExportContext setExportLifetime(byte[] exportContextBytes, long currentTime, long
terminationTime, long refreshDuration) throws OperationFailed, OperationNotSupported;
void releaseExport(byte[] bytes) throws IOException;
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportPersistenceManager.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportPersistenceManager.java 2010-09-07
21:59:31 UTC (rev 4076)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportPersistenceManager.java 2010-09-08
04:25:46 UTC (rev 4077)
@@ -34,19 +34,7 @@
* @version $Revision$
*/
public interface ExportPersistenceManager
-{
- String storeExportContextData(ExportContext exportContextData);
-
- String storeExportPortletData(ExportPortletData exportPortletData);
-
- ExportContext retrieveExportContextData(String refid);
-
- ExportPortletData retrieveExportPortletData(String refid);
-
- Lifetime updateExportLifetime(ExportContext exportContext, Lifetime lifetime);
-
- void releaseExport(byte[] bytes);
-
+{
/**
* Returns true if the PersistenceManager knows how to decode a byte array with
* the specified type and version.
@@ -56,21 +44,28 @@
* @return True if the persistence manager can support the specified type and
version.
*/
boolean supports(String type, double version);
+
+ String getExportReferenceId (String type, double version, byte[] bytes) throws
UnsupportedEncodingException;
+
+ String storeExportContext(ExportContext exportContext);
+
+ ExportContext getExportContext(String refId);
+
+ //why are we returning an ExportContext here?
+ ExportContext updateExportContext(String refId, ExportContext updatedExportContext);
+
+ boolean removeExportContext(String refId);
+
+ byte[] encodeExportContext(String refId) throws IOException;
+
+ String storeExportPortletData (ExportContext exportContext, ExportPortletData
exportPortletData);
+
+ ExportPortletData getExportPortletData (String exportContextId, String
portletDataId);
- /**
- * Based on the specified type and version, the bytes will be
- * decoded into an ExportContext.
- *
- * @param type The type
- * @param version The version
- * @param bytes The bytes to decode
- * @return
- * @throws UnsupportedEncodingException
- */
- ExportContext getExportContext(String type, double version, byte[] bytes) throws
UnsupportedEncodingException;
-
- byte[] encodeExportPortletData(ExportContext exportContext, ExportPortletData
exportPortlet);
-
- byte[] encodeExportContextData(ExportContext exportContext) throws IOException;
+ ExportPortletData updateExportPortletData(String refId, ExportPortletData
updatedPortletData);
+
+ boolean removeExportPortletData(String exportContextId, String portletDataId);
+
+ byte[] encodeExportPortletData(String exportDataRefId) throws IOException;
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportContext.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportContext.java 2010-09-07
21:59:31 UTC (rev 4076)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportContext.java 2010-09-08
04:25:46 UTC (rev 4077)
@@ -22,8 +22,6 @@
*/
package org.gatein.exports.data;
-import org.oasis.wsrp.v2.Lifetime;
-
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
@@ -38,9 +36,11 @@
protected static final String ENCODING = "UTF-8";
public static final String TYPE = "WSRP_EC";
public static final double VERSION = 1.0;
-
-
- protected Lifetime lifeTime;
+
+ protected long currentTime;
+ protected long terminationTime;
+ protected long refreshDuration;
+
protected final boolean exportByValue;
protected List<String> portlets;
@@ -48,38 +48,68 @@
//for now, we don't store anything in the exported by value ExportContext
public ExportContext()
{
- this.lifeTime = null;
this.exportByValue = true;
}
- public ExportContext(boolean exportByValue, Lifetime lifetime)
+ public ExportContext(boolean exportByValue, long currentTime, long terminationTime,
long refreshDuration)
{
//ignore the lifetime if we are exporting by value
if (exportByValue)
{
- this.lifeTime = null;
+ this.currentTime = currentTime;
+ this.terminationTime = terminationTime;
+ this.refreshDuration = refreshDuration;
}
else
{
- this.lifeTime = lifetime;
+ //this.lifeTime = lifetime;
}
this.exportByValue = exportByValue;
}
+
+ public ExportContext(String refId, long currentTime, long terminationTime, long
refreshDuration)
+ {
+ this.currentTime = currentTime;
+ this.terminationTime = terminationTime;
+ this.refreshDuration = refreshDuration;
+ this.exportByValue = false;
+ }
+
public boolean isExportByValue()
{
return this.exportByValue;
}
-
- public Lifetime getLifeTime()
+
+ public long getCurrentTime ()
{
- return lifeTime;
+ return currentTime;
}
-
- public void setLifeTime(Lifetime lifetime)
+
+ public void setCurrentTime(long currentTime)
{
- this.lifeTime = lifetime;
+ this.currentTime = currentTime;
}
+
+ public long getTermintationTime()
+ {
+ return terminationTime;
+ }
+
+ public void setTerminationTime(long terminationTime)
+ {
+ this.terminationTime = terminationTime;
+ }
+
+ public long getRefreshDuration()
+ {
+ return refreshDuration;
+ }
+
+ public void setRefreshDuration(long refreshDuration)
+ {
+ this.refreshDuration = refreshDuration;
+ }
public void addPortlet(String portletName)
{
@@ -89,6 +119,11 @@
}
this.portlets.add(portletName);
}
+
+ public List<String> getPortlets()
+ {
+ return portlets;
+ }
public static ExportContext create(byte[] bytes)
{
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java 2010-09-07
21:59:31 UTC (rev 4076)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java 2010-09-08
04:25:46 UTC (rev 4077)
@@ -28,7 +28,6 @@
import org.gatein.exports.data.ExportData;
import org.gatein.exports.data.ExportPortletData;
import org.gatein.wsrp.WSRPExceptionFactory;
-import org.oasis.wsrp.v2.Lifetime;
import org.oasis.wsrp.v2.OperationFailed;
import org.oasis.wsrp.v2.OperationNotSupported;
@@ -60,7 +59,7 @@
this.exportPersistenceManager = exportPersistenceManager;
}
- public ExportContext createExportContext(boolean exportByValueRequired, Lifetime
lifetime)
+ public ExportContext createExportContext(boolean exportByValueRequired, long
currentTime, long terminationTime, long refreshDuration)
throws UnsupportedEncodingException
{
boolean useExportByValue = false;
@@ -68,8 +67,8 @@
{
useExportByValue = true;
}
-
- return new ExportContext(useExportByValue, lifetime);
+
+ return new ExportContext(useExportByValue, currentTime, terminationTime,
refreshDuration);
}
public boolean supportsExportByValue()
@@ -95,7 +94,8 @@
}
else if (exportPersistenceManager != null &&
exportPersistenceManager.supports(type, version))
{
- return exportPersistenceManager.getExportContext(type, version,
ExportData.getInternalBytes(bytes));
+ String refId = exportPersistenceManager.getExportReferenceId(type, version,
ExportData.getInternalBytes(bytes));
+ return exportPersistenceManager.getExportContext(refId);
}
else
{
@@ -118,7 +118,7 @@
return new ExportPortletData(portletHandle, portletState);
}
- public ExportPortletData createExportPortletData(ExportContext exportContextData,
Lifetime lifetime, byte[] bytes) throws OperationFailed
+ public ExportPortletData createExportPortletData(ExportContext exportContextData, long
currentTime, long terminationTime, long refreshDuration, byte[] bytes) throws
OperationFailed
{
try
{
@@ -152,34 +152,62 @@
}
else
{
- return exportPersistenceManager.encodeExportPortletData(exportContextData,
exportPortletData);
+ String refId =
exportPersistenceManager.storeExportPortletData(exportContextData, exportPortletData);
+ return exportPersistenceManager.encodeExportPortletData(refId);
}
}
- public byte[] encodeExportContextData(ExportContext exportContextData) throws
IOException
+ public byte[] encodeExportContextData(ExportContext exportContext) throws IOException
{
- if (exportContextData.isExportByValue())
+ if (exportContext.isExportByValue())
{
- return exportContextData.encodeAsBytes();
+ return exportContext.encodeAsBytes();
}
else
{
- return exportPersistenceManager.encodeExportContextData(exportContextData);
+ String refId = exportPersistenceManager.storeExportContext(exportContext);
+ return exportPersistenceManager.encodeExportContext(refId);
}
}
- public Lifetime setExportLifetime(ExportContext exportContext, Lifetime lifetime)
throws OperationFailed, OperationNotSupported
- {
+ public ExportContext setExportLifetime(byte[] exportContextBytes, long currentTime,
long terminationTime, long refreshDuration) throws OperationFailed, OperationNotSupported
+ {
if (getPersistenceManager() == null)
{
WSRPExceptionFactory.throwWSException(OperationNotSupported.class, "The
producer only supports export by value. Cannot call setExportLifetime on this
producer", null);
}
- else if (exportContext.isExportByValue())
+
+ try
{
- WSRPExceptionFactory.throwWSException(OperationFailed.class, "Cannot set
the lifetime for an export that was exported by value.", null);
+ String type = ExportData.getType(exportContextBytes);
+ double version = ExportData.getVersion(exportContextBytes);
+
+ if (getPersistenceManager().supports(type, version))
+ {
+ String refId = getPersistenceManager().getExportReferenceId(type, version,
ExportData.getInternalBytes(exportContextBytes));
+ ExportContext exportContext =
getPersistenceManager().getExportContext(refId);
+
+ if (exportContext.isExportByValue())
+ {
+ WSRPExceptionFactory.throwWSException(OperationFailed.class, "Cannot
set the lifetime for an export that was exported by value.", null);
+ }
+
+ exportContext.setCurrentTime(currentTime);
+ exportContext.setTerminationTime(terminationTime);
+ exportContext.setRefreshDuration(refreshDuration);
+
+ ExportContext updatedExportContext =
getPersistenceManager().updateExportContext(refId, exportContext);
+ return updatedExportContext;
+ }
+ else
+ {
+ throw WSRPExceptionFactory.createWSException(OperationFailed.class,
"Byte array format not recognized.", null);
+ }
}
-
- return getPersistenceManager().updateExportLifetime(exportContext, lifetime);
+ catch (IOException e)
+ {
+ throw WSRPExceptionFactory.createWSException(OperationFailed.class, "Could
not decode the byte array.", e);
+ }
}
public void releaseExport(byte[] bytes) throws IOException
@@ -191,7 +219,8 @@
double version = ExportData.getVersion(bytes);
if (exportPersistenceManager.supports(type, version))
{
- exportPersistenceManager.releaseExport(ExportData.getInternalBytes(bytes));
+ String refId = exportPersistenceManager.getExportReferenceId(type, version,
ExportData.getInternalBytes(bytes));
+ exportPersistenceManager.removeExportContext(refId);
}
}
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java 2010-09-07
21:59:31 UTC (rev 4076)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java 2010-09-08
04:25:46 UTC (rev 4077)
@@ -103,9 +103,15 @@
import org.oasis.wsrp.v2.SetPortletsLifetimeResponse;
import org.oasis.wsrp.v2.UserContext;
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.Duration;
+import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Date;
+import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -538,9 +544,19 @@
{
RegistrationLocal.setRegistration(registration);
- //TODO: try catch here?
- ExportContext exportContext =
producer.getExportManager().createExportContext(exportByValueRequired,
exportPortlets.getLifetime());
-
+ ExportContext exportContext;
+ if (exportPortlets.getLifetime() != null)
+ {
+ long currentTime =
toLongDate(exportPortlets.getLifetime().getCurrentTime());
+ long terminationTime =
toLongDate(exportPortlets.getLifetime().getTerminationTime());
+ long refreshDuration =
exportPortlets.getLifetime().getRefreshDuration().getTimeInMillis(exportPortlets.getLifetime().getCurrentTime().toGregorianCalendar());
+ exportContext =
producer.getExportManager().createExportContext(exportByValueRequired, currentTime,
terminationTime, refreshDuration);
+ }
+ else
+ {
+ exportContext =
producer.getExportManager().createExportContext(exportByValueRequired, -1, -1, -1);
+ }
+
for (PortletContext portletContext : exportPortlets.getPortletContext())
{
try
@@ -616,7 +632,17 @@
byte[] exportContextBytes =
producer.getExportManager().encodeExportContextData(exportContext);
- return WSRPTypeFactory.createExportPortletsResponse(exportContextBytes,
exportedPortlets, new ArrayList<FailedPortlets>(failedPortletsMap.values()),
exportContext.getLifeTime(), resourceList);
+ Lifetime lifetime = null;
+
+ if (exportContext.getCurrentTime() > 0)
+ {
+ lifetime = new Lifetime();
+
lifetime.setCurrentTime(toXMLGregorianCalendar(exportContext.getCurrentTime()));
+
lifetime.setTerminationTime(toXMLGregorianCalendar(exportContext.getTermintationTime()));
+ lifetime.setRefreshDuration(toDuration(exportContext.getRefreshDuration()));
+ }
+
+ return WSRPTypeFactory.createExportPortletsResponse(exportContextBytes,
exportedPortlets, new ArrayList<FailedPortlets>(failedPortletsMap.values()),
lifetime, resourceList);
}
catch (Exception e)
{
@@ -668,8 +694,19 @@
{
byte[] portletData = importPortlet.getExportData();
- ExportPortletData exportPortletData =
producer.getExportManager().createExportPortletData(exportContext, lifeTime,
portletData);
-
+ ExportPortletData exportPortletData;
+ if (lifeTime != null)
+ {
+ long currentTime = toLongDate(lifeTime.getCurrentTime());
+ long terminationTime = toLongDate(lifeTime.getTerminationTime());
+ long refreshDuration =
lifeTime.getRefreshDuration().getTimeInMillis(lifeTime.getCurrentTime().toGregorianCalendar());
+ exportPortletData =
producer.getExportManager().createExportPortletData(exportContext, currentTime,
terminationTime, refreshDuration, portletData);
+ }
+ else
+ {
+ exportPortletData =
producer.getExportManager().createExportPortletData(exportContext, -1, -1, -1,
portletData);
+ }
+
String portletHandle = exportPortletData.getPortletHandle();
byte[] portletState = exportPortletData.getPortletState();
@@ -786,11 +823,20 @@
try
{
RegistrationLocal.setRegistration(registration);
-
- ExportContext exportContext =
producer.getExportManager().createExportContext(exportContextBytes);
-
- return producer.getExportManager().setExportLifetime(exportContext,
setExportLifetime.getLifetime());
-
+
+ ExportContext exportContext;
+ if (setExportLifetime != null)
+ {
+ long currentTime =
toLongDate(setExportLifetime.getLifetime().getCurrentTime());
+ long terminationTime =
toLongDate(setExportLifetime.getLifetime().getTerminationTime());
+ long refreshDuration =
setExportLifetime.getLifetime().getRefreshDuration().getTimeInMillis(setExportLifetime.getLifetime().getCurrentTime().toGregorianCalendar());
+ exportContext =
producer.getExportManager().setExportLifetime(exportContextBytes, currentTime,
terminationTime, refreshDuration);
+ }
+ else
+ {
+ exportContext =
producer.getExportManager().setExportLifetime(exportContextBytes, -1, -1, -1);
+ }
+ return getLifetime(exportContext);
}
catch (Exception e)
{
@@ -829,4 +875,46 @@
RegistrationLocal.setRegistration(null);
}
}
+
+ //TODO: move these classes to the common module and write up proper lifetime utilities
+ private XMLGregorianCalendar toXMLGregorianCalendar(long time) throws
DatatypeConfigurationException
+ {
+ Date date = new Date(time);
+ GregorianCalendar gregorianCalendar = new GregorianCalendar();
+ gregorianCalendar.setTime(date);
+ return DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);
+ }
+
+ private long toLongDate(XMLGregorianCalendar calendar)
+ {
+ return calendar.toGregorianCalendar().getTime().getTime();
+ }
+
+ private Duration toDuration(long duration) throws DatatypeConfigurationException
+ {
+ return DatatypeFactory.newInstance().newDuration(duration);
+ }
+
+ private Lifetime getLifetime(ExportContext exportContext) throws
DatatypeConfigurationException
+ {
+ if (exportContext.getCurrentTime() >= 0)
+ {
+ Lifetime lifetime = new Lifetime();
+
+ XMLGregorianCalendar currentTime =
toXMLGregorianCalendar(exportContext.getCurrentTime());
+ XMLGregorianCalendar terminationTime =
toXMLGregorianCalendar(exportContext.getTermintationTime());
+
+ Duration duration = toDuration(exportContext.getRefreshDuration());
+
+ lifetime.setCurrentTime(currentTime);
+ lifetime.setTerminationTime(terminationTime);
+ lifetime.setRefreshDuration(duration);
+
+ return lifetime;
+ }
+ else
+ {
+ return null;
+ }
+ }
}
Modified:
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java
===================================================================
---
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java 2010-09-07
21:59:31 UTC (rev 4076)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java 2010-09-08
04:25:46 UTC (rev 4077)
@@ -133,13 +133,22 @@
@Test
public void testExport() throws Exception
{
- String handle = getDefaultHandle();
- List<PortletContext> portletContexts = createPortletContextList(handle);
+ try
+ {
+ String handle = getDefaultHandle();
+ List<PortletContext> portletContexts = createPortletContextList(handle);
- ExportPortlets exportPortlets = createSimpleExportPortlets(portletContexts);
- ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
+ ExportPortlets exportPortlets = createSimpleExportPortlets(portletContexts);
+ ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
- checkValidHandle(response, handle);
+ checkValidHandle(response, handle);
+ }
+ catch (Exception e)
+ {
+ System.out.println("An exception occurred when running testExport");
+ e.printStackTrace();
+ throw new Exception(e);
+ }
}
@Test
@@ -853,7 +862,8 @@
//Test that doing a release export actually removed the stored RefId
TestMockExportPersistenceManager persistenceManager =
(TestMockExportPersistenceManager)producer.getExportManager().getPersistenceManager();
- assertEquals(0, persistenceManager.getExportContexts().keySet().size());
+ assertEquals(0, persistenceManager.getExportContextKeys().size());
+ assertEquals(0, persistenceManager.getExportPortletsKeys().size());
}
@Test
@@ -887,12 +897,14 @@
exportPortlets.setExportByValueRequired(false);
//Test that we don't have anything in the PM before doing an export
- assertEquals(0, persistenceManager.getExportContexts().keySet().size());
+ assertEquals(0, persistenceManager.getExportContextKeys().size());
+ assertEquals(0, persistenceManager.getExportPortletsKeys().size());
ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
//Test that we have an entry in the PM after doing an export
- assertEquals(1, persistenceManager.getExportContexts().keySet().size());
+ assertEquals(1, persistenceManager.getExportContextKeys().size());
+ assertEquals(1, persistenceManager.getExportPortletsKeys().size());
return response;
}
@@ -960,7 +972,19 @@
for (ExportedPortlet exportPortlet : exportedPortlets)
{
- ExportPortletData exportPortletData =
exportManager.createExportPortletData(exportContext, exportPortletsResponse.getLifetime(),
exportPortlet.getExportData());
+ ExportPortletData exportPortletData;
+ Lifetime lifetime = exportPortletsResponse.getLifetime();
+ if (lifetime != null)
+ {
+ long currentTime =
lifetime.getCurrentTime().toGregorianCalendar().getTime().getTime();
+ long terminationTime =
lifetime.getTerminationTime().toGregorianCalendar().getTime().getTime();
+ long refreshDuration =
lifetime.getRefreshDuration().getTimeInMillis(lifetime.getCurrentTime().toGregorianCalendar());
+ exportPortletData = exportManager.createExportPortletData(exportContext,
currentTime, terminationTime, refreshDuration, exportPortlet.getExportData());
+ }
+ else
+ {
+ exportPortletData = exportManager.createExportPortletData(exportContext, -1,
-1, -1, exportPortlet.getExportData());
+ }
String portletHandle = exportPortletData.getPortletHandle();
byte[] portletState = exportPortletData.getPortletState();
portletContexts.add(WSRPTypeFactory.createPortletContext(portletHandle,
portletState));
Modified:
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/support/TestMockExportPersistenceManager.java
===================================================================
---
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/support/TestMockExportPersistenceManager.java 2010-09-07
21:59:31 UTC (rev 4076)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/support/TestMockExportPersistenceManager.java 2010-09-08
04:25:46 UTC (rev 4077)
@@ -32,7 +32,9 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.UUID;
/**
@@ -44,22 +46,24 @@
public static final String PEC_TYPE = "P_EC";
public static final double PEC_VERSION = 1.0;
-
+
+ public static final String PED_TYPE = "P_ED";
+ public static final double PED_VERSION = 1.0;
+
Map<String, ExportContext> exportContexts = new HashMap<String,
ExportContext>();
+ Map<String, ExportPortletData> exportPortletDatas = new HashMap<String,
ExportPortletData>();
- //For testing purposes only
- public Map<String, ExportContext> getExportContexts()
+ public ExportContext getExportContext(String refId)
{
- return exportContexts;
+ return exportContexts.get(refId);
}
- public ExportContext getExportContext(String type, double version, byte[] bytes)
throws UnsupportedEncodingException
+ public ExportPortletData getExportPortletData(String exportContextId, String
portletDataID)
{
- if (supports(type, version))
+ ExportContext exportContext = exportContexts.get(exportContextId);
+ if (exportContext.getPortlets().contains(portletDataID))
{
- PersistedExportData persistedExportData = PersistedExportData.create(bytes);
- String refId = persistedExportData.getRefId();
- return exportContexts.get(refId);
+ return exportPortletDatas.get(portletDataID);
}
else
{
@@ -67,81 +71,137 @@
}
}
- public void releaseExport(byte[] bytes)
+ //For testing purposes only
+ public Set<String> getExportContextKeys()
{
- try
+ return exportContexts.keySet();
+ }
+
+ //For testing purposes only
+ public Set<String> getExportPortletsKeys()
+ {
+ return exportPortletDatas.keySet();
+ }
+
+ public String getExportReferenceId(String type, double version, byte[] bytes) throws
UnsupportedEncodingException
+ {
+ if (supports(type, version))
+ {
+ PersistedExportData persistedExportData = PersistedExportData.create(bytes);
+ return persistedExportData.getRefId();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public boolean removeExportContext(String refId)
+ {
+ if (exportContexts.containsKey(refId))
{
- PersistedExportData persistedExportData = PersistedExportData.create(bytes);
- String refId = persistedExportData.getRefId();
- if (exportContexts.containsKey(refId))
+ List<String> portlets = exportContexts.get(refId).getPortlets();
+ for (String portlet: portlets)
{
- exportContexts.remove(refId);
+ exportPortletDatas.remove(portlet);
}
+ exportContexts.remove(refId);
+ return true;
}
- catch (Exception e)
+ else
{
- System.out.println("ERROR When trying to release exports");
- e.printStackTrace();
+ return false;
}
}
- public ExportContext retrieveExportContextData(String refid)
+ public boolean removeExportPortletData(String exportContextId, String exportDataId)
{
- if (exportContexts.containsKey(refid))
+ if (exportContexts.containsKey(exportDataId))
{
- return exportContexts.get(refid);
+ List<String> portlets = exportContexts.get(exportDataId).getPortlets();
+ if (portlets.contains(exportDataId))
+ {
+ portlets.remove(exportContextId);
+ exportPortletDatas.remove(exportDataId);
+ return true;
+ }
}
- else
- {
- return null;
- }
+ return false;
}
- public ExportPortletData retrieveExportPortletData(String refid)
+ public boolean supports(String type, double version)
{
- throw new NotYetImplemented();
+ return (type.equals(PEC_TYPE) && (version == PEC_VERSION)) ||
((type.equals(PED_TYPE) && (version == PED_VERSION)));
}
- public String storeExportContextData(ExportContext exportContextData)
+ public ExportContext updateExportContext(String refId, ExportContext
updatedExportContext)
{
- if (exportContextData != null)
+ if (updatedExportContext != null && refId != null &&
exportContexts.containsKey(refId))
{
- String refId = UUID.randomUUID().toString();
- exportContexts.put(refId, exportContextData);
- return refId;
+ exportContexts.put(refId, updatedExportContext);
+ return updatedExportContext;
}
else
{
+ //throw some error here
return null;
}
}
- public String storeExportPortletData(ExportPortletData exportPortletData)
+ public ExportPortletData updateExportPortletData(String refId, ExportPortletData
updatedPortletData)
{
- throw new NotYetImplemented();
+ if (updatedPortletData != null && refId != null &&
exportContexts.containsKey(refId))
+ {
+ exportPortletDatas.put(refId, updatedPortletData);
+ return updatedPortletData;
+ }
+ else
+ {
+ return null;
+ }
}
- public boolean supports(String type, double version)
+ public byte[] encodeExportContext(String refId) throws IOException
{
- return type.equals(PEC_TYPE) && (version == PEC_VERSION);
+ PersistedExportData persistedExportData = new PersistedExportData(PEC_TYPE,
refId);
+ return persistedExportData.encodeAsBytes();
}
- public Lifetime updateExportLifetime(ExportContext exportContext, Lifetime lifetime)
+ public byte[] encodeExportPortletData(String exportDataRefId) throws IOException
{
- throw new NotYetImplemented();
+ PersistedExportData persistedExportData = new PersistedExportData(PED_TYPE,
exportDataRefId);
+ return persistedExportData.encodeAsBytes();
}
- public byte[] encodeExportContextData(ExportContext exportContext) throws IOException
+ public String storeExportContext(ExportContext exportContext)
{
- String refId = storeExportContextData(exportContext);
- PersistedExportData persistedExportData = new PersistedExportData(PEC_TYPE,
refId);
- return persistedExportData.encodeAsBytes();
+ if (exportContext != null)
+ {
+ String refId = UUID.randomUUID().toString();
+ exportContexts.put(refId, exportContext);
+ return refId;
+ }
+ else
+ {
+ return null;
+ }
}
- public byte[] encodeExportPortletData(ExportContext exportContext, ExportPortletData
exportPortlet)
+ public String storeExportPortletData(ExportContext exportContext, ExportPortletData
exportPortletData)
{
- // FIXME encodeExportPortletData
- return null;
+ if (exportPortletData != null && exportContext != null)
+ {
+ String refId = UUID.randomUUID().toString();
+ exportContext.addPortlet(refId);
+
+ exportPortletDatas.put(refId, exportPortletData);
+
+ return refId;
+ }
+ else
+ {
+ return null;
+ }
}
}