Add configuration option to allow LibrePlan developers collect usage stats

FEA: ItEr76S10NewVersionsNotification
This commit is contained in:
Manuel Rego Casasnovas 2012-01-13 13:37:34 +01:00
parent d71e270f3e
commit 2adf4d357e
11 changed files with 101 additions and 15 deletions

View file

@ -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;

View file

@ -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;
}
}

View file

@ -45,4 +45,17 @@
columnDataType="BOOLEAN" />
</changeSet>
<changeSet id="add-new-column-allow_to_gather_usage_stats_enabled" author="mrego">
<comment>Add new column allow_to_gather_usage_stats_enabled with default value FALSE to configuration table</comment>
<addColumn tableName="configuration">
<column name="allow_to_gather_usage_stats_enabled" type="BOOLEAN" />
</addColumn>
<addDefaultValue tableName="configuration" columnName="allow_to_gather_usage_stats_enabled"
defaultValueBoolean="FALSE" />
<addNotNullConstraint tableName="configuration"
columnName="allow_to_gather_usage_stats_enabled"
defaultNullValue="FALSE"
columnDataType="BOOLEAN" />
</changeSet>
</databaseChangeLog>

View file

@ -53,6 +53,8 @@
column="enabled_autocomplete_login" />
<property name="checkNewVersionEnabled" not-null="true"
column="check_new_version_enabled" />
<property name="allowToGatherUsageStatsEnabled" not-null="true"
column="allow_to_gather_usage_stats_enabled" />
<property name="progressType" column="progress_type">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">org.libreplan.business.common.entities.ProgressType</param>

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -154,4 +154,9 @@ public interface IConfigurationModel {
boolean isCheckNewVersionEnabled();
void setCheckNewVersionEnabled(boolean checkNewVersionEnabled);
boolean isAllowToGatherUsageStatsEnabled();
void setAllowToGatherUsageStatsEnabled(
boolean allowToGatherUsageStatsEnabled);
}

View file

@ -60,4 +60,6 @@ public interface ITemplateModel {
boolean isCheckNewVersionEnabled();
boolean isAllowToGatherUsageStatsEnabled();
}

View file

@ -188,7 +188,8 @@ public class TemplateController extends GenericForwardComposer {
return false;
}
return VersionInformation.isNewVersionAvailable();
return VersionInformation.isNewVersionAvailable(templateModel
.isAllowToGatherUsageStatsEnabled());
}
}

View file

@ -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();
}
}

View file

@ -94,10 +94,16 @@
</row>
<row>
<label value="${i18n:_('Warning new version')}" />
<checkbox
label="${i18n:_('Enable/Disable')}"
tooltiptext="${i18n:_('Enable/Disable warning about new LibrePlan versions available')}"
checked="@{configurationController.checkNewVersionEnabled}" />
<vbox>
<checkbox
label="${i18n:_('Show a warning when new LibrePlan versions are released')}"
tooltiptext="${i18n:_('Enable/Disable warning about new LibrePlan versions available')}"
checked="@{configurationController.checkNewVersionEnabled}" />
<checkbox
label="${i18n:_('Help project developers to collect information about LibrePlan usage thanks to this feature')}"
tooltiptext="${i18n:_('If you ask us to do so, we will not use your requests to generate usage statistics')}"
checked="@{configurationController.allowToGatherUsageStatsEnabled}" />
</vbox>
</row>
<row>
<label value="${i18n:_('Generate code for')}" />