Author: chris.laprun(a)jboss.com
Date: 2011-07-12 11:18:10 -0400 (Tue, 12 Jul 2011)
New Revision: 6863
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/NavigationImpl.java
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/PortalImpl.java
Log:
- Adapted for API changes.
- Extracted anonymous classes into inner ones.
- Fleshed out implementation some more.
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java 2011-07-12
09:49:09 UTC (rev 6862)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java 2011-07-12
15:18:10 UTC (rev 6863)
@@ -22,13 +22,12 @@
package org.gatein.portal.api.impl;
-import org.exoplatform.commons.utils.LazyPageList;
import org.exoplatform.container.ExoContainer;
import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.container.component.RequestLifeCycle;
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.portal.config.Query;
-import org.exoplatform.portal.config.model.PortalConfig;
import org.exoplatform.portal.mop.SiteType;
import org.exoplatform.portal.mop.navigation.NavigationService;
import org.exoplatform.portal.pom.config.POMSession;
@@ -38,24 +37,25 @@
import org.exoplatform.portal.pom.data.PortalKey;
import org.gatein.api.GateIn;
import org.gatein.api.IterableResult;
-import org.gatein.api.Portal;
import org.gatein.api.content.Application;
import org.gatein.api.content.Content;
import org.gatein.api.content.Gadget;
import org.gatein.api.content.ManagedContent;
import org.gatein.api.id.Id;
import org.gatein.api.id.Identifiable;
-import org.gatein.api.navigation.Site;
+import org.gatein.api.portal.Portal;
+import org.gatein.api.portal.Site;
import org.gatein.mop.api.workspace.ObjectType;
import org.picocontainer.Startable;
import java.net.URI;
import java.util.Iterator;
+import java.util.List;
/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
public class GateInImpl implements GateIn, Startable
{
- private static final Query<PortalConfig> PORTALS = new
Query<PortalConfig>(SiteType.PORTAL.getName(), null, PortalConfig.class);
+ private static final Query<PortalData> PORTALS = new
Query<PortalData>(SiteType.PORTAL.getName(), null, PortalData.class);
private ExoContainer container;
private ModelDataStorage dataStorage;
private NavigationService navigationService;
@@ -70,53 +70,27 @@
{
try
{
- LazyPageList<PortalConfig> portals = dataStorage.find(PORTALS);
+ RequestLifeCycle.begin(container);
+ final List<PortalData> portals = dataStorage.find(PORTALS).getAll();
- return new IterableResult<Portal>()
- {
- private int size = -1;
-
- public int size()
- {
- if (size != -1)
- {
- return size;
- }
- else
- {
- POMSession session = pomSessionManager.getSession();
- size = session.findObjects(ObjectType.PORTAL_SITE,
ObjectType.PORTAL_SITE, null, null, 0, 1).hits();
- session.close();
- return size;
- }
- }
-
- public boolean contains(Portal portal)
- {
- POMSession session = pomSessionManager.getSession();
- boolean found = portal != null &&
session.findObjectById(portal.getId().toString()) != null;
- session.close();
- return found;
- }
-
- public Iterator<Portal> iterator()
- {
- return null;
- }
- };
+ return new PortalIterableResult(portals);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
+ finally
+ {
+ RequestLifeCycle.end();
+ }
}
public Portal getPortal(Id<Portal> portalId)
{
try
{
- PortalData portalConfig =
dataStorage.getPortalConfig(PortalKey.create(portalId.toString()));
- return new PortalImpl(portalConfig, this);
+ PortalData portalData =
dataStorage.getPortalConfig(PortalKey.create(portalId.toString()));
+ return new PortalImpl(portalData, this);
}
catch (Exception e)
{
@@ -126,7 +100,7 @@
public Portal getDefaultPortal()
{
- return getPortal(portalId("default")); // todo: check
+ return getPortal(portalId("classic")); // todo: check
}
public IterableResult<Site> getSites()
@@ -230,4 +204,75 @@
{
return navigationService;
}
+
+ private static class PortalIterator implements Iterator<Portal>
+ {
+ private int current;
+ private int size;
+ private final List<PortalData> portals;
+ private final GateInImpl gateIn;
+
+ public PortalIterator(List<PortalData> portals, GateInImpl gateIn)
+ {
+ this.portals = portals;
+ size = portals.size();
+ this.gateIn = gateIn;
+ }
+
+
+ public boolean hasNext()
+ {
+ return current > size;
+ }
+
+ public Portal next()
+ {
+ return new PortalImpl(portals.get(current++), gateIn);
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ private class PortalIterableResult implements IterableResult<Portal>
+ {
+ private int size;
+ private final List<PortalData> portals;
+
+ public PortalIterableResult(List<PortalData> portals)
+ {
+ this.portals = portals;
+ size = -1;
+ }
+
+ public int size()
+ {
+ if (size != -1)
+ {
+ return size;
+ }
+ else
+ {
+ POMSession session = pomSessionManager.getSession();
+ size = session.findObjects(ObjectType.PORTAL_SITE, ObjectType.PORTAL_SITE,
null, null, 0, 1).hits();
+ session.close();
+ return size;
+ }
+ }
+
+ public boolean contains(Id<Portal> id)
+ {
+ POMSession session = pomSessionManager.getSession();
+ boolean found = id != null && session.findObjectById(id.toString()) !=
null;
+ session.close();
+ return found;
+ }
+
+ public Iterator<Portal> iterator()
+ {
+ return new PortalIterator(portals, GateInImpl.this);
+ }
+ }
}
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/NavigationImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/NavigationImpl.java 2011-07-12
09:49:09 UTC (rev 6862)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/NavigationImpl.java 2011-07-12
15:18:10 UTC (rev 6863)
@@ -26,9 +26,9 @@
import org.gatein.api.Filter;
import org.gatein.api.IterableResult;
import org.gatein.api.Query;
-import org.gatein.api.navigation.Navigation;
-import org.gatein.api.navigation.Page;
-import org.gatein.api.navigation.Site;
+import org.gatein.api.portal.Navigation;
+import org.gatein.api.portal.Page;
+import org.gatein.api.portal.Site;
/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
public class NavigationImpl extends IdentifiableImpl<Navigation> implements
Navigation
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/PortalImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/PortalImpl.java 2011-07-12
09:49:09 UTC (rev 6862)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/PortalImpl.java 2011-07-12
15:18:10 UTC (rev 6863)
@@ -30,13 +30,13 @@
import org.exoplatform.portal.mop.navigation.Scope;
import org.exoplatform.portal.pom.data.PortalData;
import org.gatein.api.Container;
-import org.gatein.api.Portal;
import org.gatein.api.content.ContentRegistry;
import org.gatein.api.id.Context;
import org.gatein.api.id.Id;
-import org.gatein.api.navigation.Navigation;
-import org.gatein.api.navigation.Page;
-import org.gatein.api.navigation.Site;
+import org.gatein.api.portal.Navigation;
+import org.gatein.api.portal.Page;
+import org.gatein.api.portal.Portal;
+import org.gatein.api.portal.Site;
import java.util.regex.Pattern;