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 19219 22e7a5c9fbda
parent 19088 814d8af3a240
child 19220 e9062b9c6180
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	Fri Dec 21 04:43:20 2012 +0000
+++ b/src/org/openbravo/dal/xml/EntityResolver.java	Thu Jan 10 15:50:42 2013 +0100
@@ -98,6 +98,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();
@@ -131,12 +136,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
@@ -533,15 +542,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;
   }
@@ -600,6 +604,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	Fri Dec 21 04:43:20 2012 +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) {