[gatein-commits] gatein SVN: r8853 - in epp/portal/branches/EPP_5_2_2_GA_BZ851985: component/portal/src/main/java/org/exoplatform/portal/mop/user and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Sep 28 10:54:40 EDT 2012


Author: mputz
Date: 2012-09-28 10:54:40 -0400 (Fri, 28 Sep 2012)
New Revision: 8853

Modified:
   epp/portal/branches/EPP_5_2_2_GA_BZ851985/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeContext.java
   epp/portal/branches/EPP_5_2_2_GA_BZ851985/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodeFilter.java
   epp/portal/branches/EPP_5_2_2_GA_BZ851985/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodeFilterConfig.java
   epp/portal/branches/EPP_5_2_2_GA_BZ851985/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageActionListener.java
   epp/portal/branches/EPP_5_2_2_GA_BZ851985/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIApplicationList.java
Log:
Resolved BZ#851985 - Performance issue in EPP 5.2 due to additional pages being loaded

Modified: epp/portal/branches/EPP_5_2_2_GA_BZ851985/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeContext.java
===================================================================
--- epp/portal/branches/EPP_5_2_2_GA_BZ851985/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeContext.java	2012-09-28 14:48:13 UTC (rev 8852)
+++ epp/portal/branches/EPP_5_2_2_GA_BZ851985/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeContext.java	2012-09-28 14:54:40 UTC (rev 8853)
@@ -304,7 +304,7 @@
 
    private void doFilter(int depth, NodeFilter filter)
    {
-      boolean accept = filter.accept(depth, getId(), name, getState());
+      boolean accept = filter.accept(depth, getId(), getName(), getState());
       setHidden(!accept);
       if (expanded)
       {

Modified: epp/portal/branches/EPP_5_2_2_GA_BZ851985/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodeFilter.java
===================================================================
--- epp/portal/branches/EPP_5_2_2_GA_BZ851985/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodeFilter.java	2012-09-28 14:48:13 UTC (rev 8852)
+++ epp/portal/branches/EPP_5_2_2_GA_BZ851985/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodeFilter.java	2012-09-28 14:54:40 UTC (rev 8853)
@@ -96,6 +96,10 @@
 
    public boolean accept(int depth, String id, String name, NodeState state)
    {
+      if (config.customFilter != null && !config.customFilter.accept(depth, id, name, state)) 
+	  {
+	    return false; 
+	  }
       Visibility visibility = state.getVisibility();
 
       // Correct null -> displayed

Modified: epp/portal/branches/EPP_5_2_2_GA_BZ851985/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodeFilterConfig.java
===================================================================
--- epp/portal/branches/EPP_5_2_2_GA_BZ851985/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodeFilterConfig.java	2012-09-28 14:48:13 UTC (rev 8852)
+++ epp/portal/branches/EPP_5_2_2_GA_BZ851985/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodeFilterConfig.java	2012-09-28 14:54:40 UTC (rev 8853)
@@ -21,7 +21,7 @@
 
 import org.exoplatform.commons.utils.Safe;
 import org.exoplatform.portal.mop.Visibility;
-
+import org.exoplatform.portal.mop.navigation.NodeFilter;
 import java.util.Collections;
 import java.util.EnumSet;
 import java.util.Set;
@@ -50,6 +50,9 @@
 
    /** . */
    final boolean temporalCheck;
+   
+   /** . */
+   final NodeFilter customFilter;
 
    public UserNodeFilterConfig(Builder builder)
    {
@@ -62,6 +65,7 @@
       this.visibility = Safe.unmodifiableSet(builder.withVisibility);
       this.authorizationMode = builder.withAuthorizationMode;
       this.temporalCheck = builder.withTemporalCheck;
+	  this.customFilter = builder.withCustomFilter;
    }
 
    public Set<Visibility> getVisibility()
@@ -100,6 +104,9 @@
 
       /** . */
       private boolean withTemporalCheck;
+	  
+	  /** . */
+	  private NodeFilter withCustomFilter;
 
       private Builder()
       {
@@ -191,6 +198,12 @@
          this.withAuthorizationMode = AUTH_NO_CHECK;
          return this;
       }
+	  
+	  public Builder withCustomFilter(NodeFilter customFilter)
+	  {
+        this.withCustomFilter = customFilter;
+		return this;
+      }
 
       public UserNodeFilterConfig build()
       {

Modified: epp/portal/branches/EPP_5_2_2_GA_BZ851985/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageActionListener.java
===================================================================
--- epp/portal/branches/EPP_5_2_2_GA_BZ851985/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageActionListener.java	2012-09-28 14:48:13 UTC (rev 8852)
+++ epp/portal/branches/EPP_5_2_2_GA_BZ851985/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageActionListener.java	2012-09-28 14:54:40 UTC (rev 8853)
@@ -19,15 +19,19 @@
 
 package org.exoplatform.portal.webui.page;
 
+import org.apache.commons.lang.StringUtils;
 import org.exoplatform.portal.application.PortalRequestContext;
 import org.exoplatform.portal.config.DataStorage;
 import org.exoplatform.portal.config.UserPortalConfig;
+import org.exoplatform.portal.config.UserPortalConfigService;
 import org.exoplatform.portal.config.model.Container;
 import org.exoplatform.portal.config.model.ModelObject;
 import org.exoplatform.portal.config.model.Page;
 import org.exoplatform.portal.config.model.PortalConfig;
 import org.exoplatform.portal.mop.SiteKey;
 import org.exoplatform.portal.mop.SiteType;
+import org.exoplatform.portal.mop.navigation.NodeFilter;
+import org.exoplatform.portal.mop.navigation.NodeState;
 import org.exoplatform.portal.mop.user.UserNavigation;
 import org.exoplatform.portal.mop.user.UserNode;
 import org.exoplatform.portal.mop.user.UserNodeFilterConfig;
@@ -36,6 +40,7 @@
 import org.exoplatform.portal.webui.portal.PageNodeEvent;
 import org.exoplatform.portal.webui.portal.UIPortal;
 import org.exoplatform.portal.webui.util.PortalDataMapper;
+import org.exoplatform.portal.webui.util.Util;
 import org.exoplatform.portal.webui.workspace.UIPortalApplication;
 import org.exoplatform.portal.webui.workspace.UIWorkingWorkspace;
 import org.exoplatform.web.application.ApplicationMessage;
@@ -64,11 +69,17 @@
          UIPortalApplication uiPortalApp = event.getSource();
          UIPortal showedUIPortal = uiPortalApp.getCurrentSite();
    
-         UserNodeFilterConfig.Builder builder = UserNodeFilterConfig.builder();
-         builder.withReadCheck();
 
+
          PageNodeEvent<UIPortalApplication> pageNodeEvent = (PageNodeEvent<UIPortalApplication>)event;
          String nodePath = pageNodeEvent.getTargetNodeUri();
+		          
+         UserNodeFilterConfig.Builder pathFilterBuild = UserNodeFilterConfig.builder();
+         pathFilterBuild.withReadCheck();
+         pathFilterBuild.withCustomFilter(new PathFilter(nodePath));
+         
+         UserNodeFilterConfig.Builder defNodeBuild = UserNodeFilterConfig.builder();
+         defNodeBuild.withCustomFilter(new DefaultNodeFilter()); 
 
          UserNode targetNode = null;
          SiteKey siteKey = pageNodeEvent.getSiteKey();
@@ -77,13 +88,13 @@
             UserNavigation navigation = userPortal.getNavigation(siteKey);
             if (navigation != null)
             {
-               targetNode = userPortal.resolvePath(navigation, builder.build(), nodePath);
+               targetNode = userPortal.resolvePath(navigation, pathFilterBuild.build(), nodePath);
                if (targetNode == null)
                {
                   // If unauthenticated users have no permission on PORTAL node and URL is valid, they will be required to login
                   if (pcontext.getRemoteUser() == null && siteKey.getType().equals(SiteType.PORTAL))
                   {
-                     targetNode = userPortal.resolvePath(navigation, builder.withAuthMode(UserNodeFilterConfig.AUTH_NO_CHECK).build(), nodePath); 
+                      targetNode = userPortal.resolvePath(navigation, null, nodePath); 
                      if (targetNode != null)
                      {
                         uiPortalApp.setLastRequestURI(null);
@@ -94,7 +105,7 @@
                   else
                   {
                      // If path to node is invalid, get the default node instead of.
-                     targetNode = userPortal.getDefaultPath(navigation, builder.build());
+                     targetNode = userPortal.getDefaultPath(navigation, defNodeBuild.build());
                   }
                }
             }
@@ -102,7 +113,7 @@
          
          if (targetNode == null)
          {
-            targetNode = userPortal.getDefaultPath(builder.build());
+            targetNode = userPortal.getDefaultPath(defNodeBuild.build());
             if (targetNode == null)
             {
                if (showedUIPortal != null)
@@ -184,8 +195,84 @@
          //Reset selected navigation on userPortalConfig
          PortalDataMapper.toUIPortal(uiPortal, userPortalConfig.getPortalConfig());
          return uiPortal;
+      }      
+      
+      private class PathFilter implements NodeFilter
+      {
+         private List<String> paths;
+         
+         public PathFilter(String nodePath)
+         {
+            String[] tmp = StringUtils.split(nodePath, "/");
+            
+            paths = new ArrayList<String>();
+            if (tmp != null)
+            {
+               for (String str : tmp)
+               {
+                  if (str != null && !"".equals(str.trim()))
+                  {
+                     paths.add(str.trim());
+                  }
+               }
+            }
+         }
+         
+         @Override
+         public boolean accept(int depth, String id, String name, NodeState state)
+         {            
+            return depth == 0 || (depth <= paths.size() && paths.get(depth -1).equals(name));
+         }
       }
-   }
+      
+      private class DefaultNodeFilter implements NodeFilter
+      {
+         private boolean found;         
+         
+         @Override
+         public boolean accept(int depth, String id, String name, NodeState state)
+         {            
+            if (depth == 0)
+            {
+               return true;               
+            }
+            else
+            {
+               if (found)
+               {
+                  return false;
+               }
+               else
+               {
+                  found = hasPermission(state.getPageRef());
+                  return found;                  
+               }               
+            }
+         }
+         
+         private boolean hasPermission(String pageRef)
+         {
+            UIPortalApplication uiPortalApp = Util.getUIPortalApplication();
+            UserPortalConfigService service = uiPortalApp.getApplicationComponent(UserPortalConfigService.class);
+            if (pageRef != null)
+            {
+               try
+               {
+                  Page page = service.getPage(pageRef);
+                  if (page != null)
+                  {
+                     return service.getUserACL().hasPermission(page);
+                  }
+               }
+               catch (Exception e) {}
+            }
+            return false;
+         }
+      }            
+    }
+   
+      
+
   
    static public class DeleteGadgetActionListener extends EventListener<UIPage>
    {

Modified: epp/portal/branches/EPP_5_2_2_GA_BZ851985/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIApplicationList.java
===================================================================
--- epp/portal/branches/EPP_5_2_2_GA_BZ851985/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIApplicationList.java	2012-09-28 14:48:13 UTC (rev 8852)
+++ epp/portal/branches/EPP_5_2_2_GA_BZ851985/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIApplicationList.java	2012-09-28 14:54:40 UTC (rev 8853)
@@ -90,8 +90,35 @@
    {
       if (selectedCategory == null)
          return null;
-      List<Application> apps = selectedCategory.getApplications();
 
+      String remoteUser = Util.getPortalRequestContext().getRemoteUser();
+      if (remoteUser == null || remoteUser.equals(""))
+      { return null; }         
+         
+      ApplicationRegistryService service = getApplicationComponent(ApplicationRegistryService.class);
+      UserACL userACL = Util.getUIPortalApplication().getApplicationComponent(UserACL.class);
+               
+      List<Application> allApps = selectedCategory.getApplications();
+      List<Application> apps = new ArrayList<Application>();
+      
+      for (Application app : allApps)      
+      {
+         List<String> accessPermission = app.getAccessPermissions();
+         if(accessPermission == null || accessPermission.size()==0)
+         {
+            continue;
+         }  
+         accessCheck:
+         for (String p : accessPermission)
+         {
+            if (userACL.hasPermission(p))
+            {
+               apps.add(app);
+            }
+            break accessCheck;
+         }         
+      }    
+
       //Correct IconURL of Gadget
       GadgetRegistryService gadgetService = getApplicationComponent(GadgetRegistryService.class);
       for (Application app : apps)
@@ -199,4 +226,4 @@
       }
 
    }
-}
\ No newline at end of file
+}



More information about the gatein-commits mailing list