Author: chris.laprun(a)jboss.com
Date: 2011-07-19 17:08:02 -0400 (Tue, 19 Jul 2011)
New Revision: 6889
Added:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/PageImpl.java
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/portal/NavigationImpl.java
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/SiteImpl.java
Log:
- First implementation of Group sites: fixed some issues with Contexts for Ids.
- Added Page implementation and support for Page retrieval from Navigation and GateIn.
- Added NavigationImpl.loadChildrenIfNeeded to progressively load layers of chilren when
needed.
- Improved NavigationImpl.toString method.
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-19
19:06:54 UTC (rev 6888)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java 2011-07-19
21:08:02 UTC (rev 6889)
@@ -33,8 +33,11 @@
import org.exoplatform.portal.pom.data.DashboardData;
import org.exoplatform.portal.pom.data.ModelDataStorage;
import org.exoplatform.portal.pom.data.PageData;
+import org.exoplatform.portal.pom.data.PageKey;
import org.exoplatform.portal.pom.data.PortalData;
import org.exoplatform.portal.pom.data.PortalKey;
+import org.exoplatform.services.organization.Group;
+import org.exoplatform.services.organization.OrganizationService;
import org.gatein.api.GateIn;
import org.gatein.api.content.Application;
import org.gatein.api.content.Content;
@@ -48,12 +51,18 @@
import org.gatein.api.portal.Site;
import org.gatein.api.util.IterableResult;
import org.gatein.api.util.ParameterValidation;
+import org.gatein.portal.api.impl.portal.GroupSiteImpl;
+import org.gatein.portal.api.impl.portal.PageImpl;
import org.gatein.portal.api.impl.portal.PortalImpl;
import org.gatein.portal.api.impl.util.AdaptedIterableResult;
import org.picocontainer.Startable;
import java.net.URI;
+import java.util.Collection;
+import java.util.Iterator;
import java.util.List;
+import java.util.SortedMap;
+import java.util.TreeMap;
import java.util.regex.Pattern;
/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
@@ -62,13 +71,18 @@
private static final Query<PortalData> PORTALS = new
Query<PortalData>(SiteType.PORTAL.getName(), null, PortalData.class);
private static final Query<DashboardData> DASHBOARDS = new
Query<DashboardData>(SiteType.USER.getName(), null, DashboardData.class);
private static final Query<PageData> GROUPS = new
Query<PageData>(SiteType.GROUP.getName(), null, PageData.class);
- public static final Context CONTEXT =
Context.builder().requiredComponent("owner", Site.class,
Pattern.compile("\\w+"))
- .requiredComponent("portal", Portal.class,
Pattern.compile("\\w+"))
+ private static final String GROUP_CHARS = "\\w|-|_";
+ public static final Context CONTEXT = Context.builder()
+ .requiredComponent("owner", Site.class,
Pattern.compile(Site.Type.PORTAL_NAME + "|" + Site.Type.GROUP_NAME +
"|" + Site.Type.DASHBOARD_NAME))
+ .requiredComponent("portal", Portal.class, Pattern.compile("("
+ GROUP_CHARS + "|\\/)+"))
.optionalComponent("page", Page.class,
Pattern.compile("\\w+"))
.withDefaultSeparator("::").build();
+ public static final Context GROUP_CONTEXT =
Context.builder().requiredUnboundedHierarchicalComponent("group",
Identifiable.class, Pattern.compile("(" + GROUP_CHARS + ")+"))
+ .withDefaultSeparator("/").requireSeparatorInFirstPosition().build();
private ExoContainer container;
private ModelDataStorage dataStorage;
private NavigationService navigationService;
+ private OrganizationService organizationService;
public GateInImpl(ExoContainerContext context, InitParams params, ConfigurationManager
configurationManager)
{
@@ -128,12 +142,47 @@
public IterableResult<Site> getGroupSites()
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ try
+ {
+ Collection groups = organizationService.getGroupHandler().getAllGroups(); //
todo: a method that would just retrieve the group names would be a lot better for
performance...
+ final SortedMap<Id<Site>, Site> groupSites = new
TreeMap<Id<Site>, Site>();
+ for (Object o : groups)
+ {
+ Group group = (Group)o;
+ Site site = getGroupSite(Id.parse(GROUP_CONTEXT, group.getId()));
+ groupSites.put(site.getId(), site);
+ }
+
+ return new IterableResult<Site>()
+ {
+ public int size()
+ {
+ return groupSites.size();
+ }
+
+ public boolean contains(Id<Site> siteId)
+ {
+ return groupSites.containsKey(siteId);
+ }
+
+ public Iterator<Site> iterator()
+ {
+ return groupSites.values().iterator();
+ }
+ };
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
}
public Site getGroupSite(Id groupId)
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ String groupName = groupId.toString();
+ Id<Site> siteId = siteId(Site.Type.GROUP, groupName);
+
+ return new GroupSiteImpl(siteId, groupName, this);
}
public IterableResult<Site> getGroupSites(Id userId)
@@ -163,6 +212,23 @@
{
result = getPortal((Id<Portal>)id);
}
+ else if (Page.class.getCanonicalName().equals(canonicalName))
+ {
+ try
+ {
+ begin();
+ PageData pageData = dataStorage.getPage(PageKey.create(id.toString()));
+ result = new PageImpl(pageData, id.getParent(), this);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ finally
+ {
+ end();
+ }
+ }
else
{
throw new UnsupportedOperationException("Id<" +
type.getSimpleName() + "> not yet supported");
@@ -211,15 +277,22 @@
return null; //To change body of implemented methods use File | Settings | File
Templates.
}
- public <T extends Site> Id<T> siteId(Site.Type<T> siteType, String
portalName)
+ public <T extends Site> Id<T> siteId(Site.Type<T> siteType, String
siteName)
{
- return Id.create(CONTEXT, siteType.getValueType(), siteType.getName(),
portalName);
+ return Id.create(CONTEXT, siteType.getValueType(), siteType.getName(), siteName);
}
+ public <T extends Site> Id<Page> pageId(Id<T> ownerSite, String
pageName)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(ownerSite, "Owner Site
Id");
+ return ownerSite.getIdforChild(pageName);
+ }
+
public void start()
{
dataStorage =
(ModelDataStorage)container.getComponentInstanceOfType(ModelDataStorage.class);
navigationService =
(NavigationService)container.getComponentInstanceOfType(NavigationService.class);
+ organizationService =
(OrganizationService)container.getComponentInstanceOfType(OrganizationService.class);
}
public void stop()
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/NavigationImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/NavigationImpl.java 2011-07-19
19:06:54 UTC (rev 6888)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/NavigationImpl.java 2011-07-19
21:08:02 UTC (rev 6889)
@@ -22,9 +22,11 @@
package org.gatein.portal.api.impl.portal;
+import org.exoplatform.portal.mop.navigation.NavigationService;
import org.exoplatform.portal.mop.navigation.NodeContext;
import org.exoplatform.portal.mop.navigation.NodeModel;
import org.exoplatform.portal.mop.navigation.NodeState;
+import org.exoplatform.portal.mop.navigation.Scope;
import org.gatein.api.GateIn;
import org.gatein.api.id.Context;
import org.gatein.api.id.Id;
@@ -61,13 +63,27 @@
@Override
public String toString()
{
- String s = "Navigation@" + getId() + " target:" +
context.getState().getPageRef() + "\nchildren:\n";
- Iterator<NavigationImpl> children = context.iterator();
- while (children.hasNext())
+ String pageRef = context.getState().getPageRef();
+ StringBuilder s = new StringBuilder("Navigation(a)").append(getId());
+
+ if (pageRef != null)
{
- s += " " + children.next() + "\n";
+ s.append("-target->").append(pageRef);
}
- return s;
+
+ if (size() != 0)
+ {
+ loadChildrenIfNeeded();
+ s.append("\n|");
+ Iterator<NavigationImpl> children = context.iterator();
+ while (children.hasNext())
+ {
+ s.append("\n+--").append(children.next());
+ }
+ s.append("\n");
+ }
+
+ return s.toString();
}
public NodeContext<NavigationImpl> getContext()
@@ -77,7 +93,15 @@
public Page getTargetPage()
{
- return null;
+ String pageRef = context.getState().getPageRef();
+ if (pageRef != null)
+ {
+ return gateIn.get(gateIn.pageId(site, pageRef));
+ }
+ else
+ {
+ return null;
+ }
}
public void setTargetPage(Page target)
@@ -97,6 +121,8 @@
public IterableResult<Navigation> getAll()
{
+ loadChildrenIfNeeded();
+
return new AdaptedIterableResult<NavigationImpl, Navigation>(size(),
context.iterator())
{
public Navigation adapt(NavigationImpl old)
@@ -104,13 +130,30 @@
return old;
}
- public boolean contains(Id<Navigation> t)
+ public boolean contains(Id<Navigation> id)
{
- return context.get(t.toString()) != null;
+ return NavigationImpl.this.contains(id);
}
};
}
+ private void loadChildrenIfNeeded()
+ {
+ if (!context.isExpanded())
+ {
+ NavigationService service = gateIn.getNavigationService();
+ try
+ {
+ gateIn.begin();
+ service.rebaseNode(context, Scope.CHILDREN, null);
+ }
+ finally
+ {
+ gateIn.end();
+ }
+ }
+ }
+
public int size()
{
return context.getNodeSize();
@@ -118,17 +161,19 @@
public boolean contains(String key)
{
- return false; //To change body of implemented methods use File | Settings | File
Templates.
+ return contains(getIdForChild(key));
}
public boolean contains(Id<Navigation> navigationId)
{
- return false; //To change body of implemented methods use File | Settings | File
Templates.
+ loadChildrenIfNeeded();
+
+ return context.get(navigationId.toString()) != null;
}
public Navigation createAndAdd(String key)
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ return createAndAdd(getIdForChild(key));
}
public Navigation createAndAdd(Id<Navigation> navigationId)
@@ -138,7 +183,7 @@
public Navigation get(String key)
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ return get(getIdForChild(key));
}
public Navigation get(Id<Navigation> navigationId)
@@ -148,7 +193,7 @@
public Id<Navigation> getIdForChild(String key)
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ return site.getIdforChild(key);
}
public <U extends Navigation> IterableResult<U>
getAllWhere(Filter<U> filter)
Added:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/PageImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/PageImpl.java
(rev 0)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/PageImpl.java 2011-07-19
21:08:02 UTC (rev 6889)
@@ -0,0 +1,71 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.gatein.portal.api.impl.portal;
+
+import org.exoplatform.portal.pom.data.PageData;
+import org.gatein.api.id.Id;
+import org.gatein.api.portal.Navigation;
+import org.gatein.api.portal.Page;
+import org.gatein.api.portal.Site;
+import org.gatein.api.util.IterableResult;
+import org.gatein.portal.api.impl.GateInImpl;
+import org.gatein.portal.api.impl.IdentifiableImpl;
+
+/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
+public class PageImpl extends IdentifiableImpl<Page> implements Page
+{
+ private final Id<? extends Site> site;
+ private String title;
+
+ public PageImpl(PageData pageData, Id<? extends Site> parent, GateInImpl
gateIn)
+ {
+ super(gateIn.pageId(parent, pageData.getName()), pageData.getName(), gateIn);
+ this.site = parent;
+ this.title = pageData.getTitle();
+ }
+
+ public Site getSite()
+ {
+ return getGateIn().get(site);
+ }
+
+ public String getTitle()
+ {
+ return title;
+ }
+
+ public void setTitle(String title)
+ {
+ this.title = title;
+ }
+
+ public IterableResult<Navigation> getInboundNavigations()
+ {
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public Navigation createInboundNavigationIn(Site site, Navigation parent)
+ {
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+}
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/SiteImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/SiteImpl.java 2011-07-19
19:06:54 UTC (rev 6888)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/SiteImpl.java 2011-07-19
21:08:02 UTC (rev 6889)
@@ -59,9 +59,16 @@
gateIn.begin();
NavigationContext navigation = service.loadNavigation(getSiteKey());
- NodeModel<NavigationImpl> nodeModel = new
NavigationImpl.NavigationNodeModel(getId(), gateIn);
+ if (navigation != null)
+ {
+ NodeModel<NavigationImpl> nodeModel = new
NavigationImpl.NavigationNodeModel(getId(), gateIn);
- return service.loadNode(nodeModel, navigation, Scope.CHILDREN, null).getNode();
+ return service.loadNode(nodeModel, navigation, Scope.CHILDREN,
null).getNode();
+ }
+ else
+ {
+ return null;
+ }
}
finally
{