Author: mwringe
Date: 2010-11-16 12:20:26 -0500 (Tue, 16 Nov 2010)
New Revision: 5108
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ModelAdapter.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletActionListener.java
Log:
GTNPORTAL-736, GTNWSRP-160: Move some of the state handling code to the ModelAdapter. The
model adapters will now be able to extract the state from the modified or cloned
PortletContext themselves. This allows for the WSRP adapter to handle its state better.
Note that there are still some issue with the wsrp state being handled in conditionals,
this needs to be cleaned up and abstracted out to other classes.
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ModelAdapter.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ModelAdapter.java 2010-11-16
12:49:08 UTC (rev 5107)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ModelAdapter.java 2010-11-16
17:20:26 UTC (rev 5108)
@@ -152,6 +152,36 @@
return pref;
}
}
+
+ @Override
+ public ExoPortletState getStateFromModifiedContext(PortletContext
originalPortletContext,
+ PortletContext modifiedPortletContext)
+ {
+ if (modifiedPortletContext != null && modifiedPortletContext instanceof
StatefulPortletContext)
+ {
+ StatefulPortletContext statefulContext = (StatefulPortletContext)
modifiedPortletContext;
+ if (statefulContext.getState() instanceof ExoPortletState)
+ {
+ return (ExoPortletState)statefulContext.getState();
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public ExoPortletState getstateFromClonedContext(PortletContext
originalPortletContext,
+ PortletContext clonedPortletContext)
+ {
+ if (clonedPortletContext != null && clonedPortletContext instanceof
StatefulPortletContext)
+ {
+ StatefulPortletContext statefulContext = (StatefulPortletContext)
clonedPortletContext;
+ if (statefulContext.getState() instanceof ExoPortletState)
+ {
+ return (ExoPortletState)statefulContext.getState();
+ }
+ }
+ return null;
+ }
};
private static final ModelAdapter<Gadget, ExoPortletState> GADGET = new
ModelAdapter<Gadget, ExoPortletState>()
@@ -195,6 +225,36 @@
// For now we return null as it does not make sense to edit the gadget
preferences
return null;
}
+
+ @Override
+ public ExoPortletState getStateFromModifiedContext(PortletContext
originalPortletContext,
+ PortletContext modifiedPortletContext)
+ {
+ if (modifiedPortletContext != null && modifiedPortletContext instanceof
StatefulPortletContext)
+ {
+ StatefulPortletContext statefulContext = (StatefulPortletContext)
modifiedPortletContext;
+ if (statefulContext.getState() instanceof ExoPortletState)
+ {
+ return (ExoPortletState)statefulContext.getState();
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public ExoPortletState getstateFromClonedContext(PortletContext
originalPortletContext,
+ PortletContext clonedPortletContext)
+ {
+ if (clonedPortletContext != null && clonedPortletContext instanceof
StatefulPortletContext)
+ {
+ StatefulPortletContext statefulContext = (StatefulPortletContext)
clonedPortletContext;
+ if (statefulContext.getState() instanceof ExoPortletState)
+ {
+ return (ExoPortletState)statefulContext.getState();
+ }
+ }
+ return null;
+ }
};
/**
@@ -256,6 +316,52 @@
return dataStorage.save(state, updateState);
}
}
+
+ @Override
+ public WSRP getStateFromModifiedContext(PortletContext originalPortletContext,
+ PortletContext modifiedPortletContext)
+ {
+ WSRP wsrp = new WSRP();
+ wsrp.setPortletId(modifiedPortletContext.getId());
+
+ // from the originalPortletContext see if we are dealing with a cloned context
or not.
+ if (originalPortletContext instanceof StatefulPortletContext)
+ {
+ Object originalState =
((StatefulPortletContext)originalPortletContext).getState();
+ if (originalState instanceof WSRP)
+ {
+ wsrp.setCloned(((WSRP)originalState).isCloned());
+ }
+ }
+
+ if (modifiedPortletContext instanceof StatefulPortletContext)
+ {
+ Object modifiedState =
((StatefulPortletContext)modifiedPortletContext).getState();
+ if (modifiedState instanceof byte[])
+ {
+ wsrp.setState((byte[])modifiedState);
+ }
+ }
+
+ return wsrp;
+ }
+
+ @Override
+ public WSRP getstateFromClonedContext(PortletContext originalPortletContext,
PortletContext clonedPortletContext)
+ {
+ WSRP wsrp = new WSRP();
+ wsrp.setPortletId(clonedPortletContext.getId());
+ wsrp.setCloned(true);
+
+ // if we have an associated state, record it as well...
+ if (clonedPortletContext instanceof StatefulPortletContext)
+ {
+ StatefulPortletContext statefulPortletContext =
(StatefulPortletContext)clonedPortletContext;
+ wsrp.setState((byte[])statefulPortletContext.getState());
+ }
+
+ return wsrp;
+ }
};
public abstract PortletContext getProducerOfferedPortletContext(String
applicationId);
@@ -275,5 +381,23 @@
* @throws Exception any exception
*/
public abstract Portlet getState(ExoContainer container, ApplicationState<S>
applicationState) throws Exception;
+
+ /**
+ * Extracts the state based on what the current PortletContext is and the new modified
PortletContext.
+ *
+ * @param originalPortletContext The current PortletContext for the Portlet
+ * @param modifiedPortletContext The new modified PortletContext
+ * @return
+ */
+ public abstract C getStateFromModifiedContext(PortletContext originalPortletContext,
PortletContext modifiedPortletContext);
+
+ /**
+ * Extracts the state based on what the current PortletContext is and the new cloned
PortletContext
+ *
+ * @param originalPortletContext The current PortletContext for the Portlet
+ * @param clonedPortletContext The new cloned PortletContext
+ * @return
+ */
+ public abstract C getstateFromClonedContext(PortletContext originalPortletContext,
PortletContext clonedPortletContext);
}
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java 2010-11-16
12:49:08 UTC (rev 5107)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java 2010-11-16
17:20:26 UTC (rev 5108)
@@ -56,6 +56,7 @@
import org.gatein.pc.api.PortletContext;
import org.gatein.pc.api.PortletInvoker;
import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.pc.api.PortletStateType;
import org.gatein.pc.api.StateString;
import org.gatein.pc.api.StatefulPortletContext;
import org.gatein.pc.api.cache.CacheLevel;
@@ -472,7 +473,14 @@
if (portlet == null)
{
- log.info("Could not find portlet with ID : " +
producerOfferedPortletContext.getId());
+ if (producerOfferedPortletContext != null)
+ {
+ log.info("Could not find portlet with ID : " +
producerOfferedPortletContext.getId());
+ }
+ else
+ {
+ log.info("Could not find portlet. The producerOfferedPortletContext
is null");
+ }
return false;
}
@@ -843,10 +851,25 @@
// instance context
ExoPortletInstanceContext instanceContext;
+ // TODO: we should not be having these wsrp specific conditions through the code
like
+ // this, it should either work the same was as normal portlets or abstracted out to
another class.
if (ApplicationType.WSRP_PORTLET.equals(state.getApplicationType()))
{
WSRP wsrp = (WSRP)preferencesPortletContext.getState();
AccessMode accessMode = AccessMode.CLONE_BEFORE_WRITE;
+
+ if (wsrp.getState() != null)
+ {
+ StatefulPortletContext statefulPortletContext =
StatefulPortletContext.create(preferencesPortletContext.getId(),
+ PortletStateType.OPAQUE, wsrp.getState());
+
+ invocation.setTarget(statefulPortletContext);
+ }
+ else
+ {
+ PortletContext portletContext =
PortletContext.createPortletContext(preferencesPortletContext.getId());
+ invocation.setTarget(portletContext);
+ }
// if the portlet is a cloned one already, we can modify it directly instead of
requesting a clone
if (wsrp.isCloned())
@@ -858,6 +881,7 @@
else
{
instanceContext = new
ExoPortletInstanceContext(preferencesPortletContext.getId());
+ invocation.setTarget(preferencesPortletContext);
}
invocation.setInstanceContext(instanceContext);
@@ -869,9 +893,6 @@
invocation.setSecurityContext(new AbstractSecurityContext(servletRequest));
//
- invocation.setTarget(preferencesPortletContext);
-
- //
return invocation;
}
@@ -980,10 +1001,19 @@
public void update(C updateState) throws Exception
{
WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
- ExoContainer container =
context.getApplication().getApplicationServiceContainer();
- state.setApplicationState(adapter.update(container, updateState,
state.getApplicationState()));
+ ExoContainer container = context.getApplication().getApplicationServiceContainer();
state.setApplicationState(adapter.update(container, updateState,
state.getApplicationState()));
setState(state);
}
+
+ public C getModifiedState(PortletContext modifiedContext) throws Exception
+ {
+ return adapter.getStateFromModifiedContext(this.getPortletContext(),
modifiedContext);
+ }
+
+ public C getClonedState(PortletContext clonedContext) throws Exception
+ {
+ return adapter.getstateFromClonedContext(this.getPortletContext(), clonedContext);
+ }
/** This is used by the dashboard portlet and should not be used else where. It will
be removed some day. */
private static final ThreadLocal<UIPortlet> currentPortlet = new
ThreadLocal<UIPortlet>();
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletActionListener.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletActionListener.java 2010-11-16
12:49:08 UTC (rev 5107)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletActionListener.java 2010-11-16
17:20:26 UTC (rev 5108)
@@ -25,7 +25,6 @@
import org.exoplatform.portal.Constants;
import org.exoplatform.portal.application.PortalRequestContext;
-import org.exoplatform.portal.pom.spi.wsrp.WSRP;
import org.exoplatform.portal.webui.page.UIPage;
import org.exoplatform.portal.webui.page.UIPageBody;
import org.exoplatform.portal.webui.portal.UIPortal;
@@ -121,7 +120,7 @@
if (instanceCtx.getModifiedContext() != null)
{
StatefulPortletContext<C> updatedCtx =
(StatefulPortletContext<C>)instanceCtx.getModifiedContext();
- C portletState = updatedCtx.getState();
+ C portletState = uiPortlet.getModifiedState(updatedCtx);
uiPortlet.update(portletState);
}
else
@@ -130,17 +129,8 @@
PortletContext clonedContext = instanceCtx.getClonedContext();
if (clonedContext != null)
{
- WSRP wsrp = new WSRP();
- wsrp.setPortletId(clonedContext.getId());
- wsrp.setCloned(true); // mark the state as cloned
-
- // if we have an associated state, record it as well...
- if (clonedContext instanceof StatefulPortletContext)
- {
- StatefulPortletContext statefulPortletContext =
(StatefulPortletContext)clonedContext;
- wsrp.setState((byte[])statefulPortletContext.getState());
- }
- uiPortlet.update((C)wsrp);
+ C state = uiPortlet.getClonedState(clonedContext);
+ uiPortlet.update(state);
}
}