Fixed issue 32880: Instance Activation window should displayed extra info
authorInigo Sanchez <inigo.sanchez@openbravo.com>
Fri, 06 May 2016 10:09:56 +0200
changeset 29449 58bacde3f953
parent 29438 14e14d88f186 (current diff)
parent 29448 f16a58c86875 (diff)
child 29450 098506f49242
child 29489 1c0637886cfe
Fixed issue 32880: Instance Activation window should displayed extra info

Instance Activation window should displayed extra information in an
activated instance:
* Number of calls to web services at current day.
* Current concurrent users.
* Active POS terminals.
--- a/src-db/database/sourcedata/AD_MESSAGE.xml	Fri May 06 09:38:49 2016 +0200
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml	Fri May 06 10:09:56 2016 +0200
@@ -26569,6 +26569,18 @@
 <!--E54B403F2B0944E6A68D06661BD7F47E-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--E54B403F2B0944E6A68D06661BD7F47E--></AD_MESSAGE>
 
+<!--E5591DEB3EF44C7493DAA1A7A4429105--><AD_MESSAGE>
+<!--E5591DEB3EF44C7493DAA1A7A4429105-->  <AD_MESSAGE_ID><![CDATA[E5591DEB3EF44C7493DAA1A7A4429105]]></AD_MESSAGE_ID>
+<!--E5591DEB3EF44C7493DAA1A7A4429105-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--E5591DEB3EF44C7493DAA1A7A4429105-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--E5591DEB3EF44C7493DAA1A7A4429105-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--E5591DEB3EF44C7493DAA1A7A4429105-->  <VALUE><![CDATA[OPSWSCounterDay]]></VALUE>
+<!--E5591DEB3EF44C7493DAA1A7A4429105-->  <MSGTEXT><![CDATA[Current Web Services calls]]></MSGTEXT>
+<!--E5591DEB3EF44C7493DAA1A7A4429105-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--E5591DEB3EF44C7493DAA1A7A4429105-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--E5591DEB3EF44C7493DAA1A7A4429105-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--E5591DEB3EF44C7493DAA1A7A4429105--></AD_MESSAGE>
+
 <!--E584531278034B1BA298C7CEBB58EAD2--><AD_MESSAGE>
 <!--E584531278034B1BA298C7CEBB58EAD2-->  <AD_MESSAGE_ID><![CDATA[E584531278034B1BA298C7CEBB58EAD2]]></AD_MESSAGE_ID>
 <!--E584531278034B1BA298C7CEBB58EAD2-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -26750,6 +26762,18 @@
 <!--E7EBD616ABA7417DB1759D8B7E901405-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--E7EBD616ABA7417DB1759D8B7E901405--></AD_MESSAGE>
 
+<!--E7EBD96FEE9A4B9790F47EB089F72888--><AD_MESSAGE>
+<!--E7EBD96FEE9A4B9790F47EB089F72888-->  <AD_MESSAGE_ID><![CDATA[E7EBD96FEE9A4B9790F47EB089F72888]]></AD_MESSAGE_ID>
+<!--E7EBD96FEE9A4B9790F47EB089F72888-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--E7EBD96FEE9A4B9790F47EB089F72888-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--E7EBD96FEE9A4B9790F47EB089F72888-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--E7EBD96FEE9A4B9790F47EB089F72888-->  <VALUE><![CDATA[OPSCurrentConcurrentUsers]]></VALUE>
+<!--E7EBD96FEE9A4B9790F47EB089F72888-->  <MSGTEXT><![CDATA[Current concurrent users]]></MSGTEXT>
+<!--E7EBD96FEE9A4B9790F47EB089F72888-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--E7EBD96FEE9A4B9790F47EB089F72888-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--E7EBD96FEE9A4B9790F47EB089F72888-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--E7EBD96FEE9A4B9790F47EB089F72888--></AD_MESSAGE>
+
 <!--E83760BF3C4E4BE9BEEE76CD6CBE734F--><AD_MESSAGE>
 <!--E83760BF3C4E4BE9BEEE76CD6CBE734F-->  <AD_MESSAGE_ID><![CDATA[E83760BF3C4E4BE9BEEE76CD6CBE734F]]></AD_MESSAGE_ID>
 <!--E83760BF3C4E4BE9BEEE76CD6CBE734F-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src/org/openbravo/erpCommon/obps/ActivationKey.java	Fri May 06 09:38:49 2016 +0200
+++ b/src/org/openbravo/erpCommon/obps/ActivationKey.java	Fri May 06 10:09:56 2016 +0200
@@ -1126,21 +1126,6 @@
     return lastRequestTime.compareTo(lastValidPingTime) < 0;
   }
 
-  /**
-   * Returns the number of current active sessions
-   */
-  private int getActiveSessions(String currentSession) {
-    OBCriteria<Session> obCriteria = OBDal.getInstance().createCriteria(Session.class);
-    obCriteria.add(Restrictions.eq(Session.PROPERTY_SESSIONACTIVE, true));
-    obCriteria.add(Restrictions.not(Restrictions.in(Session.PROPERTY_LOGINSTATUS,
-        NO_CU_SESSION_TYPES)));
-
-    if (currentSession != null && !currentSession.equals("")) {
-      obCriteria.add(Restrictions.ne(Session.PROPERTY_ID, currentSession));
-    }
-    return obCriteria.count();
-  }
-
   private int getActiveSessionsForNamedUser(String currentSession, String username) {
     OBCriteria<Session> obCriteria = OBDal.getInstance().createCriteria(Session.class);
     obCriteria.add(Restrictions.eq(Session.PROPERTY_SESSIONACTIVE, true));
@@ -1223,6 +1208,11 @@
           sb.append("<tr><td>").append(Utility.messageBD(conn, "OPSConcurrentUsersWarn", lang))
               .append("</td><td>").append(getProperty("limituserswarn")).append("</td></tr>");
         }
+
+        sb.append("<tr><td>").append(Utility.messageBD(conn, "OPSCurrentConcurrentUsers", lang))
+            .append("</td><td>");
+        sb.append(getActiveSessions(null));
+        sb.append("</td></tr>");
       }
 
       sb.append("<tr><td>").append(Utility.messageBD(conn, "OPSInstanceNo", lang))
@@ -1238,11 +1228,23 @@
       sb.append(getWSExplanation(conn, lang));
       sb.append("</td></tr>");
 
+      sb.append("<tr><td>").append(Utility.messageBD(conn, "OPSWSCounterDay", lang))
+          .append("</td><td>");
+      sb.append(getNumberWSDayCounter());
+      sb.append("</td></tr>");
+
       sb.append("<tr><td>").append(Utility.messageBD(conn, "OPSPOSLimitation", lang))
           .append("</td><td>");
       sb.append(getPOSTerminalsExplanation());
       sb.append("</td></tr>");
 
+      for (ModuleLicenseRestrictions.AdditionalInfo addInfo : getAdditionalMessageInfo()) {
+        sb.append("<tr><td>").append(Utility.messageBD(conn, addInfo.getKey(), lang))
+            .append("</td><td>");
+        sb.append(addInfo.getValue());
+        sb.append("</td></tr>");
+      }
+
     } else {
       sb.append(Utility.messageBD(conn, "OPSNonActiveInstance", lang));
     }
@@ -1345,6 +1347,32 @@
   }
 
   /**
+   * get all additional messages to be printed in Instance Activation window.
+   */
+  private List<ModuleLicenseRestrictions.AdditionalInfo> getAdditionalMessageInfo() {
+    List<ModuleLicenseRestrictions.AdditionalInfo> additionalInfo = new ArrayList<ModuleLicenseRestrictions.AdditionalInfo>();
+    for (ModuleLicenseRestrictions moduleRestriction : getModuleLicenseRestrictions()) {
+      additionalInfo.addAll(moduleRestriction.getAdditionalMessage());
+    }
+    return additionalInfo;
+  }
+
+  /**
+   * Returns the number of current active sessions
+   */
+  private int getActiveSessions(String currentSession) {
+    OBCriteria<Session> obCriteria = OBDal.getInstance().createCriteria(Session.class);
+    obCriteria.add(Restrictions.eq(Session.PROPERTY_SESSIONACTIVE, true));
+    obCriteria.add(Restrictions.not(Restrictions.in(Session.PROPERTY_LOGINSTATUS,
+        NO_CU_SESSION_TYPES)));
+
+    if (currentSession != null && !currentSession.equals("")) {
+      obCriteria.add(Restrictions.ne(Session.PROPERTY_ID, currentSession));
+    }
+    return obCriteria.count();
+  }
+
+  /**
    * Same as {@link ActivationKey#getSubscribedModules()} with the includeDisabled parameter. When
    * this parameter is true, disabled modules are returned with the DISABLED status, other way they
    * are returned with the status they would have if they were not disabled.
@@ -1882,16 +1910,21 @@
     initWsCountTime = getDayAt0(new Date());
     OBContext.setAdminMode();
     try {
-      OBCriteria<Session> qLogins = OBDal.getInstance().createCriteria(Session.class);
-      qLogins.add(Restrictions.eq(Session.PROPERTY_LOGINSTATUS, "WS"));
-      qLogins.add(Restrictions.ge(Session.PROPERTY_CREATIONDATE, initWsCountTime));
-      wsDayCounter = qLogins.count();
+      wsDayCounter = getNumberWSDayCounter();
       log.info("Initialized ws count to " + wsDayCounter + " from " + initWsCountTime);
     } finally {
       OBContext.restorePreviousMode();
     }
   }
 
+  private int getNumberWSDayCounter() {
+    Date date = getDayAt0(new Date());
+    OBCriteria<Session> qLogins = OBDal.getInstance().createCriteria(Session.class);
+    qLogins.add(Restrictions.eq(Session.PROPERTY_LOGINSTATUS, "WS"));
+    qLogins.add(Restrictions.ge(Session.PROPERTY_CREATIONDATE, date));
+    return qLogins.count();
+  }
+
   private void initializeWsCounter() {
     StringBuilder hql = new StringBuilder();
     hql.append("select min(creationDate)\n");
--- a/src/org/openbravo/erpCommon/obps/ModuleLicenseRestrictions.java	Fri May 06 09:38:49 2016 +0200
+++ b/src/org/openbravo/erpCommon/obps/ModuleLicenseRestrictions.java	Fri May 06 10:09:56 2016 +0200
@@ -11,13 +11,15 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2015 Openbravo SLU 
+ * All portions are Copyright (C) 2015-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.obps;
 
+import java.util.List;
+
 import javax.enterprise.context.ApplicationScoped;
 
 import org.openbravo.erpCommon.obps.ActivationKey.LicenseRestriction;
@@ -49,6 +51,33 @@
   /** Provides the HTML to be injected in Instance Activation window to perform additional actions */
   public String getInstanceActivationExtraActionsHtml(XmlEngine xmlEngine);
 
+  /**
+   * Provides a mechanism to returns an extra message. This information will be shown in Instance
+   * Activation window.
+   */
+  public List<AdditionalInfo> getAdditionalMessage();
+
+  /**
+   * Holder for additional messages. The key is used for retrieves a message from ad_message table.
+   */
+  public static class AdditionalInfo {
+    private String key;
+    private String value;
+
+    public AdditionalInfo(String key, String value) {
+      this.key = key;
+      this.value = value;
+    }
+
+    public String getKey() {
+      return key;
+    }
+
+    public String getValue() {
+      return value;
+    }
+  }
+
   public enum MsgSeverity {
     WARN("Warning"), ERROR("Error");