Author: chris.laprun(a)jboss.com
Date: 2010-10-27 08:28:29 -0400 (Wed, 27 Oct 2010)
New Revision: 4861
Modified:
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPConsumerStructureProvider.java
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/WSRPServiceIntegration.java
Log:
- GTNPORTAL-1600, GTNWSRP-112: Made MOPConsumerStructureProvider listen to page events so
that the internal page information structure is updated accordingly.
- Updated listeners registration to use proper method version since we're using eXo
Kernel 2.2.5-GA now.
Modified:
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPConsumerStructureProvider.java
===================================================================
---
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPConsumerStructureProvider.java 2010-10-27
12:22:03 UTC (rev 4860)
+++
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPConsumerStructureProvider.java 2010-10-27
12:28:29 UTC (rev 4861)
@@ -24,11 +24,15 @@
package org.gatein.portal.wsrp;
import org.exoplatform.container.ExoContainer;
+import org.exoplatform.portal.config.DataStorage;
import org.exoplatform.portal.mop.Described;
import org.exoplatform.portal.pom.config.POMSession;
import org.exoplatform.portal.pom.config.POMSessionManager;
+import org.exoplatform.portal.pom.data.Mapper;
import org.exoplatform.portal.pom.data.PageKey;
import org.exoplatform.portal.pom.spi.wsrp.WSRP;
+import org.exoplatform.services.listener.Event;
+import org.exoplatform.services.listener.Listener;
import org.gatein.common.util.ParameterValidation;
import org.gatein.mop.api.content.Customization;
import org.gatein.mop.api.workspace.ObjectType;
@@ -54,35 +58,40 @@
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision$
*/
-public class MOPConsumerStructureProvider implements ConsumerStructureProvider
+public class MOPConsumerStructureProvider extends Listener<DataStorage,
org.exoplatform.portal.config.model.Page> implements ConsumerStructureProvider
{
+ private static final String PAGES_CHILD_NAME = "pages";
private final POMSessionManager pomManager;
private Map<String, PageInfo> pageInfos;
private Map<String, String> windowIdToUUIDs;
+ private boolean pagesHaveBeenInitialized;
public MOPConsumerStructureProvider(ExoContainer container)
{
pomManager =
(POMSessionManager)container.getComponentInstanceOfType(POMSessionManager.class);
windowIdToUUIDs = new HashMap<String, String>();
+ pageInfos = new HashMap<String, PageInfo>();
}
public List<String> getPageIdentifiers()
{
- if (pageInfos == null)
+ if (!pagesHaveBeenInitialized)
{
+ // initialize page information
POMSession session = pomManager.getSession();
Workspace workspace = session.getWorkspace();
Collection<Site> sites = workspace.getSites(ObjectType.PORTAL_SITE);
- pageInfos = new HashMap<String, PageInfo>();
for (Site site : sites)
{
- Page page = site.getRootPage().getChild("pages");
+ Page page = getPagesFrom(site);
if (page != null)
{
- processPage(page, true);
+ addPage(page, true);
}
}
+
+ pagesHaveBeenInitialized = true;
}
LinkedList<String> identifiers = new
LinkedList<String>(pageInfos.keySet());
@@ -90,8 +99,16 @@
return identifiers;
}
- private void processPage(Page page, boolean ignoreCurrent)
+ private Page getPagesFrom(Site site)
{
+ // a site contains a root page with templates and pages
+ // more info at
http://code.google.com/p/chromattic/wiki/MOPUseCases
+
+ return site.getRootPage().getChild(PAGES_CHILD_NAME);
+ }
+
+ private void addPage(Page page, boolean ignoreCurrent)
+ {
if (!ignoreCurrent)
{
Described described = page.adapt(Described.class);
@@ -106,7 +123,7 @@
{
for (Page child : children)
{
- processPage(child, false);
+ addPage(child, false);
}
}
}
@@ -185,6 +202,55 @@
session.close(true);
}
+ @Override
+ public void onEvent(Event<DataStorage, org.exoplatform.portal.config.model.Page>
event) throws Exception
+ {
+ String eventName = event.getEventName();
+
+ // get the MOP page from the event data
+ org.exoplatform.portal.config.model.Page portalPage = event.getData();
+ Site site =
pomManager.getSession().getWorkspace().getSite(Mapper.parseSiteType(portalPage.getOwnerType()),
portalPage.getOwnerId());
+ Page page = getPagesFrom(site).getChild(portalPage.getName());
+
+ if (page != null)
+ {
+ if (DataStorage.PAGE_CREATED.equals(eventName))
+ {
+ // add information for new page
+ addPage(page, false);
+ }
+ else if (DataStorage.PAGE_REMOVED.equals(eventName))
+ {
+ removePage(page);
+ }
+ else if (DataStorage.PAGE_UPDATED.equals(eventName))
+ {
+ removePage(page);
+ addPage(page, false);
+ }
+ }
+ }
+
+ private void removePage(Page page)
+ {
+ Described described = page.adapt(Described.class);
+ String name = described.getName();
+
+ PageInfo pageInfo = pageInfos.get(name);
+ if (pageInfo != null)
+ {
+ // remove window information associated to the page
+ List<String> windows = pageInfo.getChildrenWindows();
+ for (String window : windows)
+ {
+ windowIdToUUIDs.remove(window);
+ }
+
+ // remove page info
+ pageInfos.remove(name);
+ }
+ }
+
private static class PageInfo
{
private String uuid;
Modified:
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/WSRPServiceIntegration.java
===================================================================
---
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/WSRPServiceIntegration.java 2010-10-27
12:22:03 UTC (rev 4860)
+++
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/WSRPServiceIntegration.java 2010-10-27
12:28:29 UTC (rev 4861)
@@ -27,6 +27,7 @@
import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.portal.config.DataStorage;
import org.exoplatform.portal.pc.ExoKernelIntegration;
import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator;
import org.exoplatform.services.listener.ListenerService;
@@ -267,20 +268,26 @@
// add our Session event listener to the ListenerService for use in
org.exoplatform.web.GenericHttpListener
ListenerService listenerService =
(ListenerService)container.getComponentInstanceOfType(ListenerService.class);
SessionEventListenerAndBroadcaster sessionEventBroadcaster = new
SessionEventListenerAndBroadcaster();
-
sessionEventBroadcaster.setName("org.exoplatform.web.GenericHttpListener.sessionCreated");
- listenerService.addListener(sessionEventBroadcaster);
-
sessionEventBroadcaster.setName("org.exoplatform.web.GenericHttpListener.sessionDestroyed");
- listenerService.addListener(sessionEventBroadcaster);
+ // events from org.exoplatform.web.GenericHttpListener
+
listenerService.addListener("org.exoplatform.web.GenericHttpListener.sessionCreated",
sessionEventBroadcaster);
+
listenerService.addListener("org.exoplatform.web.GenericHttpListener.sessionDestroyed",
sessionEventBroadcaster);
+
try
{
consumerRegistry = new JCRConsumerRegistry(container);
consumerRegistry.setFederatingPortletInvoker(federatingPortletInvoker);
consumerRegistry.setSessionEventBroadcaster(sessionEventBroadcaster);
+ // create ConsumerStructureProvider and register it to listen to page events
+ MOPConsumerStructureProvider structureprovider = new
MOPConsumerStructureProvider(container);
+ listenerService.addListener(DataStorage.PAGE_CREATED, structureprovider);
+ listenerService.addListener(DataStorage.PAGE_REMOVED, structureprovider);
+ listenerService.addListener(DataStorage.PAGE_UPDATED, structureprovider);
+
// migration service
MigrationService migrationService = new JCRMigrationService(container);
- migrationService.setStructureProvider(new
MOPConsumerStructureProvider(container));
+ migrationService.setStructureProvider(structureprovider);
consumerRegistry.setMigrationService(migrationService);
consumerRegistry.start();