details:   https://code.openbravo.com/erp/devel/pi/rev/7c5fbca07334
changeset: 33398:7c5fbca07334
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu Feb 01 09:13:43 2018 +0100
summary:   related to bug 37437: useless session cache of window.isSOTrx

  Reapplied backed out changeset.

  Some code minor clean up:
    - Removed some duplicity
    - Fixed format in some comments
    - ...

details:   https://code.openbravo.com/erp/devel/pi/rev/2cce4b505c16
changeset: 33399:2cce4b505c16
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Mon Feb 05 15:27:37 2018 +0100
summary:   fixed bug 37437: useless session cache of window.isSOTrx

  Now isSOTrx propery is not cached in session for each window in the system,
  instead its value is obtained from application scoped ADCS when required:
   - In Utility.getConext
   - In OBBindings

diffstat:

 
modules/org.openbravo.client.application/src/org/openbravo/client/application/OBBindings.java
 |  11 +-
 src/org/openbravo/base/secureApp/Attribute_data.xsql                           
               |  11 +-
 src/org/openbravo/base/secureApp/LoginUtils.java                               
               |   9 +-
 src/org/openbravo/erpCommon/utility/Utility.java                               
               |  86 +++++----
 4 files changed, 59 insertions(+), 58 deletions(-)

diffs (268 lines):

diff -r afdc2c3ecac2 -r 2cce4b505c16 
modules/org.openbravo.client.application/src/org/openbravo/client/application/OBBindings.java
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/OBBindings.java
     Mon Feb 05 14:50:16 2018 +0100
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/OBBindings.java
     Mon Feb 05 15:27:37 2018 +0100
@@ -11,7 +11,7 @@
  * 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-2017 Openbravo SLU
+ * All portions are Copyright (C) 2010-2018 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -30,8 +30,10 @@
 import org.openbravo.base.util.Check;
 import org.openbravo.base.util.OBClassLoader;
 import org.openbravo.base.weld.WeldUtils;
+import 
org.openbravo.client.application.window.ApplicationDictionaryCachedStructures;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.ad.ui.Window;
 import org.openbravo.service.json.JsonUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -134,6 +136,13 @@
     if (value != null) {
       return "Y".equalsIgnoreCase(value) || "true".equalsIgnoreCase(value);
     }
+
+    ApplicationDictionaryCachedStructures adcs = WeldUtils
+        
.getInstanceFromStaticBeanManager(ApplicationDictionaryCachedStructures.class);
+    Window w = adcs.getWindow(getWindowId());
+    if (w != null) {
+      return w.isSalesTransaction();
+    }
     return null;
   }
 
diff -r afdc2c3ecac2 -r 2cce4b505c16 
src/org/openbravo/base/secureApp/Attribute_data.xsql
--- a/src/org/openbravo/base/secureApp/Attribute_data.xsql      Mon Feb 05 
14:50:16 2018 +0100
+++ b/src/org/openbravo/base/secureApp/Attribute_data.xsql      Mon Feb 05 
15:27:37 2018 +0100
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!--
  
************************************************************************************
- * Copyright (C) 2001-2016 Openbravo S.L.U.
+ * Copyright (C) 2001-2018 Openbravo S.L.U.
  * Licensed under the Apache Software License version 2.0
  * You may obtain a copy of the License at 
http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to  in writing,  software  
distributed
@@ -44,14 +44,7 @@
       <Parameter name="acctId"/>
       <Parameter name="clientlist" optional="true" type="replace" after="AND 
a.AD_CLIENT_ID IN (" text="'1'"/>
    </SqlMethod>
-   <SqlMethod name="selectIsSOTrx" type="preparedStatement" return="multiple">
-      <SqlMethodComment></SqlMethodComment>
-      <Sql>
-        <![CDATA[
-        SELECT ad_window_id, isSOTrx as value FROM AD_WINDOW 
-        ]]>
-      </Sql>
-   </SqlMethod>
+
    <SqlMethod name="selectStdPrecision" type="preparedStatement" 
return="String" default="">
       <SqlMethodComment></SqlMethodComment>
       <Sql>
diff -r afdc2c3ecac2 -r 2cce4b505c16 
src/org/openbravo/base/secureApp/LoginUtils.java
--- a/src/org/openbravo/base/secureApp/LoginUtils.java  Mon Feb 05 14:50:16 
2018 +0100
+++ b/src/org/openbravo/base/secureApp/LoginUtils.java  Mon Feb 05 15:27:37 
2018 +0100
@@ -1,6 +1,6 @@
 /*
  
************************************************************************************
- * Copyright (C) 2001-2017 Openbravo S.L.U.
+ * Copyright (C) 2001-2018 Openbravo S.L.U.
  * Licensed under the Apache Software License version 2.0
  * You may obtain a copy of the License at 
http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to  in writing,  software  
distributed
@@ -358,13 +358,6 @@
           Preferences.savePreferenceInSession(vars, preference);
         }
 
-        attr = AttributeData.selectIsSOTrx(conn);
-        if (attr != null && attr.length > 0) {
-          for (int i = 0; i < attr.length; i++)
-            vars.setSessionValue(attr[i].adWindowId + "|isSOTrx", 
attr[i].value);
-        }
-        attr = null;
-
         DefaultSessionValuesData[] ds = DefaultSessionValuesData.select(conn);
         if (ds != null && ds.length > 0) {
           for (int i = 0; i < ds.length; i++) {
diff -r afdc2c3ecac2 -r 2cce4b505c16 
src/org/openbravo/erpCommon/utility/Utility.java
--- a/src/org/openbravo/erpCommon/utility/Utility.java  Mon Feb 05 14:50:16 
2018 +0100
+++ b/src/org/openbravo/erpCommon/utility/Utility.java  Mon Feb 05 15:27:37 
2018 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2017 Openbravo SLU
+ * All portions are Copyright (C) 2001-2018 Openbravo SLU
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -58,10 +58,8 @@
 import javax.imageio.ImageIO;
 import javax.servlet.ServletException;
 
-import net.sf.jasperreports.engine.JRException;
-import net.sf.jasperreports.engine.JasperReport;
-
 import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 import org.hibernate.Query;
 import org.openbravo.base.HttpBaseServlet;
@@ -70,7 +68,9 @@
 import org.openbravo.base.secureApp.OrgTree;
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.base.structure.BaseOBObject;
+import org.openbravo.base.weld.WeldUtils;
 import org.openbravo.client.application.report.ReportingUtils;
+import 
org.openbravo.client.application.window.ApplicationDictionaryCachedStructures;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.data.FieldProvider;
@@ -94,6 +94,9 @@
 import org.openbravo.utils.FileUtility;
 import org.openbravo.utils.FormatUtilities;
 
+import net.sf.jasperreports.engine.JRException;
+import net.sf.jasperreports.engine.JasperReport;
+
 /**
  * @author Fernando Iriazabal
  * 
@@ -348,7 +351,7 @@
 
   /**
    * Gets a value from the context. For client 0 is always added (used for 
references), to check if
-   * it must by added or not use the getContext with accesslevel method.
+   * it must be added or not use the getContext with accesslevel method.
    * 
    * @param conn
    *          Handler for the database connection.
@@ -362,18 +365,38 @@
    */
   public static String getContext(ConnectionProvider conn, VariablesSecureApp 
vars, String context,
       String window) {
-    if (context == null || context.equals(""))
+    if (StringUtils.isBlank(context)) {
       throw new IllegalArgumentException("getContext - require context");
-    String retValue = "";
+    }
+
+    String retValue;
 
     if (!context.startsWith("#") && !context.startsWith("$")) {
       retValue = getPreference(vars, context, window);
-      if (!window.equals("") && retValue.equals(""))
+      if (!window.equals("") && retValue.equals("")) {
         retValue = vars.getSessionValue(window + "|" + context);
-      if (retValue.equals(""))
+      }
+      if (retValue.equals("")) {
         retValue = vars.getSessionValue("#" + context);
-      if (retValue.equals(""))
+      }
+      if (retValue.equals("")) {
         retValue = vars.getSessionValue("$" + context);
+      }
+      if (retValue.equals("") && "IsSOTrx".equalsIgnoreCase(context)
+          && StringUtils.isNotBlank(window)) {
+        OBContext.setAdminMode(true);
+        try {
+          ApplicationDictionaryCachedStructures adcs = WeldUtils
+              
.getInstanceFromStaticBeanManager(ApplicationDictionaryCachedStructures.class);
+          Window w = adcs.getWindow(window);
+          retValue = w.isSalesTransaction() ? "Y" : "N";
+        } catch (Exception ignore) {
+          // not a valid window id, continue
+          retValue = "";
+        } finally {
+          OBContext.restorePreviousMode();
+        }
+      }
     } else {
       try {
         if (context.equalsIgnoreCase("#Date"))
@@ -438,25 +461,14 @@
    */
   public static String getContext(ConnectionProvider conn, VariablesSecureApp 
vars, String context,
       String strWindow, int accessLevel) {
-    if (context == null || context.equals(""))
+    if (StringUtils.isBlank(context)) {
       throw new IllegalArgumentException("getContext - require context");
-    String retValue = "";
+    }
+    String retValue;
 
-    if (!context.startsWith("#") && !context.startsWith("$")) {
-      retValue = getPreference(vars, context, strWindow);
-      if (!strWindow.equals("") && retValue.equals(""))
-        retValue = vars.getSessionValue(strWindow + "|" + context);
-      if (retValue.equals(""))
-        retValue = vars.getSessionValue("#" + context);
-      if (retValue.equals(""))
-        retValue = vars.getSessionValue("$" + context);
+    if ((!context.startsWith("#") && !context.startsWith("$")) || 
context.equalsIgnoreCase("#Date")) {
+      retValue = getContext(conn, vars, context, strWindow);
     } else {
-      try {
-        if (context.equalsIgnoreCase("#Date"))
-          return DateTimeData.today(conn);
-      } catch (final ServletException e) {
-      }
-
       retValue = vars.getSessionValue(context);
 
       final String userLevel = vars.getSessionValue("#User_Level");
@@ -483,13 +495,8 @@
             else
               return transactionalOrgs;
           } else {
-            if ((accessLevel == 1) || (userLevel.equals("  O"))) { // No
-              // *:
-              // remove
-              // 0
-              // from
-              // current
-              // list
+            if ((accessLevel == 1) || (userLevel.equals("  O"))) {
+              // No *: remove 0 from current list
               if (retValue.equals("'0'"))
                 retValue = "";
               else if (retValue.startsWith("'0',"))
@@ -498,10 +505,8 @@
                 retValue = retValue.replace(",'0'", "");
             } else {// Any: add 0 to current list
               if (!retValue.equals("'0'") && !retValue.startsWith("'0',")
-                  && retValue.indexOf(",'0'") == -1) {// Any:
-                // current
-                // list
-                // and *
+                  && retValue.indexOf(",'0'") == -1) {
+                // Any: current list and *
                 retValue = "'0'" + (retValue.equals("") ? "" : ",") + retValue;
               }
             }
@@ -1451,8 +1456,8 @@
             if (data[j].value.equals(localCurrentValue)) {
               retVal += "<span>(<u>" + i + "</u>)</span>";
               reservedButtonShortCuts.put(Integer.valueOf(i).toString(), "");
-              usedButtonShortCuts.put(Integer.valueOf(i).toString(), 
"executeWindowButton('" + buttonId
-                  + "');");
+              usedButtonShortCuts.put(Integer.valueOf(i).toString(), 
"executeWindowButton('"
+                  + buttonId + "');");
             }
           }
         } else {
@@ -1556,7 +1561,8 @@
    * @param list
    * @return a comma separated String containing the contents of the array.
    *
-   * @deprecated Use instead the more generic {@link 
StringCollectionUtils#commaSeparated(Collection, boolean)}
+   * @deprecated Use instead the more generic
+   *             {@link StringCollectionUtils#commaSeparated(Collection, 
boolean)}
    */
   @Deprecated
   public static String arrayListToString(ArrayList<String> list, boolean 
addQuotes) {

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to