dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #40485
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20534: System settings. Introduced enum Seting with all valid system settings with their default values ...
------------------------------------------------------------
revno: 20534
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-10-06 18:57:39 +0200
message:
System settings. Introduced enum Seting with all valid system settings with their default values and class types. Applied to system setting web api resource in order to save system settings with their expected class type.
added:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/Setting.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SystemSettingController.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/servlet/filter/ExcludableShallowEtagHeaderFilter.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/schedule/ScheduleSendMessageTasksAction.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/Setting.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/Setting.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/Setting.java 2015-10-06 16:57:39 +0000
@@ -0,0 +1,189 @@
+package org.hisp.dhis.setting;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import org.hisp.dhis.common.ListMap;
+import org.hisp.dhis.configuration.Configuration;
+import org.hisp.dhis.sms.config.SmsConfiguration;
+
+/**
+ * @author Lars Helge Overland
+ */
+public enum Setting
+{
+ APPLICATION_TITLE( "applicationTitle", "District Health Information Software 2", String.class ),
+ APPLICATION_INTRO( "keyApplicationIntro" ),
+ APPLICATION_NOTIFICATION( "keyApplicationNotification" ),
+ APPLICATION_FOOTER( "keyApplicationFooter" ),
+ APPLICATION_RIGHT_FOOTER( "keyApplicationRightFooter" ),
+ FLAG( "keyFlag", "dhis2", String.class ),
+ FLAG_IMAGE( "keyFlagImage" ),
+ START_MODULE( "startModule", "dhis-web-dashboard-integration", String.class ),
+ FACTOR_OF_DEVIATION( "factorDeviation", 2d, Double.class ),
+ EMAIL_HOST_NAME( "keyEmailHostName" ),
+ EMAIL_PORT( "keyEmailPort", 587, Integer.class ),
+ EMAIL_USERNAME( "keyEmailUsername" ),
+ EMAIL_PASSWORD( "keyEmailPassword" ),
+ EMAIL_TLS( "keyEmailTls", Boolean.class ),
+ EMAIL_SENDER( "keyEmailSender" ),
+ INSTANCE_BASE_URL( "keyInstanceBaseUrl", ListMap.class ),
+ SMS_CONFIG( "keySmsConfig", SmsConfiguration.class ),
+ CACHE_STRATEGY( "keyCacheStrategy", "CACHE_6AM_TOMORROW", String.class ),
+ TIME_FOR_SENDING_MESSAGE( "timeSendingMessage", "08:00", String.class ),
+ SEND_MESSAGE_SCHEDULED_TASKS( "sendMessageScheduled" ),
+ SCHEDULE_MESSAGE_TASKS( "scheduleMessage" ),
+ PHONE_NUMBER_AREA_CODE( "phoneNumberAreaCode" ),
+ MULTI_ORGANISATION_UNIT_FORMS( "multiOrganisationUnitForms", Boolean.class ),
+ SCHEDULE_AGGREGATE_QUERY_BUILDER_TASKS( "scheduleAggregateQueryBuilder", Map.class ),
+ SCHEDULE_AGGREGATE_QUERY_BUILDER_TASK_STRATEGY( "scheduleAggregateQueryBuilderTackStrategy", "lastMonth", String.class ),
+ CONFIGURATION( "keyConfig", Configuration.class ),
+ ACCOUNT_RECOVERY( "keyAccountRecovery", Boolean.class ),
+ GOOGLE_ANALYTICS_UA( "googleAnalyticsUA" ),
+ CREDENTIALS_EXPIRES( "credentialsExpires", Integer.class ),
+ SELF_REGISTRATION_NO_RECAPTCHA( "keySelfRegistrationNoRecaptcha", Boolean.class ),
+ OPENID_PROVIDER( "keyOpenIdProvider" ),
+ OPENID_PROVIDER_LABEL( "keyOpenIdProviderLabel" ),
+ CAN_GRANT_OWN_USER_AUTHORITY_GROUPS( "keyCanGrantOwnUserAuthorityGroups", Boolean.class ),
+ HIDE_UNAPPROVED_DATA_IN_ANALYTICS( "keyHideUnapprovedDataInAnalytics", Boolean.class ),
+ ANALYTICS_MAX_LIMIT( "keyAnalyticsMaxLimit", 50000, Integer.class ),
+ CUSTOM_LOGIN_PAGE_LOGO( "keyCustomLoginPageLogo", Boolean.class ),
+ CUSTOM_TOP_MENU_LOGO( "keyCustomTopMenuLogo", Boolean.class ),
+ ANALYTICS_MAINTENANCE_MODE( "keyAnalyticsMaintenanceMode", Boolean.FALSE, Boolean.class ),
+ DATABASE_SERVER_CPUS( "keyDatabaseServerCpus", 0, Integer.class ),
+ LAST_SUCCESSFUL_ANALYTICS_TABLES_RUNTIME( "keyLastSuccessfulAnalyticsTablesRuntime" ),
+ LAST_MONITORING_RUN( "keyLastMonitoringRun", Date.class ),
+ LAST_SUCCESSFUL_DATA_SYNC( "keyLastSuccessfulDataSynch", Date.class ),
+ LAST_SUCCESSFUL_ANALYTICS_TABLES_UPDATE( "keyLastSuccessfulAnalyticsTablesUpdate", Date.class ),
+ LAST_SUCCESSFUL_RESOURCE_TABLES_UPDATE( "keyLastSuccessfulResourceTablesUpdate", Date.class ),
+ LAST_SUCCESSFUL_MONITORING( "keyLastSuccessfulMonitoring", Date.class ),
+ HELP_PAGE_LINK( "helpPageLink", "../dhis-web-commons-about/help.action", String.class ),
+ ACCEPTANCE_REQUIRED_FOR_APPROVAL( "keyAcceptanceRequiredForApproval", Boolean.class ),
+ SYSTEM_NOTIFICATIONS_EMAIL( "keySystemNotificationsEmail" ),
+ ANALYSIS_RELATIVE_PERIOD( "keyAnalysisRelativePeriod", "LAST_12_MONTHS", String.class ),
+ CORS_WHITELIST( "keyCorsWhitelist", List.class ),
+ REQUIRE_ADD_TO_VIEW( "keyRequireAddToView", Boolean.class ),
+ ALLOW_OBJECT_ASSIGNMENT( "keyAllowObjectAssignment", Boolean.class ),
+ USE_CUSTOM_LOGO_FRONT( "keyUseCustomLogoFront", Boolean.class ),
+ USE_CUSTOM_LOGO_BANNER( "keyUseCustomLogoBanner", Boolean.class ),
+ METADATA_REPO_URL( "keyMetaDataRepoUrl", "http://metadata.dhis2.org", String.class ),
+ DATA_IMPORT_STRICT_PERIODS( "keyDataImportStrictPeriods", Boolean.class ),
+ DATA_IMPORT_STRICT_CATEGORY_OPTION_COMBOS( "keyDataImportStrictCategoryOptionCombos", Boolean.class ),
+ DATA_IMPORT_STRICT_ORGANISATION_UNITS( "keyDataImportStrictOrganisationUnits", Boolean.class ),
+ DATA_IMPORT_STRICT_ATTRIBUTE_OPTION_COMBOS( "keyDataImportStrictAttributeOptionCombos", Boolean.class ),
+ DATA_IMPORT_REQUIRE_CATEGORY_OPTION_COMBO( "keyDataImportRequireCategoryOptionCombo", Boolean.class ),
+ DATA_IMPORT_REQUIRE_ATTRIBUTE_OPTION_COMBO( "keyDataImportRequireAttributeOptionCombo", Boolean.class );
+
+ private final String name;
+
+ private final Serializable defaultValue;
+
+ private final Class<?> clazz;
+
+ private Setting( String name )
+ {
+ this.name = name;
+ this.defaultValue = null;
+ this.clazz = String.class;
+ }
+
+ private Setting( String name, Class<?> clazz )
+ {
+ this.name = name;
+ this.defaultValue = null;
+ this.clazz = clazz;
+ }
+
+ private Setting( String name, Serializable defaultValue, Class<?> clazz )
+ {
+ this.name = name;
+ this.defaultValue = defaultValue;
+ this.clazz = clazz;
+ }
+
+ public static Optional<Setting> getByName( String name )
+ {
+ for ( Setting setting : Setting.values() )
+ {
+ if ( setting.getName().equals( name ) )
+ {
+ return Optional.of( setting );
+ }
+ }
+
+ return Optional.empty();
+ }
+
+ public static Serializable getAsRealClass( String name, String value )
+ {
+ Optional<Setting> setting = getByName( name );
+
+ if ( setting.isPresent() )
+ {
+ Class<?> settingClazz = setting.get().getClazz();
+
+ if ( Double.class.isAssignableFrom( settingClazz ) )
+ {
+ return Double.valueOf( value );
+ }
+ else if ( Integer.class.isAssignableFrom( settingClazz ) )
+ {
+ return Integer.valueOf( value );
+ }
+ else if ( Boolean.class.isAssignableFrom( settingClazz ) )
+ {
+ return Boolean.valueOf( value );
+ }
+
+ //TODO handle Dates
+ }
+
+ return value;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public Serializable getDefaultValue()
+ {
+ return defaultValue;
+ }
+
+ public Class<?> getClazz()
+ {
+ return clazz;
+ }
+}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java 2015-10-06 15:33:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java 2015-10-06 16:57:39 +0000
@@ -47,6 +47,8 @@
{
String ID = SystemSettingManager.class.getName();
+ //TODO migrate from strings to Setting enum throughout system
+
String KEY_APPLICATION_TITLE = "applicationTitle";
String KEY_APPLICATION_INTRO = "keyApplicationIntro";
String KEY_APPLICATION_NOTIFICATION = "keyApplicationNotification";
@@ -101,7 +103,8 @@
String KEY_REQUIRE_ADD_TO_VIEW = "keyRequireAddToView";
String KEY_ALLOW_OBJECT_ASSIGNMENT = "keyAllowObjectAssignment";
String KEY_USE_CUSTOM_LOGO_FRONT = "keyUseCustomLogoFront";
- String KEY_USE_CUSTOM_LOGO_BANNER = "keyUseCustomLogoBanner";
+ String KEY_USE_CUSTOM_LOGO_BANNER = "keyUseCustomLogoBanner";
+ String KEY_METADATA_REPO_URL = "keyMetaDataRepoUrl";
String KEY_DATA_IMPORT_STRICT_PERIODS = "keyDataImportStrictPeriods";
String KEY_DATA_IMPORT_STRICT_CATEGORY_OPTION_COMBOS = "keyDataImportStrictCategoryOptionCombos";
String KEY_DATA_IMPORT_STRICT_ORGANISATION_UNITS = "keyDataImportStrictOrganisationUnits";
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java 2015-06-17 14:52:34 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java 2015-10-06 16:57:39 +0000
@@ -221,7 +221,7 @@
@Override
public Integer credentialsExpires()
{
- return (Integer) (getSystemSetting( KEY_CREDENTIALS_EXPIRES ) == null ? 0 : getSystemSetting( KEY_CREDENTIALS_EXPIRES ));
+ return (Integer) (getSystemSetting( KEY_CREDENTIALS_EXPIRES ) == null ? 0 : getSystemSetting( KEY_CREDENTIALS_EXPIRES ) );
}
@Override
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SystemSettingController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SystemSettingController.java 2015-09-22 15:27:57 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SystemSettingController.java 2015-10-06 16:57:39 +0000
@@ -28,9 +28,19 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Map;
+import java.util.Set;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.hisp.dhis.dxf2.render.RenderService;
import org.hisp.dhis.dxf2.webmessage.WebMessageException;
+import org.hisp.dhis.setting.Setting;
import org.hisp.dhis.setting.SystemSettingManager;
+import org.hisp.dhis.util.ObjectUtils;
import org.hisp.dhis.webapi.service.WebMessageService;
import org.hisp.dhis.webapi.utils.ContextUtils;
import org.hisp.dhis.webapi.utils.WebMessageUtils;
@@ -47,14 +57,6 @@
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.Map;
-import java.util.Set;
-
/**
* @author Lars Helge Overland
*/
@@ -90,13 +92,15 @@
throw new WebMessageException( WebMessageUtils.conflict( "Value must be specified as query param or as payload" ) );
}
- value = value != null ? value : valuePayload;
-
- key = key != null ? key : keyParam;
-
- systemSettingManager.saveSystemSetting( key, value );
-
- webMessageService.send( WebMessageUtils.ok( "System setting " + key + " set as value '" + value + "'." ), response, request );
+ key = ObjectUtils.firstNonNull( key, keyParam );
+
+ value = ObjectUtils.firstNonNull( value, valuePayload );
+
+ Serializable valueObject = Setting.getAsRealClass( key, value );
+
+ systemSettingManager.saveSystemSetting( key, valueObject );
+
+ webMessageService.send( WebMessageUtils.ok( "System setting " + key + " set as value '" + valueObject + "'." ), response, request );
}
@RequestMapping( method = RequestMethod.POST, consumes = { ContextUtils.CONTENT_TYPE_JSON } )
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/servlet/filter/ExcludableShallowEtagHeaderFilter.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/servlet/filter/ExcludableShallowEtagHeaderFilter.java 2015-10-06 15:57:15 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/servlet/filter/ExcludableShallowEtagHeaderFilter.java 2015-10-06 16:57:39 +0000
@@ -41,11 +41,14 @@
import org.springframework.web.filter.ShallowEtagHeaderFilter;
/**
- * Subclass of {@link org.springframework.web.filter.ShallowEtagHeaderFilter} which allows exclusion of URIs matching a regex.
+ * Subclass of {@link org.springframework.web.filter.ShallowEtagHeaderFilter}
+ * which allows exclusion of URIs matching a regex.
*
- * The regex is given as the init-param named 'excludeUriRegex' in the filter configuration.
+ * The regex is given as the init-param named 'excludeUriRegex' in the filter
+ * configuration.
*
* Example configuration:
+ *
* {@code
* <filter>
* <filter-name>ShallowEtagHeaderFilter</filter-name>
@@ -57,7 +60,8 @@
* </filter>
* }
*
- * The example exactly matches and excludes any request to the '/api/dataValues' and '/api/dataValues/files' from the filter.
+ * The example exactly matches and excludes any request to the '/api/dataValues'
+ * and '/api/dataValues/files' from the filter.
*
* @author Lars Helge Overland
* @author Halvdan Hoem Grelland
@@ -75,7 +79,7 @@
{
FilterConfig filterConfig = getFilterConfig();
- String excludeRegex = filterConfig != null ? filterConfig.getInitParameter( EXCLUDE_URI_REGEX_NAME ) : "";
+ String excludeRegex = filterConfig != null ? filterConfig.getInitParameter( EXCLUDE_URI_REGEX_NAME ) : null;
if ( StringUtils.isNotBlank( excludeRegex ) )
{
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/schedule/ScheduleSendMessageTasksAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/schedule/ScheduleSendMessageTasksAction.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/schedule/ScheduleSendMessageTasksAction.java 2015-10-06 16:57:39 +0000
@@ -172,6 +172,7 @@
{
minute = "0";
}
+
String cron = "0 " + Integer.parseInt( minute ) + " " + Integer.parseInt( hour ) + " ? * *";
keyCronMap.put( KEY_SEND_MESSAGE_SCHEDULED_TASKS, cron );