details:   https://code.openbravo.com/erp/devel/pi/rev/a5e71dc58364
changeset: 20360:a5e71dc58364
user:      Augusto Mauch <augusto.mauch <at> openbravo.com>
date:      Tue May 14 10:58:14 2013 +0200
summary:   Related to issue 23801: Restore previous resolving mode after 
DALWebService

The original resolving mode of the EntityResolver is 
ResolvingMode.ALLOW_NOT_EXIST. The DalWebService changes it to 
ResolvingMode.MUST_EXIST if the change action is ChangeAction.UPDATE, but it 
never reverts it to its previous mode.

details:   https://code.openbravo.com/erp/devel/pi/rev/d41072c387c4
changeset: 20361:d41072c387c4
user:      Augusto Mauch <augusto.mauch <at> openbravo.com>
date:      Tue May 14 16:54:34 2013 +0200
summary:   Fixes issue 23801:Inserting several entities in one web service call 
works

It was not possible to insert in a same web service call an entity and one 
child. To support this, the classes DalWebService and EntityResolver have been 
modified. The approach using the lookForTranslatedIDs [1] has been reverted. 
Now, the EntityResolver.resolve method first tries to resolve the entity as it 
used to do it before the regression was introduced, and if it does not find the 
entity then it tries to fetch it using an OBCriteria without applying the 
organization filter, so that this issue [2] is not reproduced.

A new function has been created to search for the entity. It accepts a boolean 
that will be used to specify if the organization filter should be applied. The 
old doSearch method calls the new method passing true to this flag, so it keeps 
working as usual.

[1] 
https://code.openbravo.com/erp/devel/pi/rev/8525372a1fce7047ee3baead23e1ddfc208b6dd9
[2] https://issues.openbravo.com/view.php?id=21716

diffstat:

 src/org/openbravo/dal/xml/EntityResolver.java     |  36 ++++++++++++----------
 src/org/openbravo/service/rest/DalWebService.java |   6 +++-
 2 files changed, 24 insertions(+), 18 deletions(-)

diffs (100 lines):

diff -r ecedca8c2103 -r d41072c387c4 
src/org/openbravo/dal/xml/EntityResolver.java
--- a/src/org/openbravo/dal/xml/EntityResolver.java     Tue May 14 10:11:19 
2013 +0200
+++ b/src/org/openbravo/dal/xml/EntityResolver.java     Tue May 14 16:54:34 
2013 +0200
@@ -102,7 +102,6 @@
   // 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();
@@ -137,17 +136,18 @@
     BaseOBObject result = null;
     // note id can be null if someone did not care to add it in a manual
     // xml file
-    if (lookForTranslatedIDs) {
-      if (id != null) {
-        result = data.get(getKey(entityName, id));
-        if (result != null) {
-          return result;
-        }
-        result = searchInstance(entity, id);
+    if (id != null) {
+      result = data.get(getKey(entityName, id));
+      if (result != null) {
+        return result;
       }
-    } else if (id != null) {
-      // Only try to fetch the object if the id is not null
-      result = OBDal.getInstance().get(entityName, id);
+      result = searchInstance(entity, id);
+    }
+
+    // Only try to fetch the object if the id is not null
+    if (result == null && id != null) {
+      boolean filterOrgs = false;
+      result = doSearch(id, entity, client.getId(), filterOrgs, "");
     }
 
     // search using the id if it is a view, note can be wrong as there can
@@ -402,6 +402,12 @@
   }
 
   protected BaseOBObject doSearch(String id, Entity entity, String clientId, 
String orgId) {
+    boolean filterOrgs = true;
+    return doSearch(id, entity, clientId, filterOrgs, orgId);
+  }
+
+  protected BaseOBObject doSearch(String id, Entity entity, String clientId, 
boolean filterOrgs,
+      String orgId) {
     final String[] searchOrgIds = getOrgIds(orgId);
     final OBCriteria<?> obc = 
OBDal.getInstance().createCriteria(entity.getName());
     obc.setFilterOnActive(false);
@@ -410,7 +416,7 @@
     if (entity.isClientEnabled()) {
       obc.add(Restrictions.eq(PROPERTY_CLIENT + "." + 
Organization.PROPERTY_ID, clientId));
     }
-    if (entity.isOrganizationEnabled()) {
+    if (filterOrgs && entity.isOrganizationEnabled()) {
       // Note the query is for other types than client but the client
       // property names
       // are good standard ones to use
@@ -613,11 +619,7 @@
     this.optionCreateReferencedIfNotFound = optionCreateReferencedIfNotFound;
   }
 
-  public void setLookForTranslatedIDs(boolean lookForTranslatedIDs) {
-    this.lookForTranslatedIDs = lookForTranslatedIDs;
-  }
-
-  protected ResolvingMode getResolvingMode() {
+  public ResolvingMode getResolvingMode() {
     return resolvingMode;
   }
 
diff -r ecedca8c2103 -r d41072c387c4 
src/org/openbravo/service/rest/DalWebService.java
--- a/src/org/openbravo/service/rest/DalWebService.java Tue May 14 10:11:19 
2013 +0200
+++ b/src/org/openbravo/service/rest/DalWebService.java Tue May 14 16:54:34 
2013 +0200
@@ -408,6 +408,9 @@
     // for a webservice referenced entities should not be created at all!
     xec.getEntityResolver().setOptionCreateReferencedIfNotFound(false);
 
+    // Retrieves the current resolving mode, to restore it after importing the 
data
+    ResolvingMode prevResolvingMode = 
xec.getEntityResolver().getResolvingMode();
+
     // the create action also supports updating
     // an update action should only update
     // and a delete action should be lenient, allowing non existing
@@ -417,9 +420,10 @@
       xec.getEntityResolver().setResolvingMode(ResolvingMode.MUST_EXIST);
     }
 
-    xec.getEntityResolver().setLookForTranslatedIDs(false);
     final List<BaseOBObject> processedObjects = xec.process(doc);
 
+    xec.getEntityResolver().setResolvingMode(prevResolvingMode);
+
     if (xec.getErrorMessages() != null) {
       throw new InvalidContentException(xec.getErrorMessages());
     }

------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to