Author: chris.laprun(a)jboss.com
Date: 2011-07-23 14:45:44 -0400 (Sat, 23 Jul 2011)
New Revision: 6922
Added:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/AdaptedIterableCollection.java
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/AdaptedIterableIdentifiableCollection.java
Removed:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/AdaptedIterableResult.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/content/CategoryImpl.java
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/ContentRegistryImpl.java
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/ManagedContentImpl.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/PageImpl.java
Log:
- Adapted to API changes.
- Fixed implementation of GateInImpl.getGroupSites
- Added implementations for ContentRegistry.getCategoryNames and getAllCategories.
- Renamed AdaptedIterableResult to AdaptedIterableCollection and added
AdaptedIterableIdentifiableCollection class.
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-23
13:50:44 UTC (rev 6921)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java 2011-07-23
18:45:44 UTC (rev 6922)
@@ -40,6 +40,7 @@
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.GroupHandler;
import org.exoplatform.services.organization.OrganizationService;
import org.gatein.api.GateIn;
import org.gatein.api.content.Application;
@@ -53,21 +54,18 @@
import org.gatein.api.portal.Page;
import org.gatein.api.portal.Portal;
import org.gatein.api.portal.Site;
-import org.gatein.api.util.IterableResult;
+import org.gatein.api.util.IterableIdentifiableCollection;
import org.gatein.api.util.Type;
import org.gatein.common.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.gatein.portal.api.impl.util.AdaptedIterableIdentifiableCollection;
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> */
@@ -99,14 +97,14 @@
container = context.getContainer();
}
- public IterableResult<Portal> getPortals()
+ public IterableIdentifiableCollection<Portal> getPortals()
{
try
{
begin();
final List<PortalData> portals = dataStorage.find(PORTALS).getAll();
- return new AdaptedIterableResult<PortalData, Portal>(portals.size(),
portals.iterator())
+ return new AdaptedIterableIdentifiableCollection<PortalData,
Portal>(portals.size(), portals.iterator())
{
public Portal adapt(PortalData old)
{
@@ -145,39 +143,36 @@
return getPortal(siteId(Site.PORTAL, "classic")); // todo: check
}
- public IterableResult<Site> getSites()
+ public IterableIdentifiableCollection<Site> getSites()
{
return null; //To change body of implemented methods use File | Settings | File
Templates.
}
- public IterableResult<Site> getGroupSites()
+ public IterableIdentifiableCollection<Site> getGroupSites()
{
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);
- }
+ final GroupHandler groupHandler = organizationService.getGroupHandler();
+ Collection groups = groupHandler.getAllGroups();
- return new IterableResult<Site>()
+ return new AdaptedIterableIdentifiableCollection<Object,
Site>(groups.size(), groups.iterator())
{
- public int size()
- {
- return groupSites.size();
- }
-
public boolean contains(Id<Site> siteId)
{
- return groupSites.containsKey(siteId);
+ try
+ {
+ return groupHandler.findGroupById(siteId.toString()) != null;
+ }
+ catch (Exception e)
+ {
+ return false;
+ }
}
- public Iterator<Site> iterator()
+ public Site adapt(Object old)
{
- return groupSites.values().iterator();
+ Group group = (Group)old;
+ return getGroupSite(Id.parse(GROUP_CONTEXT, group.getId()));
}
};
}
@@ -195,12 +190,12 @@
return new GroupSiteImpl(siteId, groupName, this);
}
- public IterableResult<Site> getGroupSites(Id userId)
+ public IterableIdentifiableCollection<Site> getGroupSites(Id userId)
{
return null; //To change body of implemented methods use File | Settings | File
Templates.
}
- public IterableResult<Portal> getPortalSites(Id userId)
+ public IterableIdentifiableCollection<Portal> getPortalSites(Id userId)
{
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/content/CategoryImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/CategoryImpl.java 2011-07-23
13:50:44 UTC (rev 6921)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/CategoryImpl.java 2011-07-23
18:45:44 UTC (rev 6922)
@@ -32,14 +32,16 @@
import org.gatein.api.content.Content;
import org.gatein.api.content.ManagedContent;
import org.gatein.api.id.Id;
+import org.gatein.api.util.IterableCollection;
import org.gatein.api.util.Type;
import org.gatein.mop.api.content.ContentType;
import org.gatein.portal.api.impl.GateInImpl;
+import org.gatein.portal.api.impl.util.AdaptedIterableCollection;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
public class CategoryImpl implements Category
@@ -54,6 +56,19 @@
this.gateIn = gateIn;
}
+ @Override
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder("Category
'").append(getName()).append("':\n");
+
+ for (ManagedContent content : managed.values())
+ {
+ sb.append('\t').append(content).append('\n');
+ }
+
+ return sb.toString();
+ }
+
public boolean contains(String managedContentName)
{
return getApplication(managedContentName) != null;
@@ -147,9 +162,21 @@
return managed.get(name);
}
- public Collection<String> getKnownManagedContentNames()
+ public IterableCollection<String> getKnownManagedContentNames()
{
- return managed.keySet();
+ Set<String> strings = managed.keySet();
+ return new AdaptedIterableCollection<String, String>(strings.size(),
strings.iterator())
+ {
+ public String adapt(String old)
+ {
+ return old;
+ }
+
+ public boolean contains(String s)
+ {
+ return managed.containsKey(s);
+ }
+ };
}
public Id<Category> getId()
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/ContentRegistryImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/ContentRegistryImpl.java 2011-07-23
13:50:44 UTC (rev 6921)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/ContentRegistryImpl.java 2011-07-23
18:45:44 UTC (rev 6922)
@@ -32,10 +32,15 @@
import org.gatein.api.content.ManagedContent;
import org.gatein.api.id.Id;
import org.gatein.api.util.Filter;
-import org.gatein.api.util.IterableResult;
+import org.gatein.api.util.IterableCollection;
+import org.gatein.api.util.IterableIdentifiableCollection;
import org.gatein.api.util.Query;
import org.gatein.portal.api.impl.GateInImpl;
+import org.gatein.portal.api.impl.util.AdaptedIterableCollection;
+import org.gatein.portal.api.impl.util.AdaptedIterableIdentifiableCollection;
+import java.util.List;
+
/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
public class ContentRegistryImpl implements ContentRegistry
{
@@ -56,6 +61,54 @@
return getOrCreateCategory(name, false);
}
+ public IterableCollection<String> getCategoryNames()
+ {
+ try
+ {
+ final List<ApplicationCategory> categories =
gateIn.getRegistryService().getApplicationCategories();
+ return new AdaptedIterableCollection<ApplicationCategory,
String>(categories.size(), categories.iterator())
+ {
+ public String adapt(ApplicationCategory old)
+ {
+ return old.getName();
+ }
+
+ public boolean contains(String s)
+ {
+ return doesCategoryExist(s);
+ }
+ };
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public IterableIdentifiableCollection<Category> getAllCategories()
+ {
+ try
+ {
+ final List<ApplicationCategory> categories =
gateIn.getRegistryService().getApplicationCategories();
+ return new AdaptedIterableIdentifiableCollection<ApplicationCategory,
Category>(categories.size(), categories.iterator())
+ {
+ public Category adapt(ApplicationCategory old)
+ {
+ return new CategoryImpl(old, gateIn);
+ }
+
+ public boolean contains(Id<Category> t)
+ {
+ return doesCategoryExist(t.toString());
+ }
+ };
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
private Category getOrCreateCategory(String name, boolean forceCreate)
{
try
@@ -84,6 +137,18 @@
}
}
+ private boolean doesCategoryExist(String name)
+ {
+ try
+ {
+ return gateIn.getRegistryService().getApplicationCategory(name) != null;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
public <T extends Content> T get(Id<T> id)
{
Class<T> type = id.getIdentifiableType();
@@ -117,7 +182,7 @@
return type.cast(result);
}
- public IterableResult<ManagedContent>
getManagedContents(Query<ManagedContent> query)
+ public IterableIdentifiableCollection<ManagedContent>
getManagedContents(Query<ManagedContent> query)
{
return null; //To change body of implemented methods use File | Settings | File
Templates.
}
@@ -127,7 +192,7 @@
return null; //To change body of implemented methods use File | Settings | File
Templates.
}
- public IterableResult<Content> getAll()
+ public IterableIdentifiableCollection<Content> getAll()
{
return null; //To change body of implemented methods use File | Settings | File
Templates.
}
@@ -142,12 +207,12 @@
return false; //To change body of implemented methods use File | Settings | File
Templates.
}
- public <U extends Content> IterableResult<U> getAllWhere(Filter<U>
filter)
+ public <U extends Content> IterableIdentifiableCollection<U>
getAllWhere(Filter<U> filter)
{
return null; //To change body of implemented methods use File | Settings | File
Templates.
}
- public <U extends Content> IterableResult<U>
getAllSatisfying(Query<U> query)
+ public <U extends Content> IterableIdentifiableCollection<U>
getAllSatisfying(Query<U> query)
{
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/content/ManagedContentImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/ManagedContentImpl.java 2011-07-23
13:50:44 UTC (rev 6921)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/ManagedContentImpl.java 2011-07-23
18:45:44 UTC (rev 6922)
@@ -58,6 +58,12 @@
this.category = category;
}
+ @Override
+ public String toString()
+ {
+ return "ManagedContent '" + name + "' =>" +
content;
+ }
+
public Id<ManagedContent<T>> getId()
{
return id;
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-23
13:50:44 UTC (rev 6921)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/NavigationImpl.java 2011-07-23
18:45:44 UTC (rev 6922)
@@ -35,10 +35,10 @@
import org.gatein.api.portal.Page;
import org.gatein.api.portal.Site;
import org.gatein.api.util.Filter;
-import org.gatein.api.util.IterableResult;
+import org.gatein.api.util.IterableIdentifiableCollection;
import org.gatein.api.util.Query;
import org.gatein.portal.api.impl.GateInImpl;
-import org.gatein.portal.api.impl.util.AdaptedIterableResult;
+import org.gatein.portal.api.impl.util.AdaptedIterableIdentifiableCollection;
import java.util.Iterator;
import java.util.regex.Pattern;
@@ -119,11 +119,11 @@
return getGateIn().get(site);
}
- public IterableResult<Navigation> getAll()
+ public IterableIdentifiableCollection<Navigation> getAll()
{
loadChildrenIfNeeded();
- return new AdaptedIterableResult<NavigationImpl, Navigation>(size(),
context.iterator())
+ return new AdaptedIterableIdentifiableCollection<NavigationImpl,
Navigation>(size(), context.iterator())
{
public Navigation adapt(NavigationImpl old)
{
@@ -196,12 +196,12 @@
return site.getIdforChild(key);
}
- public <U extends Navigation> IterableResult<U>
getAllWhere(Filter<U> filter)
+ public <U extends Navigation> IterableIdentifiableCollection<U>
getAllWhere(Filter<U> filter)
{
return null; //To change body of implemented methods use File | Settings | File
Templates.
}
- public <U extends Navigation> IterableResult<U>
getAllSatisfying(Query<U> query)
+ public <U extends Navigation> IterableIdentifiableCollection<U>
getAllSatisfying(Query<U> query)
{
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/PageImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/PageImpl.java 2011-07-23
13:50:44 UTC (rev 6921)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/PageImpl.java 2011-07-23
18:45:44 UTC (rev 6922)
@@ -27,7 +27,7 @@
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.api.util.IterableIdentifiableCollection;
import org.gatein.portal.api.impl.GateInImpl;
import org.gatein.portal.api.impl.IdentifiableImpl;
@@ -59,7 +59,7 @@
this.title = title;
}
- public IterableResult<Navigation> getInboundNavigations()
+ public IterableIdentifiableCollection<Navigation> getInboundNavigations()
{
return null; //To change body of implemented methods use File | Settings | File
Templates.
}
Copied:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/AdaptedIterableCollection.java
(from rev 6876,
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/AdaptedIterableResult.java)
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/AdaptedIterableCollection.java
(rev 0)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/AdaptedIterableCollection.java 2011-07-23
18:45:44 UTC (rev 6922)
@@ -0,0 +1,56 @@
+/*
+* 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.util;
+
+import org.gatein.api.util.IterableCollection;
+
+import java.util.Iterator;
+
+/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
+public abstract class AdaptedIterableCollection<O, N> implements
IterableCollection<N>, Adaptor<O, N>
+{
+ private final int size;
+ private final Iterator<O> adaptee;
+
+ public AdaptedIterableCollection(int size, Iterator<O> adaptee)
+ {
+ this.size = size;
+ this.adaptee = adaptee;
+ }
+
+ public int size()
+ {
+ return size;
+ }
+
+ public Iterator<N> iterator()
+ {
+ return new AdaptedIterator<O, N>(adaptee)
+ {
+ public N adapt(O old)
+ {
+ return AdaptedIterableCollection.this.adapt(old);
+ }
+ };
+ }
+}
Added:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/AdaptedIterableIdentifiableCollection.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/AdaptedIterableIdentifiableCollection.java
(rev 0)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/AdaptedIterableIdentifiableCollection.java 2011-07-23
18:45:44 UTC (rev 6922)
@@ -0,0 +1,43 @@
+/*
+* 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.util;
+
+
+import org.gatein.api.id.Identifiable;
+import org.gatein.api.util.IterableIdentifiableCollection;
+
+import java.util.Iterator;
+
+/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
+public abstract class AdaptedIterableIdentifiableCollection<O, N extends
Identifiable> extends AdaptedIterableCollection<O, N> implements
IterableIdentifiableCollection<N>
+{
+ public AdaptedIterableIdentifiableCollection(int size, Iterator<O> adaptee)
+ {
+ super(size, adaptee);
+ }
+
+ public boolean contains(N n)
+ {
+ return this.contains(n.getId());
+ }
+}
Deleted:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/AdaptedIterableResult.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/AdaptedIterableResult.java 2011-07-23
13:50:44 UTC (rev 6921)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/AdaptedIterableResult.java 2011-07-23
18:45:44 UTC (rev 6922)
@@ -1,57 +0,0 @@
-/*
-* 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.util;
-
-import org.gatein.api.id.Identifiable;
-import org.gatein.api.util.IterableResult;
-
-import java.util.Iterator;
-
-/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
-public abstract class AdaptedIterableResult<O, N extends Identifiable> implements
IterableResult<N>, Adaptor<O, N>
-{
- private final int size;
- private final Iterator<O> adaptee;
-
- public AdaptedIterableResult(int size, Iterator<O> adaptee)
- {
- this.size = size;
- this.adaptee = adaptee;
- }
-
- public int size()
- {
- return size;
- }
-
- public Iterator<N> iterator()
- {
- return new AdaptedIterator<O, N>(adaptee)
- {
- public N adapt(O old)
- {
- return AdaptedIterableResult.this.adapt(old);
- }
- };
- }
-}