Fixed issue 32880: Instance Activation window should displayed extra info
authorInigo Sanchez <inigo.sanchez@openbravo.com>
Fri, 06 May 2016 10:09:56 +0200
changeset 29449 58bacde3f953
parent 29438 14e14d88f186 (diff)
parent 29448 f16a58c86875 (current diff)
child 29450 098506f49242
child 29489 1c0637886cfe
Fixed issue 32880: Instance Activation window should displayed extra info

Instance Activation window should displayed extra information in an
activated instance:
* Number of calls to web services at current day.
* Current concurrent users.
* Active POS terminals.
--- a/.hgsigs	Thu May 05 14:01:19 2016 +0200
+++ b/.hgsigs	Fri May 06 10:09:56 2016 +0200
@@ -189,4 +189,6 @@
 24d2967df096de06913c9991553c1d84b07df9b6 0 iEYEABECAAYFAla9YYIACgkQCX/oGf+2qkNH7wCfV32iOyR/TQKzW/mH1iHTir6f6h4AoIlh4QBWIShpJqbJvx2IhfARpvUZ
 f016ea545c924ad099e9e402689035f1dd73baa2 0 iEYEABECAAYFAlbTzQoACgkQCX/oGf+2qkP28wCdFpNqpw+ODgF0p3cMJAbTZy1IPfoAoNEuRHkZIM5bNJMjwU0/GhjCtwah
 a53670f00eb6c9225829a660075fcfffa1109a1e 0 iEYEABECAAYFAlbqRpEACgkQCX/oGf+2qkN5qQCgsO1APX5AJ4cpb0oJX5vUQnvPMusAoPoDaQxGDihvsB4BSGW60RIxBdGC
+bdeb5a373f19eb7a144377621926d877ae2322f1 0 iEYEABECAAYFAlcgSPgACgkQCX/oGf+2qkMPLwCgzV//EHUa2bHmP8FA2IwnrFWB1X4AnjGHHjYKfSwiucQhltXR9POZXGaX
 38ef1dc10aa3d6fb8210b85beab370f62a4545ca 0 iEYEABECAAYFAlbiTM0ACgkQCX/oGf+2qkNBDwCfXmKXkqNGsAsfiofYOBBdvjA/XgkAoIwLK3DkmHeM71JihwfVOWyB4hmj
+265e8eccf704614fe88220026f2e2bafcebaaf00 0 iEYEABECAAYFAlcgZEQACgkQCX/oGf+2qkPuZgCcDPuB9d77M+51AglMvvmtpCDtnvoAnjqst7QgD6IP3Sv21+4vlqEjLVqU
--- a/.hgtags	Thu May 05 14:01:19 2016 +0200
+++ b/.hgtags	Fri May 06 10:09:56 2016 +0200
@@ -200,4 +200,6 @@
 9985680adffaf70ffcc1f560860feb10f0ee6b33 3.0PR15Q4.3
 70df4e4c5cab6d37f10eceee6b66be039c381556 3.0PR15Q4.4
 21c8ed48293c94cbe5875a8edef08aca0efd2bf4 3.0PR15Q4.5
+8828e6e8e071247f329320c63da66e30c357da9f 3.0PR15Q4.6
 ee5383e071318afe8eece515b4b264cfb46c1a84 3.0PR16Q1
+d386f41fa755d23e0e23f881aece691009051ebd 3.0PR16Q1.1
--- a/modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListDataSource.java	Thu May 05 14:01:19 2016 +0200
+++ b/modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListDataSource.java	Fri May 06 10:09:56 2016 +0200
@@ -102,12 +102,12 @@
         accessibleWidgetInForm = isAccessibleWidgetInForm(widgetClass);
       }
       if (!accessibleWidgetInForm
-          && (wi == null || wi.getWidgetClass().getId() != widgetClass.getId())) {
+          && (wi == null || !wi.getWidgetClass().getId().equals(widgetClass.getId()))) {
         // weird stuff: widget class doesn't match widget instance's class, most probably URL is
         // not generated by UI, but user is typing it
         log.error("User " + OBContext.getOBContext().getUser() + " with role "
             + OBContext.getOBContext().getRole() + " is trying to access widget '"
-            + widgetClass.getWidgetTitle() + "' but widget istance doesn't match with class");
+            + widgetClass.getWidgetTitle() + "' but widget instance doesn't match with class");
         throw new OBSecurityException(OBMessageUtils.getI18NMessage("OBCQL_NoAccessToWidget",
             new String[] { widgetClass.getWidgetTitle() }));
       }
--- a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceServlet.java	Thu May 05 14:01:19 2016 +0200
+++ b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceServlet.java	Fri May 06 10:09:56 2016 +0200
@@ -142,7 +142,7 @@
 
       SessionInfo.setModuleId(request.getParameter("moduleId"));
       SessionInfo.setCommand(request.getParameter(DataSourceConstants.OPERATION_TYPE_PARAM));
-      SessionInfo.setProcessId(request.getParameter("tabId"));
+      SessionInfo.setProcessId(request.getParameter(JsonConstants.TAB_PARAMETER));
       SessionInfo.setProcessType("W");
 
       super.service(request, response);
@@ -208,7 +208,7 @@
       getRequestContent(request);
     }
     try {
-      if (!hasAccess(request, parameters.get("tabId"))) {
+      if (!hasAccess(request, parameters.get(JsonConstants.TAB_PARAMETER))) {
         throw new OBUserException("AccessTableNoView");
       }
 
@@ -236,10 +236,9 @@
           try {
             OBContext.setAdminMode();
             try {
-              Window window = parameters.get(JsonConstants.TAB_PARAMETER) == null
-                  || parameters.get(JsonConstants.TAB_PARAMETER).equals("undefined") ? null : OBDal
-                  .getInstance().get(Tab.class, parameters.get(JsonConstants.TAB_PARAMETER))
-                  .getWindow();
+              Window window = JsonUtils.isValueEmpty(parameters.get(JsonConstants.TAB_PARAMETER)) ? null
+                  : OBDal.getInstance().get(Tab.class, parameters.get(JsonConstants.TAB_PARAMETER))
+                      .getWindow();
               String encoding = Preferences.getPreferenceValue("OBSERDS_CSVTextEncoding", true,
                   OBContext.getOBContext().getCurrentClient(), OBContext.getOBContext()
                       .getCurrentOrganization(), OBContext.getOBContext().getUser(), OBContext
@@ -312,9 +311,9 @@
         response.setHeader("Content-Disposition", "attachment; filename=ExportedData.csv");
         writer = response.getWriter();
         VariablesSecureApp vars = new VariablesSecureApp(request);
-        Window window = parameters.get(JsonConstants.TAB_PARAMETER) == null
-            || parameters.get(JsonConstants.TAB_PARAMETER).equals("undefined") ? null : OBDal
-            .getInstance().get(Tab.class, parameters.get(JsonConstants.TAB_PARAMETER)).getWindow();
+        Window window = JsonUtils.isValueEmpty(parameters.get(JsonConstants.TAB_PARAMETER)) ? null
+            : OBDal.getInstance().get(Tab.class, parameters.get(JsonConstants.TAB_PARAMETER))
+                .getWindow();
         try {
           prefDecimalSeparator = Preferences.getPreferenceValue("OBSERDS_CSVDecimalSeparator",
               true, OBContext.getOBContext().getCurrentClient(), OBContext.getOBContext()
@@ -370,8 +369,7 @@
         }
 
         fieldProperties = new ArrayList<String>();
-        if (parameters.get("viewState") != null
-            && !parameters.get("viewState").toString().equals("undefined")) {
+        if (!JsonUtils.isValueEmpty(parameters.get("viewState"))) {
           String viewStateO = parameters.get("viewState");
           String viewStateWithoutParenthesis = viewStateO.substring(1, viewStateO.length() - 1);
           JSONObject viewState = new JSONObject(viewStateWithoutParenthesis);
@@ -701,10 +699,9 @@
       try {
         String csvMessage = null;
         try {
-          Window window = parameters.get(JsonConstants.TAB_PARAMETER) == null
-              || parameters.get(JsonConstants.TAB_PARAMETER).equals("undefined") ? null : OBDal
-              .getInstance().get(Tab.class, parameters.get(JsonConstants.TAB_PARAMETER))
-              .getWindow();
+          Window window = JsonUtils.isValueEmpty(parameters.get(JsonConstants.TAB_PARAMETER)) ? null
+              : OBDal.getInstance().get(Tab.class, parameters.get(JsonConstants.TAB_PARAMETER))
+                  .getWindow();
           csvMessage = Preferences.getPreferenceValue(property, true, OBContext.getOBContext()
               .getCurrentClient(), OBContext.getOBContext().getCurrentOrganization(), OBContext
               .getOBContext().getUser(), OBContext.getOBContext().getRole(), window);
@@ -764,7 +761,7 @@
     setSessionInfo();
 
     try {
-      if (!hasAccess(request, parameters.get("tabId"))) {
+      if (!hasAccess(request, parameters.get(JsonConstants.TAB_PARAMETER))) {
         throw new OBUserException("AccessTableNoView");
       }
 
@@ -797,7 +794,7 @@
       if (!checkSetParameters(request, response, parameters)) {
         return;
       }
-      if (!hasAccess(request, parameters.get("tabId"))) {
+      if (!hasAccess(request, parameters.get(JsonConstants.TAB_PARAMETER))) {
         throw new OBUserException("AccessTableNoView");
       }
 
@@ -836,7 +833,7 @@
     final Map<String, String> parameters = getParameterMap(request);
     setSessionInfo();
     try {
-      if (!hasAccess(request, parameters.get("tabId"))) {
+      if (!hasAccess(request, parameters.get(JsonConstants.TAB_PARAMETER))) {
         throw new OBUserException("AccessTableNoView");
       }
 
@@ -998,7 +995,7 @@
    */
   private boolean hasAccess(HttpServletRequest req, String tabId) {
     try {
-      if (tabId == null || tabId.isEmpty()) {
+      if (JsonUtils.isValueEmpty(tabId)) {
         return true;
       }
       VariablesSecureApp vars = new VariablesSecureApp(req);
--- a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/TreeDatasourceService.java	Thu May 05 14:01:19 2016 +0200
+++ b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/TreeDatasourceService.java	Fri May 06 10:09:56 2016 +0200
@@ -139,9 +139,15 @@
 
   @Override
   public void checkEditDatasourceAccess(Map<String, String> parameter) {
-    Entity theEntity = getEntity();
-    if (!hasAccess(theEntity, null, false)) {
-      throw new OBException(OBMessageUtils.messageBD("AccessTableNoView"));
+    final OBContext obContext = OBContext.getOBContext();
+    String tableId = parameter.get("referencedTableId");
+    try {
+      Entity treeEntity = ModelProvider.getInstance().getEntityByTableId(tableId);
+      if (treeEntity != null) {
+        obContext.getEntityAccessChecker().checkWritableAccess(treeEntity);
+      }
+    } catch (OBSecurityException e) {
+      handleExceptionUnsecuredDSAccess(e);
     }
   }
 
--- a/modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonConstants.java	Thu May 05 14:01:19 2016 +0200
+++ b/modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonConstants.java	Fri May 06 10:09:56 2016 +0200
@@ -128,4 +128,7 @@
   public static final String WHERE_CLAUSE_HAS_BEEN_CHECKED = "whereClauseHasBeenChecked";
   public static final String WINDOW_ID = "windowId";
   public static final String DATASOURCE_NAME = "dataSourceName";
+
+  public static final String UNDEFINED = "undefined";
+  public static final String NULL = "null";
 }
--- a/modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonUtils.java	Thu May 05 14:01:19 2016 +0200
+++ b/modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonUtils.java	Fri May 06 10:09:56 2016 +0200
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2009-2015 Openbravo SLU 
+ * All portions are Copyright (C) 2009-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -25,6 +25,7 @@
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 import org.codehaus.jettison.json.JSONArray;
 import org.codehaus.jettison.json.JSONException;
@@ -391,4 +392,18 @@
     }
   }
 
+  /**
+   * Returns whether a JSON value is empty. The following values are considered as empty:
+   * <ul>
+   * <li>An empty string
+   * <li>{@code null}
+   * <li>{@code "null"} literal
+   * <li>{@code "undefined"} literal
+   * </ul>
+   */
+  public static boolean isValueEmpty(String value) {
+    return StringUtils.isEmpty(value) || JsonConstants.UNDEFINED.equals(value)
+        || JsonConstants.NULL.equals(value);
+  }
+
 }
--- a/src-db/database/model/functions/M_INVENTORY_LISTUPDATE.xml	Thu May 05 14:01:19 2016 +0200
+++ b/src-db/database/model/functions/M_INVENTORY_LISTUPDATE.xml	Fri May 06 10:09:56 2016 +0200
@@ -19,7 +19,7 @@
   * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
   * All Rights Reserved.
   * Contributor(s): Openbravo SLU
-  * Contributions are Copyright (C) 2001-2015 Openbravo, S.L.U.
+  * Contributions are Copyright (C) 2001-2016 Openbravo, S.L.U.
   *
   * Specifically, this derivative work is based upon the following Compiere
   * file and version.
@@ -100,7 +100,8 @@
   */
   IF(NOT END_PROCESS) THEN
     v_ResultStr:='UpdatingLine';
-    DELETE FROM M_InventoryLine
+    UPDATE M_InventoryLine
+    SET QtyBook = 0, QuantityOrderBook = 0
       WHERE M_Inventory_ID=v_Record_ID
         AND (NOT EXISTS
         (SELECT *
@@ -122,10 +123,6 @@
           AND (s.QTYORDERONHAND = 0 OR s.QTYORDERONHAND IS NULL)
         ))
     ;
-    rowcount:=SQL%ROWCOUNT;
-    IF(rowcount<>0) THEN
-      v_Message:='@Deleted@=' || rowcount || ', ';  
-    END IF;
     UPDATE M_InventoryLine
       SET QtyBook=
       (SELECT QtyOnHand
--- a/src-test/src/org/openbravo/test/datasource/DataSourceSecurity.java	Thu May 05 14:01:19 2016 +0200
+++ b/src-test/src/org/openbravo/test/datasource/DataSourceSecurity.java	Fri May 06 10:09:56 2016 +0200
@@ -29,6 +29,7 @@
 import java.util.List;
 import java.util.Map;
 
+import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -74,6 +75,9 @@
   private static final String ID_TESTING = "11";
   private static final Object PROD_RESERVATION = "DA7FC1BB3BA44EC48EC1AB9C74168CED";
 
+  private static final String OPERATION_FETCH = "fetch";
+  private static final String OPERATION_UPDATE = "update";
+
   private RoleType role;
   private DataSource dataSource;
   private int expectedResponseStatus;
@@ -92,147 +96,235 @@
     }
   }
 
+  private enum JSONObjectURL {
+    // Move node in Account Tree
+    MOVEMENT_NODE(
+        "?_skinVersion=Default&_create=true&Constants_FIELDSEPARATOR=$&_new=true"
+            + "&_contextUrl=http://localhost:8080/openbravo&Constants_IDENTIFIER=_identifier"
+            + "&_startRow=0&_endRow=200&referencedTableId=188&parentRecordId=56E65CF592BD4DAF8A8A879810646266&tabId=132"
+            + "&_selectedProperties=['searchKey','name','elementLevel','accountType','showValueCondition','summaryLevel']"
+            + "&@FinancialMgmtElement.client@=23C59575B9CF467C9620760EB255B389"
+            + "&@FinancialMgmtElement.id@=56E65CF592BD4DAF8A8A879810646266"
+            + "&@FinancialMgmtElement.organization@=B843C30461EA4501935CB1D125C9C25A&@FinancialMgmtElement.type@=A"
+            + "&@FinancialMgmtElementValue.organization@=B843C30461EA4501935CB1D125C9C25A"
+            + "&@FinancialMgmtElementValue.client@=23C59575B9CF467C9620760EB255B389"
+            + "&@FinancialMgmtElementValue.accountingElement@=56E65CF592BD4DAF8A8A879810646266"
+            + "&@FinancialMgmtElementValue.id@=A45B7570F9BE4A69A3BF53CFEBB29FC0&dropIndex=2"
+            + "&nextNodeId=FF30CF29CE614360AF85020438BFE328&isc_dataFormat=json&prevNodeId=C3FE5804602E481FAEDCA5D4D71B6CF",
+        createJsonObjectForNodeMovement()), //
+    NO_APPLIED("", "");
+
+    private String url;
+    private String content;
+
+    private JSONObjectURL(String url, String content) {
+      this.url = url;
+      this.content = content;
+    }
+
+    private static String createJsonObjectForNodeMovement() {
+      JSONObject dataObject = new JSONObject();
+      JSONObject oldValuesJSON = new JSONObject();
+      JSONObject contentJson = new JSONObject();
+      try {
+        dataObject.put("_identifier", "P - PATRIMONIO NETO Y PASIVO");
+        dataObject.put("_entityName", "FinancialMgmtElementValue");
+        dataObject.put("$ref", "FinancialMgmtElementValue/C3FE5804602E481FAEDCA5D4D71B6CF3");
+        dataObject.put("id", "C3FE5804602E481FAEDCA5D4D71B6CF3");
+        dataObject.put("client", "23C59575B9CF467C9620760EB255B389");
+        dataObject.put("parentId", "-1");
+        dataObject.put("organization", "B843C30461EA4501935CB1D125C9C25A");
+        dataObject.put("searchKey", "A");
+        dataObject.put("accountingElement", "56E65CF592BD4DAF8A8A879810646266");
+        dataObject.put("nodeId", "A45B7570F9BE4A69A3BF53CFEBB29FC0");
+        dataObject.put("seqno", "210");
+
+        oldValuesJSON.put("_identifier", "A - ACTIVO");
+        oldValuesJSON.put("_entityName", "FinancialMgmtElementValue");
+        oldValuesJSON.put("$ref", "FinancialMgmtElementValue/A45B7570F9BE4A69A3BF53CFEBB29FC0");
+        oldValuesJSON.put("id", "A45B7570F9BE4A69A3BF53CFEBB29FC0");
+        oldValuesJSON.put("client", "23C59575B9CF467C9620760EB255B389");
+        oldValuesJSON.put("organization", "B843C30461EA4501935CB1D125C9C25A");
+        oldValuesJSON.put("organization", "B843C30461EA4501935CB1D125C9C25A");
+        oldValuesJSON.put("searchKey", "A");
+        oldValuesJSON.put("name", "ACTIVO");
+        oldValuesJSON.put("accountingElement", "56E65CF592BD4DAF8A8A879810646266");
+        oldValuesJSON.put("nodeId", "A45B7570F9BE4A69A3BF53CFEBB29FC0");
+
+        contentJson.put("dataSource",
+            "D2F94DC86DEC48D69E4BFCE59DC670CF_1462265510526_1462271742157");
+        contentJson.put("operationType", "update");
+        contentJson.put("data", dataObject);
+        contentJson.put("oldValues", oldValuesJSON);
+      } catch (JSONException e) {
+        e.printStackTrace();
+      }
+      return contentJson.toString();
+    }
+  }
+
   @SuppressWarnings("serial")
   private enum DataSource {
-    Order("Order"), //
-    Alert("DB9F062472294F12A0291A7BD203F922"), //
-    ProductByPriceAndWarehouse("ProductByPriceAndWarehouse", new HashMap<String, String>() {
-      {
-        try {
-          put("_selectorDefinitionId", "2E64F551C7C4470C80C29DBA24B34A5F");
-          put("filterClass", "org.openbravo.userinterface.selector.SelectorDataSourceFilter");
-          put("_sortBy", "_identifier");
-          put("_requestType", "Window");
-          put("_distinct", "productPrice");
+    Order("Order", JSONObjectURL.NO_APPLIED, OPERATION_FETCH), //
+    Alert("DB9F062472294F12A0291A7BD203F922", JSONObjectURL.NO_APPLIED, OPERATION_FETCH), //
+    ProductByPriceAndWarehouse("ProductByPriceAndWarehouse", JSONObjectURL.NO_APPLIED,
+        OPERATION_FETCH, new HashMap<String, String>() {
+          {
+            try {
+              put("_selectorDefinitionId", "2E64F551C7C4470C80C29DBA24B34A5F");
+              put("filterClass", "org.openbravo.userinterface.selector.SelectorDataSourceFilter");
+              put("_sortBy", "_identifier");
+              put("_requestType", "Window");
+              put("_distinct", "productPrice");
 
-          // To reproduce this problem is important not to add the targetProperty parameter. For
-          // this reason targetProperty=null.
-          put("_inpTableId", "293");
-          put("_textMatchStyle", "substring");
+              // To reproduce this problem is important not to add the targetProperty parameter. For
+              // this reason targetProperty=null.
+              put("_inpTableId", "293");
+              put("_textMatchStyle", "substring");
 
-          // Filter selector
-          JSONObject criteria = new JSONObject();
-          criteria.put("fieldName", "productPrice$priceListVersion$_identifier");
-          criteria.put("operator", "iContains");
-          criteria.put("value", "Tarifa");
-          put("criteria", criteria.toString());
-        } catch (Exception ignore) {
-        }
-      }
-    }), //
-    PropertySelector("83B60C4C19AE4A9EBA947B948C5BA04D", new HashMap<String, String>() {
-      {
-        // Property selector invocation from Windows > Tab > Field > Property field
-        put("_selectorDefinitionId", "387D9FFC48A74054835C5DF6E6FD08F7");
-        put("inpadTableId", "259");
-        put("inpTabId", "107");
-        put("targetProperty", "property");
-      }
-    }), //
-    ManageVariants("6654D607F650425A9DFF7B6961D54920", new HashMap<String, String>() {
-      {
-        put("@Product.id@", ID_TESTING);
-      }
-    }), //
-    Note("090A37D22E61FE94012E621729090048", new HashMap<String, String>() {
-      {
-        // Note of a record in Windows, Tabs and Fields.
-        String criteria = "{\"fieldName\":\"table\",\"operator\":\"equals\",\"value\":\""
-            + TABLE_WINDOWS_TABS_FIELDS_ID
-            + "\"}__;__{\"fieldName\":\"record\",\"operator\":\"equals\",\"value\":\""
-            + RECORD_OF_WINDOWS_TABS_FIELDS_ID + "\"}";
-        String entityName = "OBUIAPP_Note";
-        put("criteria", criteria);
-        put("_entityName", entityName);
-      }
-    }), //
-    ProductCharacteristics("BE2735798ECC4EF88D131F16F1C4EC72"), //
-    Combo("ComboTableDatasourceService", new HashMap<String, String>() {
-      {
-        // Sales Order > Payment Terms
-        put("fieldId", "1099");
-      }
-    }), //
-    CustomQuerySelectorDatasource("F8DD408F2F3A414188668836F84C21AF",
+              // Filter selector
+              JSONObject criteria = new JSONObject();
+              criteria.put("fieldName", "productPrice$priceListVersion$_identifier");
+              criteria.put("operator", "iContains");
+              criteria.put("value", "Tarifa");
+              put("criteria", criteria.toString());
+            } catch (Exception ignore) {
+            }
+          }
+        }), //
+    PropertySelector("83B60C4C19AE4A9EBA947B948C5BA04D", JSONObjectURL.NO_APPLIED, OPERATION_FETCH,
         new HashMap<String, String>() {
           {
+            // Property selector invocation from Windows > Tab > Field > Property field
+            put("_selectorDefinitionId", "387D9FFC48A74054835C5DF6E6FD08F7");
+            put("inpadTableId", "259");
+            put("inpTabId", "107");
+            put("targetProperty", "property");
+          }
+        }), //
+    ManageVariants("6654D607F650425A9DFF7B6961D54920", JSONObjectURL.NO_APPLIED, OPERATION_FETCH,
+        new HashMap<String, String>() {
+          {
+            put("@Product.id@", ID_TESTING);
+          }
+        }), //
+    Note("090A37D22E61FE94012E621729090048", JSONObjectURL.NO_APPLIED, OPERATION_FETCH,
+        new HashMap<String, String>() {
+          {
+            // Note of a record in Windows, Tabs and Fields.
+            String criteria = "{\"fieldName\":\"table\",\"operator\":\"equals\",\"value\":\""
+                + TABLE_WINDOWS_TABS_FIELDS_ID
+                + "\"}__;__{\"fieldName\":\"record\",\"operator\":\"equals\",\"value\":\""
+                + RECORD_OF_WINDOWS_TABS_FIELDS_ID + "\"}";
+            String entityName = "OBUIAPP_Note";
+            put("criteria", criteria);
+            put("_entityName", entityName);
+          }
+        }), //
+    ProductCharacteristics("BE2735798ECC4EF88D131F16F1C4EC72", JSONObjectURL.NO_APPLIED,
+        OPERATION_FETCH), //
+    Combo("ComboTableDatasourceService", JSONObjectURL.NO_APPLIED, OPERATION_FETCH,
+        new HashMap<String, String>() {
+          {
+            // Sales Order > Payment Terms
+            put("fieldId", "1099");
+          }
+        }), //
+    CustomQuerySelectorDatasource("F8DD408F2F3A414188668836F84C21AF", JSONObjectURL.NO_APPLIED,
+        OPERATION_FETCH, new HashMap<String, String>() {
+          {
             // Sales Invoice > Selector Business Partner
             put("_selectorDefinitionId", "862F54CB1B074513BD791C6789F4AA42");
             put("inpTableId", "318");
             put("targetProperty", "businessPartner");
           }
         }), //
-    CustomQuerySelectorDatasourceProcess("ADList", new HashMap<String, String>() {
-      {
-        // Sales Order > Add Payment process > Selector Action Regarding Document
-        put("_selectorDefinitionId", "41B3A5EA61AB46FBAF4567E3755BA190");
-        put("_processDefinitionId", "9BED7889E1034FE68BD85D5D16857320");
-        put("targetProperty", "businessPartner");
-      }
-    }), //
-    SelectorGLItemDatasource("FinancialMgmtGLItem", new HashMap<String, String>() {
-      {
-        // Payment In > Add Details process > GLItem section > Selector GLItem
-        put("_selectorDefinitionId", "9FAD469CE4414A25974CF45C0AD22D35");
-        put("inpTableId", "D1A97202E832470285C9B1EB026D54E2");
-        put("targetProperty", "gLItem");
-      }
-    }), //
-    QuickLaunch("99B9CC42FDEA4CA7A4EE35BC49D61E0E"), //
-    QuickCreate("C17951F970E942FD9F3771B7BE91D049"), //
-    HQLDataSource("3C1148C0AB604DE1B51B7EA4112C325F", new HashMap<String, String>() {
-      {
-        // Invocation from Sales Order > Add Payment process > Credit to Use.
-        put("tableId", "58AF4D3E594B421A9A7307480736F03E");
-      }
-    }), //
-    ADTree("90034CAE96E847D78FBEF6D38CB1930D", new HashMap<String, String>() {
-      {
-        // Organization tree view.
-        put("referencedTableId", "155");
-        put("tabId", "143");
-        String selectedPro = "[\"searchKey\",\"name\",\"description\",\"active\",\"summaryLevel\",\"socialName\",\"organizationType\",\"currency\",\"allowPeriodControl\",\"calendar\"]";
-        put("_selectedProperties", selectedPro);
-      }
-    }), //
-    AccountTree("D2F94DC86DEC48D69E4BFCE59DC670CF", new HashMap<String, String>() {
-      {
-        // Account tree > Element value > Open tree view.
-        put("referencedTableId", "188");
-        put("tabId", "132");
-        String selectedPro = "[\"searchKey\",\"name\",\"elementLevel\",\"accountType\",\"showValueCondition\",\"summaryLevel\"]";
-        put("_selectedProperties", selectedPro);
-        put("@FinancialMgmtElement.client@", CLIENT);
-        put("@FinancialMgmtElement.id@", "56E65CF592BD4DAF8A8A879810646266");
-        put("@FinancialMgmtElement.organization@", "B843C30461EA4501935CB1D125C9C25A");
-      }
-    }), //
-    StockReservations("2F5B70D7F12E4F5C8FE20D6F17D69ECF", new HashMap<String, String>() {
-      {
-        // Manage Stock from Stock Reservations
-        put("@MaterialMgmtReservation.id@", ID_TESTING);
-      }
-    }), //
-    QueryList("DD17275427E94026AD721067C3C91C18", new HashMap<String, String>() {
-      {
-        // Query List Widget > Best Sellers
-        put("widgetId", "CD1B06C4ED974B5F905A5A01B097DF4E");
-      }
-    });
+    CustomQuerySelectorDatasourceProcess("ADList", JSONObjectURL.NO_APPLIED, OPERATION_FETCH,
+        new HashMap<String, String>() {
+          {
+            // Sales Order > Add Payment process > Selector Action Regarding Document
+            put("_selectorDefinitionId", "41B3A5EA61AB46FBAF4567E3755BA190");
+            put("_processDefinitionId", "9BED7889E1034FE68BD85D5D16857320");
+            put("targetProperty", "businessPartner");
+          }
+        }), //
+    SelectorGLItemDatasource("FinancialMgmtGLItem", JSONObjectURL.NO_APPLIED, OPERATION_FETCH,
+        new HashMap<String, String>() {
+          {
+            // Payment In > Add Details process > GLItem section > Selector GLItem
+            put("_selectorDefinitionId", "9FAD469CE4414A25974CF45C0AD22D35");
+            put("inpTableId", "D1A97202E832470285C9B1EB026D54E2");
+            put("targetProperty", "gLItem");
+          }
+        }), //
+    QuickLaunch("99B9CC42FDEA4CA7A4EE35BC49D61E0E", JSONObjectURL.NO_APPLIED, OPERATION_FETCH), //
+    QuickCreate("C17951F970E942FD9F3771B7BE91D049", JSONObjectURL.NO_APPLIED, OPERATION_FETCH), //
+    HQLDataSource("3C1148C0AB604DE1B51B7EA4112C325F", JSONObjectURL.NO_APPLIED, OPERATION_FETCH,
+        new HashMap<String, String>() {
+          {
+            // Invocation from Sales Order > Add Payment process > Credit to Use.
+            put("tableId", "58AF4D3E594B421A9A7307480736F03E");
+          }
+        }), //
+    ADTree("90034CAE96E847D78FBEF6D38CB1930D", JSONObjectURL.NO_APPLIED, OPERATION_FETCH,
+        new HashMap<String, String>() {
+          {
+            // Organization tree view.
+            put("referencedTableId", "155");
+            put("tabId", "143");
+            String selectedPro = "[\"searchKey\",\"name\",\"description\",\"active\",\"summaryLevel\",\"socialName\",\"organizationType\",\"currency\",\"allowPeriodControl\",\"calendar\"]";
+            put("_selectedProperties", selectedPro);
+          }
+        }), //
+    AccountTree("D2F94DC86DEC48D69E4BFCE59DC670CF", JSONObjectURL.NO_APPLIED, OPERATION_FETCH,
+        new HashMap<String, String>() {
+          {
+            // Account tree > Element value > Open tree view.
+            put("referencedTableId", "188");
+            put("tabId", "132");
+            String selectedPro = "[\"searchKey\",\"name\",\"elementLevel\",\"accountType\",\"showValueCondition\",\"summaryLevel\"]";
+            put("_selectedProperties", selectedPro);
+            put("@FinancialMgmtElement.client@", CLIENT);
+            put("@FinancialMgmtElement.id@", "56E65CF592BD4DAF8A8A879810646266");
+            put("@FinancialMgmtElement.organization@", "B843C30461EA4501935CB1D125C9C25A");
+          }
+        }), //
+    StockReservations("2F5B70D7F12E4F5C8FE20D6F17D69ECF", JSONObjectURL.NO_APPLIED,
+        OPERATION_FETCH, new HashMap<String, String>() {
+          {
+            // Manage Stock from Stock Reservations
+            put("@MaterialMgmtReservation.id@", ID_TESTING);
+          }
+        }), //
+    QueryList("DD17275427E94026AD721067C3C91C18", JSONObjectURL.NO_APPLIED, OPERATION_FETCH,
+        new HashMap<String, String>() {
+          {
+            // Query List Widget > Best Sellers
+            put("widgetId", "CD1B06C4ED974B5F905A5A01B097DF4E");
+          }
+        }), //
+    AccountTreeMovement("D2F94DC86DEC48D69E4BFCE59DC670CF", JSONObjectURL.MOVEMENT_NODE,
+        OPERATION_UPDATE);
 
     private String ds;
+    private JSONObjectURL urlAndJson;
+    private String operation;
     private Map<String, String> params;
 
-    private DataSource(String ds) {
+    private DataSource(String ds, JSONObjectURL urlAndJson, String operation) {
       this.ds = ds;
+      this.urlAndJson = urlAndJson;
+      this.operation = operation;
+
       params = new HashMap<String, String>();
-      params.put("_operationType", "fetch");
+      params.put("_operationType", operation);
       params.put("_startRow", "0");
       params.put("_endRow", "1");
     }
 
-    private DataSource(String ds, Map<String, String> extraParams) {
-      this(ds);
+    private DataSource(String ds, JSONObjectURL urlAndJson, String operation,
+        Map<String, String> extraParams) {
+      this(ds, urlAndJson, operation);
       params.putAll(extraParams);
     }
   }
@@ -293,6 +385,9 @@
       // Selector into a datasource into a P&E Window.
       testCases.add(new Object[] { type, DataSource.SelectorGLItemDatasource,
           accessForAdminAndSystemOnly });
+
+      // Moving a tree node : https://issues.openbravo.com/view.php?id=32833
+      testCases.add(new Object[] { type, DataSource.AccountTreeMovement, accessForAdminOnly });
     }
     // testing a problem detected in how properties are initialized.
     testCases.add(new Object[] { RoleType.ADMIN_ROLE, DataSource.ProductByPriceAndWarehouse,
@@ -373,10 +468,21 @@
   public void fetchShouldBeAllowedOnlyIfRoleIsGranted() throws Exception {
     OBContext.setOBContext(CONTEXT_USER);
     changeProfile(role.roleId, LANGUAGE_ID, role.orgId, WAREHOUSE_ID);
+
     JSONObject jsonResponse = null;
-    jsonResponse = fetchDataSource();
+    if (dataSource.operation.equals(OPERATION_FETCH)) {
+      jsonResponse = fetchDataSource();
+    } else if (dataSource.operation.equals(OPERATION_UPDATE)) {
+      jsonResponse = updateDataSource();
+    }
     assertThat("Request status", jsonResponse.getInt("status"), is(expectedResponseStatus));
+  }
 
+  private JSONObject updateDataSource() throws Exception {
+    String responseUpdate = doRequest("/org.openbravo.service.datasource/" + dataSource.ds
+        + dataSource.urlAndJson.url, dataSource.urlAndJson.content, 200, "PUT", "application/json");
+
+    return new JSONObject(responseUpdate).getJSONObject("response");
   }
 
   private JSONObject fetchDataSource() throws Exception {
--- a/src/org/openbravo/base/secureApp/HttpSecureAppServlet.java	Thu May 05 14:01:19 2016 +0200
+++ b/src/org/openbravo/base/secureApp/HttpSecureAppServlet.java	Fri May 06 10:09:56 2016 +0200
@@ -432,12 +432,16 @@
         UsageAudit.auditActionNoDal(this, vars1, this.getClass().getName(),
             System.currentTimeMillis() - t);
       } else {
-        if ((strPopUp != null && !strPopUp.equals("")) || (classInfo.type.equals("S")))
+        if ((strPopUp != null && !strPopUp.equals("")) || classInfo.type.equals("S")) {
           bdErrorGeneralPopUp(request, response,
               Utility.messageBD(this, "Error", variables.getLanguage()),
               Utility.messageBD(this, "AccessTableNoView", variables.getLanguage()));
-        else
+        } else {
           bdError(request, response, "AccessTableNoView", vars1.getLanguage());
+        }
+        String roleStr = "".equals(vars1.getRole()) ? "" : " (" + vars1.getRole() + ")";
+        log4j
+            .warn("Role" + roleStr + " tried to access ungranted resource with ID " + classInfo.id);
       }
     } catch (final ServletException ex) {
       log4j.error("Error captured: ", ex);
--- a/src/org/openbravo/dal/core/OBInterceptor.java	Thu May 05 14:01:19 2016 +0200
+++ b/src/org/openbravo/dal/core/OBInterceptor.java	Fri May 06 10:09:56 2016 +0200
@@ -298,8 +298,8 @@
             && bob.getEntity().getProperty(propertyNames[i]).isAllowedCrossOrgReference();
 
         if (!skipCrossOrgCheck
-            && !obContext.getOrganizationStructureProvider(o1.getClient().getId()).isInNaturalTree(
-                o1, o2)) {
+            && !obContext.getOrganizationStructureProvider((String) DalUtil.getId(o1.getClient()))
+                .isInNaturalTree(o1, o2)) {
           throw new OBSecurityException("Entity " + bob.getIdentifier() + " ("
               + bob.getEntityName() + ") with organization " + o1.getIdentifier()
               + " references an entity " + ((BaseOBObject) currentState[i]).getIdentifier()
--- a/src/org/openbravo/dal/security/EntityAccessChecker.java	Thu May 05 14:01:19 2016 +0200
+++ b/src/org/openbravo/dal/security/EntityAccessChecker.java	Fri May 06 10:09:56 2016 +0200
@@ -668,10 +668,8 @@
         + SELECTOR_REFERENCE + "' and f.tab.id in(" + tabs + ")";
     @SuppressWarnings("unchecked")
     final List<Reference> references = SessionHandler.getInstance().createQuery(hql).list();
-    if (!references.isEmpty()) {
-      for (Reference ref : references) {
-        addEntitiesOfSelectorReference(mp, ref);
-      }
+    for (Reference ref : references) {
+      addEntitiesOfSelectorReference(mp, ref);
     }
   }
 
--- a/src/org/openbravo/erpCommon/ad_forms/GenerateInvoicesmanual_data.xsql	Thu May 05 14:01:19 2016 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/GenerateInvoicesmanual_data.xsql	Fri May 06 10:09:56 2016 +0200
@@ -12,7 +12,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2014 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -29,7 +29,7 @@
     <Sql>
     <![CDATA[
       SELECT ic.C_Order_ID, o.Name as adorgname, COALESCE(dttrl.Name, dt.Name) as cdoctypename, ic.DocumentNo, bp.Name as cbpartnername, ic.DateOrdered,
-      amountlines, notinvoicedlines, l.Name as TermName, l.Value as TermValue, pendinglines as pendinglines, '' as amountlinesgross, '' as notinvoicedlinesgross,
+      amountlines, notinvoicedlines, COALESCE(ltrl.Name, l.Name) as TermName, l.Value as TermValue, pendinglines as pendinglines, '' as amountlinesgross, '' as notinvoicedlinesgross,
       '' as pendinglinesgross, ic.qtyordered as qtyordered, ic.qtydelivered as qtydelivered, (amountlines-notinvoicedlines) as linesinvoiced, amountlinesgross as totalgross
       FROM C_Invoice_Candidate_v ic, C_ORDER ord, AD_Org o, C_BPartner bp, AD_Ref_List l left join AD_Ref_List_trl ltrl on l.AD_Ref_List_ID=ltrl.AD_Ref_List_ID and ltrl.ad_language=?, 
       C_DocType dt left join C_DocType_trl dttrl on dt.C_DocType_ID=dttrl.C_DocType_ID AND dttrl.ad_language=?
@@ -61,7 +61,7 @@
     <Sql>
     <![CDATA[
       SELECT ic.C_Order_ID, o.Name as adorgname, COALESCE(dttrl.Name, dt.Name) as cdoctypename, ic.DocumentNo, bp.Name as cbpartnername, ic.DateOrdered,
-      amountlinesgross as amountlines, notinvoicedlinesgross as notinvoicedlines, l.Name as TermName, l.Value as TermValue, pendinglinesgross as pendinglines,
+      amountlinesgross as amountlines, notinvoicedlinesgross as notinvoicedlines, COALESCE(ltrl.Name, l.Name) as TermName, l.Value as TermValue, pendinglinesgross as pendinglines,
       ic.qtyordered as qtyordered, ic.qtydelivered as qtydelivered, (amountlinesgross-notinvoicedlinesgross) as linesinvoiced, amountlinesgross as totalgross
       FROM C_Invoice_Candidate_v ic, C_ORDER ord, AD_Org o, C_BPartner bp, AD_Ref_List l left join AD_Ref_List_trl ltrl on l.AD_Ref_List_ID=ltrl.AD_Ref_List_ID and ltrl.ad_language=?, 
       C_DocType dt left join C_DocType_trl dttrl on dt.C_DocType_ID=dttrl.C_DocType_ID AND dttrl.ad_language=?