details:   https://code.openbravo.com/erp/devel/pi/rev/f96e99de3b0f
changeset: 22996:f96e99de3b0f
user:      Augusto Mauch <augusto.mauch <at> openbravo.com>
date:      Thu May 08 10:47:28 2014 +0200
summary:   Fixes issue 26420: Cannot modify an existing AD Tree Table Tree 
Category record

The problem was that there was an event handler on the ADTableTree table that 
checked that at most one ADTree tree is defined for a particular table at all 
times.

The logic that handled this checked on record creation and edition that no 
ADTree trees were already defined for that table. But there was a bug: if an 
ADTree tree was modified, then that same tree was detected as an existing 
ADTree tree, and the event handler returned with an exception.

To fix this now the event handler takes into account the id of the ADTableTree 
being modified when looking for exisint ADTree trees.

diffstat:

 
modules/org.openbravo.client.application/src/org/openbravo/client/application/event/TableTreeEventHandler.java
 |  16 ++++++++-
 1 files changed, 13 insertions(+), 3 deletions(-)

diffs (41 lines):

diff -r 5289988f8d2e -r f96e99de3b0f 
modules/org.openbravo.client.application/src/org/openbravo/client/application/event/TableTreeEventHandler.java
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/event/TableTreeEventHandler.java
    Thu May 08 05:39:08 2014 +0000
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/event/TableTreeEventHandler.java
    Thu May 08 10:47:28 2014 +0200
@@ -66,7 +66,7 @@
     Property tableProperty = entities[0].getProperty(TableTree.PROPERTY_TABLE);
     String treeStructureValue = (String) 
event.getCurrentState(treeStructureProperty);
     Table tableValue = (Table) event.getCurrentState(tableProperty);
-    checkTreeStructure(tableValue, treeStructureValue);
+    checkTreeStructure(tableValue, treeStructureValue, null);
   }
 
   public void onUpdate(@Observes EntityUpdateEvent event) {
@@ -76,16 +76,26 @@
     Property treeStructureProperty = 
entities[0].getProperty(TableTree.PROPERTY_TREESTRUCTURE);
     Property tableProperty = entities[0].getProperty(TableTree.PROPERTY_TABLE);
     String treeStructureValue = (String) 
event.getCurrentState(treeStructureProperty);
+    String recordId = event.getId();
     Table tableValue = (Table) event.getCurrentState(tableProperty);
-    checkTreeStructure(tableValue, treeStructureValue);
+    checkTreeStructure(tableValue, treeStructureValue, recordId);
   }
 
-  private void checkTreeStructure(Table table, String treeStructure) {
+  /**
+   * Checks that no other ADTree structured tree exists for this table, throws 
an exception if this occurs
+   * @param table table being checked
+   * @param treeStructure treestructure of the added/updated tree
+   * @param recordId null if a new record is being created or id of the record 
being modified
+   */
+  private void checkTreeStructure(Table table, String treeStructure, String 
recordId) {
     if (ADTREE_STRUCTURE.equals(treeStructure)) {
       // Check that there is no other ADTree Defined for this table
       OBCriteria<TableTree> obq = 
OBDal.getInstance().createCriteria(TableTree.class);
       obq.add(Restrictions.eq(TableTree.PROPERTY_TABLE, table));
       obq.add(Restrictions.eq(TableTree.PROPERTY_TREESTRUCTURE, 
treeStructure));
+      if (recordId != null) {
+          obq.add(Restrictions.ne(TableTree.PROPERTY_ID, recordId));
+      }
       if (obq.count() > 0) {
         String language = OBContext.getOBContext().getLanguage().getLanguage();
         ConnectionProvider conn = new DalConnectionProvider(false);

------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
&#149; 3 signs your SCM is hindering your productivity
&#149; Requirements for releasing software faster
&#149; Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to