fixed bug 40897: broken system if tying to create a ws row with unlimited WS
authorAsier Lostalé <asier.lostale@openbravo.com>
Fri, 17 May 2019 11:14:19 +0200
changeset 35804 1596542c21af
parent 35803 59e2bd0cc7fa
child 35805 ec509bcc31cc
child 35827 8d004aaabef9
child 35842 4401e5eb48cf
fixed bug 40897: broken system if tying to create a ws row with unlimited WS

System became unreacheable after trtying to create/update a record through WS
as first action after Tomcat restart having unlimited WS access license.

This occurred because TreeTablesEventHandler initialization assumed to be in
admin mode. As unlimited access license does not do any DB modification on login,
which is what occurs in standard login and with limited acess licenses, first
flush with dirty entities causes TreeTablesEventHandler init to fail in a
unrecoverable manner.

Now TreeTablesEventHandler is initialized in admin mode to prevent this case.
modules/org.openbravo.client.application/src/org/openbravo/client/application/event/TreeTablesEventHandler.java
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/event/TreeTablesEventHandler.java	Fri May 17 09:49:39 2019 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/event/TreeTablesEventHandler.java	Fri May 17 11:14:19 2019 +0200
@@ -164,13 +164,18 @@
   }
 
   private static Entity[] getTreeTables() {
-    OBCriteria<Table> treeTablesCriteria = OBDal.getInstance().createCriteria(Table.class);
-    treeTablesCriteria.add(Restrictions.eq(Table.PROPERTY_ISTREE, true));
-    List<Table> treeTableList = treeTablesCriteria.list();
-    ArrayList<Entity> entityArray = new ArrayList<>();
-    for (Table treeTable : treeTableList) {
-      entityArray.add(ModelProvider.getInstance().getEntityByTableId(treeTable.getId()));
+    OBContext.setAdminMode(true);
+    try {
+      OBCriteria<Table> treeTablesCriteria = OBDal.getInstance().createCriteria(Table.class);
+      treeTablesCriteria.add(Restrictions.eq(Table.PROPERTY_ISTREE, true));
+      List<Table> treeTableList = treeTablesCriteria.list();
+      ArrayList<Entity> entityArray = new ArrayList<>();
+      for (Table treeTable : treeTableList) {
+        entityArray.add(ModelProvider.getInstance().getEntityByTableId(treeTable.getId()));
+      }
+      return entityArray.toArray(new Entity[entityArray.size()]);
+    } finally {
+      OBContext.restorePreviousMode();
     }
-    return entityArray.toArray(new Entity[entityArray.size()]);
   }
 }