Related to 0031384: Backout.
authorMiguel de Juana <miguel.dejuana@openbravo.com>
Tue, 10 Nov 2015 13:23:46 +0100
changeset 27848 a7ba1d39303c
parent 27847 488b5488e994
child 27849 3a55fee4da9b
Related to 0031384: Backout.

- There is an API change
modules/org.openbravo.client.application/src/org/openbravo/client/application/navigationbarcomponents/UserInfoWidgetActionHandler.java
src/org/openbravo/base/secureApp/HttpSecureAppServlet.java
src/org/openbravo/base/secureApp/LoginUtils.java
src/org/openbravo/erpCommon/ad_forms/Role.java
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/navigationbarcomponents/UserInfoWidgetActionHandler.java	Tue Sep 15 14:02:13 2015 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/navigationbarcomponents/UserInfoWidgetActionHandler.java	Tue Nov 10 13:23:46 2015 +0100
@@ -467,7 +467,7 @@
         throw new IllegalArgumentException("Error when saving default values");
       }
       readProperties(vars);
-      LoginUtils.readNumberFormat(vars, KernelServlet.getGlobalParameters().getFormatPath());
+      readNumberFormat(vars, KernelServlet.getGlobalParameters().getFormatPath());
     }
 
     private String toSaveStr(String value) {
--- a/src/org/openbravo/base/secureApp/HttpSecureAppServlet.java	Tue Sep 15 14:02:13 2015 +0200
+++ b/src/org/openbravo/base/secureApp/HttpSecureAppServlet.java	Tue Nov 10 13:23:46 2015 +0100
@@ -31,6 +31,10 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import net.sf.jasperreports.engine.JRDataSource;
 
 import org.codehaus.jettison.json.JSONObject;
 import org.hibernate.criterion.Restrictions;
@@ -52,6 +56,7 @@
 import org.openbravo.erpCommon.obps.ActivationKey;
 import org.openbravo.erpCommon.obps.ActivationKey.FeatureRestriction;
 import org.openbravo.erpCommon.obps.ActivationKey.LicenseRestriction;
+import org.openbravo.erpCommon.security.SessionLogin;
 import org.openbravo.erpCommon.security.UsageAudit;
 import org.openbravo.erpCommon.utility.JRFieldProviderDataSource;
 import org.openbravo.erpCommon.utility.JRScrollableFieldProviderDataSource;
@@ -69,8 +74,10 @@
 import org.openbravo.utils.FileUtility;
 import org.openbravo.utils.Replace;
 import org.openbravo.xmlEngine.XmlDocument;
-
-import net.sf.jasperreports.engine.JRDataSource;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 public class HttpSecureAppServlet extends HttpBaseServlet {
   private static final long serialVersionUID = 1L;
@@ -291,8 +298,8 @@
           if (LoginUtils.fillSessionArguments(this, vars, strUserAuth, strLanguage, strIsRTL,
               strRole, strClient, strOrg, strWarehouse)) {
             readProperties(vars);
-            LoginUtils.readNumberFormat(vars, globalParameters.getFormatPath());
-            LoginUtils.saveLoginBD(request, vars, "0", "0");
+            readNumberFormat(vars, globalParameters.getFormatPath());
+            saveLoginBD(request, vars, "0", "0");
           } else {
             // Re-login
             log4j.error("Unable to fill session Arguments for: " + strUserAuth);
@@ -1101,6 +1108,79 @@
     }
   }
 
+  protected void readNumberFormat(VariablesSecureApp vars, String strFormatFile) {
+    String strNumberFormat = "###,##0.00"; // Default number format
+    String strGroupingSeparator = ","; // Default grouping separator
+    String strDecimalSeparator = "."; // Default decimal separator
+    final String formatNameforJrxml = "euroInform"; // Name of the format to use
+    final HashMap<String, String> formatMap = new HashMap<String, String>();
+
+    try {
+      // Reading number format configuration
+      final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+      final DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
+      final Document doc = docBuilder.parse(new File(strFormatFile));
+      doc.getDocumentElement().normalize();
+      final NodeList listOfNumbers = doc.getElementsByTagName("Number");
+      final int totalNumbers = listOfNumbers.getLength();
+      for (int s = 0; s < totalNumbers; s++) {
+        final Node NumberNode = listOfNumbers.item(s);
+        if (NumberNode.getNodeType() == Node.ELEMENT_NODE) {
+          final Element NumberElement = (Element) NumberNode;
+          final String strNumberName = NumberElement.getAttributes().getNamedItem("name")
+              .getNodeValue();
+          // store in session all the formats
+          final String strFormatOutput = NumberElement.getAttributes().getNamedItem("formatOutput")
+              .getNodeValue();
+          formatMap.put(strNumberName, strFormatOutput);
+          vars.setSessionValue("#FormatOutput|" + strNumberName, strFormatOutput);
+          vars.setSessionValue("#DecimalSeparator|" + strNumberName, NumberElement.getAttributes()
+              .getNamedItem("decimal").getNodeValue());
+          vars.setSessionValue("#GroupSeparator|" + strNumberName, NumberElement.getAttributes()
+              .getNamedItem("grouping").getNodeValue());
+          // set the numberFormat to be used in the renderJR function
+          if (strNumberName.equals(formatNameforJrxml)) {
+            strDecimalSeparator = NumberElement.getAttributes().getNamedItem("decimal")
+                .getNodeValue();
+            strGroupingSeparator = NumberElement.getAttributes().getNamedItem("grouping")
+                .getNodeValue();
+            strNumberFormat = strFormatOutput;
+          }
+        }
+      }
+    } catch (final Exception e) {
+      log4j.error("error reading number format", e);
+    }
+    vars.setSessionObject("#FormatMap", formatMap);
+    vars.setSessionValue("#AD_ReportNumberFormat", strNumberFormat);
+    vars.setSessionValue("#AD_ReportGroupingSeparator", strGroupingSeparator);
+    vars.setSessionValue("#AD_ReportDecimalSeparator", strDecimalSeparator);
+  }
+
+  private void saveLoginBD(HttpServletRequest request, VariablesSecureApp vars, String strCliente,
+      String strOrganizacion) throws ServletException {
+
+    if ("Y".equals(request.getSession().getAttribute("forceLogin"))) {
+      // don't create a DB session for bypass authentication resources
+      log4j.debug("Bypass session " + request.getRequestURI());
+      return;
+    }
+
+    final SessionLogin sl = new SessionLogin(request, strCliente, strOrganizacion,
+        vars.getSessionValue("#AD_User_ID"));
+
+    // session_ID should have been created in LoginHandler
+    String sessionId = vars.getDBSession();
+    sl.setServerUrl(strDireccion);
+    sl.setSessionID(sessionId);
+
+    if (sessionId == null || sessionId.equals("")) {
+      sl.setStatus("S");
+      sl.save();
+      vars.setSessionValue("#AD_Session_ID", sl.getSessionID());
+    }
+  }
+
   protected void renderJR(VariablesSecureApp variables, HttpServletResponse response,
       String strReportName, String strOutputType, HashMap<String, Object> designParameters,
       FieldProvider[] data, Map<Object, Object> exportParameters) throws ServletException {
--- a/src/org/openbravo/base/secureApp/LoginUtils.java	Tue Sep 15 14:02:13 2015 +0200
+++ b/src/org/openbravo/base/secureApp/LoginUtils.java	Tue Nov 10 13:23:46 2015 +0100
@@ -11,18 +11,12 @@
  */
 package org.openbravo.base.secureApp;
 
-import java.io.File;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.apache.log4j.Logger;
-import org.openbravo.base.HttpBaseUtils;
 import org.openbravo.base.exception.OBException;
 import org.openbravo.base.exception.OBSecurityException;
 import org.openbravo.dal.core.OBContext;
@@ -30,7 +24,6 @@
 import org.openbravo.dal.service.OBQuery;
 import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.businessUtility.Preferences;
-import org.openbravo.erpCommon.security.SessionLogin;
 import org.openbravo.erpCommon.utility.DimensionDisplayUtility;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.model.ad.access.RoleOrganization;
@@ -38,10 +31,6 @@
 import org.openbravo.model.ad.system.Client;
 import org.openbravo.service.db.DalConnectionProvider;
 import org.openbravo.utils.FormatUtilities;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
 
 public class LoginUtils {
 
@@ -444,131 +433,4 @@
     public String org;
     public String warehouse;
   }
-
-  /**
-   * It saves session in the DB when login
-   * 
-   */
-  public static void saveLoginBD(HttpServletRequest request, VariablesSecureApp vars,
-      String strCliente, String strOrganizacion) throws ServletException {
-
-    if ("Y".equals(request.getSession().getAttribute("forceLogin"))) {
-      // don't create a DB session for bypass authentication resources
-      // log4j.debug("Bypass session " + request.getRequestURI());
-      return;
-    }
-
-    final SessionLogin sl = new SessionLogin(request, strCliente, strOrganizacion,
-        vars.getSessionValue("#AD_User_ID"));
-
-    // session_ID should have been created in LoginHandler
-    String sessionId = vars.getDBSession();
-    sl.setServerUrl(HttpBaseUtils.getLocalAddress(request));
-    sl.setSessionID(sessionId);
-
-    if (sessionId == null || sessionId.equals("")) {
-      sl.setStatus("S");
-      sl.save();
-      vars.setSessionValue("#AD_Session_ID", sl.getSessionID());
-    }
-  }
-
-  /**
-   * It reads number format configuration
-   * 
-   */
-  public static void readNumberFormat(VariablesSecureApp vars, String strFormatFile) {
-    String strNumberFormat = "###,##0.00"; // Default number format
-    String strGroupingSeparator = ","; // Default grouping separator
-    String strDecimalSeparator = "."; // Default decimal separator
-    final String formatNameforJrxml = "euroInform"; // Name of the format to use
-    final HashMap<String, String> formatMap = new HashMap<String, String>();
-
-    try {
-      // Reading number format configuration
-      final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-      final DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-      final Document doc = docBuilder.parse(new File(strFormatFile));
-      doc.getDocumentElement().normalize();
-      final NodeList listOfNumbers = doc.getElementsByTagName("Number");
-      final int totalNumbers = listOfNumbers.getLength();
-      for (int s = 0; s < totalNumbers; s++) {
-        final Node NumberNode = listOfNumbers.item(s);
-        if (NumberNode.getNodeType() == Node.ELEMENT_NODE) {
-          final Element NumberElement = (Element) NumberNode;
-          final String strNumberName = NumberElement.getAttributes().getNamedItem("name")
-              .getNodeValue();
-          // store in session all the formats
-          final String strFormatOutput = NumberElement.getAttributes().getNamedItem("formatOutput")
-              .getNodeValue();
-          formatMap.put(strNumberName, strFormatOutput);
-          vars.setSessionValue("#FormatOutput|" + strNumberName, strFormatOutput);
-          vars.setSessionValue("#DecimalSeparator|" + strNumberName, NumberElement.getAttributes()
-              .getNamedItem("decimal").getNodeValue());
-          vars.setSessionValue("#GroupSeparator|" + strNumberName, NumberElement.getAttributes()
-              .getNamedItem("grouping").getNodeValue());
-          // set the numberFormat to be used in the renderJR function
-          if (strNumberName.equals(formatNameforJrxml)) {
-            strDecimalSeparator = NumberElement.getAttributes().getNamedItem("decimal")
-                .getNodeValue();
-            strGroupingSeparator = NumberElement.getAttributes().getNamedItem("grouping")
-                .getNodeValue();
-            strNumberFormat = strFormatOutput;
-          }
-        }
-      }
-    } catch (final Exception e) {
-      // log4j.error("error reading number format", e);
-    }
-    vars.setSessionObject("#FormatMap", formatMap);
-    vars.setSessionValue("#AD_ReportNumberFormat", strNumberFormat);
-    vars.setSessionValue("#AD_ReportGroupingSeparator", strGroupingSeparator);
-    vars.setSessionValue("#AD_ReportDecimalSeparator", strDecimalSeparator);
-  }
-
-  /**
-   * It reads number format configuration
-   * 
-   * @return
-   * @throws ServletException
-   * 
-   */
-  public static String getDefaultLanguage(ConnectionProvider connectionProvider, String aduserid)
-      throws ServletException {
-
-    DefaultOptionsData dataLanguage[] = DefaultOptionsData.defaultLanguage(connectionProvider,
-        aduserid);
-    if (dataLanguage != null && dataLanguage.length > 0) {
-      return dataLanguage[0].getField("DEFAULT_AD_LANGUAGE");
-    }
-    dataLanguage = DefaultOptionsData.getDefaultLanguage(connectionProvider);
-    if (dataLanguage != null && dataLanguage.length > 0) {
-      return dataLanguage[0].getField("DEFAULT_AD_LANGUAGE");
-    }
-    return null;
-
-  }
-
-  /**
-   * It reads number format configuration
-   * 
-   * @return
-   * @throws ServletException
-   * 
-   */
-  public static String isDefaultRtl(ConnectionProvider connectionProvider, String aduserid)
-      throws ServletException {
-
-    DefaultOptionsData dataLanguage[] = DefaultOptionsData.defaultLanguage(connectionProvider,
-        aduserid);
-    if (dataLanguage != null && dataLanguage.length > 0) {
-      return dataLanguage[0].getField("ISRTL");
-    }
-    dataLanguage = DefaultOptionsData.getDefaultLanguage(connectionProvider);
-    if (dataLanguage != null && dataLanguage.length > 0) {
-      return dataLanguage[0].getField("ISRTL");
-    }
-    return null;
-
-  }
 }
--- a/src/org/openbravo/erpCommon/ad_forms/Role.java	Tue Sep 15 14:02:13 2015 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/Role.java	Tue Nov 10 13:23:46 2015 +0100
@@ -183,7 +183,7 @@
     if (!result)
       return false;
     readProperties(vars);
-    LoginUtils.readNumberFormat(vars, globalParameters.getFormatPath());
+    readNumberFormat(vars, globalParameters.getFormatPath());
     return true;
   }