Add configuration option to allow LibrePlan developers collect usage stats
FEA: ItEr76S10NewVersionsNotification
This commit is contained in:
parent
d71e270f3e
commit
2adf4d357e
11 changed files with 101 additions and 15 deletions
|
|
@ -46,6 +46,8 @@ public class VersionInformation {
|
||||||
*/
|
*/
|
||||||
private static final String LIBREPLAN_VERSION_URL = "http://libreplan.org/VERSION";
|
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
|
* Delay to wait till we check the URL again
|
||||||
*/
|
*/
|
||||||
|
|
@ -60,27 +62,32 @@ public class VersionInformation {
|
||||||
private Date lastVersionCachedDate = new Date();
|
private Date lastVersionCachedDate = new Date();
|
||||||
|
|
||||||
private VersionInformation() {
|
private VersionInformation() {
|
||||||
loadNewVersionFromURL();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadNewVersionFromURL() {
|
private void loadNewVersionFromURL(boolean allowToGatherUsageStatsEnabled) {
|
||||||
lastVersionCachedDate = new Date();
|
lastVersionCachedDate = new Date();
|
||||||
try {
|
try {
|
||||||
URL url = new URL(LIBREPLAN_VERSION_URL);
|
URL url = getURL(allowToGatherUsageStatsEnabled);
|
||||||
String lastVersion = (new BufferedReader(new InputStreamReader(
|
String lastVersion = (new BufferedReader(new InputStreamReader(
|
||||||
url.openStream()))).readLine();
|
url.openStream()))).readLine();
|
||||||
if (projectVersion != null && lastVersion != null) {
|
if (projectVersion != null && lastVersion != null) {
|
||||||
newVersionCached = !projectVersion.equals(lastVersion);
|
newVersionCached = !projectVersion.equals(lastVersion);
|
||||||
}
|
}
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
LOG.warn("Problems reading LibrePlan version from "
|
|
||||||
+ LIBREPLAN_VERSION_URL, e);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.warn("Problems reading LibrePlan version from "
|
LOG.warn("Problems reading LibrePlan version from "
|
||||||
+ LIBREPLAN_VERSION_URL, e);
|
+ 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() {
|
public static VersionInformation getInstance() {
|
||||||
return singleton;
|
return singleton;
|
||||||
}
|
}
|
||||||
|
|
@ -98,13 +105,20 @@ public class VersionInformation {
|
||||||
|
|
||||||
public void setProjectVersion(String argVersion) {
|
public void setProjectVersion(String argVersion) {
|
||||||
projectVersion = argVersion;
|
projectVersion = argVersion;
|
||||||
|
loadNewVersionFromURL(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if a new version of the project is published.
|
* 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() {
|
public static boolean isNewVersionAvailable(
|
||||||
return singleton.checkIsNewVersionAvailable();
|
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
|
* Otherwise, during one day it returns the cached value. And it checks it
|
||||||
* again after that time.
|
* again after that time.
|
||||||
*/
|
*/
|
||||||
private boolean checkIsNewVersionAvailable() {
|
private boolean checkIsNewVersionAvailable(
|
||||||
|
boolean allowToGatherUsageStatsEnabled) {
|
||||||
if (!newVersionCached) {
|
if (!newVersionCached) {
|
||||||
long oneDayLater = lastVersionCachedDate.getTime()
|
long oneDayLater = lastVersionCachedDate.getTime()
|
||||||
+ DELAY_TO_CHECK_URL;
|
+ DELAY_TO_CHECK_URL;
|
||||||
if (oneDayLater < new Date().getTime()) {
|
if (oneDayLater < new Date().getTime()) {
|
||||||
loadNewVersionFromURL();
|
loadNewVersionFromURL(allowToGatherUsageStatsEnabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return newVersionCached;
|
return newVersionCached;
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,8 @@ public class Configuration extends BaseEntity {
|
||||||
|
|
||||||
private Boolean checkNewVersionEnabled = true;
|
private Boolean checkNewVersionEnabled = true;
|
||||||
|
|
||||||
|
private Boolean allowToGatherUsageStatsEnabled = false;
|
||||||
|
|
||||||
public void setDefaultCalendar(BaseCalendar defaultCalendar) {
|
public void setDefaultCalendar(BaseCalendar defaultCalendar) {
|
||||||
this.defaultCalendar = defaultCalendar;
|
this.defaultCalendar = defaultCalendar;
|
||||||
}
|
}
|
||||||
|
|
@ -351,4 +353,14 @@ public class Configuration extends BaseEntity {
|
||||||
this.checkNewVersionEnabled = checkNewVersionEnabled;
|
this.checkNewVersionEnabled = checkNewVersionEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAllowToGatherUsageStatsEnabled() {
|
||||||
|
return allowToGatherUsageStatsEnabled != null ? allowToGatherUsageStatsEnabled
|
||||||
|
: false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAllowToGatherUsageStatsEnabled(
|
||||||
|
boolean allowToGatherUsageStatsEnabled) {
|
||||||
|
this.allowToGatherUsageStatsEnabled = allowToGatherUsageStatsEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,4 +45,17 @@
|
||||||
columnDataType="BOOLEAN" />
|
columnDataType="BOOLEAN" />
|
||||||
</changeSet>
|
</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>
|
</databaseChangeLog>
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,8 @@
|
||||||
column="enabled_autocomplete_login" />
|
column="enabled_autocomplete_login" />
|
||||||
<property name="checkNewVersionEnabled" not-null="true"
|
<property name="checkNewVersionEnabled" not-null="true"
|
||||||
column="check_new_version_enabled" />
|
column="check_new_version_enabled" />
|
||||||
|
<property name="allowToGatherUsageStatsEnabled" not-null="true"
|
||||||
|
column="allow_to_gather_usage_stats_enabled" />
|
||||||
<property name="progressType" column="progress_type">
|
<property name="progressType" column="progress_type">
|
||||||
<type name="org.hibernate.type.EnumType">
|
<type name="org.hibernate.type.EnumType">
|
||||||
<param name="enumClass">org.libreplan.business.common.entities.ProgressType</param>
|
<param name="enumClass">org.libreplan.business.common.entities.ProgressType</param>
|
||||||
|
|
|
||||||
|
|
@ -847,4 +847,14 @@ public class ConfigurationController extends GenericForwardComposer {
|
||||||
configurationModel.setCheckNewVersionEnabled(checkNewVersionEnabled);
|
configurationModel.setCheckNewVersionEnabled(checkNewVersionEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAllowToGatherUsageStatsEnabled() {
|
||||||
|
return configurationModel.isAllowToGatherUsageStatsEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAllowToGatherUsageStatsEnabled(
|
||||||
|
boolean allowToGatherUsageStatsEnabled) {
|
||||||
|
configurationModel
|
||||||
|
.setAllowToGatherUsageStatsEnabled(allowToGatherUsageStatsEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -564,4 +564,17 @@ public class ConfigurationModel implements IConfigurationModel {
|
||||||
public void setCheckNewVersionEnabled(boolean checkNewVersionEnabled) {
|
public void setCheckNewVersionEnabled(boolean checkNewVersionEnabled) {
|
||||||
configuration.setCheckNewVersionEnabled(checkNewVersionEnabled);
|
configuration.setCheckNewVersionEnabled(checkNewVersionEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAllowToGatherUsageStatsEnabled() {
|
||||||
|
return configuration.isAllowToGatherUsageStatsEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setAllowToGatherUsageStatsEnabled(
|
||||||
|
boolean allowToGatherUsageStatsEnabled) {
|
||||||
|
configuration
|
||||||
|
.setAllowToGatherUsageStatsEnabled(allowToGatherUsageStatsEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -154,4 +154,9 @@ public interface IConfigurationModel {
|
||||||
boolean isCheckNewVersionEnabled();
|
boolean isCheckNewVersionEnabled();
|
||||||
|
|
||||||
void setCheckNewVersionEnabled(boolean checkNewVersionEnabled);
|
void setCheckNewVersionEnabled(boolean checkNewVersionEnabled);
|
||||||
|
|
||||||
|
boolean isAllowToGatherUsageStatsEnabled();
|
||||||
|
|
||||||
|
void setAllowToGatherUsageStatsEnabled(
|
||||||
|
boolean allowToGatherUsageStatsEnabled);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,4 +60,6 @@ public interface ITemplateModel {
|
||||||
|
|
||||||
boolean isCheckNewVersionEnabled();
|
boolean isCheckNewVersionEnabled();
|
||||||
|
|
||||||
|
boolean isAllowToGatherUsageStatsEnabled();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,8 @@ public class TemplateController extends GenericForwardComposer {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return VersionInformation.isNewVersionAvailable();
|
return VersionInformation.isNewVersionAvailable(templateModel
|
||||||
|
.isAllowToGatherUsageStatsEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -490,4 +490,11 @@ public class TemplateModel implements ITemplateModel {
|
||||||
public boolean isCheckNewVersionEnabled() {
|
public boolean isCheckNewVersionEnabled() {
|
||||||
return configurationDAO.getConfiguration().isCheckNewVersionEnabled();
|
return configurationDAO.getConfiguration().isCheckNewVersionEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public boolean isAllowToGatherUsageStatsEnabled() {
|
||||||
|
return configurationDAO.getConfiguration().isCheckNewVersionEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -94,10 +94,16 @@
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<label value="${i18n:_('Warning new version')}" />
|
<label value="${i18n:_('Warning new version')}" />
|
||||||
<checkbox
|
<vbox>
|
||||||
label="${i18n:_('Enable/Disable')}"
|
<checkbox
|
||||||
tooltiptext="${i18n:_('Enable/Disable warning about new LibrePlan versions available')}"
|
label="${i18n:_('Show a warning when new LibrePlan versions are released')}"
|
||||||
checked="@{configurationController.checkNewVersionEnabled}" />
|
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>
|
||||||
<row>
|
<row>
|
||||||
<label value="${i18n:_('Generate code for')}" />
|
<label value="${i18n:_('Generate code for')}" />
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue