Author: hoang_to
Date: 2011-07-22 06:46:32 -0400 (Fri, 22 Jul 2011)
New Revision: 6915
Modified:
portal/branches/branch-GTNPORTAL-1963/component/application-registry/src/main/java/org/exoplatform/application/registry/impl/ApplicationRegistryServiceImpl.java
portal/branches/branch-GTNPORTAL-1963/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIApplicationList.java
Log:
GTNPORTAL-1959: Use lazy query from UI instead of cache on service component
Modified:
portal/branches/branch-GTNPORTAL-1963/component/application-registry/src/main/java/org/exoplatform/application/registry/impl/ApplicationRegistryServiceImpl.java
===================================================================
---
portal/branches/branch-GTNPORTAL-1963/component/application-registry/src/main/java/org/exoplatform/application/registry/impl/ApplicationRegistryServiceImpl.java 2011-07-22
10:09:29 UTC (rev 6914)
+++
portal/branches/branch-GTNPORTAL-1963/component/application-registry/src/main/java/org/exoplatform/application/registry/impl/ApplicationRegistryServiceImpl.java 2011-07-22
10:46:32 UTC (rev 6915)
@@ -52,7 +52,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import java.util.concurrent.atomic.AtomicReference;
/**
* The fundamental reason that motives to use tasks is because of the JMX access that
does not setup a context and
@@ -86,8 +85,6 @@
/** . */
final POMSessionManager mopManager;
- private final AtomicReference<List<ApplicationCategory>> allCategories;
-
/** Should match WSRPPortletInfo.PRODUCER_NAME_META_INFO_KEY */
private static final String PRODUCER_NAME_META_INFO_KEY = "producer-name";
public static final String PRODUCER_CATEGORY_NAME_SUFFIX = " Producer";
@@ -101,8 +98,6 @@
this.manager = manager;
this.lifeCycle = lifeCycle;
this.mopManager = mopManager;
-
- this.allCategories = new AtomicReference<List<ApplicationCategory>>();
}
public ContentRegistry getContentRegistry()
@@ -133,11 +128,6 @@
String accessUser,
final ApplicationType<?>... appTypes) throws Exception
{
- if(appTypes == null || appTypes.length == 0)
- {
- return getAllApplicationCategories(sortComparator);
- }
-
final List<ApplicationCategory> categories = new
ArrayList<ApplicationCategory>();
//
@@ -160,38 +150,6 @@
return categories;
}
- private List<ApplicationCategory>
getAllApplicationCategories(Comparator<ApplicationCategory> comparator) throws
Exception
- {
- if(allCategories.get() == null)
- {
- List<ApplicationCategory> categories = new
ArrayList<ApplicationCategory>();
- ContentRegistry registry = getContentRegistry();
-
- for(CategoryDefinition categoryDef : registry.getCategoryList())
- {
- ApplicationCategory category = new ApplicationCategory();
-
- category.setName(categoryDef.getName());
- category.setDisplayName(categoryDef.getDisplayName());
- category.setDescription(categoryDef.getDescription());
- category.setAccessPermissions(categoryDef.getAccessPermissions());
- category.setCreatedDate(categoryDef.getCreationDate());
- category.setModifiedDate(categoryDef.getLastModificationDate());
-
- for(ContentDefinition contentDef : categoryDef.getContentList())
- {
- category.getApplications().add(load(contentDef));
- }
-
- categories.add(category);
- }
-
- allCategories.compareAndSet(null, categories);
- }
-
- return allCategories.get();
- }
-
public List<ApplicationCategory> getApplicationCategories(String accessUser,
ApplicationType<?>... appTypes) throws Exception
{
return getApplicationCategories(null, accessUser, appTypes);
@@ -225,8 +183,6 @@
public void save(final ApplicationCategory category) throws Exception
{
- allCategories.set(null);
-
ContentRegistry registry = getContentRegistry();
//
@@ -249,8 +205,6 @@
public void remove(final ApplicationCategory category) throws Exception
{
- allCategories.set(null);
-
ContentRegistry registry = getContentRegistry();
registry.getCategoryMap().remove(category.getName());
}
@@ -333,8 +287,6 @@
public void save(final ApplicationCategory category, final Application application)
throws Exception
{
- allCategories.set(null);
-
ContentRegistry registry = getContentRegistry();
//
@@ -373,9 +325,6 @@
public void update(final Application application) throws Exception
{
- //Invalidate the categories cache
- allCategories.set(null);
-
ContentRegistry registry = getContentRegistry();
//
@@ -399,9 +348,6 @@
public void remove(final Application app) throws Exception
{
- //Invalidate the categories cache
- allCategories.set(null);
-
if (app == null)
{
throw new NullPointerException();
@@ -425,9 +371,6 @@
public void importExoGadgets() throws Exception
{
- //Invalidate the categories cache
- allCategories.set(null);
-
ContentRegistry registry = getContentRegistry();
//
@@ -469,9 +412,6 @@
public void importAllPortlets() throws Exception
{
- //Invalidate the categories cache
- allCategories.set(null);
-
ContentRegistry registry = getContentRegistry();
//
Modified:
portal/branches/branch-GTNPORTAL-1963/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIApplicationList.java
===================================================================
---
portal/branches/branch-GTNPORTAL-1963/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIApplicationList.java 2011-07-22
10:09:29 UTC (rev 6914)
+++
portal/branches/branch-GTNPORTAL-1963/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIApplicationList.java 2011-07-22
10:46:32 UTC (rev 6915)
@@ -54,51 +54,11 @@
public UIApplicationList() throws Exception
{
- ApplicationRegistryService service =
getApplicationComponent(ApplicationRegistryService.class);
- String remoteUser = Util.getPortalRequestContext().getRemoteUser();
- if (remoteUser == null || remoteUser.equals(""))
- return;
- UserACL userACL =
Util.getUIPortalApplication().getApplicationComponent(UserACL.class);
-
- PortletComparator portletComparator = new PortletComparator();
- categories = service.getApplicationCategories(remoteUser);
-
- Iterator<ApplicationCategory> cateItr = categories.iterator();
- while (cateItr.hasNext())
- {
- ApplicationCategory cate = cateItr.next();
- List<Application> applications = cate.getApplications();
- boolean hasPermission = false;
- List<String> accessPermission = cate.getAccessPermissions();
- if (accessPermission == null)
- {
- accessPermission = new ArrayList<String>();
- }
- if (accessPermission.size() == 0)
- {
- accessPermission.add(null);
- }
- for (String permssion : accessPermission)
- {
- hasPermission = userACL.hasPermission(permssion);
- if (hasPermission)
- break;
- }
-
- if (!hasPermission || applications.size() < 1)
- cateItr.remove();
- else
- Collections.sort(applications, portletComparator);
- }
- if (categories.size() > 0)
- setSelectedCategory(categories.get(0).getName());
-
- Collections.sort(categories, new PortletCategoryComparator());
}
public Application getApplication(String id) throws Exception
{
- for (ApplicationCategory category : categories)
+ for (ApplicationCategory category : getCategories())
{
List<Application> items = category.getApplications();
for (Application item : items)
@@ -117,7 +77,7 @@
public void setSelectedCategory(String categoryName)
{
- for (ApplicationCategory category : categories)
+ for (ApplicationCategory category : getCategories())
{
if (category.getName().equals(categoryName))
{
@@ -155,22 +115,76 @@
public List<ApplicationCategory> getCategories()
{
- return categories;
+ try
+ {
+ //TODO: Handle concurrent requests associated with current session
+ if (categories == null)
+ {
+ initAllCategories();
+ }
+ return categories;
+ }
+ catch (Exception ex)
+ {
+ return null;
+ }
}
- static class PortletCategoryComparator implements
Comparator<ApplicationCategory>
+ private void initAllCategories() throws Exception
{
- public int compare(ApplicationCategory cat1, ApplicationCategory cat2)
+ String remoteUser = Util.getPortalRequestContext().getRemoteUser();
+ if (remoteUser == null || remoteUser.equals(""))
+ { return; }
+
+ ApplicationRegistryService service =
getApplicationComponent(ApplicationRegistryService.class);
+ UserACL userACL =
Util.getUIPortalApplication().getApplicationComponent(UserACL.class);
+
+ final Comparator<Application> appComparator = new
Comparator<Application>()
{
- return cat1.getDisplayName().compareToIgnoreCase(cat2.getDisplayName());
+ public int compare(Application p_1, Application p_2)
+ {
+ return p_1.getDisplayName().compareToIgnoreCase(p_2.getDisplayName());
+ }
+ };
+ final Comparator<ApplicationCategory> cateComparator = new
Comparator<ApplicationCategory>()
+ {
+ public int compare(ApplicationCategory p_1, ApplicationCategory p_2)
+ {
+ return p_1.getDisplayName().compareToIgnoreCase(p_2.getDisplayName());
+ }
+ };
+
+ List<ApplicationCategory> allCategories =
service.getApplicationCategories(remoteUser);
+ categories = new ArrayList<ApplicationCategory>();
+
+ for (ApplicationCategory category : allCategories)
+ {
+ List<Application> apps = category.getApplications();
+ List<String> accessPermission = category.getAccessPermissions();
+ if(accessPermission == null)
+ {
+ continue;
+ }
+
+ accessCheck:
+ for (String p : accessPermission)
+ {
+ if (userACL.hasPermission(p))
+ {
+ if (apps.size() > 0)
+ {
+ Collections.sort(apps, appComparator);
+ }
+ categories.add(category);
+ }
+ break accessCheck;
+ }
}
- }
- static class PortletComparator implements Comparator<Application>
- {
- public int compare(Application p1, Application p2)
+ if (categories.size() > 0)
{
- return p1.getDisplayName().compareToIgnoreCase(p2.getDisplayName());
+ Collections.sort(categories, cateComparator);
+ selectedCategory = categories.get(0);
}
}