details:   /erp/devel/pi/rev/a2ef2f6cf23b
changeset: 8207:a2ef2f6cf23b
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Tue Aug 24 13:41:03 2010 +0200
summary:   Fixes issue 14276: Need feature to disable maintaining audit info 
via dal for one request/dal-session

diffstat:

 src-test/org/openbravo/test/dal/IssuesTest.java  |  48 ++++++++++++++++++++++++
 src/org/openbravo/dal/core/DalRequestFilter.java |   2 +
 src/org/openbravo/dal/core/OBInterceptor.java    |  16 ++++++++
 3 files changed, 66 insertions(+), 0 deletions(-)

diffs (123 lines):

diff -r fee84cd1b187 -r a2ef2f6cf23b 
src-test/org/openbravo/test/dal/IssuesTest.java
--- a/src-test/org/openbravo/test/dal/IssuesTest.java   Tue Aug 24 16:04:55 
2010 +0530
+++ b/src-test/org/openbravo/test/dal/IssuesTest.java   Tue Aug 24 13:41:03 
2010 +0200
@@ -39,6 +39,7 @@
 import org.openbravo.base.structure.BaseOBObject;
 import org.openbravo.base.structure.IdentifierProvider;
 import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.core.OBInterceptor;
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.dal.service.OBQuery;
@@ -46,6 +47,7 @@
 import org.openbravo.data.UtilSql;
 import org.openbravo.model.ad.access.Role;
 import org.openbravo.model.ad.access.User;
+import org.openbravo.model.ad.datamodel.Table;
 import org.openbravo.model.ad.module.Module;
 import org.openbravo.model.ad.process.ProcessInstance;
 import org.openbravo.model.ad.system.Client;
@@ -109,6 +111,9 @@
  * https://issues.openbravo.com/view.php?id=13509: In a OBCriteria you can't 
use list() after a
  * count() call
  * 
+ * https://issues.openbravo.com/view.php?id=14276: Need feature to disable 
maintaining audit info
+ * via dal for one request/dal-session
+ * 
  * @author mtaal
  * @author iperdomo
  */
@@ -473,4 +478,47 @@
     assertTrue(null != org);
     assertTrue(cnt == orgs.list().size());
   }
+
+  /**
+   * https://issues.openbravo.com/view.php?id=14276: Need feature to disable 
maintaining audit info
+   * via dal for one request/dal-session
+   */
+  public void test14276() throws Exception {
+    setSystemAdministratorContext();
+    OBInterceptor.setPreventUpdateInfoChange(true);
+    boolean oldIndevelopment = false;
+    String oldName = null;
+    try {
+      Table table = OBDal.getInstance().get(Table.class, "100");
+      oldIndevelopment = table.getDataPackage().getModule().isInDevelopment();
+      table.getDataPackage().getModule().setInDevelopment(true);
+      OBDal.getInstance().save(table.getDataPackage().getModule());
+      OBDal.getInstance().flush();
+      oldName = table.getName();
+      final Date oldUpdated = table.getUpdated();
+      table.setName(table.getName() + "t");
+      OBDal.getInstance().save(table);
+      OBDal.getInstance().commitAndClose();
+      table = OBDal.getInstance().get(Table.class, "100");
+      assertFalse(oldName.equals(table.getName()));
+      assertTrue(table.getUpdated().getTime() == oldUpdated.getTime());
+    } finally {
+      OBInterceptor.setPreventUpdateInfoChange(null);
+    }
+
+    // now do the same with preventupdate disabled
+    {
+      Table table = OBDal.getInstance().get(Table.class, "100");
+      final Date oldUpdated = table.getUpdated();
+      table.setName(oldName);
+      OBDal.getInstance().save(table);
+      OBDal.getInstance().flush();
+      table.getDataPackage().getModule().setInDevelopment(oldIndevelopment);
+      OBDal.getInstance().save(table.getDataPackage().getModule());
+      OBDal.getInstance().commitAndClose();
+      table = OBDal.getInstance().get(Table.class, "100");
+      assertTrue(oldName.equals(table.getName()));
+      assertFalse(table.getUpdated().getTime() == oldUpdated.getTime());
+    }
+  }
 }
\ No newline at end of file
diff -r fee84cd1b187 -r a2ef2f6cf23b 
src/org/openbravo/dal/core/DalRequestFilter.java
--- a/src/org/openbravo/dal/core/DalRequestFilter.java  Tue Aug 24 16:04:55 
2010 +0530
+++ b/src/org/openbravo/dal/core/DalRequestFilter.java  Tue Aug 24 13:41:03 
2010 +0200
@@ -94,6 +94,8 @@
 
         OBContext.clearAdminModeStack();
 
+        OBInterceptor.setPreventUpdateInfoChange(null);
+
         super.doFinal(errorOccured);
       }
     };
diff -r fee84cd1b187 -r a2ef2f6cf23b 
src/org/openbravo/dal/core/OBInterceptor.java
--- a/src/org/openbravo/dal/core/OBInterceptor.java     Tue Aug 24 16:04:55 
2010 +0530
+++ b/src/org/openbravo/dal/core/OBInterceptor.java     Tue Aug 24 13:41:03 
2010 +0200
@@ -59,6 +59,18 @@
 
   private static final long serialVersionUID = 1L;
 
+  private static ThreadLocal<Boolean> preventUpdateInfoChange = new 
ThreadLocal<Boolean>();
+
+  /**
+   * If true is passed then the update info (updated/updatedBy) is not updated 
when an object gets
+   * updated.
+   * 
+   * @param value
+   */
+  public static void setPreventUpdateInfoChange(Boolean value) {
+    preventUpdateInfoChange.set(value);
+  }
+
   /**
    * Determines if the object is transient (==new and not yet persisted in 
Hibernate).
    * 
@@ -329,6 +341,10 @@
   // Sets the updated/updatedby
   // TODO: can the client/organization change?
   protected void onUpdate(Traceable t, String[] propertyNames, Object[] 
currentState) {
+    if (OBContext.getOBContext().isInAdministratorMode() && 
preventUpdateInfoChange.get() != null
+        && preventUpdateInfoChange.get()) {
+      return;
+    }
     final User currentUser = getCurrentUser();
     log.debug("OBEvent for updated object " + t.getClass().getName() + " user "
         + currentUser.getName());

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to