[DynamicRebuildWindow] Changes done to make the final message (Error message, warning message, success message) shown in the rebuild window dynamic.
authorAntonio Moreno <antonio.moreno@openbravo.com>
Mon, 10 May 2010 19:56:44 +0200
changeset 7519 647c337ada59
parent 7518 cc5f433a8c29
child 7520 040e2c2c2640
[DynamicRebuildWindow] Changes done to make the final message (Error message, warning message, success message) shown in the rebuild window dynamic.
build.xml
src-core/src/org/openbravo/base/BuildTask.java
src-db/database/lib/dbsourcemanager.jar
src/org/openbravo/erpCommon/ad_process/ApplyModules.html
src/org/openbravo/erpCommon/ad_process/ApplyModules.java
src/org/openbravo/erpCommon/ad_process/ApplyModulesCallServlet.java
src/org/openbravo/erpCommon/ad_process/buildStructure/Build.java
src/org/openbravo/erpCommon/ad_process/buildStructure/BuildTranslation.java
src/org/openbravo/erpCommon/ad_process/buildStructure/buildStructure.xml
src/org/openbravo/erpCommon/ad_process/buildStructure/mapping.xml
--- a/build.xml	Fri May 07 18:02:35 2010 +0200
+++ b/build.xml	Mon May 10 19:56:44 2010 +0200
@@ -650,8 +650,6 @@
     <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-core/src/org/openbravo/base/BuildTask.java	Fri May 07 18:02:35 2010 +0200
+++ b/src-core/src/org/openbravo/base/BuildTask.java	Mon May 10 19:56:44 2010 +0200
@@ -76,7 +76,7 @@
         System.out.println(task);
       System.out.println("modules: " + unnappliedModules);
       ant.runTask(tasks);
-      log.info("fin");
+      updateFinalState();
     } catch (Exception e) {
       e.printStackTrace();
       throw new Exception("jarl");
@@ -152,6 +152,20 @@
     return true;
   }
 
+  private static boolean updateFinalState() {
+    try {
+      String strSql = "UPDATE AD_SYSTEM_INFO SET SYSTEM_STATUS='RB60'";
+      ConnectionProvider cp = getConnectionProvider();
+      PreparedStatement ps = cp.getPreparedStatement(strSql);
+      ResultSet rs = ps.executeQuery();
+      rs.next();
+      return rs.getInt(1) != 0;
+    } catch (Exception e) {
+      // What should we do here?
+    }
+    return true;
+  }
+
   private static ConnectionProvider getConnectionProvider() {
     ConnectionProvider cp = null;
     cp = new CPStandAlone(propertiesFile);
Binary file src-db/database/lib/dbsourcemanager.jar has changed
--- a/src/org/openbravo/erpCommon/ad_process/ApplyModules.html	Fri May 07 18:02:35 2010 +0200
+++ b/src/org/openbravo/erpCommon/ad_process/ApplyModules.html	Mon May 10 19:56:44 2010 +0200
@@ -407,8 +407,9 @@
         var msg = eval("("+strText+")");
           
         var state=msg.Response.state;
+        var errorStatus=msg.Response.statusofstate;
         if(state==first_state || start===true){
-          if(contains(end_states,state)){
+          if(contains(end_states,state) || errorStatus=="Error"){
             stopLocalTimer();
             processing = false;
             top.opener.setProcessingMode('window', false);
@@ -416,7 +417,6 @@
             submitXmlHttpRequest(getError, frm, "GETERR", "ApplyModulesCallServlet.html", false, null, null);
           }
           start=true;
-          var errorStatus=msg.Response.statusofstate;
           var stateindex=getStatusIndex(state);
           if(stateindex>current_state){
             pending_states=stateindex-current_state;
@@ -445,7 +445,7 @@
           current_state=stateindex;
         }
       }
-      if(contains(end_states,state)){
+      if(contains(end_states,state) || errorStatus=="Error"){
     	processing = false;
     	top.opener.setProcessingMode('window', false);
     	var frm = document.frmMain;
--- a/src/org/openbravo/erpCommon/ad_process/ApplyModules.java	Fri May 07 18:02:35 2010 +0200
+++ b/src/org/openbravo/erpCommon/ad_process/ApplyModules.java	Mon May 10 19:56:44 2010 +0200
@@ -23,7 +23,6 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.sql.PreparedStatement;
-import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -296,6 +295,7 @@
         return nodeData;
       } else {
         BuildTranslation buildTranslation = getBuildTranslationFromFile(vars.getLanguage());
+        buildTranslation.setBuild(build);
         if (buildTranslation == null) {
           FieldProvider[] nodeData = build.getFieldProvidersForBuild();
           return nodeData;
@@ -309,7 +309,7 @@
     return null;
   }
 
-  private BuildTranslation getBuildTranslationFromFile(String language) throws Exception {
+  protected static BuildTranslation getBuildTranslationFromFile(String language) throws Exception {
 
     String source = OBPropertiesProvider.getInstance().getOpenbravoProperties().get("source.path")
         .toString();
@@ -341,26 +341,15 @@
     return build;
   }
 
-  private Build getBuildFromXMLFile() {
+  protected 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");
+      return Build.getBuildFromXMLFile(source
+          + "/src/org/openbravo/erpCommon/ad_process/buildStructure/buildStructure.xml", new File(
+          source, "/src/org/openbravo/erpCommon/ad_process/buildStructure/mapping.xml")
+          .getAbsolutePath());
 
-      BeanReader beanReader = new BeanReader();
-
-      beanReader.getBindingConfiguration().setMapIDs(false);
-
-      beanReader.getXMLIntrospector().register(
-          new InputSource(new FileReader(new File(source,
-              "/src/org/openbravo/erpCommon/ad_process/buildStructure/mapping.xml"))));
-
-      beanReader.registerBeanClass("Build", Build.class);
-
-      Build build = (Build) beanReader.parse(xmlReader);
-
-      return build;
     } catch (Exception e) {
       log4j.error("Error while reading the build information file");
       return null;
@@ -425,18 +414,6 @@
       updateSession.executeUpdate();
       ant.runTask(tasks);
 
-      PreparedStatement psErr = getPreparedStatement("SELECT MESSAGE FROM AD_ERROR_LOG WHERE ERROR_LEVEL='ERROR'");
-      psErr.executeQuery();
-      ResultSet rsErr = psErr.getResultSet();
-      if (!rsErr.next()) {
-        ps3 = getPreparedStatement("UPDATE AD_SYSTEM_INFO SET SYSTEM_STATUS='RB60'");
-        ps3.executeUpdate();
-        ps4 = getPreparedStatement("UPDATE AD_MODULE SET STATUS='A' WHERE STATUS='P'");
-        ps4.executeUpdate();
-      } else {
-        ps3 = getPreparedStatement("UPDATE AD_SYSTEM_INFO SET SYSTEM_STATUS='RB59'");
-        ps3.executeUpdate();
-      }
       out.close();
     } catch (final Exception e) {
       // rolback the old transaction and start a new one
--- a/src/org/openbravo/erpCommon/ad_process/ApplyModulesCallServlet.java	Fri May 07 18:02:35 2010 +0200
+++ b/src/org/openbravo/erpCommon/ad_process/ApplyModulesCallServlet.java	Mon May 10 19:56:44 2010 +0200
@@ -18,6 +18,7 @@
  */
 package org.openbravo.erpCommon.ad_process;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.sql.PreparedStatement;
@@ -31,6 +32,12 @@
 
 import org.openbravo.base.HttpBaseServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.base.session.OBPropertiesProvider;
+import org.openbravo.erpCommon.ad_process.buildStructure.Build;
+import org.openbravo.erpCommon.ad_process.buildStructure.BuildMainStep;
+import org.openbravo.erpCommon.ad_process.buildStructure.BuildMainStepTranslation;
+import org.openbravo.erpCommon.ad_process.buildStructure.BuildStep;
+import org.openbravo.erpCommon.ad_process.buildStructure.BuildTranslation;
 import org.openbravo.erpCommon.utility.OBError;
 import org.openbravo.erpCommon.utility.Utility;
 
@@ -210,7 +217,7 @@
       ResultSet rs = ps.getResultSet();
       rs.next();
       String state = rs.getString(1);
-      ApplyModulesResponse resp = fillResponse(vars, state, "Processing", false);
+      ApplyModulesResponse resp = fillResponse(vars, state, "Processing", true);
       response.setContentType("text/plain; charset=UTF-8");
       final PrintWriter out = response.getWriter();
       String strResult;
@@ -270,6 +277,7 @@
     if (ln == null || ln.equals("")) {
       return;
     }
+    String finalMessageType = "";
     OBError error = new OBError();
     PreparedStatement ps;
     PreparedStatement ps2;
@@ -278,41 +286,120 @@
       ps.executeQuery();
       ResultSet rs = ps.getResultSet();
       if (rs.next()) {
-        error.setType("Error");
-        error.setTitle(Utility.messageBD(myPool, "Error", vars.getLanguage()));
-        error
-            .setMessage(Utility.messageBD(myPool, "BuildError", vars.getLanguage())
-                + "<a href=\"http://wiki.openbravo.com/wiki/ERP/2.50/Update_Tips\" target=\"_blank\" class=\"MessageBox_TextLink\">"
-                + Utility.messageBD(myPool, "ThisLink", vars.getLanguage()) + "</a>");
-
+        finalMessageType = "Error";
       } else {
         ps2 = getPreparedStatement("SELECT MESSAGE FROM AD_ERROR_LOG WHERE ERROR_LEVEL='WARN'");
         ps2.executeQuery();
         ResultSet rs2 = ps2.getResultSet();
         if (rs2.next()) {
-          error.setType("Warning");
-          error.setTitle(Utility.messageBD(myPool, "Warning", vars.getLanguage()));
-          error
-              .setMessage(Utility.messageBD(myPool, "BuildWarning", vars.getLanguage())
-                  + "<a href=\"http://wiki.openbravo.com/wiki/ERP/2.50/Update_Tips\" target=\"_blank\" class=\"MessageBox_TextLink\">"
-                  + Utility.messageBD(myPool, "ThisLink", vars.getLanguage()) + "</a>"
-                  + Utility.messageBD(myPool, "BuildWarning2", vars.getLanguage()));
+          finalMessageType = "Warning";
+        } else {
+          finalMessageType = "Success";
+        }
+      }
 
-        } else {
-          error.setType("Success");
-          error.setTitle(Utility.messageBD(myPool, "Success", vars.getLanguage()));
-          error.setMessage(Utility.messageBD(myPool, "BuildSuccessful", vars.getLanguage()));
+      error.setType(finalMessageType);
+      error.setTitle(Utility.messageBD(myPool, finalMessageType, vars.getLanguage()));
+      error.setMessage("");
+
+      String source = OBPropertiesProvider.getInstance().getOpenbravoProperties()
+          .get("source.path").toString();
+      Build build = Build.getBuildFromXMLFile(source
+          + "/src/org/openbravo/erpCommon/ad_process/buildStructure/buildStructure.xml", new File(
+          source, "/src/org/openbravo/erpCommon/ad_process/buildStructure/mapping.xml")
+          .getAbsolutePath());
+
+      BuildMainStep finalStep;
+      if (finalMessageType.equals("Error")) {
+        PreparedStatement ps3 = getPreparedStatement("SELECT SYSTEM_STATUS FROM AD_SYSTEM_INFO");
+        ps3.executeQuery();
+        ResultSet rs3 = ps3.getResultSet();
+        rs3.next();
+        String state = rs3.getString(1);
+        finalStep = build.mainStepOfCode(state);
+      } else {
+        finalStep = build.getMainSteps().get(build.getMainSteps().size() - 1);
+      }
+      if (vars.getLanguage().equals("en_US")) {
+        if (finalMessageType.equals("Error")) {
+          error.setMessage(finalStep.getErrorMessage());
+        } else if (finalMessageType.equals("Warning")) {
+          error.setMessage(finalStep.getWarningMessage());
+        } else if (finalMessageType.equals("Success")) {
+          error.setMessage(finalStep.getSuccessMessage());
         }
+      } else {
+        BuildTranslation buildTranslation = ApplyModules.getBuildTranslationFromFile(vars
+            .getLanguage());
+        buildTranslation.setBuild(build);
+        BuildMainStepTranslation stepTranslation = buildTranslation
+            .getBuildMainStepTranslationForCode(finalStep.getCode());
+        String message = null;
+        if (finalMessageType.equals("Error")) {
+          message = stepTranslation.getTranslatedErrorMessage();
+        } else if (finalMessageType.equals("Warning")) {
+          message = stepTranslation.getTranslatedWarningMessage();
+        } else if (finalMessageType.equals("Success")) {
+          message = stepTranslation.getTranslatedSuccessMessage();
+        }
+        if (message == null || message.equals("")) {
+          if (finalMessageType.equals("Error")) {
+            message = finalStep.getErrorMessage();
+          } else if (finalMessageType.equals("Warning")) {
+            message = finalStep.getWarningMessage();
+          } else if (finalMessageType.equals("Success")) {
+            message = finalStep.getSuccessMessage();
+          }
+        }
+        error.setMessage(message);
+      }
+
+      XStream xs = new XStream(new JettisonMappedXmlDriver());
+      xs.alias("OBError", OBError.class);
+      String strResult = xs.toXML(error);
+      response.setContentType("text/html; charset=UTF-8");
+      final PrintWriter out = response.getWriter();
+      out.print(strResult);
+      out.close();
+
+      PreparedStatement psErr = getPreparedStatement("SELECT MESSAGE FROM AD_ERROR_LOG WHERE ERROR_LEVEL='ERROR'");
+      psErr.executeQuery();
+      ResultSet rsErr = psErr.getResultSet();
+      if (!rsErr.next()) {
+        String successCode = build.getMainSteps().get(build.getMainSteps().size() - 1)
+            .getSuccessCode();
+        PreparedStatement ps3 = getPreparedStatement("UPDATE AD_SYSTEM_INFO SET SYSTEM_STATUS='"
+            + successCode + "'");
+        ps3.executeUpdate();
+        PreparedStatement ps4 = getPreparedStatement("UPDATE AD_MODULE SET STATUS='A' WHERE STATUS='P'");
+        ps4.executeUpdate();
+      } else {
+        ps = getPreparedStatement("SELECT SYSTEM_STATUS FROM AD_SYSTEM_INFO");
+        ps.executeQuery();
+        ResultSet rs1 = ps.getResultSet();
+        rs1.next();
+        String state = rs1.getString(1);
+        BuildMainStep finalMainStep = build.mainStepOfCode(state);
+        String errorCode = finalMainStep.getErrorCode();
+        PreparedStatement ps3 = getPreparedStatement("UPDATE AD_SYSTEM_INFO SET SYSTEM_STATUS='"
+            + errorCode + "'");
+        ps3.executeUpdate();
       }
     } catch (Exception e) {
     }
+  }
 
-    XStream xs = new XStream(new JettisonMappedXmlDriver());
-    xs.alias("OBError", OBError.class);
-    String strResult = xs.toXML(error);
-    response.setContentType("text/html; charset=UTF-8");
-    final PrintWriter out = response.getWriter();
-    out.print(strResult);
-    out.close();
+  private BuildMainStep getMainStep(Build build, String stepCode) {
+    for (BuildMainStep mstep : build.getMainSteps()) {
+      if (mstep.getCode().equals(stepCode)) {
+        return mstep;
+      }
+      for (BuildStep step : mstep.getStepList()) {
+        if (step.getCode().equals(stepCode)) {
+          return mstep;
+        }
+      }
+    }
+    return null;
   }
 }
--- a/src/org/openbravo/erpCommon/ad_process/buildStructure/Build.java	Fri May 07 18:02:35 2010 +0200
+++ b/src/org/openbravo/erpCommon/ad_process/buildStructure/Build.java	Mon May 10 19:56:44 2010 +0200
@@ -1,9 +1,14 @@
 package org.openbravo.erpCommon.ad_process.buildStructure;
 
+import java.io.File;
+import java.io.FileReader;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.commons.betwixt.io.BeanReader;
+import org.openbravo.base.session.OBPropertiesProvider;
 import org.openbravo.data.FieldProvider;
+import org.xml.sax.InputSource;
 
 public class Build {
   private List<BuildMainStep> mainSteps;
@@ -45,4 +50,43 @@
     return fps;
   }
 
+  public static Build getBuildFromXMLFile(String buildFilePath, String mappingFilePath)
+      throws Exception {
+
+    String source = OBPropertiesProvider.getInstance().getOpenbravoProperties().get("source.path")
+        .toString();
+    FileReader xmlReader = new FileReader(buildFilePath);
+
+    BeanReader beanReader = new BeanReader();
+
+    beanReader.getBindingConfiguration().setMapIDs(false);
+
+    beanReader.getXMLIntrospector().register(
+        new InputSource(new FileReader(new File(mappingFilePath))));
+
+    beanReader.registerBeanClass("Build", Build.class);
+
+    Build build = (Build) beanReader.parse(xmlReader);
+    return build;
+  }
+
+  public BuildMainStep mainStepOfCode(String state) {
+
+    for (BuildMainStep mstep : getMainSteps()) {
+      if (mstep.getCode().equals(state))
+        return mstep;
+      for (BuildStep step : mstep.getStepList()) {
+        if (step.getCode().equals(state)) {
+          return mstep;
+        }
+      }
+      if (state.equals(mstep.getSuccessCode()))
+        return mstep;
+      if (state.equals(mstep.getWarningCode()))
+        return mstep;
+      if (state.equals(mstep.getErrorCode()))
+        return mstep;
+    }
+    return null;
+  }
 }
--- a/src/org/openbravo/erpCommon/ad_process/buildStructure/BuildTranslation.java	Fri May 07 18:02:35 2010 +0200
+++ b/src/org/openbravo/erpCommon/ad_process/buildStructure/BuildTranslation.java	Mon May 10 19:56:44 2010 +0200
@@ -1,13 +1,17 @@
 package org.openbravo.erpCommon.ad_process.buildStructure;
 
+import java.io.FileReader;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.commons.betwixt.io.BeanReader;
 import org.openbravo.data.FieldProvider;
+import org.xml.sax.InputSource;
 
 public class BuildTranslation {
   private String language;
   private List<BuildMainStepTranslation> mainStepTranslations;
+  private Build build;
 
   public BuildTranslation() {
     mainStepTranslations = new ArrayList<BuildMainStepTranslation>();
@@ -44,9 +48,29 @@
         }
       }
     }
+    if (build != null) {
+      for (BuildMainStep mainStep : build.getMainSteps()) {
+        if (mainStep.getCode().equalsIgnoreCase(code)) {
+          return mainStep.getName();
+        }
+        for (BuildStep step : mainStep.getStepList()) {
+          if (step.getCode().equalsIgnoreCase(code)) {
+            return step.getName();
+          }
+        }
+      }
+    }
     return "";
   }
 
+  public BuildMainStepTranslation getBuildMainStepTranslationForCode(String code) {
+    for (BuildMainStepTranslation tr : mainStepTranslations) {
+      if (tr.getCode().equals(code))
+        return tr;
+    }
+    return null;
+  }
+
   public FieldProvider[] getFieldProvidersForBuild() {
     ArrayList<FieldProvider> fieldProviderList = new ArrayList<FieldProvider>();
     for (BuildMainStepTranslation mainStep : mainStepTranslations) {
@@ -62,4 +86,26 @@
       fps[i++] = fp;
     return fps;
   }
+
+  public static BuildTranslation getTranslationFileFromXML(String translationFilePath,
+      String mappingFilePath) throws Exception {
+
+    FileReader xmlReader = new FileReader(translationFilePath);
+
+    BeanReader beanReader = new BeanReader();
+
+    beanReader.getBindingConfiguration().setMapIDs(false);
+
+    beanReader.getXMLIntrospector().register(new InputSource(new FileReader(mappingFilePath)));
+
+    beanReader.registerBeanClass("BuildTranslation", BuildTranslation.class);
+
+    BuildTranslation build = (BuildTranslation) beanReader.parse(xmlReader);
+
+    return build;
+  }
+
+  public void setBuild(Build build) {
+    this.build = build;
+  }
 }
--- a/src/org/openbravo/erpCommon/ad_process/buildStructure/buildStructure.xml	Fri May 07 18:02:35 2010 +0200
+++ b/src/org/openbravo/erpCommon/ad_process/buildStructure/buildStructure.xml	Mon May 10 19:56:44 2010 +0200
@@ -19,15 +19,5 @@
           <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>
   </Build>
--- a/src/org/openbravo/erpCommon/ad_process/buildStructure/mapping.xml	Fri May 07 18:02:35 2010 +0200
+++ b/src/org/openbravo/erpCommon/ad_process/buildStructure/mapping.xml	Mon May 10 19:56:44 2010 +0200
@@ -43,14 +43,17 @@
       <attribute name="code"          property="code"/>
       <attribute name="originalName"    property="originalName"/>
       <attribute name="translatedName"      property="translatedName"/>
-      <element name="translatedSuccessMessage"      property="originalSuccessMessage">
-        <attribute name="originalSuccessMessage"      property="translatedSuccessMessage"/>
+      <element name="translatedSuccessMessage">
+        <attribute name="originalSuccessMessage"      property="originalSuccessMessage"/>
+        <attribute name="translatedSuccessMessage"      property="translatedSuccessMessage"/>
       </element>
-      <element name="translatedWarningMessage"      property="originalWarningMessage">
-        <attribute name="originalWarningMessage"      property="translatedWarningMessage"/>
+      <element name="translatedWarningMessage">
+        <attribute name="originalWarningMessage"      property="originalWarningMessage"/>
+        <attribute name="translatedWarningMessage"      property="translatedWarningMessage"/>
       </element>
-      <element name="translatedErrorMessage"      property="originalErrorMessage">
-        <attribute name="originalErrorMessage"      property="translatedErrorMessage"/>
+      <element name="translatedErrorMessage">
+        <attribute name="originalErrorMessage"      property="originalErrorMessage"/>
+        <attribute name="translatedErrorMessage"      property="translatedErrorMessage"/>
       </element>
       <addDefaults/>
     </element>