Fixed issue 38350: Unmark in development modules in production instances
authorJavier Armendáriz <javier.armendariz@openbravo.com>
Thu, 03 May 2018 10:58:06 +0200
changeset 33913 3d4d46f2c932
parent 33898 07cbc0d9c389 (current diff)
parent 33912 46704bfeb4b2 (diff)
child 33914 225d04f42766
Fixed issue 38350: Unmark in development modules in production instances
src-db/database/sourcedata/AD_MESSAGE.xml
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/ApplicationDictionaryCachedStructures.java	Fri Apr 27 19:14:34 2018 -0400
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/ApplicationDictionaryCachedStructures.java	Thu May 03 10:58:06 2018 +0200
@@ -42,6 +42,7 @@
 import org.openbravo.model.ad.domain.ReferencedTable;
 import org.openbravo.model.ad.domain.ReferencedTree;
 import org.openbravo.model.ad.domain.ReferencedTreeField;
+import org.openbravo.model.ad.module.Module;
 import org.openbravo.model.ad.ui.AuxiliaryInput;
 import org.openbravo.model.ad.ui.Field;
 import org.openbravo.model.ad.ui.Tab;
@@ -476,4 +477,23 @@
   public boolean isInDevelopment(String moduleId) {
     return this.inDevelopmentModules.contains(moduleId);
   }
+
+  /**
+   * Marks all modules as not in development and updates the cache status
+   */
+  public void setNotInDevelopment() {
+    setAllModulesAsNotInDevelopment();
+    inDevelopmentModules.clear();
+    useCache = true;
+    log.info("Setting all modules as not In Development");
+  }
+
+  private void setAllModulesAsNotInDevelopment() {
+    OBDal
+        .getInstance()
+        .getSession()
+        .createQuery(
+            "update " + Module.ENTITY_NAME + " set " + Module.PROPERTY_INDEVELOPMENT + " = false")
+        .executeUpdate();
+  }
 }
--- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelApplicationInitializer.java	Fri Apr 27 19:14:34 2018 -0400
+++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelApplicationInitializer.java	Thu May 03 10:58:06 2018 +0200
@@ -29,9 +29,11 @@
 import org.hibernate.type.StandardBasicTypes;
 import org.hibernate.type.StringType;
 import org.openbravo.client.application.report.JmxReportCache;
+import org.openbravo.client.application.window.ApplicationDictionaryCachedStructures;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.erpCommon.utility.DateTimeData;
 import org.openbravo.jmx.MBeanRegistry;
+import org.openbravo.model.ad.system.SystemInformation;
 import org.openbravo.service.db.DalConnectionProvider;
 
 /**
@@ -43,10 +45,11 @@
  */
 @ApplicationScoped
 public class KernelApplicationInitializer implements ApplicationInitializer {
-  private static Logger log4j = Logger.getLogger(KernelApplicationInitializer.class);
+  private static final Logger log4j = Logger.getLogger(KernelApplicationInitializer.class);
   private static final String sqlDateTimeFormat = "DD-MM-YYYY HH24:MI:SS";
   private static final String javaDateTimeFormat = "dd-MM-yyyy HH:mm:ss";
   private static final long THRESHOLD = 5000; // 5 seconds
+  private static final String PRODUCTION_INSTANCE = "P";
 
   @Inject
   private StaticResourceProvider resourceProvider;
@@ -54,10 +57,14 @@
   @Inject
   private JmxReportCache reportCache;
 
+  @Inject
+  private ApplicationDictionaryCachedStructures adCachedStructures;
+
   public void initialize() {
     registerSQLFunctions();
     checkDatabaseAndTomcatDateTime();
     registerMBeans();
+    setModulesAsNotInDevelopment();
   }
 
   private void registerSQLFunctions() {
@@ -110,4 +117,20 @@
     MBeanRegistry.registerMBean(KernelConstants.RESOURCE_COMPONENT_ID, resourceProvider);
     MBeanRegistry.registerMBean(JmxReportCache.MBEAN_NAME, reportCache);
   }
+
+  private void setModulesAsNotInDevelopment() {
+    log4j.debug("Checking instance purpose and In Development modules");
+    if (PRODUCTION_INSTANCE.equals(getInstancePurpose()) && adCachedStructures.isInDevelopment()) {
+      adCachedStructures.setNotInDevelopment();
+    }
+  }
+
+  private String getInstancePurpose() {
+    return (String) OBDal
+        .getInstance()
+        .getSession()
+        .createQuery(
+            "select " + SystemInformation.PROPERTY_INSTANCEPURPOSE + " from "
+                + SystemInformation.ENTITY_NAME).uniqueResult();
+  }
 }
--- a/src-db/database/model/triggers/AD_MODULE_TRG.xml	Fri Apr 27 19:14:34 2018 -0400
+++ b/src-db/database/model/triggers/AD_MODULE_TRG.xml	Thu May 03 10:58:06 2018 +0200
@@ -14,63 +14,70 @@
   * under the License.
   * The Original Code is Openbravo ERP.
   * The Initial Developer of the Original Code is Openbravo SLU
-  * All portions are Copyright (C) 2008-2012 Openbravo SLU
+  * All portions are Copyright (C) 2008-2018 Openbravo SLU
   * All Rights Reserved.
   * Contributor(s):  ______________________________________.
   ************************************************************************/
+  v_InstancePurpose CHAR(1);
+
 BEGIN
-    
-    IF AD_isTriggerEnabled()='N' THEN RETURN;
-    END IF;
 
-   IF :new.ENABLED = 'N' AND :new.AD_Module_ID = '0' THEN
-     RAISE_APPLICATION_ERROR(-20000, '@CannotDisableCore@');
-   END IF;
+  IF AD_isTriggerEnabled()='N' THEN RETURN;
+  END IF;
 
-   --Tranlsation management
-   IF INSERTING THEN
+  IF :new.ENABLED = 'N' AND :new.AD_Module_ID = '0' THEN
+    RAISE_APPLICATION_ERROR(-20000, '@CannotDisableCore@');
+  END IF;
+
+  --Prevents modules in "In Development" status in Production instances
+  SELECT instance_purpose INTO v_InstancePurpose FROM ad_system_info;
+  IF :new.isindevelopment = 'Y' AND v_InstancePurpose = 'P' THEN
+    RAISE_APPLICATION_ERROR(-20000, '@AD_MODULE_INDEV_IN_PROD@');
+  END IF;
+
+  --Tranlsation management
+  IF INSERTING THEN
     --  Create Translation Row
-      INSERT INTO AD_Module_Trl
-        (
-          AD_Module_Trl_ID, AD_Module_ID, AD_Language, AD_Client_ID,
-          AD_Org_ID, IsActive, Created,
-          CreatedBy, Updated, UpdatedBy,
-          Description, Help, License,
-          IsTranslated
-        )
-      SELECT get_uuid(), :new.AD_Module_ID, AD_Language, :new.AD_Client_ID, 
-        :new.AD_Org_ID, :new.IsActive, :new.Created, 
-        :new.CreatedBy, :new.Updated, :new.UpdatedBy, 
+    INSERT INTO AD_Module_Trl
+    (
+      AD_Module_Trl_ID, AD_Module_ID, AD_Language, AD_Client_ID,
+      AD_Org_ID, IsActive, Created,
+      CreatedBy, Updated, UpdatedBy,
+      Description, Help, License,
+      IsTranslated
+    )
+      SELECT get_uuid(), :new.AD_Module_ID, AD_Language, :new.AD_Client_ID,
+        :new.AD_Org_ID, :new.IsActive, :new.Created,
+        :new.CreatedBy, :new.Updated, :new.UpdatedBy,
         :new.Description, :new.Help, :new.License,
         'N'
       FROM AD_Language
       WHERE IsActive='Y'
-        AND IsSystemLanguage='Y'
-        and (AD_Language.AD_Language != :new.ad_language or :new.ad_language is null);
-   END IF;
- 
-   IF UPDATING THEN
-    IF :new.IsRegistered ='Y' 
-      AND (COALESCE(:NEW.NAME, '.') <> COALESCE(:NEW.NAME, '.')
-        OR COALESCE(:NEW.TYPE, '.') <> COALESCE(:NEW.TYPE, '.')
-        OR COALESCE(:NEW.JAVAPACKAGE, '.') <> COALESCE(:NEW.JAVAPACKAGE, '.')) THEN
+            AND IsSystemLanguage='Y'
+            and (AD_Language.AD_Language != :new.ad_language or :new.ad_language is null);
+  END IF;
+
+  IF UPDATING THEN
+    IF :new.IsRegistered ='Y'
+       AND (COALESCE(:NEW.NAME, '.') <> COALESCE(:NEW.NAME, '.')
+            OR COALESCE(:NEW.TYPE, '.') <> COALESCE(:NEW.TYPE, '.')
+            OR COALESCE(:NEW.JAVAPACKAGE, '.') <> COALESCE(:NEW.JAVAPACKAGE, '.')) THEN
       RAISE_APPLICATION_ERROR(-20000, '@20534@');
     END IF;
-    
-    
+
+
     IF(COALESCE(:old.License, '.') <> COALESCE(:NEW.License, '.')
-    OR COALESCE(:old.Description, '.') <> COALESCE(:NEW.Description, '.')
-    OR COALESCE(:old.Help, '.') <> COALESCE(:NEW.Help, '.'))
+       OR COALESCE(:old.Description, '.') <> COALESCE(:NEW.Description, '.')
+       OR COALESCE(:old.Help, '.') <> COALESCE(:NEW.Help, '.'))
     THEN
       UPDATE AD_Module_Trl
-        SET IsTranslated='N',
+      SET IsTranslated='N',
         Updated=now()
       WHERE AD_Module_ID=:new.AD_Module_ID;
     END IF;
-   END IF;
-   
+  END IF;
 
-END AD_MODULE_TRG
+  END AD_MODULE_TRG
 ]]></body>
     </trigger>
   </database>
--- a/src-db/database/sourcedata/AD_MESSAGE.xml	Fri Apr 27 19:14:34 2018 -0400
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml	Thu May 03 10:58:06 2018 +0200
@@ -17185,6 +17185,18 @@
 <!--1CF066F6A68F419CA5241635305B9B77-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--1CF066F6A68F419CA5241635305B9B77--></AD_MESSAGE>
 
+<!--1D16D5D832AD4431A169647C6470CDCA--><AD_MESSAGE>
+<!--1D16D5D832AD4431A169647C6470CDCA-->  <AD_MESSAGE_ID><![CDATA[1D16D5D832AD4431A169647C6470CDCA]]></AD_MESSAGE_ID>
+<!--1D16D5D832AD4431A169647C6470CDCA-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--1D16D5D832AD4431A169647C6470CDCA-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--1D16D5D832AD4431A169647C6470CDCA-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--1D16D5D832AD4431A169647C6470CDCA-->  <VALUE><![CDATA[AD_MODULE_INDEV_IN_PROD]]></VALUE>
+<!--1D16D5D832AD4431A169647C6470CDCA-->  <MSGTEXT><![CDATA[Cannot have modules in "In Development" status in a Production instance]]></MSGTEXT>
+<!--1D16D5D832AD4431A169647C6470CDCA-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--1D16D5D832AD4431A169647C6470CDCA-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--1D16D5D832AD4431A169647C6470CDCA-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--1D16D5D832AD4431A169647C6470CDCA--></AD_MESSAGE>
+
 <!--1D2905EAB15A4DB0B794BF8DC11F2678--><AD_MESSAGE>
 <!--1D2905EAB15A4DB0B794BF8DC11F2678-->  <AD_MESSAGE_ID><![CDATA[1D2905EAB15A4DB0B794BF8DC11F2678]]></AD_MESSAGE_ID>
 <!--1D2905EAB15A4DB0B794BF8DC11F2678-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src/org/openbravo/erpCommon/ad_forms/InstancePurpose.java	Fri Apr 27 19:14:34 2018 -0400
+++ b/src/org/openbravo/erpCommon/ad_forms/InstancePurpose.java	Thu May 03 10:58:06 2018 +0200
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2010-2012 Openbravo SLU 
+ * All portions are Copyright (C) 2010-2018 Openbravo SLU
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -22,6 +22,7 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 
+import javax.inject.Inject;
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -32,6 +33,7 @@
 import org.openbravo.base.filter.ValueListFilter;
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.client.application.window.ApplicationDictionaryCachedStructures;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.erpCommon.ad_process.HeartbeatProcess;
@@ -47,6 +49,10 @@
   private static final long serialVersionUID = 1L;
   private static final ValueListFilter availablePurposeFilter = new ValueListFilter("P", "D", "T",
       "E");
+  private static final String PRODUCTION_INSTANCE = "P";
+
+  @Inject
+  private ApplicationDictionaryCachedStructures adCachedStructures;
 
   @Override
   public void init(ServletConfig config) {
@@ -160,6 +166,10 @@
     if (HeartbeatProcess.isClonedInstance()) {
       InstanceManagement.insertDummyHBLog();
     }
+
+    if (PRODUCTION_INSTANCE.equals(strPurpose)) {
+      adCachedStructures.setNotInDevelopment();
+    }
   }
 
   @Override
--- a/src/org/openbravo/erpCommon/obps/ActiveInstanceProcess.java	Fri Apr 27 19:14:34 2018 -0400
+++ b/src/org/openbravo/erpCommon/obps/ActiveInstanceProcess.java	Thu May 03 10:58:06 2018 +0200
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2009-2017 Openbravo SLU 
+ * All portions are Copyright (C) 2009-2018 Openbravo SLU
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -28,6 +28,9 @@
 import org.apache.log4j.Logger;
 import org.hibernate.Query;
 import org.openbravo.base.provider.OBProvider;
+import org.openbravo.base.session.SessionFactoryController;
+import org.openbravo.base.weld.WeldUtils;
+import org.openbravo.client.application.window.ApplicationDictionaryCachedStructures;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.erpCommon.ad_forms.MaturityLevel;
@@ -50,6 +53,7 @@
   private static final Logger log = Logger.getLogger(ActiveInstanceProcess.class);
   private static final String BUTLER_URL = "https://butler.openbravo.com:443/heartbeat-server/activate";
   private static final String EVALUATION_PURPOSE = "E";
+  private static final String PRODUCTION_PURPOSE = "P";
 
   @Override
   public void execute(ProcessBundle bundle) throws Exception {
@@ -141,6 +145,10 @@
           if (HeartbeatProcess.isClonedInstance()) {
             insertDummyHBLog();
           }
+
+          if (PRODUCTION_PURPOSE.equals(purpose)) {
+            setModulesAsNotInDevelopment();
+          }
         } else {
           msg.setType("Error");
           msg.setMessage(ak.getErrorMessage());
@@ -159,6 +167,21 @@
 
   }
 
+  private void setModulesAsNotInDevelopment() {
+    if (SessionFactoryController.isRunningInWebContainer()) {
+      WeldUtils.getInstanceFromStaticBeanManager(ApplicationDictionaryCachedStructures.class)
+          .setNotInDevelopment();
+    } else {
+      // executing from ant activate.instance task
+      OBDal
+          .getInstance()
+          .getSession()
+          .createQuery(
+              "update " + Module.ENTITY_NAME + " set " + Module.PROPERTY_INDEVELOPMENT + " = false")
+          .executeUpdate();
+    }
+  }
+
   public static void updateShowProductionFields(String value) {
     String hql = "update ADPreference set searchKey = :value where property = 'showMRPandProductionFields' and module.id is null";
     Query q = OBDal.getInstance().getSession().createQuery(hql);
@@ -174,7 +197,7 @@
 
   /**
    * Sends the request for the activation key.
-   * 
+   *
    * @param publickey
    *          Instance's public key
    * @param purpose