details:   /erp/devel/pi/rev/bffcb013674f
changeset: 10677:bffcb013674f
user:      Stefan Hühner <stefan.huehner <at> openbravo.com>
date:      Tue Feb 15 19:52:21 2011 +0100
summary:   Move user-dependant resources of 'static' part of getstaticresources;
to not create one cached web/js/gen/*.js file per user, mark parts
depending on the current user as dynamic so only a request for them
will be included in the generated file and not their (dynamic) content
as well.
- ApplicationComponentProvider mark MainLayout.Application as dynamic
  (as it contains the menu for the current user
- related change in MenuManger as now now done in a different request
- MyOpenbravoComponentProvider mark MyOpenbravoComponent as dynamic
  as its contains flags based on users access rights
- Split application-js.ftl into two parts
  application-js.ftl all parts not depending on current user
  application-dynamic-js.ftl for the parts moved out of application-js.ftl
  - similar add new ApplicationDynamiComponent + template definition
    related to the new application-dynamic-js.ftl
  - add specific getETag function to delcare the parameters the output
    depends on to get the correct caching behavior.

diffstat:

 
modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationComponentProvider.java
 |   6 +-
 
modules/org.openbravo.client.application/src/org/openbravo/client/application/MenuManager.java
                  |   5 +-
 
modules/org.openbravo.client.kernel/src-db/database/sourcedata/OBCLKER_TEMPLATE.xml
                             |  13 +
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/ApplicationComponent.java
                   |  15 +-
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/ApplicationDynamicComponent.java
            |  72 ++++++++++
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelComponentProvider.java
                |  15 +-
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelConstants.java
                        |   7 +
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/templates/application-dynamic-js.ftl
        |  40 +++++
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/templates/application-js.ftl
                |  23 +---
 
modules/org.openbravo.client.myob/src/org/openbravo/client/myob/MyOpenbravoComponentProvider.java
               |   4 +-
 10 files changed, 154 insertions(+), 46 deletions(-)

diffs (truncated from 355 to 300 lines):

diff -r 9d19ec616689 -r bffcb013674f 
modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationComponentProvider.java
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationComponentProvider.java
   Tue Feb 15 19:45:25 2011 +0100
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationComponentProvider.java
   Tue Feb 15 19:52:21 2011 +0100
@@ -245,9 +245,9 @@
             + KernelConstants.SKIN_VERSION_PARAMETER
             + "/org.openbravo.client.application/ob-application-styles.js", 
false));
 
-    // Application
-    globalResources.add(createStaticResource("org.openbravo.client.kernel/"
-        + ApplicationConstants.COMPONENT_TYPE + "/" + 
ApplicationConstants.MAIN_LAYOUT_ID, false));
+    // Application - dynamic as it contains the generated menu also (which is 
user/role dependant)
+    globalResources.add(createDynamicResource("org.openbravo.client.kernel/"
+        + ApplicationConstants.COMPONENT_TYPE + "/" + 
ApplicationConstants.MAIN_LAYOUT_ID));
 
     globalResources.add(createStaticResource(
         "web/org.openbravo.client.application/js/ob-view-manager.js", false));
diff -r 9d19ec616689 -r bffcb013674f 
modules/org.openbravo.client.application/src/org/openbravo/client/application/MenuManager.java
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/MenuManager.java
    Tue Feb 15 19:45:25 2011 +0100
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/MenuManager.java
    Tue Feb 15 19:52:21 2011 +0100
@@ -599,7 +599,10 @@
 
     public boolean isModal() {
       if (isProcess()) {
-        return Utility.isModalProcess(getMenu().getProcess());
+        // done via isModelProcess(String) as is called from different request 
and getProcess() is
+        // not initialized
+        String processId = (String) DalUtil.getId(getMenu().getProcess());
+        return Utility.isModalProcess(processId);
       }
       return true;
     }
diff -r 9d19ec616689 -r bffcb013674f 
modules/org.openbravo.client.kernel/src-db/database/sourcedata/OBCLKER_TEMPLATE.xml
--- 
a/modules/org.openbravo.client.kernel/src-db/database/sourcedata/OBCLKER_TEMPLATE.xml
       Tue Feb 15 19:45:25 2011 +0100
+++ 
b/modules/org.openbravo.client.kernel/src-db/database/sourcedata/OBCLKER_TEMPLATE.xml
       Tue Feb 15 19:52:21 2011 +0100
@@ -39,4 +39,17 @@
 <!--DBAC211182304F7784DAB4EDE7B6AA1D-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--DBAC211182304F7784DAB4EDE7B6AA1D--></OBCLKER_TEMPLATE>
 
+<!--FF8081812E297131012E2A061112001C--><OBCLKER_TEMPLATE>
+<!--FF8081812E297131012E2A061112001C-->  
<OBCLKER_TEMPLATE_ID><![CDATA[FF8081812E297131012E2A061112001C]]></OBCLKER_TEMPLATE_ID>
+<!--FF8081812E297131012E2A061112001C-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF8081812E297131012E2A061112001C-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF8081812E297131012E2A061112001C-->  
<AD_MODULE_ID><![CDATA[4B828F4D03264080AA1D2057B13F613C]]></AD_MODULE_ID>
+<!--FF8081812E297131012E2A061112001C-->  <NAME><![CDATA[Application template 
(dynamic parts)]]></NAME>
+<!--FF8081812E297131012E2A061112001C-->  <DESCRIPTION><![CDATA[Creates 
javacript for the User and accessibleEntities parts of the global openbravo 
object]]></DESCRIPTION>
+<!--FF8081812E297131012E2A061112001C-->  
<TEMPLATECLASSPATHLOCATION><![CDATA[/org/openbravo/client/kernel/templates/application-dynamic-js.ftl]]></TEMPLATECLASSPATHLOCATION>
+<!--FF8081812E297131012E2A061112001C-->  
<TEMPLATE_LANGUAGE><![CDATA[OBCLFRE_Freemarker]]></TEMPLATE_LANGUAGE>
+<!--FF8081812E297131012E2A061112001C-->  
<COMPONENT_TYPE><![CDATA[OBCLKER_Kernel]]></COMPONENT_TYPE>
+<!--FF8081812E297131012E2A061112001C-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF8081812E297131012E2A061112001C--></OBCLKER_TEMPLATE>
+
 </data>
diff -r 9d19ec616689 -r bffcb013674f 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/ApplicationComponent.java
--- 
a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/ApplicationComponent.java
     Tue Feb 15 19:45:25 2011 +0100
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/ApplicationComponent.java
     Tue Feb 15 19:52:21 2011 +0100
@@ -21,9 +21,7 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
-import java.util.Set;
 
-import org.openbravo.base.model.Entity;
 import org.openbravo.base.session.OBPropertiesProvider;
 import org.openbravo.client.kernel.reference.UIDefinitionController;
 import 
org.openbravo.client.kernel.reference.UIDefinitionController.FormatDefinition;
@@ -40,7 +38,7 @@
 import org.openbravo.model.common.enterprise.Organization;
 
 /**
- * The component responsible for generating the application js file.
+ * The component responsible for generating the static part of the application 
js file.
  * 
  * @author mtaal
  */
@@ -58,13 +56,6 @@
     return formatDefinition;
   }
 
-  public Set<Entity> getAccessibleEntities() {
-    final Set<Entity> entities = 
OBContext.getOBContext().getEntityAccessChecker()
-        .getReadableEntities();
-    
entities.addAll(OBContext.getOBContext().getEntityAccessChecker().getWritableEntities());
-    return entities;
-  }
-
   public String getDefaultGroupingSymbol() {
     return getFormatDefinition().getGroupingSymbol();
   }
@@ -104,18 +95,22 @@
     return props.getProperty(KernelConstants.DATETIME_FORMAT_PROPERTY, 
"dd-MM-yyyy HH:mm:ss");
   }
 
+  @Deprecated
   public User getUser() {
     return OBContext.getOBContext().getUser();
   }
 
+  @Deprecated
   public Client getClient() {
     return OBContext.getOBContext().getCurrentClient();
   }
 
+  @Deprecated
   public Organization getOrganization() {
     return OBContext.getOBContext().getCurrentOrganization();
   }
 
+  @Deprecated
   public Role getRole() {
     return OBContext.getOBContext().getRole();
   }
diff -r 9d19ec616689 -r bffcb013674f 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/ApplicationDynamicComponent.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/ApplicationDynamicComponent.java
      Tue Feb 15 19:52:21 2011 +0100
@@ -0,0 +1,72 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU 
+ * All portions are Copyright (C) 2010 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.client.kernel;
+
+import java.util.Set;
+
+import org.openbravo.base.model.Entity;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.ad.access.Role;
+import org.openbravo.model.ad.access.User;
+import org.openbravo.model.ad.system.Client;
+import org.openbravo.model.common.enterprise.Organization;
+
+/**
+ * The component responsible for generating the dynamic part of the 
application js file.
+ * 
+ * @author mtaal
+ */
+public class ApplicationDynamicComponent extends BaseTemplateComponent {
+
+  public Set<Entity> getAccessibleEntities() {
+    final Set<Entity> entities = 
OBContext.getOBContext().getEntityAccessChecker()
+        .getReadableEntities();
+    
entities.addAll(OBContext.getOBContext().getEntityAccessChecker().getWritableEntities());
+    return entities;
+  }
+
+  @Override
+  protected Template getComponentTemplate() {
+    return OBDal.getInstance().get(Template.class, 
KernelConstants.APPLICATION_DYNAMIC_TEMPLATE_ID);
+  }
+
+  public User getUser() {
+    return OBContext.getOBContext().getUser();
+  }
+
+  public Client getClient() {
+    return OBContext.getOBContext().getCurrentClient();
+  }
+
+  public Organization getOrganization() {
+    return OBContext.getOBContext().getCurrentOrganization();
+  }
+
+  public Role getRole() {
+    return OBContext.getOBContext().getRole();
+  }
+
+  @Override
+  public String getETag() {
+    OBContext c = OBContext.getOBContext();
+    return super.getETag() + "_" + c.getRole().getId() + "_" + 
c.getUser().getId() + "_"
+        + c.getCurrentClient().getId() + "_" + 
c.getCurrentOrganization().getId();
+  }
+}
diff -r 9d19ec616689 -r bffcb013674f 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelComponentProvider.java
--- 
a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelComponentProvider.java
  Tue Feb 15 19:45:25 2011 +0100
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelComponentProvider.java
  Tue Feb 15 19:52:21 2011 +0100
@@ -56,6 +56,8 @@
       return getComponent(StaticResourceComponent.class);
     } else if (componentId.equals(KernelConstants.APPLICATION_COMPONENT_ID)) {
       return getComponent(ApplicationComponent.class);
+    } else if 
(componentId.equals(KernelConstants.APPLICATION_DYNAMIC_COMPONENT_ID)) {
+      return getComponent(ApplicationDynamicComponent.class);
     } else if (componentId.equals(KernelConstants.TEST_COMPONENT_ID)) {
       return getComponent(TestComponent.class);
     } else if (componentId.equals(KernelConstants.DOCUMENT_COMPONENT_ID)) {
@@ -70,29 +72,26 @@
   // also covers client dependency
   public String getVersionParameters(String resource) {
     final String versionParam = super.getVersionParameters(resource);
-    if (resource.contains(KernelConstants.APPLICATION_COMPONENT_ID)) {
+    if (resource.contains(KernelConstants.APPLICATION_COMPONENT_ID)
+        || 
resource.contains(KernelConstants.APPLICATION_DYNAMIC_COMPONENT_ID)) {
       return versionParam + "&_role=" + 
OBContext.getOBContext().getRole().getId() + "&_org="
           + OBContext.getOBContext().getCurrentOrganization().getId();
     }
     return versionParam;
   }
 
-  /**
-   * @return an empty String (no global resources)
-   * @see 
org.openbravo.client.kernel.ComponentProvider#getGlobalComponentResources()
-   */
   public List<ComponentResource> getGlobalComponentResources() {
     final List<ComponentResource> globalResources = new 
ArrayList<ComponentResource>();
     globalResources.add(createStaticResource("org.openbravo.client.kernel/"
         + KernelConstants.KERNEL_COMPONENT_TYPE + "/" + 
KernelConstants.APPLICATION_COMPONENT_ID,
         true));
+    globalResources.add(createDynamicResource("org.openbravo.client.kernel/"
+        + KernelConstants.KERNEL_COMPONENT_TYPE + "/"
+        + KernelConstants.APPLICATION_DYNAMIC_COMPONENT_ID));
     globalResources.add(createStaticResource("org.openbravo.client.kernel/"
         + KernelConstants.KERNEL_COMPONENT_TYPE + "/" + 
KernelConstants.LABELS_COMPONENT_ID, true));
     globalResources.add(createStaticResource(
         "web/org.openbravo.client.kernel/js/ob-kernel-utilities.js", true));
-    // globalResources.add(KernelConstants.RESOURCE_STRING_TAG
-    // + "document.write(\"<\" + \"script src='\" + document.location.protocol 
+ \""
-    // + Utility.BUTLER_UTILS_URL + "'><\" + \"/script>\");");
 
     return globalResources;
   }
diff -r 9d19ec616689 -r bffcb013674f 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelConstants.java
--- 
a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelConstants.java
  Tue Feb 15 19:45:25 2011 +0100
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelConstants.java
  Tue Feb 15 19:52:21 2011 +0100
@@ -67,6 +67,8 @@
 
   public static final String APPLICATION_COMPONENT_ID = "Application";
 
+  public static final String APPLICATION_DYNAMIC_COMPONENT_ID = 
"ApplicationDynamic";
+
   public static final String LABELS_COMPONENT_ID = "Labels";
 
   /**
@@ -80,6 +82,11 @@
   public static final String APPLICATION_TEMPLATE_ID = 
"0627967E56584D3B8B13A3C77ABC48E2";
 
   /**
+   * The primary key of the application dynamic template
+   */
+  public static final String APPLICATION_DYNAMIC_TEMPLATE_ID = 
"FF8081812E297131012E2A061112001C";
+
+  /**
    * The primary key of the documentation template
    */
   public static final String DOCUMENTATION_TEMPLATE_ID = 
"DBAC211182304F7784DAB4EDE7B6AA1D";
diff -r 9d19ec616689 -r bffcb013674f 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/templates/application-dynamic-js.ftl
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/templates/application-dynamic-js.ftl
  Tue Feb 15 19:52:21 2011 +0100
@@ -0,0 +1,40 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2009-2011 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+*/
+//jslint
+
+OB.User = {
+        id : '${data.user.id}',
+        firstName : '${(data.user.firstName!'')?js_string}',
+        lastName : '${(data.user.lastName!'')?js_string}',
+        userName : '${(data.user.username!'')?js_string}',
+        name : '${(data.user.name!'')?js_string}',
+        email : '${(data.user.email!'')?js_string}',
+        roleId: '${data.role.id}',
+        roleName: '${data.role.name}',
+        clientId: '${data.client.id}',
+        clientName: '${data.client.name}',
+        organizationId: '${data.organization.id}',
+        organizationName: '${data.organization.name}'
+};
+
+OB.AccessibleEntities = {
+    <#list data.accessibleEntities as entity>
+    '${entity.name?js_string}':  true<#if entity_has_next>,</#if>

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to