Author: chris.laprun(a)jboss.com
Date: 2011-08-08 13:51:25 -0400 (Mon, 08 Aug 2011)
New Revision: 7010
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/ManagedContentImpl.java
portal/branches/api/component/application-registry/src/main/java/org/exoplatform/application/registry/ApplicationRegistryService.java
portal/branches/api/component/application-registry/src/main/java/org/exoplatform/application/registry/impl/ApplicationRegistryServiceImpl.java
portal/branches/api/examples/portlets/api/src/main/java/org/gatein/portal/samples/api/ContentRegistryPortlet.java
Log:
- Updated for API changes.
- GTNPORTAL-1981: now properly saving changes to ManagedContent.
- Renamed ApplicationRegistryService.createOrReplaceContentIn to
createOrUpdateApplication.
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-08
17:17:41 UTC (rev 7009)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/CategoryImpl.java 2011-08-08
17:51:25 UTC (rev 7010)
@@ -24,10 +24,10 @@
import org.exoplatform.application.registry.Application;
import org.exoplatform.application.registry.ApplicationCategory;
+import org.exoplatform.application.registry.ApplicationRegistryService;
import org.exoplatform.portal.config.UserACL;
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;
@@ -65,7 +65,7 @@
{
public ManagedContent adapt(Application old)
{
- return new ManagedContentImpl(old.getApplicationName(),
GateInImpl.getContentIdFrom(old), CategoryImpl.this);
+ return new ManagedContentImpl(old.getApplicationName(),
GateInImpl.getContentIdFrom(old), old, CategoryImpl.this);
}
public boolean contains(ManagedContent managedContent)
@@ -126,9 +126,22 @@
ArrayList<String> permissions = new ArrayList<String>();
permissions.add(UserACL.EVERYONE);
- gateIn.getRegistryService().createOrReplaceContentIn(category.getName(), name,
contentType, contentId.toString(), name, null, permissions);
+ try
+ {
+ gateIn.begin();
- return new ManagedContentImpl<T>(name, contentId, this);
+ final ApplicationRegistryService registryService = gateIn.getRegistryService();
+ final Application application =
registryService.createOrUpdateApplication(category.getName(), name, contentType,
contentId.toString(), name, null, permissions);
+ return new ManagedContentImpl<T>(name, contentId, application, this);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ finally
+ {
+ gateIn.end();
+ }
}
private ContentType<?> getContentTypeFor(Type type)
@@ -235,7 +248,7 @@
}
final Id<? extends Content> contentId =
GateInImpl.getContentIdFrom(application);
- return new ManagedContentImpl(name, contentId, this);
+ return new ManagedContentImpl(name, contentId, application, this);
}
public IterableCollection<String> getKnownManagedContentNames()
@@ -270,30 +283,8 @@
return category.getDisplayName();
}
- public GateIn getGateIn()
+ public GateInImpl getGateIn()
{
return gateIn;
}
-
- void renameManagedContent(String oldName, String newName)
- {
- Application application = getApplication(oldName);
- if (application != null)
- {
- 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/ManagedContentImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/ManagedContentImpl.java 2011-08-08
17:17:41 UTC (rev 7009)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/ManagedContentImpl.java 2011-08-08
17:51:25 UTC (rev 7010)
@@ -23,11 +23,11 @@
package org.gatein.portal.api.impl.content;
-import org.gatein.api.GateIn;
+import org.exoplatform.application.registry.Application;
import org.gatein.api.content.Content;
import org.gatein.api.content.ManagedContent;
import org.gatein.api.id.Id;
-import org.gatein.common.util.ParameterValidation;
+import org.gatein.portal.api.impl.GateInImpl;
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
@@ -39,26 +39,14 @@
private final Id<T> contentId;
private final Id<ManagedContent<T>> id;
private final CategoryImpl category;
- private String name;
- private String displayName;
- private String description;
+ private final Application application;
-
- ManagedContentImpl(T content, CategoryImpl category)
+ ManagedContentImpl(String name, Id contentId, Application application, CategoryImpl
category)
{
- ParameterValidation.throwIllegalArgExceptionIfNull(content, "Content");
- this.content = content;
- this.contentId = content.getId();
- this.id = content.getGateIn().managedContentId(category.getId(), content.getName(),
content.getId());
- this.category = category;
- }
-
- ManagedContentImpl(String name, Id contentId, CategoryImpl category)
- {
- this.name = name;
this.contentId = contentId;
this.id = category.getGateIn().managedContentId(category.getId(), name,
contentId);
this.category = category;
+ this.application = application;
}
@Override
@@ -74,38 +62,36 @@
public String getName()
{
- if (name != null)
- {
- return name;
- }
- return getContent().getName();
+ return application.getApplicationName();
}
- public void setName(String name)
+ public String getDisplayName()
{
- category.renameManagedContent(this.name, name);
- this.name = name;
+ return application.getDisplayName();
}
- public String getDisplayName()
+ public void setDisplayName(String displayName)
{
- if (displayName != null)
- {
- return displayName;
- }
- return getContent().getDisplayName();
+ application.setDisplayName(displayName);
+ save();
}
- public GateIn getGateIn()
+ public String getDescription()
{
- return getContent().getGateIn();
+ return application.getDescription();
}
- public void setDisplayName(String displayName)
+ public void setDescription(String description)
{
- this.displayName = displayName;
+ application.setDescription(description);
+ save();
}
+ public GateInImpl getGateIn()
+ {
+ return category.getGateIn();
+ }
+
public T getContent()
{
if (content == null)
@@ -116,13 +102,20 @@
return content;
}
- public String getDescription()
+ private void save()
{
- return description;
+ try
+ {
+ getGateIn().begin();
+ getGateIn().getRegistryService().update(application);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ finally
+ {
+ getGateIn().end();
+ }
}
-
- public void setDescription(String description)
- {
- this.description = description;
- }
}
Modified:
portal/branches/api/component/application-registry/src/main/java/org/exoplatform/application/registry/ApplicationRegistryService.java
===================================================================
---
portal/branches/api/component/application-registry/src/main/java/org/exoplatform/application/registry/ApplicationRegistryService.java 2011-08-08
17:17:41 UTC (rev 7009)
+++
portal/branches/api/component/application-registry/src/main/java/org/exoplatform/application/registry/ApplicationRegistryService.java 2011-08-08
17:51:25 UTC (rev 7010)
@@ -159,7 +159,7 @@
*/
public void importExoGadgets() throws Exception;
- void createOrReplaceContentIn(String categoryName, String definitionName,
ContentType<?> contentType, String contentId, String displayName, String
description, List<String> permissions);
+ Application createOrUpdateApplication(String categoryName, String definitionName,
ContentType<?> contentType, String contentId, String displayName, String
description, List<String> permissions);
Application createApplicationFrom(org.gatein.pc.api.Portlet portlet);
}
\ No newline at end of file
Modified:
portal/branches/api/component/application-registry/src/main/java/org/exoplatform/application/registry/impl/ApplicationRegistryServiceImpl.java
===================================================================
---
portal/branches/api/component/application-registry/src/main/java/org/exoplatform/application/registry/impl/ApplicationRegistryServiceImpl.java 2011-08-08
17:17:41 UTC (rev 7009)
+++
portal/branches/api/component/application-registry/src/main/java/org/exoplatform/application/registry/impl/ApplicationRegistryServiceImpl.java 2011-08-08
17:51:25 UTC (rev 7010)
@@ -402,7 +402,7 @@
}
}
- public void createOrReplaceContentIn(String categoryName, String definitionName,
ContentType<?> contentType, String contentId, String displayName, String
description, List<String> permissions)
+ public Application createOrUpdateApplication(String categoryName, String
definitionName, ContentType<?> contentType, String contentId, String displayName,
String description, List<String> permissions)
{
CategoryDefinition definition = getOrCreateCategoryDefinition(categoryName,
permissions);
ContentDefinition content = definition.getContentMap().get(definitionName);
@@ -410,6 +410,13 @@
{
content = createContent(definitionName, contentType, contentId, displayName,
description, permissions, definition);
}
+ else
+ {
+ content.setAccessPermissions(permissions);
+ content.setDescription(description);
+ content.setDisplayName(displayName);
+ }
+ return load(content);
}
private ContentDefinition createContent(String definitionName, ContentType<?>
contentType, String contentId, String displayName, String description, List<String>
permissions, CategoryDefinition category)
Modified:
portal/branches/api/examples/portlets/api/src/main/java/org/gatein/portal/samples/api/ContentRegistryPortlet.java
===================================================================
---
portal/branches/api/examples/portlets/api/src/main/java/org/gatein/portal/samples/api/ContentRegistryPortlet.java 2011-08-08
17:17:41 UTC (rev 7009)
+++
portal/branches/api/examples/portlets/api/src/main/java/org/gatein/portal/samples/api/ContentRegistryPortlet.java 2011-08-08
17:51:25 UTC (rev 7010)
@@ -83,6 +83,7 @@
private void outputManagedContent(ManagedContent content, PrintWriter writer) throws
IOException
{
writer.println("<h3>" + content.getDisplayName() +
"</h3>");
+ writer.println("<h4>Name:" + content.getName() +
"</h4>");
writer.println("Content: " + content.getContent());
writer.println("<br/>");
}