details:   /erp/devel/pi/rev/09be3c03a880
changeset: 8491:09be3c03a880
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu Sep 30 15:04:49 2010 +0200
summary:   fixed issue 14677: It is possible to use an expired commercial module

  Disabled commercial modules which license has expired are not allowed
  to be enabled again.

diffstat:

 src/org/openbravo/erpCommon/ad_forms/ModuleManagement.java |   4 +-
 src/org/openbravo/erpCommon/obps/ActivationKey.java        |  40 +++++++++++++-
 2 files changed, 40 insertions(+), 4 deletions(-)

diffs (78 lines):

diff -r 58864304a60b -r 09be3c03a880 
src/org/openbravo/erpCommon/ad_forms/ModuleManagement.java
--- a/src/org/openbravo/erpCommon/ad_forms/ModuleManagement.java        Thu Sep 
30 11:35:51 2010 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/ModuleManagement.java        Thu Sep 
30 15:04:49 2010 +0200
@@ -1842,9 +1842,7 @@
       return;
     }
 
-    if (enable
-        && module.isCommercial()
-        && ActivationKey.getInstance().isModuleSubscribed(module.getId()) == 
CommercialModuleStatus.NO_SUBSCRIBED) {
+    if (enable && !ActivationKey.getInstance().isModuleEnableable(module)) {
       log4j.warn("Cannot enable not subscribed commercial module " + module);
       notEnabledModules.add(module.getName());
     } else {
diff -r 58864304a60b -r 09be3c03a880 
src/org/openbravo/erpCommon/obps/ActivationKey.java
--- a/src/org/openbravo/erpCommon/obps/ActivationKey.java       Thu Sep 30 
11:35:51 2010 +0200
+++ b/src/org/openbravo/erpCommon/obps/ActivationKey.java       Thu Sep 30 
15:04:49 2010 +0200
@@ -756,6 +756,18 @@
    * @return HashMap<String, CommercialModuleStatus> containing the subscribed 
modules
    */
   public HashMap<String, CommercialModuleStatus> getSubscribedModules() {
+    return getSubscribedModules(true);
+  }
+
+  /**
+   * 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.
+   * 
+   * @param includeDisabled
+   * @return
+   */
+  private HashMap<String, CommercialModuleStatus> getSubscribedModules(boolean 
includeDisabled) {
     HashMap<String, CommercialModuleStatus> moduleList = new HashMap<String, 
CommercialModuleStatus>();
     if (instanceProperties == null) {
       return moduleList;
@@ -778,7 +790,7 @@
         if (moduleData.length > 2) {
           validTo = sd.parse(moduleData[2]);
         }
-        if (!DisabledModules.isEnabled(Artifacts.MODULE, moduleData[0])) {
+        if (includeDisabled && !DisabledModules.isEnabled(Artifacts.MODULE, 
moduleData[0])) {
           moduleList.put(moduleData[0], CommercialModuleStatus.DISABLED);
         } else if (subscriptionActuallyConverted) {
           moduleList.put(moduleData[0], 
CommercialModuleStatus.CONVERTED_SUBSCRIPTION);
@@ -802,6 +814,32 @@
   }
 
   /**
+   * Checks whether a disabled module can be enabled again. A commercial 
module cannot be enabled in
+   * case its license has expired or the instance is not commercial.
+   * 
+   * @param moduleId
+   * @return true in case the module can be enabled
+   */
+  public boolean isModuleEnableable(Module module) {
+    if (!module.isCommercial()) {
+      return true;
+    }
+    if (!isActive()) {
+      return false;
+    }
+
+    HashMap<String, CommercialModuleStatus> moduleList = 
getSubscribedModules(false);
+
+    if (!moduleList.containsKey(module.getId())) {
+      return false;
+    }
+
+    CommercialModuleStatus status = moduleList.get(module.getId());
+    return status == CommercialModuleStatus.ACTIVE
+        || status == CommercialModuleStatus.CONVERTED_SUBSCRIPTION;
+  }
+
+  /**
    * Returns the status for the commercial module passed as parameter. Note 
that module tier is not
    * checked here, this should be correctly handled in the license itself.
    * 

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to