Author: chris.laprun(a)jboss.com
Date: 2011-07-24 17:06:59 -0400 (Sun, 24 Jul 2011)
New Revision: 6924
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/ApplicationImpl.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/GadgetImpl.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/PortalImpl.java
Log:
- Made CategoryImpl completely backed from persistence instead of maintaining local state
and fixed improper behavior.
- Improved robustness somewhat.
- Added toString methods.
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
21:39:24 UTC (rev 6923)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java 2011-07-24
21:06:59 UTC (rev 6924)
@@ -84,6 +84,7 @@
.withDefaultSeparator("/").requireSeparatorInFirstPosition().build();
public static final Context APPLICATION_CONTEXT =
Context.builder().requiredComponent("application", Identifiable.class,
Pattern.compile("\\w+"))
.requiredComponent("portlet", Application.class,
Pattern.compile("\\w+")).withDefaultSeparator("/").build();
+ private static final Context GADGET_CONTEXT =
Context.builder().requiredComponent("name", Gadget.class,
Pattern.compile("\\w+")).build();
private ExoContainer container;
private ModelDataStorage dataStorage;
private NavigationService navigationService;
@@ -262,6 +263,11 @@
return null; //To change body of implemented methods use File | Settings | File
Templates.
}
+ public <T extends Content> Id<T> contentId(String contentId,
Class<T> expectedType)
+ {
+ return Id.parse(GateInImpl.APPLICATION_CONTEXT, contentId, expectedType);
+ }
+
public Id<Content> wsrpPortletId(String invoker, String portlet)
{
return null; //To change body of implemented methods use File | Settings | File
Templates.
@@ -269,7 +275,7 @@
public Id<Gadget> gadgetId(String gadgetName)
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ return Id.create(GADGET_CONTEXT, Gadget.class, gadgetName);
}
public Id<Gadget> gadgetId(URI uri)
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/ApplicationImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/ApplicationImpl.java 2011-07-23
21:39:24 UTC (rev 6923)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/ApplicationImpl.java 2011-07-24
21:06:59 UTC (rev 6924)
@@ -40,6 +40,12 @@
this.application = application;
}
+ @Override
+ public String toString()
+ {
+ return "Application '" + getName() + "' @" + getId();
+ }
+
public Type<org.gatein.api.content.Application, Content> getType()
{
return Content.PORTLET;
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
21:39:24 UTC (rev 6923)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/CategoryImpl.java 2011-07-24
21:06:59 UTC (rev 6924)
@@ -25,11 +25,14 @@
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;
@@ -39,29 +42,60 @@
import org.gatein.portal.api.impl.util.AdaptedIterableCollection;
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
+import java.util.List;
/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
public class CategoryImpl implements Category
{
private final ApplicationCategory category;
private final GateInImpl gateIn;
- private Map<String, ManagedContent> managed = new HashMap<String,
ManagedContent>(7);
+ private final ContentRegistry registry;
- public CategoryImpl(ApplicationCategory category, GateInImpl gateIn)
+ public CategoryImpl(ApplicationCategory category, ContentRegistry registry, GateInImpl
gateIn)
{
this.category = category;
+ this.registry = registry;
this.gateIn = gateIn;
}
+ private 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));
+ return new ManagedContentImpl(content, CategoryImpl.this);
+ }
+
+ public boolean contains(ManagedContent managedContent)
+ {
+ return getApplication(managedContent.getName()) != null;
+ }
+ };
+ }
+
+ private Id<? extends Content> getContentIdFrom(Application application)
+ {
+ ApplicationType type = application.getType();
+ Class<Content> contentClass = getContentClassFor(type);
+ if (Gadget.class.isAssignableFrom(contentClass))
+ {
+ return gateIn.gadgetId(application.getContentId());
+ }
+ else
+ {
+ return gateIn.contentId(application.getId(), contentClass);
+ }
+ }
+
@Override
public String toString()
{
StringBuilder sb = new StringBuilder("Category
'").append(getName()).append("':\n");
- for (ManagedContent content : managed.values())
+ for (ManagedContent content : getManagedContents())
{
sb.append('\t').append(content).append('\n');
}
@@ -78,27 +112,40 @@
{
try
{
+ gateIn.begin();
return gateIn.getRegistryService().getApplication(category.getName(),
managedContentName);
}
catch (Exception e)
{
return null;
}
+ finally
+ {
+ gateIn.end();
+ }
}
public <T extends Content> ManagedContent<T> addContent(Id<T>
contentId)
{
- T t = gateIn.get(contentId);
+ // get content from registry
+ T t = registry.get(contentId);
+
+ if (t == null)
+ {
+ throw new IllegalArgumentException("No Content with id " + contentId +
" exists");
+ }
+
+ // figure out which type it is for the ApplicationRegistry
Type type = t.getType();
ContentType<?> contentType = getContentTypeFor(type);
+
+ // default permissions by default
ArrayList<String> permissions = new ArrayList<String>();
permissions.add(UserACL.EVERYONE);
+
gateIn.getRegistryService().createOrReplaceContentIn(category.getName(),
t.getName(), contentType, t.getId().toString(), t.getDisplayName(), null, permissions);
- ManagedContent<T> managedContent = new ManagedContentImpl<T>(t, this);
- managed.put(managedContent.getName(), managedContent);
-
- return managedContent;
+ return new ManagedContentImpl<T>(t, this);
}
private ContentType<?> getContentTypeFor(Type type)
@@ -121,24 +168,23 @@
}
}
- private <T extends Content> String getContentIdFor(T content)
+ private <T extends Content> Class<T> getContentClassFor(ApplicationType
type)
{
- Type type = content.getType();
- if (Content.GADGET.equals(type))
+ if (ApplicationType.GADGET.equals(type))
{
- return content.getName();
+ return (Class<T>)Gadget.class;
}
- else if (Content.PORTLET.equals(type))
+ else if (ApplicationType.PORTLET.equals(type))
{
- return content.getId().toString();
+ return (Class<T>)org.gatein.api.content.Application.class;
}
- else if (Content.WSRP.equals(type))
+ else if (ApplicationType.WSRP_PORTLET.equals(type))
{
- return content.getId().toString();
+ return (Class<T>)org.gatein.api.content.Application.class;
}
else
{
- throw new IllegalArgumentException("Unknown Content type: " + type);
+ throw new IllegalArgumentException("Unknown ApplicationType: " +
type);
}
}
@@ -154,27 +200,49 @@
public void removeContent(String managedContentName)
{
- managed.remove(managedContentName);
+ Application application = getApplication(managedContentName);
+
+ gateIn.begin();
+ try
+ {
+ gateIn.getRegistryService().remove(application);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ finally
+ {
+ gateIn.end();
+ }
}
- public <T extends Content> ManagedContent<T> getManagedContent(String
name)
+ public ManagedContent getManagedContent(String name)
{
- return managed.get(name);
+ Application application = getApplication(name);
+
+ if (application == null)
+ {
+ return null;
+ }
+
+ Content content = registry.get(getContentIdFrom(application));
+ return new ManagedContentImpl(content, this);
}
public IterableCollection<String> getKnownManagedContentNames()
{
- Set<String> strings = managed.keySet();
- return new AdaptedIterableCollection<String, String>(strings.size(),
strings.iterator())
+ IterableCollection<ManagedContent> managedContents = getManagedContents();
+ return new AdaptedIterableCollection<ManagedContent,
String>(managedContents.size(), managedContents.iterator())
{
- public String adapt(String old)
+ public boolean contains(String s)
{
- return old;
+ return getApplication(s) != null;
}
- public boolean contains(String s)
+ public String adapt(ManagedContent old)
{
- return managed.containsKey(s);
+ return old.getName();
}
};
}
@@ -201,10 +269,23 @@
void renameManagedContent(String oldName, String newName)
{
- ManagedContent removed = managed.remove(oldName);
- if (removed != null)
+ Application application = getApplication(oldName);
+ if (application != null)
{
- managed.put(newName, removed);
+ application.setApplicationName(newName); // todo: correct?
+ try
+ {
+ gateIn.begin();
+ gateIn.getRegistryService().save(category, application);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ finally
+ {
+ gateIn.end();
+ }
}
}
}
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
21:39:24 UTC (rev 6923)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/ContentRegistryImpl.java 2011-07-24
21:06:59 UTC (rev 6924)
@@ -36,6 +36,7 @@
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.portal.PortalImpl;
import org.gatein.portal.api.impl.util.AdaptedIterableCollection;
import org.gatein.portal.api.impl.util.AdaptedIterableIdentifiableCollection;
@@ -45,10 +46,12 @@
public class ContentRegistryImpl implements ContentRegistry
{
private final GateInImpl gateIn;
+ private final PortalImpl portal;
- public ContentRegistryImpl(GateInImpl gateIn)
+ public ContentRegistryImpl(GateInImpl gateIn, PortalImpl portal)
{
this.gateIn = gateIn;
+ this.portal = portal;
}
public Category getOrCreateCategory(String name)
@@ -100,7 +103,7 @@
{
public Category adapt(ApplicationCategory old)
{
- return new CategoryImpl(old, gateIn);
+ return new CategoryImpl(old, ContentRegistryImpl.this, gateIn);
}
public boolean contains(Id<Category> t)
@@ -140,7 +143,7 @@
}
}
- return new CategoryImpl(applicationCategory, gateIn);
+ return new CategoryImpl(applicationCategory, this, gateIn);
}
catch (Exception e)
{
@@ -178,7 +181,12 @@
try
{
gateIn.begin();
- result = new
ApplicationImpl(gateIn.getRegistryService().getApplication(id.toString()), gateIn);
+ org.exoplatform.application.registry.Application application =
gateIn.getRegistryService().getApplication(id.toString());
+ if (application == null)
+ {
+ return null;
+ }
+ result = new ApplicationImpl(application, gateIn);
}
catch (Exception e)
{
@@ -194,7 +202,12 @@
try
{
gateIn.begin();
- result = new GadgetImpl(gateIn.getGadgetService().getGadget(id.toString()),
gateIn);
+ org.exoplatform.application.gadget.Gadget gadget =
gateIn.getGadgetService().getGadget(id.toString());
+ if (gadget == null)
+ {
+ return null;
+ }
+ result = new GadgetImpl(gadget, gateIn);
}
catch (Exception e)
{
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/GadgetImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/GadgetImpl.java 2011-07-23
21:39:24 UTC (rev 6923)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/GadgetImpl.java 2011-07-24
21:06:59 UTC (rev 6924)
@@ -25,7 +25,6 @@
import org.exoplatform.application.gadget.Gadget;
import org.exoplatform.application.gadget.Source;
import org.gatein.api.content.Content;
-import org.gatein.api.id.Id;
import org.gatein.api.util.Type;
import org.gatein.portal.api.impl.GateInImpl;
import org.gatein.portal.api.impl.IdentifiableImpl;
@@ -39,10 +38,16 @@
public GadgetImpl(Gadget gadget, GateInImpl gateIn)
{
- super(Id.parse(GateInImpl.APPLICATION_CONTEXT, gadget.getName(),
org.gatein.api.content.Gadget.class), gadget.getName(), gateIn);
+ super(gateIn.gadgetId(gadget.getName()), gadget.getName(), gateIn);
this.gadget = gadget;
}
+ @Override
+ public String toString()
+ {
+ return (isLocal() ? "Local " : "") + "Gadget '" +
getName() + "' @" + getId() + " URI: " + getURI();
+ }
+
public URI getReferenceURI()
{
return URI.create(gadget.getReferenceUrl());
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
21:39:24 UTC (rev 6923)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/ManagedContentImpl.java 2011-07-24
21:06:59 UTC (rev 6924)
@@ -61,7 +61,7 @@
@Override
public String toString()
{
- return "ManagedContent '" + name + "' =>" +
content;
+ return "ManagedContent '" + getName() + "' =>" +
content;
}
public Id<ManagedContent<T>> getId()
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/PortalImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/PortalImpl.java 2011-07-23
21:39:24 UTC (rev 6923)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/PortalImpl.java 2011-07-24
21:06:59 UTC (rev 6924)
@@ -42,7 +42,7 @@
public ContentRegistry getContentRegistry()
{
- return new ContentRegistryImpl(getGateInImpl());
+ return new ContentRegistryImpl(getGateInImpl(), this);
}
public Type getType()