Author: chris.laprun(a)jboss.com
Date: 2011-07-23 09:48:27 -0400 (Sat, 23 Jul 2011)
New Revision: 6920
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/impl/ApplicationRegistryServiceImpl.java
Log:
- Added createdOrReplaceContentIn method to be able to create content from the API
implementation without needing to depend on lower-level classes.
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-07-22
15:28:32 UTC (rev 6919)
+++
portal/branches/api/component/application-registry/src/main/java/org/exoplatform/application/registry/ApplicationRegistryService.java 2011-07-23
13:48:27 UTC (rev 6920)
@@ -21,6 +21,7 @@
import org.exoplatform.container.component.ComponentPlugin;
import org.exoplatform.portal.config.model.ApplicationType;
+import org.gatein.mop.api.content.ContentType;
import java.util.Comparator;
import java.util.List;
@@ -31,21 +32,21 @@
String REMOTE_DISPLAY_NAME_SUFFIX = " (remote)";
/**
- * Return list of ApplicationCatgory (and applications in each category)
+ * Return list of ApplicationCatgory (and applications in each category)
+ *
* @param accessUser
- * @param appTypes - array of ApplicationType, used to filter applications in each
application category
- */
+ * @param appTypes - array of ApplicationType, used to filter applications in each
application category
+ */
public List<ApplicationCategory> getApplicationCategories(String accessUser,
ApplicationType<?>... appTypes) throws Exception;
public void initListener(ComponentPlugin com) throws Exception;
- /**
- * Return list of all current application categories (unsorted, all Application in all
ApplicationType)
- */
+ /** Return list of all current application categories (unsorted, all Application in
all ApplicationType) */
public List<ApplicationCategory> getApplicationCategories() throws Exception;
/**
* Return list of all current application categories (sorted, all applications in all
types)
+ *
* @param sortComparator - Comparator used to sort the returned list
*/
public List<ApplicationCategory>
getApplicationCategories(Comparator<ApplicationCategory> sortComparator)
@@ -54,6 +55,7 @@
/**
* Return ApplicationCategory with name provided <br/>
* if not found, return null
+ *
* @param name - ApplicationCategory's name
*/
public ApplicationCategory getApplicationCategory(String name) throws Exception;
@@ -61,6 +63,7 @@
/**
* Save an ApplicationCategory to database <br/>
* If it doesn't exist, a new one will be created, if not, it will be updated
+ *
* @param category - ApplicationCategory object that will be saved
*/
public void save(ApplicationCategory category) throws Exception;
@@ -68,12 +71,14 @@
/**
* Remove application category (and all application in it) from database <br/>
* If it doesn't exist, it will be ignored
+ *
* @param category - ApplicationCategory object that will be removed
*/
public void remove(ApplicationCategory category) throws Exception;
/**
* Return list of applications (unsorted) in specific category and have specific type
+ *
* @param category - ApplicationCategory that you want to list applications
* @param appTypes - array of application type
*/
@@ -81,12 +86,14 @@
/**
* Return list of applications (sorted) in specific category and have specific type
- * @param category - ApplicationCategory that you want to list applications
+ *
+ * @param category - ApplicationCategory that you want to list applications
* @param sortComparator - comparator used to sort application list
- * @param appTypes - array of application type
+ * @param appTypes - array of application type
*/
public List<Application> getApplications(ApplicationCategory category,
Comparator<Application> sortComparator,
ApplicationType<?>... appTypes) throws
Exception;
+
/**
* Return list of all Application in database (unsorted) <br/>
* If there are not any Application in database, return an empty list
@@ -95,6 +102,7 @@
/**
* Return Application with id provided
+ *
* @param id - must be valid applicationId (catgoryname/applicationName), if not, this
will throw exception
*/
public Application getApplication(String id) throws Exception;
@@ -102,8 +110,9 @@
/**
* Return Application in specific category and have name provided in param
<br/>
* If it can't be found, return null
+ *
* @param category - name of application category
- * @param name - name of application
+ * @param name - name of application
*/
public Application getApplication(String category, String name) throws Exception;
@@ -111,14 +120,16 @@
* Save Application in an ApplicationCategory <br/>
* If ApplicationCategory or Application don't exist, they'll be created
<br/>
* If Application has been already existed, it will be updated <br/>
- * @param category - ApplicationCategory that your application'll be saved to
- * @param application - Application that will be saved
+ *
+ * @param category - ApplicationCategory that your application'll be saved to
+ * @param application - Application that will be saved
*/
public void save(ApplicationCategory category, Application application) throws
Exception;
/**
* Update an Application <br/>
* It must be existed in database, if not, this will throw an IllegalStateException
+ *
* @param application - Application that you want to update
*/
public void update(Application application) throws Exception;
@@ -126,6 +137,7 @@
/**
* Remove an Application from database <br/>
* If it can't be found, it will be ignored (no exception)
+ *
* @param app - Application that you want to remove, must not be null
*/
public void remove(Application app) throws Exception;
@@ -133,16 +145,19 @@
/**
* Get all deployed portlet, add to portlet's ApplicationCategory <br/>
* If ApplicationCategory currently doesn't exist, it'll be created
<br/>
- * If Application've already existed, it'll be ignored
+ * If Application've already existed, it'll be ignored
*/
public void importAllPortlets() throws Exception;
//TODO: dang.tung
+
/**
* Get all Gadget, add to eXoGadgets application category <br/>
* When first added, it's access permission will be Everyone <br/>
* If ApplicationCategory currently doesn't exist, it'll be created
<br/>
- * Gadget that has been imported will be ignored
+ * Gadget that has been imported will be ignored
*/
public void importExoGadgets() throws Exception;
+
+ void createOrReplaceContentIn(String categoryName, String definitionName,
ContentType<?> contentType, String contentId, String displayName, String
description, List<String> permissions);
}
\ 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-07-22
15:28:32 UTC (rev 6919)
+++
portal/branches/api/component/application-registry/src/main/java/org/exoplatform/application/registry/impl/ApplicationRegistryServiceImpl.java 2011-07-23
13:48:27 UTC (rev 6920)
@@ -259,7 +259,7 @@
// If the application name contained a beginning slash (which can happen with
WSRP), we need to hack around the
// hardcoding of portlet id expectations >_<
- if(fragments.length == 3 && applicationName.length() == 0)
+ if (fragments.length == 3 && applicationName.length() == 0)
{
applicationName = "/" + fragments[2];
}
@@ -371,8 +371,6 @@
public void importExoGadgets() throws Exception
{
- ContentRegistry registry = getContentRegistry();
-
//
ExoContainer container = ExoContainerContext.getCurrentContainer();
GadgetRegistryService gadgetService =
(GadgetRegistryService)container.getComponentInstanceOfType(GadgetRegistryService.class);
@@ -386,22 +384,16 @@
String categoryName = "Gadgets";
//
- CategoryDefinition category = registry.getCategory(categoryName);
- if (category == null)
- {
- category = registry.createCategory(categoryName);
- category.setDisplayName(categoryName);
- category.setDescription(categoryName);
- category.setAccessPermissions(permissions);
- }
+ CategoryDefinition category = getOrCreateCategoryDefinition(categoryName,
permissions);
//
for (Gadget ele : eXoGadgets)
{
- ContentDefinition app = category.getContentMap().get(ele.getName());
+ String name = ele.getName();
+ ContentDefinition app = category.getContentMap().get(name);
if (app == null)
{
- app = category.createContent(ele.getName(),
org.exoplatform.portal.pom.spi.gadget.Gadget.CONTENT_TYPE, ele.getName());
+ app = category.createContent(name,
org.exoplatform.portal.pom.spi.gadget.Gadget.CONTENT_TYPE, name);
app.setDisplayName(ele.getTitle());
app.setDescription(ele.getDescription());
app.setAccessPermissions(permissions);
@@ -410,6 +402,33 @@
}
}
+ public void createOrReplaceContentIn(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);
+ if (content == null)
+ {
+ content = definition.createContent(definitionName, contentType, contentId);
+ content.setDisplayName(displayName);
+ content.setDescription(description);
+ content.setAccessPermissions(permissions);
+ }
+ }
+
+ private CategoryDefinition getOrCreateCategoryDefinition(String categoryName,
List<String> permissions)
+ {
+ ContentRegistry registry = getContentRegistry();
+ CategoryDefinition category = registry.getCategory(categoryName);
+ if (category == null)
+ {
+ category = registry.createCategory(categoryName);
+ category.setDisplayName(categoryName);
+ category.setDescription(categoryName);
+ category.setAccessPermissions(permissions);
+ }
+ return category;
+ }
+
public void importAllPortlets() throws Exception
{
ContentRegistry registry = getContentRegistry();
@@ -492,17 +511,9 @@
// Process category names
for (String categoryName : categoryNames)
{
- CategoryDefinition category = registry.getCategory(categoryName);
+ CategoryDefinition category = getOrCreateCategoryDefinition(categoryName,
permissions);
//
- if (category == null)
- {
- category = registry.createCategory(categoryName);
- category.setDisplayName(categoryName);
- category.setAccessPermissions(permissions);
- }
-
- //
ContentDefinition app = category.getContentMap().get(portletName);
if (app == null)
{
@@ -535,7 +546,7 @@
break;
}
}
-
+
if (!isExist)
{
app = category.createContent(portletName, contentType, contentId);