Author: chris.laprun(a)jboss.com
Date: 2011-08-05 18:12:23 -0400 (Fri, 05 Aug 2011)
New Revision: 7001
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
Log:
- Implemented ContentRegistry.getAll method.
- Made Category.getManagedContents public to follow API change.
- Moved getContentIdFrom and getContentClassFor methods to GateInImpl.
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-08-05
18:18:34 UTC (rev 7000)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java 2011-08-05
22:12:23 UTC (rev 7001)
@@ -24,6 +24,7 @@
import org.exoplatform.application.gadget.GadgetRegistryService;
import org.exoplatform.application.gadget.SourceStorage;
+import org.exoplatform.application.registry.Application;
import org.exoplatform.application.registry.ApplicationRegistryService;
import org.exoplatform.container.ExoContainer;
import org.exoplatform.container.ExoContainerContext;
@@ -32,6 +33,7 @@
import org.exoplatform.portal.config.Query;
import org.exoplatform.portal.config.UserACL;
import org.exoplatform.portal.config.UserPortalConfigService;
+import org.exoplatform.portal.config.model.ApplicationType;
import org.exoplatform.portal.config.model.PortalConfig;
import org.exoplatform.portal.mop.SiteType;
import org.exoplatform.portal.mop.description.DescriptionService;
@@ -130,6 +132,49 @@
container = context.getContainer();
}
+ public static Id<? extends Content> getContentIdFrom(Application application)
+ {
+ ApplicationType type = application.getType();
+ Class<Content> contentClass = getContentClassFor(type);
+ if (Gadget.class.isAssignableFrom(contentClass))
+ {
+ //TODO: for a gadget, it should probably be using application.getID instead of
getContentId
+ return staticGadgetId(application.getContentId());
+ }
+ else if (WSRP.class.isAssignableFrom(contentClass))
+ {
+ return parseWSRPPortletId(application.getId());
+ }
+ else if (Portlet.class.isAssignableFrom(contentClass))
+ {
+ return parsePortletId(application.getId());
+ }
+ else
+ {
+ throw new IllegalArgumentException("Unknown application type: " +
type);
+ }
+ }
+
+ public static <T extends Content> Class<T>
getContentClassFor(ApplicationType type)
+ {
+ if (ApplicationType.GADGET.equals(type))
+ {
+ return (Class<T>)Gadget.class;
+ }
+ else if (ApplicationType.PORTLET.equals(type))
+ {
+ return (Class<T>)Portlet.class;
+ }
+ else if (ApplicationType.WSRP_PORTLET.equals(type))
+ {
+ return (Class<T>)WSRP.class;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Unknown ApplicationType: " +
type);
+ }
+ }
+
public <T> T getProperty(Type<T> property)
{
if (property == null)
@@ -467,7 +512,7 @@
return APPLICATION_CONTEXT.create(Portlet.class, application, portlet);
}
- public Id<Portlet> parsePortletId(String contentId)
+ public static Id<Portlet> parsePortletId(String contentId)
{
if (contentId.contains(ComplexApplicationId.START))
{
@@ -481,16 +526,26 @@
public Id<WSRP> wsrpPortletId(String invoker, String portlet)
{
+ return staticWSRPPortletId(invoker, portlet);
+ }
+
+ private static Id<WSRP> staticWSRPPortletId(String invoker, String portlet)
+ {
return WSRP_CONTEXT.create(WSRP.class, invoker, portlet);
}
- public Id<WSRP> parseWSRPPortletId(String compositeId)
+ public static Id<WSRP> parseWSRPPortletId(String compositeId)
{
return WSRP_CONTEXT.parse(compositeId, WSRP.class);
}
public Id<Gadget> gadgetId(String gadgetName)
{
+ return staticGadgetId(gadgetName);
+ }
+
+ private static Id<Gadget> staticGadgetId(String gadgetName)
+ {
return GADGET_CONTEXT.create(Gadget.class, gadgetName);
}
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-08-05
18:18:34 UTC (rev 7000)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/CategoryImpl.java 2011-08-05
22:12:23 UTC (rev 7001)
@@ -25,14 +25,12 @@
import org.exoplatform.application.registry.Application;
import org.exoplatform.application.registry.ApplicationCategory;
import org.exoplatform.portal.config.UserACL;
-import org.exoplatform.portal.config.model.ApplicationType;
import org.exoplatform.portal.pom.spi.portlet.Portlet;
import org.exoplatform.portal.pom.spi.wsrp.WSRP;
import org.gatein.api.GateIn;
import org.gatein.api.content.Category;
import org.gatein.api.content.Content;
import org.gatein.api.content.ContentRegistry;
-import org.gatein.api.content.Gadget;
import org.gatein.api.content.ManagedContent;
import org.gatein.api.id.Id;
import org.gatein.api.util.IterableCollection;
@@ -58,14 +56,14 @@
this.gateIn = gateIn;
}
- private IterableCollection<ManagedContent> getManagedContents()
+ public IterableCollection<ManagedContent> getManagedContents()
{
List<Application> applications = category.getApplications();
return new AdaptedIterableCollection<Application,
ManagedContent>(applications.size(), applications.iterator())
{
public ManagedContent adapt(Application old)
{
- Content content = registry.get(getContentIdFrom(old));
+ Content content = registry.get(GateInImpl.getContentIdFrom(old));
return new ManagedContentImpl(content, CategoryImpl.this);
}
@@ -76,29 +74,6 @@
};
}
- private Id<? extends Content> getContentIdFrom(Application application)
- {
- ApplicationType type = application.getType();
- Class<Content> contentClass = getContentClassFor(type);
- if (Gadget.class.isAssignableFrom(contentClass))
- {
- //TODO: for a gadget, it should probably be using application.getID instead of
getContentId
- return gateIn.gadgetId(application.getContentId());
- }
- else if (org.gatein.api.content.WSRP.class.isAssignableFrom(contentClass))
- {
- return gateIn.parseWSRPPortletId(application.getId());
- }
- else if (org.gatein.api.content.Portlet.class.isAssignableFrom(contentClass))
- {
- return gateIn.parsePortletId(application.getId());
- }
- else
- {
- throw new IllegalArgumentException("Unknown application type: " +
type);
- }
- }
-
@Override
public String toString()
{
@@ -177,26 +152,6 @@
}
}
- private <T extends Content> Class<T> getContentClassFor(ApplicationType
type)
- {
- if (ApplicationType.GADGET.equals(type))
- {
- return (Class<T>)Gadget.class;
- }
- else if (ApplicationType.PORTLET.equals(type))
- {
- return (Class<T>)org.gatein.api.content.Portlet.class;
- }
- else if (ApplicationType.WSRP_PORTLET.equals(type))
- {
- return (Class<T>)org.gatein.api.content.WSRP.class;
- }
- else
- {
- throw new IllegalArgumentException("Unknown ApplicationType: " +
type);
- }
- }
-
public String getDescription()
{
return category.getDescription();
@@ -259,7 +214,7 @@
return null;
}
- Content content = registry.get(getContentIdFrom(application));
+ Content content = registry.get(GateInImpl.getContentIdFrom(application));
return new ManagedContentImpl(content, this);
}
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-08-05
18:18:34 UTC (rev 7000)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/ContentRegistryImpl.java 2011-08-05
22:12:23 UTC (rev 7001)
@@ -22,6 +22,7 @@
package org.gatein.portal.api.impl.content;
+import org.exoplatform.application.registry.Application;
import org.exoplatform.application.registry.ApplicationCategory;
import org.exoplatform.application.registry.ApplicationRegistryService;
import org.gatein.api.content.Category;
@@ -195,74 +196,57 @@
{
Class<T> type = id.getIdentifiableType();
Object result;
- if (Portlet.class.equals(type))
+ Object regitryItem;
+ try
{
- try
+ gateIn.begin();
+ if (Portlet.class.equals(type) || WSRP.class.equals(type))
{
- gateIn.begin();
- org.exoplatform.application.registry.Application application =
gateIn.getRegistryService().getApplication(id.toString());
- if (application == null)
- {
- return null;
- }
- result = new PortletImpl((Id<Portlet>)id, application, gateIn);
+ regitryItem = gateIn.getRegistryService().getApplication(id.toString());
}
- catch (Exception e)
+ else if (Gadget.class.equals(type))
{
- throw new RuntimeException(e);
+ regitryItem = gateIn.getGadgetService().getGadget(id.toString());
}
- finally
+ else
{
- gateIn.end();
+ throw new IllegalArgumentException("Unknown Content type: " +
type.getCanonicalName());
}
+
+ result = newContentFrom(id, regitryItem, type);
+ return type.cast(result);
}
- else if (Gadget.class.equals(type))
+ catch (Exception e)
{
- try
- {
- gateIn.begin();
- org.exoplatform.application.gadget.Gadget gadget =
gateIn.getGadgetService().getGadget(id.toString());
- if (gadget == null)
- {
- return null;
- }
- result = new GadgetImpl((Id<Gadget>)id, gadget, gateIn);
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- finally
- {
- gateIn.end();
- }
+ throw new RuntimeException(e);
}
- else if (WSRP.class.equals(type))
+ finally
{
- try
- {
- gateIn.begin();
- org.exoplatform.application.registry.Application application =
gateIn.getRegistryService().getApplication(id.toString());
- if (application == null)
- {
- return null;
- }
- result = new WSRPImpl((Id<WSRP>)id, application, gateIn);
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- finally
- {
- gateIn.end();
- }
+ gateIn.end();
}
+ }
+
+ private <T extends Content> Content newContentFrom(Id id, Object registryItem,
Class<T> wanted)
+ {
+ Object result;
+ if (Portlet.class.equals(wanted))
+ {
+ result = new PortletImpl((Id<Portlet>)id, (Application)registryItem,
gateIn);
+ }
+ else if (Gadget.class.equals(wanted))
+ {
+ result = new GadgetImpl((Id<Gadget>)id,
(org.exoplatform.application.gadget.Gadget)registryItem, gateIn);
+ }
+ else if (WSRP.class.equals(wanted))
+ {
+ result = new WSRPImpl((Id<WSRP>)id, (Application)registryItem, gateIn);
+ }
else
{
- throw new IllegalArgumentException("Unknown Content type: " +
type.getCanonicalName());
+ throw new IllegalArgumentException("Unknown Content type: " +
wanted.getCanonicalName());
}
- return type.cast(result);
+
+ return wanted.cast(result);
}
public IterableIdentifiableCollection<ManagedContent>
getManagedContents(Query<ManagedContent> query)
@@ -277,7 +261,49 @@
public IterableIdentifiableCollection<Content> getAll()
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ try
+ {
+ gateIn.begin();
+ final List<Application> applications =
gateIn.getRegistryService().getAllApplications();
+
+ return new AdaptedIterableIdentifiableCollection<Application,
Content>(applications.size(), applications.iterator())
+ {
+ public Content adapt(Application old)
+ {
+ final Id<? extends Content> id = GateInImpl.getContentIdFrom(old);
+
+ // if we're asking for a gadget, we need to retrieve it from the
gadget registry first
+ if (Gadget.class.isAssignableFrom(id.getIdentifiableType()))
+ {
+ return get(id);
+ }
+ else
+ {
+ return newContentFrom(id, old, id.getIdentifiableType());
+ }
+ }
+
+ public boolean contains(Id<Content> t)
+ {
+ try
+ {
+ return gateIn.getRegistryService().getApplication(t.toString()) !=
null;
+ }
+ catch (Exception e)
+ {
+ return false;
+ }
+ }
+ };
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ finally
+ {
+ gateIn.end();
+ }
}
public int size()
@@ -292,6 +318,6 @@
public <U extends Content> IterableIdentifiableCollection<U>
getAllSatisfying(Query<U> query)
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ return null;
}
}