svn commit: r688498 - in /ofbiz/trunk/framework: entity/entitydef/entitymodel.xml entity/src/org/ofbiz/entity/GenericDelegator.java webapp/src/org/ofbiz/webapp/control/ControlServlet.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r688498 - in /ofbiz/trunk/framework: entity/entitydef/entitymodel.xml entity/src/org/ofbiz/entity/GenericDelegator.java webapp/src/org/ofbiz/webapp/control/ControlServlet.java

jonesde
Author: jonesde
Date: Sun Aug 24 05:09:37 2008
New Revision: 688498

URL: http://svn.apache.org/viewvc?rev=688498&view=rev
Log:
Added visitId persistence to EntityAuditLog stuff

Modified:
    ofbiz/trunk/framework/entity/entitydef/entitymodel.xml
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java

Modified: ofbiz/trunk/framework/entity/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/entitydef/entitymodel.xml?rev=688498&r1=688497&r2=688498&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/framework/entity/entitydef/entitymodel.xml Sun Aug 24 05:09:37 2008
@@ -45,7 +45,8 @@
         <field name="oldValueText" type="long-varchar"></field>
         <field name="newValueText" type="long-varchar"></field>
         <field name="changedDate" type="date-time"></field>
-        <field name="changedByInfo" type="long-varchar"><description>This should contain whatever information about the user or system that changed the value that is available. This could be a userLoginId, but could be something else too, so there is no foreign key.</description></field>
+        <field name="changedByInfo" type="long-varchar"><description>This should contain whatever information is available about the user or system that changed the value. This could be a userLoginId, but could be something else too, so there is no foreign key.</description></field>
+        <field name="changedSessionInfo" type="long-varchar"><description>This should contain whatever information is available about the session during which the value was changed. This could be a visitId, but could be something else too, so there is no foreign key.</description></field>
         <prim-key field="auditHistorySeqId"/>
     </entity>
     <entity entity-name="EntityKeyStore" package-name="org.ofbiz.entity.crypto" title="Entity Key Store Entity">

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java?rev=688498&r1=688497&r2=688498&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java Sun Aug 24 05:09:37 2008
@@ -109,8 +109,11 @@
     protected SequenceUtil sequencer = null;
     protected EntityCrypto crypto = null;
     
-    /** A ThreadLocal variable to allow other methods to specify an identifier (usually the userLoginId, though technically the Entity Engine doesn't know anything about the UserLogin entity) */
+    /** A ThreadLocal variable to allow other methods to specify a user identifier (usually the userLoginId, though technically the Entity Engine doesn't know anything about the UserLogin entity) */
     protected static ThreadLocal<List<Object>> userIdentifierStack = new ThreadLocal<List<Object>>();
+    /** A ThreadLocal variable to allow other methods to specify a session identifier (usually the visitId, though technically the Entity Engine doesn't know anything about the Visit entity) */
+    protected static ThreadLocal<List<Object>> sessionIdentifierStack = new ThreadLocal<List<Object>>();
+    
 
     public static GenericDelegator getGenericDelegator(String delegatorName) {
         if (delegatorName == null) {
@@ -183,6 +186,47 @@
         curValList.clear();
     }
 
+    protected static List<Object> getSessionIdentifierStack() {
+        List<Object> curValList = sessionIdentifierStack.get();
+        if (curValList == null) {
+            curValList = FastList.newInstance();
+            sessionIdentifierStack.set(curValList);
+        }
+        return curValList;
+    }
+    
+    public static String getCurrentSessionIdentifier() {
+        List<Object> curValList = getSessionIdentifierStack();
+        Object curVal = curValList.size() > 0 ? curValList.get(0) : null;
+        if (curVal == null) {
+            return null;
+        } else {
+            return curVal.toString();
+        }
+    }
+    
+    public static void pushSessionIdentifier(String sessionIdentifier) {
+        if (sessionIdentifier == null) {
+            return;
+        }
+        List<Object> curValList = getSessionIdentifierStack();
+        curValList.add(0, sessionIdentifier);
+    }
+    
+    public static String popSessionIdentifier() {
+        List<Object> curValList = getSessionIdentifierStack();
+        if (curValList.size() == 0) {
+            return null;
+        } else {
+            return (String) curValList.remove(0);
+        }
+    }
+    
+    public static void clearSessionIdentifierStack() {
+        List<Object> curValList = getSessionIdentifierStack();
+        curValList.clear();
+    }
+
     /** Only allow creation through the factory method */
     protected GenericDelegator() {}
 
@@ -3284,6 +3328,7 @@
 
         entityAuditLog.set("changedDate", UtilDateTime.nowTimestamp());
         entityAuditLog.set("changedByInfo", getCurrentUserIdentifier());
+        entityAuditLog.set("changedSessionInfo", getCurrentSessionIdentifier());
         
         this.create(entityAuditLog);
     }

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java?rev=688498&r1=688497&r2=688498&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java Sun Aug 24 05:09:37 2008
@@ -181,7 +181,13 @@
         // setup some things that should always be there
         UtilHttp.setInitialRequestInfo(request);
         VisitHandler.getVisitor(request, response);
-        
+
+        // set the Entity Engine user info if we have a userLogin
+        String visitId = VisitHandler.getVisitId(session);
+        if (UtilValidate.isNotEmpty(visitId)) {
+            GenericDelegator.pushSessionIdentifier(visitId);
+        }
+
         // display details on the servlet objects
         if (Debug.verboseOn()) {
             logRequestInfo(request);
@@ -276,9 +282,6 @@
         } catch (GenericTransactionException e) {
             Debug.logWarning(e, module);
         }
-        
-        // sanity check 2: make sure there are no user infos in the delegator, ie clear the thread
-        GenericDelegator.clearUserIdentifierStack();
 
         // run these two again before the ServerHitBin.countRequest call because on a logout this will end up creating a new visit
         if (response.isCommitted() && request.getSession(false) == null) {
@@ -297,6 +300,10 @@
             }
         }
         if (Debug.timingOn()) timer.timerString("[" + rname + "] Done rendering page, Servlet Finished", module);
+
+        // sanity check 2: make sure there are no user or session infos in the delegator, ie clear the thread
+        GenericDelegator.clearUserIdentifierStack();
+        GenericDelegator.clearSessionIdentifierStack();
     }
 
     /**