Author: chris.laprun(a)jboss.com
Date: 2011-08-03 15:36:59 -0400 (Wed, 03 Aug 2011)
New Revision: 6991
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
portal/branches/api/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIAddApplicationForm.java
Log:
- Added ApplicationRegistryService.createApplicationFrom method so that we can avoid some
code duplication.
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-03
17:58:06 UTC (rev 6990)
+++
portal/branches/api/component/application-registry/src/main/java/org/exoplatform/application/registry/ApplicationRegistryService.java 2011-08-03
19:36:59 UTC (rev 6991)
@@ -160,4 +160,6 @@
public void importExoGadgets() throws Exception;
void createOrReplaceContentIn(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-03
17:58:06 UTC (rev 6990)
+++
portal/branches/api/component/application-registry/src/main/java/org/exoplatform/application/registry/impl/ApplicationRegistryServiceImpl.java 2011-08-03
19:36:59 UTC (rev 6991)
@@ -408,13 +408,24 @@
ContentDefinition content = definition.getContentMap().get(definitionName);
if (content == null)
{
- content = definition.createContent(definitionName, contentType, contentId);
- content.setDisplayName(displayName);
- content.setDescription(description);
- content.setAccessPermissions(permissions);
+ content = createContent(definitionName, contentType, contentId, displayName,
description, permissions, definition);
}
}
+ private ContentDefinition createContent(String definitionName, ContentType<?>
contentType, String contentId, String displayName, String description, List<String>
permissions, CategoryDefinition category)
+ {
+ ContentDefinition content = category.createContent(definitionName, contentType,
contentId);
+ content.setDisplayName(displayName);
+ content.setDescription(description);
+ content.setAccessPermissions(permissions);
+ return content;
+ }
+
+ private ContentDefinition createContentFrom(Application application,
CategoryDefinition category)
+ {
+ return createContent(application.getApplicationName(),
application.getType().getContentType(), application.getContentId(),
application.getDisplayName(), application.getDescription(),
application.getAccessPermissions(), category);
+ }
+
private CategoryDefinition getOrCreateCategoryDefinition(String categoryName,
List<String> permissions)
{
ContentRegistry registry = getContentRegistry();
@@ -431,8 +442,6 @@
public void importAllPortlets() throws Exception
{
- ContentRegistry registry = getContentRegistry();
-
//
log.info("About to import portlets in application registry");
@@ -446,21 +455,17 @@
for (org.gatein.pc.api.Portlet portlet : portlets)
{
PortletInfo info = portlet.getInfo();
+
+ final Application application = createApplicationFrom(portlet);
+
String portletApplicationName = info.getApplicationName();
- String portletName = portlet.getContext().getId();
+ final String portletName = application.getApplicationName();
- // Need to sanitize portlet and application names in case they contain
characters that would
- // cause an improper Application name
- portletApplicationName = portletApplicationName.replace('/',
'_');
- portletName = portletName.replace('/', '_');
-
MetaInfo metaInfo = portlet.getInfo().getMeta();
LocalizedString keywordsLS = metaInfo.getMetaValue(MetaInfo.KEYWORDS);
- //
+ // Process keywords
Set<String> categoryNames = new HashSet<String>();
-
- // Process keywords
if (keywordsLS != null)
{
String keywords = keywordsLS.getDefaultString();
@@ -517,30 +522,12 @@
ContentDefinition app = category.getContentMap().get(portletName);
if (app == null)
{
- LocalizedString descriptionLS =
metaInfo.getMetaValue(MetaInfo.DESCRIPTION);
- LocalizedString displayNameLS =
metaInfo.getMetaValue(MetaInfo.DISPLAY_NAME);
- String displayName = getLocalizedStringValue(displayNameLS, portletName);
-
- ContentType<?> contentType;
- String contentId;
- if (remote)
- {
- contentType = WSRP.CONTENT_TYPE;
- contentId = portlet.getContext().getId();
- displayName += REMOTE_DISPLAY_NAME_SUFFIX; // add remote to display
name to make it more obvious that the portlet is remote
- }
- else
- {
- contentType = Portlet.CONTENT_TYPE;
- contentId = info.getApplicationName() + "/" +
info.getName();
- }
-
// Check if the portlet has already existed in this category
List<Application> applications = load(category).getApplications();
boolean isExist = false;
- for (Application application : applications)
+ for (Application categoryApp : applications)
{
- if (application.getContentId().equals(contentId))
+ if (categoryApp.getContentId().equals(application.getContentId()))
{
isExist = true;
break;
@@ -549,16 +536,69 @@
if (!isExist)
{
- app = category.createContent(portletName, contentType, contentId);
- app.setDisplayName(displayName);
- app.setDescription(getLocalizedStringValue(descriptionLS,
portletName));
- app.setAccessPermissions(permissions);
+ app = createContentFrom(application, category);
}
}
}
}
}
+ public Application createApplicationFrom(org.gatein.pc.api.Portlet portlet)
+ {
+ PortletInfo info = portlet.getInfo();
+
+ String portletName = portlet.getContext().getId();
+
+ portletName = sanitize(portletName);
+
+ MetaInfo metaInfo = portlet.getInfo().getMeta();
+
+ ArrayList<String> permissions = new ArrayList<String>();
+ permissions.add(UserACL.EVERYONE);
+
+ // Additionally categorise the portlet as remote
+ boolean remote = portlet.isRemote();
+
+ LocalizedString descriptionLS = metaInfo.getMetaValue(MetaInfo.DESCRIPTION);
+ LocalizedString displayNameLS = metaInfo.getMetaValue(MetaInfo.DISPLAY_NAME);
+ String displayName = getLocalizedStringValue(displayNameLS, portletName);
+
+ ApplicationType appType;
+ String contentId;
+ if (remote)
+ {
+ appType = ApplicationType.WSRP_PORTLET;
+ contentId = portlet.getContext().getId();
+ displayName += REMOTE_DISPLAY_NAME_SUFFIX; // add remote to display name to
make it more obvious that the portlet is remote
+ }
+ else
+ {
+ appType = ApplicationType.PORTLET;
+ contentId = info.getApplicationName() + "/" + info.getName();
+ }
+
+ Application app = new Application();
+ app.setApplicationName(portletName);
+ app.setType(appType);
+ app.setDisplayName(displayName);
+ app.setDescription(getLocalizedStringValue(descriptionLS, portletName));
+ app.setAccessPermissions(permissions);
+ app.setContentId(contentId);
+
+ return app;
+ }
+
+ /**
+ * Sanitizes the specified name in case it contains characters that would cause
improper Application name.
+ *
+ * @param name
+ * @return
+ */
+ private String sanitize(String name)
+ {
+ return name.replace('/', '_');
+ }
+
private boolean isApplicationType(Application app, ApplicationType<?>...
appTypes)
{
if (appTypes == null || appTypes.length == 0)
Modified:
portal/branches/api/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIAddApplicationForm.java
===================================================================
---
portal/branches/api/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIAddApplicationForm.java 2011-08-03
17:58:06 UTC (rev 6990)
+++
portal/branches/api/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIAddApplicationForm.java 2011-08-03
19:36:59 UTC (rev 6991)
@@ -185,41 +185,17 @@
{
ExoContainer manager = ExoContainerContext.getCurrentContainer();
+ ApplicationRegistryService appRegistry =
+
(ApplicationRegistryService)manager.getComponentInstance(ApplicationRegistryService.class);
+
FederatingPortletInvoker portletInvoker =
(FederatingPortletInvoker)manager.getComponentInstance(FederatingPortletInvoker.class);
Set<Portlet> portlets = remote ? portletInvoker.getRemotePortlets() :
portletInvoker.getLocalPortlets();
+
List<Application> applications = new
ArrayList<Application>(portlets.size());
for (Portlet portlet : portlets)
{
- PortletInfo info = portlet.getInfo();
-
- LocalizedString descriptionLS =
info.getMeta().getMetaValue(MetaInfo.DESCRIPTION);
- LocalizedString displayNameLS =
info.getMeta().getMetaValue(MetaInfo.DISPLAY_NAME);
-
- String portletName = info.getName();
- Application app = new Application();
- app.setApplicationName(portletName);
- // app.setApplicationGroup(info.getApplicationName());
- ApplicationType appType;
- String contentId;
- String displayName = Util.getLocalizedStringValue(displayNameLS, portletName);
- if (remote)
- {
- appType = ApplicationType.WSRP_PORTLET;
- contentId = portlet.getContext().getId();
- displayName += ApplicationRegistryService.REMOTE_DISPLAY_NAME_SUFFIX; // add
remote to display name to make it more obvious that the portlet is remote
- }
- else
- {
- appType = ApplicationType.PORTLET;
- contentId = info.getApplicationName() + "/" + info.getName();
- }
- app.setType(appType);
- app.setDisplayName(displayName);
- app.setDescription(Util.getLocalizedStringValue(descriptionLS, portletName));
- app.setAccessPermissions(new ArrayList<String>());
- app.setContentId(contentId);
- applications.add(app);
+ applications.add(appRegistry.createApplicationFrom(portlet));
}
return applications;