details: /erp/stable/2.50/rev/b1b1346f2141
changeset: 9308:b1b1346f2141
user: Asier Lostalé <asier.lostale <at> openbravo.com>
date: Mon Mar 21 12:06:20 2011 +0100
summary: fixed issue 16396: Autorefresh license when checking commercial
modules
diffstat:
src/org/openbravo/erpCommon/obps/ActivationKey.java | 68 ++++++++++++-
src/org/openbravo/erpCommon/obps/ActiveInstanceProcess.java | 7 +-
2 files changed, 71 insertions(+), 4 deletions(-)
diffs (154 lines):
diff -r 716b8fac0501 -r b1b1346f2141
src/org/openbravo/erpCommon/obps/ActivationKey.java
--- a/src/org/openbravo/erpCommon/obps/ActivationKey.java Wed Mar 23
11:18:33 2011 +0100
+++ b/src/org/openbravo/erpCommon/obps/ActivationKey.java Mon Mar 21
12:06:20 2011 +0100
@@ -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-2010 Openbravo SLU
+ * All portions are Copyright (C) 2009-2011 Openbravo SLU
* All Rights Reserved.
* Contributor(s): ______________________________________.
************************************************************************
@@ -39,6 +39,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import java.util.zip.CRC32;
@@ -50,6 +51,7 @@
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Order;
import org.openbravo.base.exception.OBException;
+import org.openbravo.base.secureApp.VariablesSecureApp;
import org.openbravo.base.session.OBPropertiesProvider;
import org.openbravo.dal.core.DalContextListener;
import org.openbravo.dal.core.OBContext;
@@ -58,11 +60,13 @@
import org.openbravo.database.ConnectionProvider;
import org.openbravo.erpCommon.modules.VersionUtility.VersionComparator;
import org.openbravo.erpCommon.obps.DisabledModules.Artifacts;
+import org.openbravo.erpCommon.utility.OBError;
import org.openbravo.erpCommon.utility.OBVersion;
import org.openbravo.erpCommon.utility.Utility;
import org.openbravo.model.ad.access.Session;
import org.openbravo.model.ad.module.Module;
import org.openbravo.model.ad.ui.Tab;
+import org.openbravo.scheduling.ProcessBundle;
import org.openbravo.service.db.DalConnectionProvider;
public class ActivationKey {
@@ -85,6 +89,7 @@
private LicenseClass licenseClass;
private List<String> tier1Artifacts;
private List<String> tier2Artifacts;
+ private Date lastRefreshTime;
private boolean notActiveYet = false;
@@ -93,6 +98,11 @@
private static final String TIER_1_PREMIUM_FEATURE = "T1P";
private static final String TIER_2_PREMIUM_FEATURE = "T2P";
+ /**
+ * Number of minutes since last license refresh to wait before doing it again
+ */
+ private static final int REFRESH_MIN_TIME = 60;
+
public enum LicenseRestriction {
NO_RESTRICTION, OPS_INSTANCE_NOT_ACTIVE, NUMBER_OF_SOFT_USERS_REACHED,
NUMBER_OF_CONCURRENT_USERS_REACHED, MODULE_EXPIRED
}
@@ -151,6 +161,11 @@
public static synchronized void setInstance(ActivationKey ak) {
instance = ak;
+ ak.setRefreshTime(new Date());
+ }
+
+ private void setRefreshTime(Date time) {
+ lastRefreshTime = time;
}
/**
@@ -849,7 +864,56 @@
HashMap<String, CommercialModuleStatus> moduleList =
getSubscribedModules();
if (!moduleList.containsKey(moduleId)) {
- return CommercialModuleStatus.NO_SUBSCRIBED;
+ log4j.debug("Module " + moduleId + " is not in the list of subscribed
modules");
+
+ Date timeToRefresh = null;
+ if (lastRefreshTime != null) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(lastRefreshTime);
+ calendar.add(Calendar.MINUTE, REFRESH_MIN_TIME);
+ timeToRefresh = calendar.getTime();
+ }
+
+ if (timeToRefresh == null || new Date().after(timeToRefresh)) {
+ log4j.debug("Trying to refresh license, last refresh "
+ + (lastRefreshTime == null ? "never" :
lastRefreshTime.toString()));
+
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put("publicKey", strPublicKey);
+ params.put("purpose", getProperty("purpose"));
+ params.put("instanceNo", getProperty("instanceno"));
+ params.put("activate", true);
+ ProcessBundle pb = new ProcessBundle(null, new VariablesSecureApp("0",
"0", "0"));
+ pb.setParams(params);
+
+ boolean refreshed = false;
+ try {
+ new ActiveInstanceProcess().execute(pb);
+ OBError msg = (OBError) pb.getResult();
+ refreshed = msg.getType().equals("Success");
+ if (refreshed) {
+ log4j.debug("Instance refreshed");
+ } else {
+ log4j.info("Problem refreshing instance " + msg.getMessage());
+ }
+ } catch (Exception e) {
+ log4j.error("Error refreshing instance", e);
+ refreshed = false;
+ }
+
+ if (refreshed) {
+ return ActivationKey.instance.isModuleSubscribed(moduleId);
+ } else {
+ // Even license couldn't be refreshed, set lastRefreshTime not to
try to refresh in the
+ // following period of time
+ lastRefreshTime = new Date();
+ return CommercialModuleStatus.NO_SUBSCRIBED;
+ }
+ } else {
+ log4j.debug("Not refreshing, last refresh was " +
lastRefreshTime.toString()
+ + ". Next time to refresh " + timeToRefresh.toString());
+ return CommercialModuleStatus.NO_SUBSCRIBED;
+ }
}
return moduleList.get(moduleId);
diff -r 716b8fac0501 -r b1b1346f2141
src/org/openbravo/erpCommon/obps/ActiveInstanceProcess.java
--- a/src/org/openbravo/erpCommon/obps/ActiveInstanceProcess.java Wed Mar
23 11:18:33 2011 +0100
+++ b/src/org/openbravo/erpCommon/obps/ActiveInstanceProcess.java Mon Mar
21 12:06:20 2011 +0100
@@ -49,13 +49,16 @@
bundle.setResult(msg);
+ String[] result = null;
+
if (!HttpsUtils.isInternetAvailable()) {
msg.setType("Error");
msg.setMessage("@WSError@");
+ return;
+ } else {
+ result = send(publicKey, purpose, instanceNo, activate);
}
- String[] result = send(publicKey, purpose, instanceNo, activate);
-
if (result.length == 2 && result[0] != null && result[1] != null
&& result[0].equals("@Success@")) {
// now we have the activation key, lets save it
------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits