Fixed issue 14402. Added a property to bypass the checkReferencedOrganizations check.
authorAntonio Moreno <antonio.moreno@openbravo.com>
Tue, 07 Sep 2010 13:13:56 +0200
changeset 8354 c59596c69f9f
parent 8353 86a42dfae94e
child 8355 09b82e443ae8
Fixed issue 14402. Added a property to bypass the checkReferencedOrganizations check.
The way this works is by setting the disableCheckReferencedOrganizations to true. For example, in import.sample.data:
ant impo.sample.data -DdisableCheckReferencedOrganizations=true
build.xml
src/build.xml
src/org/openbravo/dal/core/OBInterceptor.java
src/org/openbravo/service/db/ImportReferenceDataTask.java
--- a/build.xml	Tue Sep 07 11:55:32 2010 +0200
+++ b/build.xml	Tue Sep 07 13:13:56 2010 +0200
@@ -101,6 +101,7 @@
   <property name="friendlyWarnings" value="false"/>
   <property name="checkTranslationConsistency" value="true"/>
   <property name="buildValidation" value="true"/>
+  <property name="disableCheckReferencedOrganizations" value="false"/>
 
   <available file=".hg" property="is.hg" />
 
--- a/src/build.xml	Tue Sep 07 11:55:32 2010 +0200
+++ b/src/build.xml	Tue Sep 07 13:13:56 2010 +0200
@@ -235,7 +235,7 @@
       <classpath refid="project.class.path" />
     </taskdef>
     <echo message="Importing sample reference data" />
-    <importsampledata userId="0" adminMode="true" propertiesFile="${base.config}/Openbravo.properties" />
+    <importsampledata userId="0" adminMode="true" propertiesFile="${base.config}/Openbravo.properties" disableCheckReferencedOrganizations="${disableCheckReferencedOrganizations}"/>
     <ant dir="${base.db}" target="database.postupdate.${bbdd.rdbms}" inheritAll="true" inheritRefs="true" />
   </target>
 
--- a/src/org/openbravo/dal/core/OBInterceptor.java	Tue Sep 07 11:55:32 2010 +0200
+++ b/src/org/openbravo/dal/core/OBInterceptor.java	Tue Sep 07 13:13:56 2010 +0200
@@ -61,6 +61,8 @@
 
   private static ThreadLocal<Boolean> preventUpdateInfoChange = new ThreadLocal<Boolean>();
 
+  private static ThreadLocal<Boolean> disableCheckReferencedOrganizations = new ThreadLocal<Boolean>();
+
   /**
    * If true is passed and we are in adminMode then the update info (updated/updatedBy) is not
    * updated when an object gets updated.
@@ -72,6 +74,15 @@
   }
 
   /**
+   * If true is passed then the checkReferencedOrganizations check is not done
+   * 
+   * @param value
+   */
+  public static void setDisableCheckReferencedOrganizations(boolean value) {
+    disableCheckReferencedOrganizations.set(value);
+  }
+
+  /**
    * Determines if the object is transient (==new and not yet persisted in Hibernate).
    * 
    * @param entity
@@ -160,9 +171,9 @@
     // }
 
     doEvent(entity, currentState, propertyNames);
-
-    checkReferencedOrganizations(entity, currentState, previousState, propertyNames);
-
+    if (!disableCheckReferencedOrganizations.get()) {
+      checkReferencedOrganizations(entity, currentState, previousState, propertyNames);
+    }
     if (entity instanceof Traceable || entity instanceof ClientEnabled
         || entity instanceof OrganizationEnabled) {
       return true;
--- a/src/org/openbravo/service/db/ImportReferenceDataTask.java	Tue Sep 07 11:55:32 2010 +0200
+++ b/src/org/openbravo/service/db/ImportReferenceDataTask.java	Tue Sep 07 13:13:56 2010 +0200
@@ -33,6 +33,7 @@
 import org.apache.ddlutils.model.Database;
 import org.apache.log4j.Logger;
 import org.openbravo.base.exception.OBException;
+import org.openbravo.dal.core.OBInterceptor;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.ddlutils.task.DatabaseUtils;
 import org.openbravo.ddlutils.util.DBSMOBUtil;
@@ -45,6 +46,7 @@
   private static final Logger log = Logger.getLogger(ImportReferenceDataTask.class);
   private Platform platform;
   private Database xmlModel;
+  private boolean disableCheckReferencedOrganizations = false;
 
   @Override
   public void execute() {
@@ -61,6 +63,7 @@
   protected void doExecute() {
     final File importDir = getReferenceDataDir();
 
+    OBInterceptor.setDisableCheckReferencedOrganizations(disableCheckReferencedOrganizations);
     for (final File importFile : importDir.listFiles()) {
       if (importFile.isDirectory() || !importFile.getName().endsWith(".xml")) {
         continue;
@@ -129,4 +132,12 @@
   private void enableConstraints() {
     platform.enableCheckConstraints(xmlModel);
   }
+
+  public void setDisableCheckReferencedOrganizations(boolean disableCheckReferencedOrganizations) {
+    this.disableCheckReferencedOrganizations = disableCheckReferencedOrganizations;
+  }
+
+  public boolean isDisableCheckReferencedOrganizations() {
+    return disableCheckReferencedOrganizations;
+  }
 }