Fixed issue 15048.Purpose is set on System Info if it is null and it is an active instance.
authorGorka Ion Damián <gorkaion.damian@openbravo.com>
Wed, 27 Oct 2010 14:44:39 +0200
changeset 8830 4845dd2480d5
parent 8829 13c29a90462c
child 8831 6dadb8e721ce
Fixed issue 15048.Purpose is set on System Info if it is null and it is an active instance.
src/org/openbravo/erpCommon/ad_process/HeartbeatProcess.java
--- a/src/org/openbravo/erpCommon/ad_process/HeartbeatProcess.java	Wed Oct 27 11:52:55 2010 +0200
+++ b/src/org/openbravo/erpCommon/ad_process/HeartbeatProcess.java	Wed Oct 27 14:44:39 2010 +0200
@@ -24,6 +24,7 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.security.GeneralSecurityException;
+import java.sql.SQLException;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -52,6 +53,7 @@
 import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.businessUtility.HeartbeatData;
 import org.openbravo.erpCommon.businessUtility.RegistrationData;
+import org.openbravo.erpCommon.obps.ActivationKey;
 import org.openbravo.erpCommon.utility.Alert;
 import org.openbravo.erpCommon.utility.HttpsUtils;
 import org.openbravo.erpCommon.utility.SystemInfo;
@@ -633,8 +635,23 @@
   public static boolean isShowInstancePurposeRequired() {
     final SystemInformation systemInformation = OBDal.getInstance().get(SystemInformation.class,
         "0");
-    return (systemInformation.getInstancePurpose() == null || systemInformation
-        .getInstancePurpose().isEmpty());
+    if (systemInformation.getInstancePurpose() == null
+        || systemInformation.getInstancePurpose().isEmpty()) {
+      if (ActivationKey.isActiveInstance()) {
+        systemInformation.setInstancePurpose(ActivationKey.getInstance().getProperty("purpose"));
+        OBDal.getInstance().save(systemInformation);
+        OBDal.getInstance().flush();
+        try {
+          OBDal.getInstance().getConnection().commit();
+        } catch (SQLException e) {
+          // ignore exception on commit
+          log.error("Error on commit", e);
+        }
+        return false;
+      }
+      return true;
+    }
+    return false;
   }
 
   public static boolean isClonedInstance() throws ServletException {