Related to issue 33650: code review improvements
authorVíctor Martínez Romanos <victor.martinez@openbravo.com>
Fri, 27 Apr 2018 10:55:13 +0200
changeset 33894 faca925fb578
parent 33893 a30751ea9d69
child 33895 d4e39005ae0e
Related to issue 33650: code review improvements
Properly format modulescript
Removed info message in module script
Increased limits
Ensure we don't work with * org and any organization where the persist org is already available
src-util/modulescript/build/classes/org/openbravo/modulescript/UpdatePersistOrgInfo.class
src-util/modulescript/build/classes/org/openbravo/modulescript/UpdatePersistOrgInfoData.class
src-util/modulescript/src/org/openbravo/modulescript/UpdatePersistOrgInfo.java
src-util/modulescript/src/org/openbravo/modulescript/UpdatePersistOrgInfo_data.xsql
Binary file src-util/modulescript/build/classes/org/openbravo/modulescript/UpdatePersistOrgInfo.class has changed
Binary file src-util/modulescript/build/classes/org/openbravo/modulescript/UpdatePersistOrgInfoData.class has changed
--- a/src-util/modulescript/src/org/openbravo/modulescript/UpdatePersistOrgInfo.java	Fri Apr 27 09:59:55 2018 +0200
+++ b/src-util/modulescript/src/org/openbravo/modulescript/UpdatePersistOrgInfo.java	Fri Apr 27 10:55:13 2018 +0200
@@ -23,28 +23,26 @@
 
 public class UpdatePersistOrgInfo extends ModuleScript {
 
-  private static final Logger log4j = Logger.getLogger(UpdatePersistOrgInfo.class);
-
   @Override
   public void execute() {
     try {
       ConnectionProvider cp = getConnectionProvider();
       boolean isPersistOrgInfoUpdated = UpdatePersistOrgInfoData.isPersistOrgInfoUpdated(cp);
       if (!isPersistOrgInfoUpdated) {
-    	long init = System.currentTimeMillis();
-    	int orgUpdated = 0;
-    	UpdatePersistOrgInfoData[] organizations = UpdatePersistOrgInfoData.selectOrgs(cp);
-    	for (UpdatePersistOrgInfoData org: organizations) {
-          String periodControlAllowedOrg = UpdatePersistOrgInfoData.getPeriodControlAllowedOrg(cp, org.adOrgId);
+        UpdatePersistOrgInfoData[] organizations = UpdatePersistOrgInfoData.selectOrgs(cp);
+        for (UpdatePersistOrgInfoData org : organizations) {
+          String periodControlAllowedOrg = UpdatePersistOrgInfoData.getPeriodControlAllowedOrg(cp,
+              org.adOrgId);
           String calendarOwnerOrg = UpdatePersistOrgInfoData.getCalendarOwnerOrg(cp, org.adOrgId);
           String calendar = UpdatePersistOrgInfoData.getCalendar(cp, calendarOwnerOrg);
-          String legalEntity = UpdatePersistOrgInfoData.getLegalEntityBusinessUnitOrg(cp, org.adOrgId, "LE");
-          String businessUnit = UpdatePersistOrgInfoData.getLegalEntityBusinessUnitOrg(cp, org.adOrgId, "BU");
-          UpdatePersistOrgInfoData.updatePersistOrgInfo(cp, periodControlAllowedOrg, calendarOwnerOrg, calendar, legalEntity, businessUnit, org.adOrgId);
-          orgUpdated ++;
-    	}
-        log4j.info(orgUpdated + " organization/s updated with Persist Info in "+(System.currentTimeMillis() - init)+" ms.");
-    	UpdatePersistOrgInfoData.createPreferencePersistOrgInfoUpdated(cp);
+          String legalEntity = UpdatePersistOrgInfoData.getLegalEntityBusinessUnitOrg(cp,
+              org.adOrgId, "LE");
+          String businessUnit = UpdatePersistOrgInfoData.getLegalEntityBusinessUnitOrg(cp,
+              org.adOrgId, "BU");
+          UpdatePersistOrgInfoData.updatePersistOrgInfo(cp, periodControlAllowedOrg,
+              calendarOwnerOrg, calendar, legalEntity, businessUnit, org.adOrgId);
+        }
+        UpdatePersistOrgInfoData.createPreferencePersistOrgInfoUpdated(cp);
       }
     } catch (Exception e) {
       handleError(e);
@@ -58,6 +56,6 @@
 
   @Override
   protected ModuleScriptExecutionLimits getModuleScriptExecutionLimits() {
-    return new ModuleScriptExecutionLimits("0", null, new OpenbravoVersion(3, 0, 33862));
+    return new ModuleScriptExecutionLimits("0", null, new OpenbravoVersion(3, 0, 33888));
   }
 }
--- a/src-util/modulescript/src/org/openbravo/modulescript/UpdatePersistOrgInfo_data.xsql	Fri Apr 27 09:59:55 2018 +0200
+++ b/src-util/modulescript/src/org/openbravo/modulescript/UpdatePersistOrgInfo_data.xsql	Fri Apr 27 10:55:13 2018 +0200
@@ -31,7 +31,13 @@
     <Sql><![CDATA[
         SELECT AD_Org_ID
         FROM AD_Org
-        WHERE isready = 'Y'
+        WHERE IsReady = 'Y'
+        AND AD_Org_ID <> '0'
+        AND AD_PeriodControlAllowed_Org_ID IS NULL
+        AND AD_CalendarOwner_Org_ID IS NULL 
+        AND AD_InheritedCalendar_ID IS NULL 
+        AND AD_LegalEntity_Org_ID IS NULL
+        AND AD_BusinessUnit_Org_ID IS NULL
     ]]></Sql>
     <Field name="dummy" value="void"/>
   </SqlMethod>