From a93be715aaf4e23a86ebbcb8570479cbe94ac8f4 Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Fri, 13 Jan 2012 13:37:34 +0100 Subject: [PATCH] Add configuration option to allow LibrePlan developers collect usage stats FEA: ItEr76S10NewVersionsNotification --- .../business/common/VersionInformation.java | 35 +++++++++++++------ .../common/entities/Configuration.java | 12 +++++++ .../src/main/resources/db.changelog-1.2.xml | 13 +++++++ .../common/entities/Configuration.hbm.xml | 2 ++ .../web/common/ConfigurationController.java | 10 ++++++ .../web/common/ConfigurationModel.java | 13 +++++++ .../web/common/IConfigurationModel.java | 5 +++ .../libreplan/web/common/ITemplateModel.java | 2 ++ .../web/common/TemplateController.java | 3 +- .../libreplan/web/common/TemplateModel.java | 7 ++++ .../src/main/webapp/common/configuration.zul | 14 +++++--- 11 files changed, 101 insertions(+), 15 deletions(-) diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/VersionInformation.java b/libreplan-business/src/main/java/org/libreplan/business/common/VersionInformation.java index 6daecdd1c..bc3d8b092 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/VersionInformation.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/VersionInformation.java @@ -46,6 +46,8 @@ public class VersionInformation { */ private static final String LIBREPLAN_VERSION_URL = "http://libreplan.org/VERSION"; + private static final String LIBREPLAN_USAGE_STATS_PARAM = "?stats=1"; + /** * Delay to wait till we check the URL again */ @@ -60,27 +62,32 @@ public class VersionInformation { private Date lastVersionCachedDate = new Date(); private VersionInformation() { - loadNewVersionFromURL(); } - private void loadNewVersionFromURL() { + private void loadNewVersionFromURL(boolean allowToGatherUsageStatsEnabled) { lastVersionCachedDate = new Date(); try { - URL url = new URL(LIBREPLAN_VERSION_URL); + URL url = getURL(allowToGatherUsageStatsEnabled); String lastVersion = (new BufferedReader(new InputStreamReader( url.openStream()))).readLine(); if (projectVersion != null && lastVersion != null) { newVersionCached = !projectVersion.equals(lastVersion); } - } catch (MalformedURLException e) { - LOG.warn("Problems reading LibrePlan version from " - + LIBREPLAN_VERSION_URL, e); } catch (IOException e) { LOG.warn("Problems reading LibrePlan version from " + LIBREPLAN_VERSION_URL, e); } } + private URL getURL(boolean allowToGatherUsageStatsEnabled) + throws MalformedURLException { + String url = LIBREPLAN_VERSION_URL; + if (allowToGatherUsageStatsEnabled) { + url += LIBREPLAN_USAGE_STATS_PARAM; + } + return new URL(url); + } + public static VersionInformation getInstance() { return singleton; } @@ -98,13 +105,20 @@ public class VersionInformation { public void setProjectVersion(String argVersion) { projectVersion = argVersion; + loadNewVersionFromURL(false); } /** * Returns true if a new version of the project is published. + * + * @param allowToGatherUsageStatsEnabled + * If true LibrePlan developers will process the requests to check + * the new versions to generate usages statistics */ - public static boolean isNewVersionAvailable() { - return singleton.checkIsNewVersionAvailable(); + public static boolean isNewVersionAvailable( + boolean allowToGatherUsageStatsEnabled) { + return singleton + .checkIsNewVersionAvailable(allowToGatherUsageStatsEnabled); } /** @@ -112,12 +126,13 @@ public class VersionInformation { * Otherwise, during one day it returns the cached value. And it checks it * again after that time. */ - private boolean checkIsNewVersionAvailable() { + private boolean checkIsNewVersionAvailable( + boolean allowToGatherUsageStatsEnabled) { if (!newVersionCached) { long oneDayLater = lastVersionCachedDate.getTime() + DELAY_TO_CHECK_URL; if (oneDayLater < new Date().getTime()) { - loadNewVersionFromURL(); + loadNewVersionFromURL(allowToGatherUsageStatsEnabled); } } return newVersionCached; diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/entities/Configuration.java b/libreplan-business/src/main/java/org/libreplan/business/common/entities/Configuration.java index c04df760e..3414abe4c 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/entities/Configuration.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/entities/Configuration.java @@ -89,6 +89,8 @@ public class Configuration extends BaseEntity { private Boolean checkNewVersionEnabled = true; + private Boolean allowToGatherUsageStatsEnabled = false; + public void setDefaultCalendar(BaseCalendar defaultCalendar) { this.defaultCalendar = defaultCalendar; } @@ -351,4 +353,14 @@ public class Configuration extends BaseEntity { this.checkNewVersionEnabled = checkNewVersionEnabled; } + public boolean isAllowToGatherUsageStatsEnabled() { + return allowToGatherUsageStatsEnabled != null ? allowToGatherUsageStatsEnabled + : false; + } + + public void setAllowToGatherUsageStatsEnabled( + boolean allowToGatherUsageStatsEnabled) { + this.allowToGatherUsageStatsEnabled = allowToGatherUsageStatsEnabled; + } + } diff --git a/libreplan-business/src/main/resources/db.changelog-1.2.xml b/libreplan-business/src/main/resources/db.changelog-1.2.xml index 29fa8c55d..336b94398 100644 --- a/libreplan-business/src/main/resources/db.changelog-1.2.xml +++ b/libreplan-business/src/main/resources/db.changelog-1.2.xml @@ -45,4 +45,17 @@ columnDataType="BOOLEAN" /> + + Add new column allow_to_gather_usage_stats_enabled with default value FALSE to configuration table + + + + + + + diff --git a/libreplan-business/src/main/resources/org/libreplan/business/common/entities/Configuration.hbm.xml b/libreplan-business/src/main/resources/org/libreplan/business/common/entities/Configuration.hbm.xml index 236e58bb8..d39b350c9 100644 --- a/libreplan-business/src/main/resources/org/libreplan/business/common/entities/Configuration.hbm.xml +++ b/libreplan-business/src/main/resources/org/libreplan/business/common/entities/Configuration.hbm.xml @@ -53,6 +53,8 @@ column="enabled_autocomplete_login" /> + org.libreplan.business.common.entities.ProgressType diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java index 086ce17cf..e928a4294 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java @@ -847,4 +847,14 @@ public class ConfigurationController extends GenericForwardComposer { configurationModel.setCheckNewVersionEnabled(checkNewVersionEnabled); } + public boolean isAllowToGatherUsageStatsEnabled() { + return configurationModel.isAllowToGatherUsageStatsEnabled(); + } + + public void setAllowToGatherUsageStatsEnabled( + boolean allowToGatherUsageStatsEnabled) { + configurationModel + .setAllowToGatherUsageStatsEnabled(allowToGatherUsageStatsEnabled); + } + } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationModel.java index 0e6228473..8f5a69405 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationModel.java @@ -564,4 +564,17 @@ public class ConfigurationModel implements IConfigurationModel { public void setCheckNewVersionEnabled(boolean checkNewVersionEnabled) { configuration.setCheckNewVersionEnabled(checkNewVersionEnabled); } + + @Override + public boolean isAllowToGatherUsageStatsEnabled() { + return configuration.isAllowToGatherUsageStatsEnabled(); + } + + @Override + public void setAllowToGatherUsageStatsEnabled( + boolean allowToGatherUsageStatsEnabled) { + configuration + .setAllowToGatherUsageStatsEnabled(allowToGatherUsageStatsEnabled); + } + } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/IConfigurationModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/IConfigurationModel.java index fb28e73fe..c070a21a2 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/IConfigurationModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/IConfigurationModel.java @@ -154,4 +154,9 @@ public interface IConfigurationModel { boolean isCheckNewVersionEnabled(); void setCheckNewVersionEnabled(boolean checkNewVersionEnabled); + + boolean isAllowToGatherUsageStatsEnabled(); + + void setAllowToGatherUsageStatsEnabled( + boolean allowToGatherUsageStatsEnabled); } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/ITemplateModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/ITemplateModel.java index b8c6e43d2..1d9087fdb 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/ITemplateModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/ITemplateModel.java @@ -60,4 +60,6 @@ public interface ITemplateModel { boolean isCheckNewVersionEnabled(); + boolean isAllowToGatherUsageStatsEnabled(); + } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/TemplateController.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/TemplateController.java index 15b038354..ec2347730 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/TemplateController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/TemplateController.java @@ -188,7 +188,8 @@ public class TemplateController extends GenericForwardComposer { return false; } - return VersionInformation.isNewVersionAvailable(); + return VersionInformation.isNewVersionAvailable(templateModel + .isAllowToGatherUsageStatsEnabled()); } } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/TemplateModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/TemplateModel.java index d663896c7..09bf5de3a 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/TemplateModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/TemplateModel.java @@ -490,4 +490,11 @@ public class TemplateModel implements ITemplateModel { public boolean isCheckNewVersionEnabled() { return configurationDAO.getConfiguration().isCheckNewVersionEnabled(); } + + @Override + @Transactional(readOnly = true) + public boolean isAllowToGatherUsageStatsEnabled() { + return configurationDAO.getConfiguration().isCheckNewVersionEnabled(); + } + } diff --git a/libreplan-webapp/src/main/webapp/common/configuration.zul b/libreplan-webapp/src/main/webapp/common/configuration.zul index 2f3771379..4b8a86fe8 100644 --- a/libreplan-webapp/src/main/webapp/common/configuration.zul +++ b/libreplan-webapp/src/main/webapp/common/configuration.zul @@ -94,10 +94,16 @@