fixed bug 24005: incomplete audit trail info in processes
authorAsier Lostalé <asier.lostale@openbravo.com>
Tue, 11 Jun 2013 17:32:55 +0200
changeset 20518 dffc58601712
parent 20517 89b8a18aaa8d
child 20519 fa7c0391e4b7
fixed bug 24005: incomplete audit trail info in processes

Audit trail information was missing process and/or user in the following cases:

1. Java processes using DAL invoked from generated windows
2. Java processes using DAL invoked from menu
3. Process definition

In cases 1 and 2, the problem was audit info was set in ThreadLocal after the
DB temporary table was updated.

In case 3, it was not set at all.
modules/org.openbravo.client.application/src/org/openbravo/client/application/process/BaseProcessActionHandler.java
src-core/src/org/openbravo/database/SessionInfo.java
src-db/database/sourcedata/AD_REF_LIST.xml
src-wad/src/org/openbravo/wad/ActionButtonJava_Responser.javaxml
src-wad/src/org/openbravo/wad/ActionButton_Responser.javaxml
src-wad/src/org/openbravo/wad/Wad.java
src-wad/src/org/openbravo/wad/javasource.javaxml
src-wad/src/org/openbravo/wad/javasource.xml
src/org/openbravo/erpCommon/businessUtility/AuditTrailPopup.java
src/org/openbravo/scheduling/ProcessBundle.java
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/process/BaseProcessActionHandler.java	Tue Jun 18 12:05:47 2013 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/process/BaseProcessActionHandler.java	Tue Jun 11 17:32:55 2013 +0200
@@ -35,6 +35,7 @@
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
+import org.openbravo.database.SessionInfo;
 import org.openbravo.erpCommon.businessUtility.Preferences;
 import org.openbravo.erpCommon.utility.OBMessageUtils;
 import org.openbravo.erpCommon.utility.PropertyException;
@@ -84,6 +85,11 @@
         }
       }
 
+      // Set information for audit trail
+      SessionInfo.setProcessType("PD");
+      SessionInfo.setProcessId(processId);
+      SessionInfo.setDBSessionInfo(OBDal.getInstance().getConnection(false));
+
       return doExecute(parameters, content);
 
     } catch (Exception e) {
--- a/src-core/src/org/openbravo/database/SessionInfo.java	Tue Jun 18 12:05:47 2013 +0200
+++ b/src-core/src/org/openbravo/database/SessionInfo.java	Tue Jun 11 17:32:55 2013 +0200
@@ -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) 2009-2012 Openbravo SLU 
+ * All portions are Copyright (C) 2009-2013 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -300,6 +300,13 @@
     }
   }
 
+  /**
+   * Forces changed info flag so next time it is checked it session info will be set in DB
+   */
+  public static void infoChanged() {
+    changedInfo.set(true);
+  }
+
   public static String getCommand() {
     return command.get();
   }
--- a/src-db/database/sourcedata/AD_REF_LIST.xml	Tue Jun 18 12:05:47 2013 +0200
+++ b/src-db/database/sourcedata/AD_REF_LIST.xml	Tue Jun 11 17:32:55 2013 +0200
@@ -11352,6 +11352,17 @@
 <!--C7F514418045445C84336792979EF513-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--C7F514418045445C84336792979EF513--></AD_REF_LIST>
 
+<!--CA00CE19E247421884EAD80D211553D5--><AD_REF_LIST>
+<!--CA00CE19E247421884EAD80D211553D5-->  <AD_REF_LIST_ID><![CDATA[CA00CE19E247421884EAD80D211553D5]]></AD_REF_LIST_ID>
+<!--CA00CE19E247421884EAD80D211553D5-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--CA00CE19E247421884EAD80D211553D5-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--CA00CE19E247421884EAD80D211553D5-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--CA00CE19E247421884EAD80D211553D5-->  <VALUE><![CDATA[PD]]></VALUE>
+<!--CA00CE19E247421884EAD80D211553D5-->  <NAME><![CDATA[Process Definition]]></NAME>
+<!--CA00CE19E247421884EAD80D211553D5-->  <AD_REFERENCE_ID><![CDATA[8A9921F241B344F3AD99B6F59173F788]]></AD_REFERENCE_ID>
+<!--CA00CE19E247421884EAD80D211553D5-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--CA00CE19E247421884EAD80D211553D5--></AD_REF_LIST>
+
 <!--CA41A540A25C4218A7FCD71F243EED7C--><AD_REF_LIST>
 <!--CA41A540A25C4218A7FCD71F243EED7C-->  <AD_REF_LIST_ID><![CDATA[CA41A540A25C4218A7FCD71F243EED7C]]></AD_REF_LIST_ID>
 <!--CA41A540A25C4218A7FCD71F243EED7C-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-wad/src/org/openbravo/wad/ActionButtonJava_Responser.javaxml	Tue Jun 18 12:05:47 2013 +0200
+++ b/src-wad/src/org/openbravo/wad/ActionButtonJava_Responser.javaxml	Tue Jun 11 17:32:55 2013 +0200
@@ -12,7 +12,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) 2008-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2013 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -60,6 +60,8 @@
     // set process type and id for audit
     SessionInfo.setProcessType("P");
     SessionInfo.setProcessId(strProcessId);
+    SessionInfo.setUserId(vars.getSessionValue("#AD_User_ID"));
+    SessionInfo.setSessionId(vars.getSessionValue("#AD_Session_ID"));
 
     try {
       OBContext.setAdminMode();
--- a/src-wad/src/org/openbravo/wad/ActionButton_Responser.javaxml	Tue Jun 18 12:05:47 2013 +0200
+++ b/src-wad/src/org/openbravo/wad/ActionButton_Responser.javaxml	Tue Jun 11 17:32:55 2013 +0200
@@ -12,7 +12,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-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2013 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -59,6 +59,8 @@
     // set process type and id for audit
     SessionInfo.setProcessType("P");
     SessionInfo.setProcessId(strProcessId);
+    SessionInfo.setUserId(vars.getSessionValue("#AD_User_ID"));
+    SessionInfo.setSessionId(vars.getSessionValue("#AD_Session_ID"));
 
     try {
       OBContext.setAdminMode();
--- a/src-wad/src/org/openbravo/wad/Wad.java	Tue Jun 18 12:05:47 2013 +0200
+++ b/src-wad/src/org/openbravo/wad/Wad.java	Tue Jun 11 17:32:55 2013 +0200
@@ -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-2012 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2013 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -2254,6 +2254,7 @@
     xmlDocument.setData("structure15java", actBtnsJava);
     xmlDocument.setData("structure16java", actBtnsJava);
     xmlDocument.setData("structureActionBtnServiceJava", actBtnsJava);
+    xmlDocument.setData("structureActionBtnServiceJavaSecuredProcess", actBtnsJava);
 
     xmlDocument.setData("structure18", selCol);
     xmlDocument.setData("structure20", selCol);
--- a/src-wad/src/org/openbravo/wad/javasource.javaxml	Tue Jun 18 12:05:47 2013 +0200
+++ b/src-wad/src/org/openbravo/wad/javasource.javaxml	Tue Jun 11 17:32:55 2013 +0200
@@ -12,7 +12,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-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2013 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -77,13 +77,21 @@
     
     boolean securedProcess = false;
     if (command.contains("BUTTON")) {
+     SessionInfo.setUserId(vars.getSessionValue("#AD_User_ID"));
+     SessionInfo.setSessionId(vars.getSessionValue("#AD_Session_ID"));
+     <FIELDS_TMP id="sectionActionButtonsServiceJava">
+      if (command.contains("<FIELD_TMP id="ProcessIDsrvJ">processId</FIELD_TMP>")) {
+        SessionInfo.setProcessType("P");
+        SessionInfo.setProcessId("<FIELD_TMP id="ProcessIDsrvJ">processId</FIELD_TMP>");
+        SessionInfo.setModuleId("<FIELD_TMP id="ProcessModulesrvJ">moduleId</FIELD_TMP>");
+      }
+     </FIELDS_TMP>
       try {
         securedProcess = "Y".equals(org.openbravo.erpCommon.businessUtility.Preferences
             .getPreferenceValue("SecuredProcess", true, vars.getClient(), vars.getOrg(), vars
                 .getUser(), vars.getRole(), windowId));
       } catch (PropertyException e) {
       }
-    
      <FIELDS_TMP id="sectionActionButtonsService">
       if (command.contains("<FIELD_TMP id="ProcessIDsrv">processId</FIELD_TMP>")) {
         SessionInfo.setProcessType("P");
@@ -95,15 +103,11 @@
         }
       }
      </FIELDS_TMP>
-     <FIELDS_TMP id="sectionActionButtonsServiceJava">
-      if (command.contains("<FIELD_TMP id="ProcessIDsrvJ">processId</FIELD_TMP>")) {
-        SessionInfo.setProcessType("P");
-        SessionInfo.setProcessId("<FIELD_TMP id="ProcessIDsrvJ">processId</FIELD_TMP>");
-        SessionInfo.setModuleId("<FIELD_TMP id="ProcessModulesrvJ">moduleId</FIELD_TMP>");
-        if (securedProcess) {
-          classInfo.type = "P";
-          classInfo.id = "<FIELD_TMP id="ProcessIDsrvJ">processId</FIELD_TMP>";
-        }
+
+     <FIELDS_TMP id="sectionActionButtonsServiceJavaSecuredProcess">
+      if (securedProcess &amp;&amp; command.contains("<FIELD_TMP id="ProcessIDsrvJSP">processId</FIELD_TMP>")) {
+        classInfo.type = "P";
+        classInfo.id = "<FIELD_TMP id="ProcessIDsrvJSP">processId</FIELD_TMP>";
       }
      </FIELDS_TMP>
     }
--- a/src-wad/src/org/openbravo/wad/javasource.xml	Tue Jun 18 12:05:47 2013 +0200
+++ b/src-wad/src/org/openbravo/wad/javasource.xml	Tue Jun 11 17:32:55 2013 +0200
@@ -12,7 +12,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-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2013 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -174,6 +174,12 @@
   <SECTION id="sectionActionButtonsServiceJava"/>
 </structure>
 
+<structure name="structureActionBtnServiceJavaSecuredProcess">
+  <FIELD id="ProcessIDsrvJSP">adProcessId</FIELD>
+  <FIELD id="ProcessModulesrvJSP">adModuleId</FIELD>
+  <SECTION id="sectionActionButtonsServiceJavaSecuredProcess"/>
+</structure>
+
 <structure name="structure14">
   <FIELD id="ProcessID1">adProcessId</FIELD>
   <FIELD id="ButtonName1">columnname</FIELD>
--- a/src/org/openbravo/erpCommon/businessUtility/AuditTrailPopup.java	Tue Jun 18 12:05:47 2013 +0200
+++ b/src/org/openbravo/erpCommon/businessUtility/AuditTrailPopup.java	Tue Jun 11 17:32:55 2013 +0200
@@ -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) 2009-2012 Openbravo SLU 
+ * All portions are Copyright (C) 2009-2013 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -47,6 +47,7 @@
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.base.structure.BaseOBObject;
+import org.openbravo.client.application.Process;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
@@ -1205,6 +1206,11 @@
       String processCFLabel = getTranslatedMessage(adMessageIdForCF);
       return processCFLabel + ": " + OBDal.getInstance().get(Table.class, process).getDBTableName();
     }
+    if ("PD".equals(processType)) {
+      String processCFLabel = getTranslatedMessage(adMessageIdForProcess);
+      return processCFLabel + ": "
+          + OBDal.getInstance().get(Process.class, process).getIdentifier();
+    }
     // all other cases -> Tab
     String windowLabel = getTranslatedMessage(adMessageIdForWindow);
     return windowLabel + ": " + getTranslatedWindowName(process);
--- a/src/org/openbravo/scheduling/ProcessBundle.java	Tue Jun 18 12:05:47 2013 +0200
+++ b/src/org/openbravo/scheduling/ProcessBundle.java	Tue Jun 11 17:32:55 2013 +0200
@@ -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) 2008-2012 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2013 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -27,6 +27,7 @@
 import org.openbravo.base.ConfigParameters;
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.database.ConnectionProvider;
+import org.openbravo.database.SessionInfo;
 import org.openbravo.erpCommon.ad_process.JasperProcess;
 import org.openbravo.erpCommon.ad_process.PinstanceProcedure;
 import org.openbravo.erpCommon.ad_process.ProcedureProcess;
@@ -232,6 +233,9 @@
   }
 
   public ConnectionProvider getConnection() {
+    // Force session info change so first time this ConnectionProvider is used, session audit info
+    // is set in DB
+    SessionInfo.infoChanged();
     return connection;
   }