Fixes issue 19273: Different criteria when saving records that contains entities that don't belong to the org tree
authorMartin Taal <martin.taal@openbravo.com>
Tue, 13 Dec 2011 18:52:27 +0100
changeset 14861 f22a1c536caf
parent 14860 b35b26fe024d
child 14862 b53f23468fa9
Fixes issue 19273: Different criteria when saving records that contains entities that don't belong to the org tree
src/org/openbravo/dal/core/OBInterceptor.java
--- a/src/org/openbravo/dal/core/OBInterceptor.java	Tue Dec 13 17:29:23 2011 +0100
+++ b/src/org/openbravo/dal/core/OBInterceptor.java	Tue Dec 13 18:52:27 2011 +0100
@@ -37,6 +37,7 @@
 import org.hibernate.type.Type;
 import org.openbravo.base.exception.OBException;
 import org.openbravo.base.exception.OBSecurityException;
+import org.openbravo.base.model.BaseOBObjectDef;
 import org.openbravo.base.model.Entity;
 import org.openbravo.base.model.Property;
 import org.openbravo.base.structure.BaseOBObject;
@@ -223,6 +224,13 @@
 
     doEvent(entity, currentState, propertyNames);
 
+    // also check for new records
+    if (disableCheckReferencedOrganizations.get() == null
+        || !disableCheckReferencedOrganizations.get()) {
+      checkReferencedOrganizations(entity, currentState, new Object[currentState.length],
+          propertyNames);
+    }
+
     boolean listenerResult = false;
     if (getInterceptorListener() != null) {
       listenerResult = getInterceptorListener().onSave(entity, id, currentState, propertyNames,
@@ -270,6 +278,20 @@
         final OrganizationEnabled oe = (OrganizationEnabled) currentState[i];
         final Organization o2 = oe.getOrganization();
 
+        // don't do the check for references to attribute set instance
+        // using a hard coded name to prevent compile time dependencies
+        // attribute set instances could be saved with the wrong org
+        // see:
+        // https://issues.openbravo.com/view.php?id=19272
+        // to not block companies with wrong data prevent the check
+        // in this case
+        // also see:
+        // https://issues.openbravo.com/view.php?id=19273
+        final BaseOBObjectDef obObject = (BaseOBObjectDef) currentState[i];
+        if (obObject.getEntity().getName().equals("AttributeSetInstance")) {
+          continue;
+        }
+
         if (!obContext.getOrganizationStructureProvider(o1.getClient().getId()).isInNaturalTree(o1,
             o2)) {
           throw new OBSecurityException("Entity " + bob.getIdentifier() + " ("