Author: chris.laprun(a)jboss.com
Date: 2010-09-14 10:29:17 -0400 (Tue, 14 Sep 2010)
New Revision: 4191
Modified:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPPortalStructureProvider.java
Log:
- Re-wrote to use POMSessionManager instead of JCR session directly to make sure that MOP
objects state is properly initialized.
Modified:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPPortalStructureProvider.java
===================================================================
---
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPPortalStructureProvider.java 2010-09-14
14:21:27 UTC (rev 4190)
+++
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPPortalStructureProvider.java 2010-09-14
14:29:17 UTC (rev 4191)
@@ -23,11 +23,10 @@
package org.gatein.portal.wsrp;
-import org.chromattic.api.ChromatticSession;
-import org.exoplatform.commons.chromattic.ChromatticLifeCycle;
-import org.exoplatform.commons.chromattic.ChromatticManager;
import org.exoplatform.container.ExoContainer;
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.spi.wsrp.WSRP;
import org.gatein.common.util.ParameterValidation;
import org.gatein.mop.api.content.Customization;
@@ -56,26 +55,25 @@
*/
public class MOPPortalStructureProvider implements PortalStructureProvider
{
- private final ChromatticLifeCycle lifeCycle;
- private Map<String, String> pageIdToUUIDs;
+ private final POMSessionManager pomManager;
+ private Map<String, PageInfo> pageInfos;
private Map<String, String> windowIdToUUIDs;
public MOPPortalStructureProvider(ExoContainer container)
{
- ChromatticManager manager =
(ChromatticManager)container.getComponentInstanceOfType(ChromatticManager.class);
- lifeCycle = manager.getLifeCycle("mop");
- pageIdToUUIDs = new HashMap<String, String>();
+ pomManager =
(POMSessionManager)container.getComponentInstanceOfType(POMSessionManager.class);
windowIdToUUIDs = new HashMap<String, String>();
}
public List<String> getPageIdentifiers()
{
- if (pageIdToUUIDs.isEmpty())
+ if (pageInfos == null)
{
- ChromatticSession session = lifeCycle.getChromattic().openSession();
- Workspace workspace = session.findByPath(Workspace.class,
"mop:workspace");
+ 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");
@@ -84,17 +82,9 @@
processPage(page, true);
}
}
-
- /*POMSession session = (POMSession) lifeCycle.getChromattic().openSession();
- Iterator<Page> pages = session.findObjects(ObjectType.PAGE,
ObjectType.PORTAL_SITE, null, null);
- while (pages.hasNext())
- {
- Page page = pages.next();
- pageIdToUUIDs.put(page.getName(), page.getObjectId());
- }*/
}
- LinkedList<String> identifiers = new
LinkedList<String>(pageIdToUUIDs.keySet());
+ LinkedList<String> identifiers = new
LinkedList<String>(pageInfos.keySet());
Collections.sort(identifiers);
return identifiers;
}
@@ -104,7 +94,10 @@
if (!ignoreCurrent)
{
Described described = page.adapt(Described.class);
- pageIdToUUIDs.put(described.getName(), page.getObjectId());
+ PageInfo pageInfo = new PageInfo(page.getObjectId());
+ pageInfos.put(described.getName(), pageInfo);
+ UIContainer container = page.getRootComponent();
+ processContainer(container, pageInfo);
}
Collection<Page> children = page.getChildren();
@@ -119,19 +112,13 @@
public List<String> getWindowIdentifiersFor(String pageId)
{
- ChromatticSession session = lifeCycle.getChromattic().openSession();
- String uuid = pageIdToUUIDs.get(pageId);
- ParameterValidation.throwIllegalArgExceptionIfNull(uuid, "UUID for " +
pageId);
- Page page = session.findById(Page.class, uuid);
+ PageInfo pageInfo = pageInfos.get(pageId);
+ ParameterValidation.throwIllegalArgExceptionIfNull(pageInfo, "PageInfo for
" + pageId);
- List<String> windows = new LinkedList<String>();
- UIContainer container = page.getRootComponent();
- processContainer(windows, container);
-
- return windows;
+ return pageInfo.getChildrenWindows();
}
- private void processContainer(List<String> windows, UIContainer container)
+ private void processContainer(UIContainer container, PageInfo pageInfo)
{
List<UIComponent> components = container.getComponents();
for (UIComponent component : components)
@@ -142,11 +129,11 @@
Described described = component.adapt(Described.class);
String name = described.getName();
windowIdToUUIDs.put(name, component.getObjectId());
- windows.add(name);
+ pageInfo.addWindow(name);
}
else if (ObjectType.CONTAINER.equals(type))
{
- processContainer(windows, (UIContainer)component);
+ processContainer((UIContainer)component, pageInfo);
}
else
{
@@ -157,10 +144,10 @@
public void assignPortletToWindow(PortletContext portletContext, String windowId,
String pageId)
{
- ChromatticSession session = lifeCycle.getChromattic().openSession();
String uuid = windowIdToUUIDs.get(windowId);
ParameterValidation.throwIllegalArgExceptionIfNull(uuid, "UUID for " +
windowId);
- UIWindow window = session.findById(UIWindow.class, uuid);
+
+ UIWindow window = pomManager.getSession().findObjectById(ObjectType.WINDOW, uuid);
WSRP wsrp = new WSRP();
String portletId = portletContext.getId();
wsrp.setPortletId(portletId);
@@ -184,4 +171,31 @@
// and re-customize
window.customize(WSRP.CONTENT_TYPE, portletId, wsrp);
}
+
+ private static class PageInfo
+ {
+ private String uuid;
+ private List<String> childrenWindows;
+
+ private PageInfo(String uuid)
+ {
+ this.uuid = uuid;
+ childrenWindows = new LinkedList<String>();
+ }
+
+ public String getUUID()
+ {
+ return uuid;
+ }
+
+ public List<String> getChildrenWindows()
+ {
+ return childrenWindows;
+ }
+
+ public void addWindow(String windowName)
+ {
+ childrenWindows.add(windowName);
+ }
+ }
}