Fixes issue 22738: Enables applying the same dataset to different organizations
authorAugusto Mauch <augusto.mauch@openbravo.com>
Thu, 10 Jan 2013 15:50:42 +0100
changeset 19208 34e5ae6132e5
parent 19207 98f5002398d1
child 19209 f4f500d33fc0
Fixes issue 22738: Enables applying the same dataset to different organizations

The getOrgIds nethod of the EntityResolver class has been backed out to the version before the changeset that causes the regression.

Now when the EntityResolver is used from the DAL webservices, it will not try to look for the translated IDs, it will just try to get the item with DAL,using DALs client and organization checks.
src/org/openbravo/dal/xml/EntityResolver.java
src/org/openbravo/service/rest/DalWebService.java
--- a/src/org/openbravo/dal/xml/EntityResolver.java	Thu Jan 10 07:15:00 2013 +0000
+++ b/src/org/openbravo/dal/xml/EntityResolver.java	Thu Jan 10 15:50:42 2013 +0100
@@ -99,6 +99,11 @@
 
   private boolean optionCreateReferencedIfNotFound = true;
 
+  // When the entity resolver is used to apply datasets, it has to look for the translated IDs
+  // When the entity resolver is used from a DAL REST webservice, there is not need to look for the
+  // translated IDs
+  private boolean lookForTranslatedIDs = true;
+
   void clear() {
     data.clear();
     originalIdObjectMapping.clear();
@@ -132,12 +137,16 @@
     BaseOBObject result = null;
     // note id can be null if someone did not care to add it in a manual
     // xml file
-    if (id != null) {
-      result = data.get(getKey(entityName, id));
-      if (result != null) {
-        return result;
+    if (lookForTranslatedIDs) {
+      if (id != null) {
+        result = data.get(getKey(entityName, id));
+        if (result != null) {
+          return result;
+        }
+        result = searchInstance(entity, id);
       }
-      result = searchInstance(entity, id);
+    } else {
+      result = OBDal.getInstance().get(entityName, id);
     }
 
     // search using the id if it is a view, note can be wrong as there can
@@ -541,15 +550,10 @@
   // a referenced one, otherwise use the naturaltree
   private String[] getOrgIds(String orgId) {
     final String[] searchOrgIds;
-    if (organization != null && orgId.equals(organization.getId())) {
+    if (orgId.equals("0")) {
+      searchOrgIds = zeroOrgTree;
+    } else {
       searchOrgIds = orgNaturalTree;
-    } else {
-      if (organizationStructureProvider != null) {
-        final Set<String> orgs = organizationStructureProvider.getNaturalTree(orgId);
-        searchOrgIds = orgs.toArray(new String[orgs.size()]);
-      } else {
-        searchOrgIds = zeroOrgTree;
-      }
     }
     return searchOrgIds;
   }
@@ -608,6 +612,10 @@
     this.optionCreateReferencedIfNotFound = optionCreateReferencedIfNotFound;
   }
 
+  public void setLookForTranslatedIDs(boolean lookForTranslatedIDs) {
+    this.lookForTranslatedIDs = lookForTranslatedIDs;
+  }
+
   protected ResolvingMode getResolvingMode() {
     return resolvingMode;
   }
--- a/src/org/openbravo/service/rest/DalWebService.java	Thu Jan 10 07:15:00 2013 +0000
+++ b/src/org/openbravo/service/rest/DalWebService.java	Thu Jan 10 15:50:42 2013 +0100
@@ -416,6 +416,8 @@
     if (changeAction == ChangeAction.UPDATE) {
       xec.getEntityResolver().setResolvingMode(ResolvingMode.MUST_EXIST);
     }
+
+    xec.getEntityResolver().setLookForTranslatedIDs(false);
     final List<BaseOBObject> processedObjects = xec.process(doc);
 
     if (xec.getErrorMessages() != null) {