[Tree Extension] ADTreeDatasource takes into account isHandleNodesManually
authorAugusto Mauch <augusto.mauch@openbravo.com>
Thu, 20 Feb 2014 12:56:13 +0100
changeset 22520 4e9a1d45f3b0
parent 22519 4ab1de66cb2a
child 22521 e121e67eaf89
[Tree Extension] ADTreeDatasource takes into account isHandleNodesManually
modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ADTreeDatasourceService.java
--- a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ADTreeDatasourceService.java	Thu Feb 20 12:54:30 2014 +0100
+++ b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ADTreeDatasourceService.java	Thu Feb 20 12:56:13 2014 +0100
@@ -76,7 +76,10 @@
       String entityName = bobProperties.getString("_entity");
       Entity entity = ModelProvider.getInstance().getEntity(entityName);
       Table table = OBDal.getInstance().get(Table.class, entity.getTableId());
-
+      TableTree tableTree = getTableTree(table);
+      if (tableTree.isHandleNodesManually()) {
+        return;
+      }
       Tree adTree = getTree(table, bobProperties);
       if (adTree == null) {
         // The adTree does not exists, create it
@@ -107,7 +110,10 @@
       String entityName = bobProperties.getString("_entity");
       Entity entity = ModelProvider.getInstance().getEntity(entityName);
       Table table = OBDal.getInstance().get(Table.class, entity.getTableId());
-
+      TableTree tableTree = getTableTree(table);
+      if (tableTree.isHandleNodesManually()) {
+        return;
+      }
       Tree tree = getTree(table, bobProperties);
       OBCriteria<TreeNode> adTreeNodeCriteria = OBDal.getInstance().createCriteria(TreeNode.class);
       adTreeNodeCriteria.add(Restrictions.eq(TreeNode.PROPERTY_TREE, tree));
@@ -124,6 +130,23 @@
   }
 
   /**
+   * Obtains the ADTree TableTree associated with the table
+   * 
+   * @param table
+   *          table whose ADTree TableTree will be returned
+   * @return the ADTree TableTree associated with the given table
+   */
+  private TableTree getTableTree(Table table) {
+    TableTree tableTree = null;
+    OBCriteria<TableTree> criteria = OBDal.getInstance().createCriteria(TableTree.class);
+    criteria.add(Restrictions.eq(TableTree.PROPERTY_TABLE, table));
+    criteria.add(Restrictions.eq(TableTree.PROPERTY_TREESTRUCTURE, "ADTree"));
+    // There can be at most one ADTree table per table, so it is safe to use uniqueResult
+    tableTree = (TableTree) criteria.uniqueResult();
+    return tableTree;
+  }
+
+  /**
    * Reparents the children of deletedNodeId, change it to newParentId
    * 
    * @param tree