[DynamicRebuildWindow] Replaced hardcoded references to specific states in the window, and added necessary logic to handle this.
authorAntonio Moreno <antonio.moreno@openbravo.com>
Fri, 07 May 2010 09:29:16 +0200
changeset 7516 896cbca4578c
parent 7515 432ccd399d73
child 7517 06ebfabafde5
[DynamicRebuildWindow] Replaced hardcoded references to specific states in the window, and added necessary logic to handle this.
build.xml
src/build.xml
src/org/openbravo/erpCommon/ad_process/ApplyModules.html
src/org/openbravo/erpCommon/ad_process/ApplyModules.java
src/org/openbravo/erpCommon/ad_process/ApplyModules.xml
src/org/openbravo/erpCommon/ad_process/buildStructure/BuildCreator.java
src/org/openbravo/erpCommon/ad_process/buildStructure/BuildStepWrapper.java
src/org/openbravo/erpCommon/ad_process/buildStructure/buildStructure.xml
--- a/build.xml	Mon May 03 18:42:20 2010 +0200
+++ b/build.xml	Fri May 07 09:29:16 2010 +0200
@@ -330,6 +330,7 @@
   </target>
 
   <target name="buildvalidation" depends="init, core.lib">
+    <updatesystemstatus v="RB10"/> 
     <ant dir="src-util/buildvalidation" target="buildvalidation" inheritAll="true" inheritRefs="true" />
   </target>
   
@@ -594,12 +595,13 @@
   </target>
 
   <target name="update.database" depends="init, core.lib, database.lib, buildvalidation">
+    <updatesystemstatus v="RB21"/>
     <ant dir="${base.db}" target="update.database.java" inheritAll="true" inheritRefs="true" />
-    <updatesystemstatus v="RB21"/>
     <antcall target="generate.entities.quick" />
   </target>
 
   <target name="update.database.mod" depends="init, core.lib, database.lib, buildvalidation">
+    <updatesystemstatus v="RB21"/>
     <ant dir="${base.db}" target="update.database.mod.java" inheritAll="true" inheritRefs="true" />
   </target>
 
@@ -632,9 +634,6 @@
 
 
   <target name="apply.modules" depends="update.database.mod">
-    <updatesystemstatus v="RB21"/>
-
-    <antcall inheritall="true" inheritrefs="true" target="apply.module" />
 
     <condition property="apply.modules.complete.compilation.var">
       <istrue value="${apply.modules.complete.compilation}"  />
@@ -643,10 +642,16 @@
     <condition property="apply.modules.simple.compilation.var">
       <isfalse value="${apply.modules.complete.compilation.var}" />
     </condition>
-    
+
+    <updatesystemstatus v="RB22"/>
     <antcall target="apply.modules.compile"/>
+
+    <updatesystemstatus v="RB23"/>
+    <antcall inheritall="true" inheritrefs="true" target="apply.module" />
     <ant dir="${base.db}" target="setApplied" inheritAll="true" inheritRefs="true" />
-     
+
+    <updatesystemstatus v="RB31"/> 
+      <updatesystemstatus v="RB32"/> 
   </target>
   
   <target name="apply.module.forked">
--- a/src/build.xml	Mon May 03 18:42:20 2010 +0200
+++ b/src/build.xml	Fri May 07 09:29:16 2010 +0200
@@ -161,7 +161,6 @@
   </target>
 
   <target name="sqlc" depends="copy.srcClient">
-    <updatesystemstatus v="RB42" />
     <java classname="org.openbravo.data.Sqlc" fork="yes" jvm="${env.JAVA_HOME}/bin/java" maxmemory="${build.maxmemory}" failonerror="true">
       <arg line="'${base.config}'/Openbravo.properties .xsql . '${build.sqlc}'/src" />
       <classpath refid="project.class.path" />
@@ -319,7 +318,6 @@
   </target>
   
   <target name="compileSqlc" depends="sqlc">
-    <updatesystemstatus v="RB43"/>
     <javac  srcdir="${basedir}:${build.sqlc}/src:${build.sqlc}/srcAD:${base.src.test}:${base.modules}" excludes="${base.modules}/*/src-wad/**,${base.modules}/*/src-util/**" destdir="${build}" encoding="UTF-8" fork="true" memorymaximumsize="${build.maxmemory}" debug="true" debuglevel="lines,vars,source" nowarn="${friendlyWarnings}">
       <classpath refid="project.class.path" />
     </javac>
@@ -402,7 +400,6 @@
   </target>
   
   <target name="wad" depends="init, wadvalidation">
-    <updatesystemstatus v="RB41"/>
     <java classname="org.openbravo.wad.Wad" jvm="${env.JAVA_HOME}/bin/java" fork="yes" maxmemory="${build.maxmemory}" failonerror="true">
       <arg line="'${base.config}' '${tab}' '${build.AD}/org/openbravo/erpWindows' '${build.AD}/org/openbravo/erpCommon' '${build.sqlc}/src' '${webTab}' '${build.AD}/org/openbravo/erpCommon/ad_actionButton' '${base.design}' '${base.translate.structure}' '${client.web.xml}' '..' '${attach.path}' '${web.url}' '${base.src}' '${complete}' '${module}' 'noquick'" />
       <classpath refid="project.class.path" />
@@ -412,7 +409,6 @@
   </target>
 
   <target name="wad.quick" depends="init, wadvalidation">
-    <updatesystemstatus v="RB41"/>
     <java classname="org.openbravo.wad.Wad" jvm="${env.JAVA_HOME}/bin/java" fork="yes" maxmemory="${build.maxmemory}">
       <arg line="'${base.config}' '${tab}' '${build.AD}/org/openbravo/erpWindows' '${build.AD}/org/openbravo/erpCommon' '${build.sqlc}/src' '${webTab}' '${build.AD}/org/openbravo/erpCommon/ad_actionButton' '${base.design}' '${base.translate.structure}' '${client.web.xml}' '..' '${attach.path}' '${web.url}' '${base.src}' '${complete}' '${module}' 'quick'" />
       <classpath refid="project.class.path" />
@@ -423,7 +419,6 @@
 
   <target name="postsrc" depends="postsrc.modules">
 
-    <updatesystemstatus v="RB44"/>
     <copy todir="${build}">
       <fileset dir="${basedir}" includes="**/*.properties" />
     </copy>
@@ -783,7 +778,6 @@
   </target>
 
   <target name="copy.files" if="mode.class">
-    <updatesystemstatus v="RB45"/>
     <mkdir dir="${jakarta.base}/webapps/${context.name}" />
     <copy todir="${jakarta.base}/webapps/${context.name}" encoding="UTF-8">
       <fileset dir="${base.context}" />
--- a/src/org/openbravo/erpCommon/ad_process/ApplyModules.html	Mon May 03 18:42:20 2010 +0200
+++ b/src/org/openbravo/erpCommon/ad_process/ApplyModules.html	Fri May 07 09:29:16 2010 +0200
@@ -39,13 +39,12 @@
       return true;
     }
   </script>
+  <script language="JavaScript" type="text/javascript" id="jsparam">
+
+  </script>
   <script language="JavaScript" type="text/javascript">
     var lc_isTimerEnabled = true;
     var current_state=0;
-    var possible_states=[59,11,12,13,14,15,21,31,41,42,43,44,45,51,60];
-    var error_status=['','','','','','','','','','','','','','',''];
-    var numofwarns=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
-    var numoferrs=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
     var start=false;
     var processing = false;
     var stopAddingWarns=false;
@@ -264,7 +263,7 @@
 
     //Returns the index of the specified state in the state array
     function getStatusIndex(state){
-      for(i=0;i<possible_states.length;i++){
+      for(var i=0;i<possible_states.length;i++){
         if(possible_states[i]==state){
           return i;
         }
@@ -320,6 +319,8 @@
     //This function is called when status information of intermediate states is required
     function askForErrorStatus(paramXMLParticular, XMLHttpRequestObj) {
       var strText = "";
+      var i;
+      var j;
       if (getReadyStateHandler(XMLHttpRequestObj,null,false)) {
         if (XMLHttpRequestObj.responseText) {
           strText = XMLHttpRequestObj.responseText;
@@ -338,27 +339,44 @@
           insertWarnsAndErrors(msg.Response);
         }
 
-        var ind11=getStatusIndex(11);
-        if(error_status[ind11]=='Success' && error_status[ind11+1]=='Success' && error_status[ind11+2]=='Success' && error_status[ind11+3]=='Success' && error_status[ind11+4]=='Success'){
-            progList_changeNode('1', 'Success');
-            progList_changeIcon('1', 'Success');
-        }else if(error_status[ind11]=='Error' || error_status[ind11+1]=='Error'|| error_status[ind11+2]=='Error'|| error_status[ind11+3]=='Error'|| error_status[ind11+4]=='Error'){
-            progList_changeNode('1', 'Error');
-            progList_changeIcon('1', 'Error');
-        }else if(error_status[ind11]=='Warning' || error_status[ind11+1]=='Warning'|| error_status[ind11+2]=='Warning'|| error_status[ind11+3]=='Warning'|| error_status[ind11+4]=='Warning'){
-            progList_changeNode('1', 'Warning');
-            progList_changeIcon('1', 'Warning');
-        }
-        var ind41=getStatusIndex(41);
-        if(error_status[ind41]=='Success' && error_status[ind41+1]=='Success' && error_status[ind41+2]=='Success' && error_status[ind41+3]=='Success' && error_status[ind41+4]=='Success'){
-            progList_changeNode('4', 'Success');
-            progList_changeIcon('4', 'Success');
-        }else if(error_status[ind41]=='Error' || error_status[ind41+1]=='Error'|| error_status[ind41+2]=='Error'|| error_status[ind41+3]=='Error'|| error_status[ind41+4]=='Error'){
-            progList_changeNode('4', 'Error');
-            progList_changeIcon('4', 'Error');
-        }else if(error_status[ind41]=='Warning' || error_status[ind41+1]=='Warning'|| error_status[ind41+2]=='Warning'|| error_status[ind41+3]=='Warning'|| error_status[ind41+4]=='Warning'){
-            progList_changeNode('4', 'Warning');
-            progList_changeIcon('4', 'Warning');
+        for(i=0;i<nodestructure.length;i++){
+            var mainStep=nodestructure[i][0];
+            var subSteps=nodestructure[i][1];
+            var success=true;
+            for(var j=0;j<subSteps.length && success;j++){
+                var ind=getStatusIndex(subSteps[j]);
+                if(error_status[ind]!=='Success'){
+                    success=false;
+                }
+            }
+            if(success){
+                progList_changeNode(correspondingNode(mainStep), 'Success');
+                progList_changeIcon(correspondingNode(mainStep), 'Success');
+            }else{
+                var error=false;
+                for(j=0;j<subSteps.length && !error;j++){
+                    var ind=getStatusIndex(subSteps[j]);
+                    if(error_status[ind]!=='Error'){
+                    	error=true;
+                    }
+                }
+                if(error){
+                    progList_changeNode(correspondingNode(getStatusIndex(mainStep)), 'Error');
+                    progList_changeIcon(correspondingNode(getStatusIndex(mainStep)), 'Error');
+                }else{
+                    var warning=false;
+                    for(j=0;j<subSteps.length && !warning;j++){
+                        var ind=getStatusIndex(subSteps[j]);
+                        if(error_status[ind]!=='Warning'){
+                            warning=true;
+                        }
+                    }
+                    if(warning){
+                        progList_changeNode(correspondingNode(getStatusIndex(mainStep)), 'Warning');
+                        progList_changeIcon(correspondingNode(getStatusIndex(mainStep)), 'Warning');
+                    }
+                }
+            }
         }
       }
     }
@@ -375,7 +393,7 @@
         var msg = eval("("+strText+")");
           
         var state=msg.Response.state;
-        if(state=="11" || start===true){
+        if(state=="10" || start===true){
           if(state=="60" || state=="59"){
             stopLocalTimer();
             processing = false;
@@ -422,37 +440,6 @@
     	        
     }
 
-    //This function resets the status of all the nodes
-    function resetAllStates(){
-      progList_changeNode('1', 'Pending');
-      progList_changeNode('1.1', 'Pending');
-      progList_changeNode('1.2', 'Pending');
-      progList_changeNode('1.3', 'Pending');
-      progList_changeNode('1.4', 'Pending');
-      progList_changeNode('1.5', 'Pending');
-      progList_changeNode('2.1', 'Pending');
-      progList_changeNode('3.1', 'Pending');
-      progList_changeNode('4', 'Pending');
-      progList_changeNode('4.1', 'Pending');
-      progList_changeNode('4.2', 'Pending');
-      progList_changeNode('4.3', 'Pending');
-      progList_changeNode('4.4', 'Pending');
-      progList_changeNode('5', 'Pending');
-      progList_changeIcon('1', 'Pending');
-      progList_changeIcon('1.1', 'Pending');
-      progList_changeIcon('1.2', 'Pending');
-      progList_changeIcon('1.3', 'Pending');
-      progList_changeIcon('1.4', 'Pending');
-      progList_changeIcon('1.5', 'Pending');
-      progList_changeIcon('2.1', 'Pending');
-      progList_changeIcon('3.1', 'Pending');
-      progList_changeIcon('4', 'Pending');
-      progList_changeIcon('4.1', 'Pending');
-      progList_changeIcon('4.2', 'Pending');
-      progList_changeIcon('4.3', 'Pending');
-      progList_changeIcon('4.4', 'Pending');
-      progList_changeIcon('5', 'Pending');
-    }
 
   </script>
   <script language="JavaScript" type="text/javascript">
--- a/src/org/openbravo/erpCommon/ad_process/ApplyModules.java	Mon May 03 18:42:20 2010 +0200
+++ b/src/org/openbravo/erpCommon/ad_process/ApplyModules.java	Fri May 07 09:29:16 2010 +0200
@@ -44,6 +44,8 @@
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.data.FieldProvider;
 import org.openbravo.erpCommon.ad_process.buildStructure.Build;
+import org.openbravo.erpCommon.ad_process.buildStructure.BuildMainStep;
+import org.openbravo.erpCommon.ad_process.buildStructure.BuildStep;
 import org.openbravo.erpCommon.ad_process.buildStructure.BuildTranslation;
 import org.openbravo.erpCommon.utility.AntExecutor;
 import org.openbravo.erpCommon.utility.OBError;
@@ -176,6 +178,7 @@
       return;
     }
 
+    Build build = getBuildFromXMLFile();
     String fileName = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
     final XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
         "org/openbravo/erpCommon/ad_process/ApplyModules").createXmlDocument();
@@ -193,9 +196,67 @@
         xmlDocument.setParameter("messageMessage", myMessage.getMessage());
       }
     }
-    FieldProvider[] nodeData = getFieldProviderFromBuild(vars);
+    FieldProvider[] nodeData = getFieldProviderFromBuild(vars, build);
     xmlDocument.setData("structureStepTree", nodeData);
 
+    String arraySteps = " var possible_states=[";
+    String errorStatus = "var error_status=[";
+    String numofWarns = "var numofwarns=[";
+    String numofErrors = "var numoferrs=[";
+    String nodeStructure = "var nodestructure=[";
+    int i = 0;
+    int k = 0;
+    for (BuildMainStep mstep : build.getMainSteps()) {
+      if (mstep.getStepList().size() > 0) {
+        if (k > 0)
+          nodeStructure += ",";
+        nodeStructure += "[" + mstep.getCode().replace("RB", "") + ",[";
+        k++;
+      } else {
+        if (i > 0) {
+          arraySteps += ",";
+          errorStatus += ",";
+          numofWarns += ",";
+          numofErrors += ",";
+        }
+        arraySteps += mstep.getCode().replace("RB", "");
+        errorStatus += "''";
+        numofWarns += "0";
+        numofErrors += "0";
+      }
+      i++;
+      int j = 0;
+      for (BuildStep step : mstep.getStepList()) {
+        if (j > 0)
+          nodeStructure += ",";
+        j++;
+        arraySteps += "," + step.getCode().replace("RB", "");
+        nodeStructure += step.getCode().replace("RB", "");
+        errorStatus += ",''";
+        numofWarns += ",0";
+        numofErrors += ",0";
+      }
+      if (mstep.getStepList().size() > 0) {
+        nodeStructure += "]]";
+      }
+    }
+    // We also add the successful final state of the last main step
+    arraySteps += ","
+        + build.getMainSteps().get(build.getMainSteps().size() - 1).getSuccessCode().replace("RB",
+            "");
+    errorStatus += ",''";
+    numofWarns += ",0";
+    numofErrors += ",0";
+    arraySteps += "];";
+    errorStatus += "];";
+    numofWarns += "];";
+    numofErrors += "];";
+    nodeStructure += "];";
+
+    String generatedJS = arraySteps + "\n" + errorStatus + "\n" + numofWarns + "\n" + numofErrors
+        + "\n" + nodeStructure + "\n" + "\n";
+    xmlDocument.setParameter("jsparam", generatedJS);
+
     response.setContentType("text/html; charset=UTF-8");
     final PrintWriter out = response.getWriter();
 
@@ -203,16 +264,14 @@
     out.close();
   }
 
-  private FieldProvider[] getFieldProviderFromBuild(VariablesSecureApp vars) {
+  private FieldProvider[] getFieldProviderFromBuild(VariablesSecureApp vars, Build build) {
     try {
       if (vars.getLanguage().equals("en_US")) {
-        Build build = getBuildFromXMLFile();
         FieldProvider[] nodeData = build.getFieldProvidersForBuild();
         return nodeData;
       } else {
         BuildTranslation buildTranslation = getBuildTranslationFromFile(vars.getLanguage());
         if (buildTranslation == null) {
-          Build build = getBuildFromXMLFile();
           FieldProvider[] nodeData = build.getFieldProvidersForBuild();
           return nodeData;
         }
@@ -257,26 +316,30 @@
     return build;
   }
 
-  private Build getBuildFromXMLFile() throws Exception {
+  private Build getBuildFromXMLFile() {
+    try {
+      String source = OBPropertiesProvider.getInstance().getOpenbravoProperties()
+          .get("source.path").toString();
+      FileReader xmlReader = new FileReader(source
+          + "/src/org/openbravo/erpCommon/ad_process/buildStructure/buildStructure.xml");
 
-    String source = OBPropertiesProvider.getInstance().getOpenbravoProperties().get("source.path")
-        .toString();
-    FileReader xmlReader = new FileReader(source
-        + "/src/org/openbravo/erpCommon/ad_process/buildStructure/buildStructure.xml");
+      BeanReader beanReader = new BeanReader();
 
-    BeanReader beanReader = new BeanReader();
+      beanReader.getBindingConfiguration().setMapIDs(false);
 
-    beanReader.getBindingConfiguration().setMapIDs(false);
+      beanReader.getXMLIntrospector().register(
+          new InputSource(new FileReader(new File(source,
+              "/src/org/openbravo/erpCommon/ad_process/buildStructure/mapping.xml"))));
 
-    beanReader.getXMLIntrospector().register(
-        new InputSource(new FileReader(new File(source,
-            "/src/org/openbravo/erpCommon/ad_process/buildStructure/mapping.xml"))));
+      beanReader.registerBeanClass("Build", Build.class);
 
-    beanReader.registerBeanClass("Build", Build.class);
+      Build build = (Build) beanReader.parse(xmlReader);
 
-    Build build = (Build) beanReader.parse(xmlReader);
-
-    return build;
+      return build;
+    } catch (Exception e) {
+      log4j.error("Error while reading the build information file");
+      return null;
+    }
   }
 
   /**
@@ -285,6 +348,7 @@
    */
   private void startApply(HttpServletResponse response, VariablesSecureApp vars)
       throws IOException, ServletException {
+    Build build = getBuildFromXMLFile();
     User currentUser = OBContext.getOBContext().getUser();
     vars.setSessionValue("ApplyModules|Last_Line_Number_Log", "-1");
     boolean admin = OBContext.getOBContext().setInAdministratorMode(true);
@@ -305,7 +369,8 @@
       }
       ps = getPreparedStatement("DELETE FROM AD_ERROR_LOG");
       ps.executeUpdate();
-      ps2 = getPreparedStatement("UPDATE AD_SYSTEM_INFO SET SYSTEM_STATUS='RB11'");
+      ps2 = getPreparedStatement("UPDATE AD_SYSTEM_INFO SET SYSTEM_STATUS='"
+          + build.getMainSteps().get(0).getCode() + "'");
       ps2.executeUpdate();
 
       Properties props = new Properties();
--- a/src/org/openbravo/erpCommon/ad_process/ApplyModules.xml	Mon May 03 18:42:20 2010 +0200
+++ b/src/org/openbravo/erpCommon/ad_process/ApplyModules.xml	Fri May 07 09:29:16 2010 +0200
@@ -27,6 +27,7 @@
   <PARAMETER id="paramCSS" name="theme" attribute="href" replace="Default"/>
   <PARAMETER id="buttonLog" name="buttonLog" attribute="onclick" replace="xx"/>
   <PARAMETER id="logfile" name="logfile" attribute="value" replace="xx"/>
+  <PARAMETER id="jsparam" name="jsparam" default=""/>
     <structure name="structureStepTree">
         <FIELD id="title_xxyy" >titleLabel</FIELD>
         <FIELD id="padding_xxyy" attribute="class" replace="xxyy">paddingLevel</FIELD>
--- a/src/org/openbravo/erpCommon/ad_process/buildStructure/BuildCreator.java	Mon May 03 18:42:20 2010 +0200
+++ b/src/org/openbravo/erpCommon/ad_process/buildStructure/BuildCreator.java	Fri May 07 09:29:16 2010 +0200
@@ -35,6 +35,7 @@
     bms1.setErrorMessage("The validation failed");
     bms1.setWarningMessage("The validation had warnings");
     build.addMainStep(bms1);
+    bms1.setSuccessCode("RB60");
 
     BuildMainStep bms2 = new BuildMainStep();
     bms2.setName("Build");
--- a/src/org/openbravo/erpCommon/ad_process/buildStructure/BuildStepWrapper.java	Mon May 03 18:42:20 2010 +0200
+++ b/src/org/openbravo/erpCommon/ad_process/buildStructure/BuildStepWrapper.java	Fri May 07 09:29:16 2010 +0200
@@ -39,7 +39,10 @@
 
   private String generateNode(String code) {
     String numCode = code.replace("RB", "");
-    return numCode.substring(0, 1) + "." + numCode.substring(1);
+    String postfix = "." + numCode.substring(1);
+    if (postfix.equals(".0"))
+      postfix = "";
+    return numCode.substring(0, 1) + postfix;
   }
 
   public String getTitleLabel() {
--- a/src/org/openbravo/erpCommon/ad_process/buildStructure/buildStructure.xml	Mon May 03 18:42:20 2010 +0200
+++ b/src/org/openbravo/erpCommon/ad_process/buildStructure/buildStructure.xml	Fri May 07 09:29:16 2010 +0200
@@ -1,22 +1,32 @@
 <?xml version='1.0' ?>
   <Build>
     <mainSteps>
-      <mainStep code="RB10">
+      <mainStep code="RB10" successCode="RB70">
         <name>Initial Build Validation</name>
         <successMessage/>
         <warningMessage>The validation had warnings</warningMessage>
         <errorMessage>The validation failed</errorMessage>
         <stepList/>
       </mainStep>
-      <mainStep code="RB20">
+      <mainStep code="RB20" successCode="RB60">
         <name>Build</name>
-        <successMessage>The build was succesfull</successMessage>
+        <successMessage>The build was successful</successMessage>
         <warningMessage/>
         <errorMessage>The build failed</errorMessage>
         <stepList>
           <step code="RB21" name="Database update"/>
           <step code="RB22" name="Compilation"/>
-          <step code="RB22" name="Deploy!"/>
+          <step code="RB23" name="Reference data"/>
+        </stepList>
+      </mainStep>
+      <mainStep code="RB30" successCode="RB60">
+        <name>Final validation</name>
+        <successMessage>The build was successful</successMessage>
+        <warningMessage/>
+        <errorMessage>The build failed</errorMessage>
+        <stepList>
+          <step code="RB31" name="Validation start"/>
+          <step code="RB32" name="Validation finish"/>
         </stepList>
       </mainStep>
     </mainSteps>