dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #42197
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21556: User settings. Using UserSettingKey enum as opposed to string. Limits user settings to enumerated...
Merge authors:
Lars Helge Øverland (larshelge)
------------------------------------------------------------
revno: 21556 [merge]
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-12-30 18:05:16 +0100
message:
User settings. Using UserSettingKey enum as opposed to string. Limits user settings to enumerated values. Introduced listing of user settings in Web API.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SettingKey.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSetting.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingKey.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/ui/locale/UserSettingLocaleManager.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/EmailMessageSender.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultSecurityService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultStyleManager.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsMessageSender.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/UserSettingDeletionHandler.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserSettingServiceTest.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/UserSettingController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/CurrentUserController.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/UserSettingInterceptor.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/GetGeneralSettingsAction.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/SetGeneralSettingsAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/GetDataElementListAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/SetAutoSaveSettingAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/ViewDataEntryFormAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/dataentryform/SetAutoSaveDataEntrySettingAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/dataentryform/SetAutoSaveProgramEntryFormSettingAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/dataentryform/ViewDataEntryFormAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/dataentryform/ViewProgramEntryFormAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/SetupTreeAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.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
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SettingKey.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SettingKey.java 2015-12-08 19:33:06 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SettingKey.java 2015-12-30 15:44:22 +0000
@@ -30,9 +30,11 @@
import java.io.Serializable;
import java.util.Date;
+import java.util.Locale;
import java.util.Map;
import java.util.Optional;
+import org.apache.commons.lang3.LocaleUtils;
import org.hisp.dhis.common.ListMap;
import org.hisp.dhis.configuration.Configuration;
import org.hisp.dhis.sms.config.SmsConfiguration;
@@ -180,6 +182,10 @@
{
return Boolean.valueOf( value );
}
+ else if ( Locale.class.isAssignableFrom( settingClazz ) )
+ {
+ return LocaleUtils.toLocale( value );
+ }
//TODO handle Dates
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSetting.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSetting.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSetting.java 2015-12-30 15:44:22 +0000
@@ -112,6 +112,11 @@
value = other.getValue() != null ? other.getValue() : value;
}
+ public boolean hasValue()
+ {
+ return value != null;
+ }
+
// -------------------------------------------------------------------------
// Getters and setters
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingKey.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingKey.java 2015-12-30 14:43:57 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingKey.java 2015-12-30 17:05:16 +0000
@@ -32,6 +32,8 @@
import java.util.Locale;
import java.util.Optional;
+import org.apache.commons.lang3.LocaleUtils;
+
/**
* @author Lars Helge Overland
*/
@@ -44,10 +46,11 @@
UI_LOCALE( "keyUiLocale", Locale.class ),
DB_LOCALE( "keyDbLocale", Locale.class ),
ANALYSIS_DISPLAY_PROPERTY( "keyAnalysisDisplayProperty", "name", String.class ),
- KEY_CURRENT_DOMAIN_TYPE( "currentDomainType" ),
+ CURRENT_DOMAIN_TYPE( "currentDomainType" ),
AUTO_SAVE_CASE_ENTRY_FORM( "autoSaveCaseEntryForm", Boolean.FALSE, Boolean.class ),
AUTO_SAVE_TRACKED_ENTITY_REGISTRATION_ENTRY_FORM( "autoSavetTrackedEntityForm", Boolean.FALSE, Boolean.class ),
- AUTO_SAVE_DATA_ENTRY_FORM( "autoSaveDataEntryForm", Boolean.FALSE, Boolean.class );
+ AUTO_SAVE_DATA_ENTRY_FORM( "autoSaveDataEntryForm", Boolean.FALSE, Boolean.class ),
+ TRACKER_DASHBOARD_LAYOUT( "keyTrackerDashboardLayout" );
private final String name;
@@ -117,6 +120,10 @@
{
return Boolean.valueOf( value );
}
+ else if ( Locale.class.isAssignableFrom( settingClazz ) )
+ {
+ return LocaleUtils.toLocale( value );
+ }
//TODO handle Dates
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingService.java 2015-12-08 19:33:06 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingService.java 2015-12-30 17:05:16 +0000
@@ -41,63 +41,37 @@
{
String ID = UserSettingService.class.getName();
- String KEY_STYLE = "stylesheet";
- String KEY_STYLE_DIRECTORY = "stylesheetDirectory";
- String KEY_MESSAGE_EMAIL_NOTIFICATION = "keyMessageEmailNotification";
- String KEY_MESSAGE_SMS_NOTIFICATION = "keyMessageSmsNotification";
- String KEY_UI_LOCALE = "keyUiLocale";
- String KEY_DB_LOCALE = "keyDbLocale";
- String KEY_ANALYSIS_DISPLAY_PROPERTY = "keyAnalysisDisplayProperty";
- String KEY_CURRENT_DOMAIN_TYPE = "currentDomainType";
- String AUTO_SAVE_CASE_ENTRY_FORM = "autoSaveCaseEntryForm";
- String AUTO_SAVE_TRACKED_ENTITY_REGISTRATION_ENTRY_FORM = "autoSavetTrackedEntityForm";
- String AUTO_SAVE_DATA_ENTRY_FORM = "autoSaveDataEntryForm";
-
- String DEFAULT_ANALYSIS_DISPLAY_PROPERTY = "name";
-
- //TODO use enum for names
-
// -------------------------------------------------------------------------
// UserSettings
// -------------------------------------------------------------------------
/**
- * Adds a UserSetting.
- *
- * @param userSetting the UserSetting to add.
- */
- void addUserSetting( UserSetting userSetting );
-
- /**
- * Saves the name/value pair as a user setting connected to the currently
+ * Saves the key/value pair as a user setting connected to the currently
* logged in user.
*
- * @param name the name/handle of the value.
- * @param value the value to store.
- * @throws NoCurrentUserException if there is no current user.
+ * @param key the user setting key.
+ * @param value the setting value.
*/
- void saveUserSetting( String name, Serializable value );
+ void saveUserSetting( UserSettingKey key, Serializable value );
/**
- * Saves the name/value pair as a user setting connected to user identified
+ * Saves the key/value pair as a user setting connected to user identified
* by username.
*
- * @param name the name/handle of the value.
- * @param value the value to store.
+ * @param key the user setting key.
+ * @param value the setting value.
* @param username the username of user.
- * @throws NoCurrentUserException if there is no user.
*/
- void saveUserSetting( String name, Serializable value, String username );
-
+ void saveUserSetting( UserSettingKey key, Serializable value, String username );
+
/**
* Saves the name/value pair as a user setting connected to user.
*
- * @param name the name/handle of the value.
- * @param value the value to store.
- * @param username the user.
- * @throws NoCurrentUserException if there is no user.
+ * @param key the user setting key.
+ * @param value the setting value.
+ * @param username the username of user.
*/
- void saveUserSetting( String name, Serializable value, User user );
+ void saveUserSetting( UserSettingKey key, Serializable value, User user );
/**
* Deletes a UserSetting.
@@ -109,67 +83,49 @@
/**
* Deletes the user setting with the given name.
*
- * @param name the name of the user setting to delete.
- * @throws NoCurrentUserException if there is no current user.
+ * @param key the user setting key.
*/
- void deleteUserSetting( String name );
+ void deleteUserSetting( UserSettingKey key );
/**
* Deletes the user setting with the given name for the given user.
*
- * @param name the name of the user setting to delete.
+ * @param key the user setting key.
* @user the user.
*/
- void deleteUserSetting( String name, User user );
+ void deleteUserSetting( UserSettingKey key, User user );
/**
* Returns the value of the user setting specified by the given name.
*
- * @param name the name of the user setting.
+ * @param key the user setting key.
* @return the value corresponding to the named user setting, or null if
* there is no match.
- * @throws NoCurrentUserException if there is no current user.
*/
- Serializable getUserSetting( String name );
+ Serializable getUserSetting( UserSettingKey key );
/**
- * Returns the value of the user setting specified by the given name. If
- * there is no current user or the user setting doesn't exist, the specified
- * default value is returned.
+ * Returns the value of the user setting specified by the given name.
*
- * @param name the name of the user setting.
- * @param defaultValue the value to return if there is no current user or no
- * user setting corresponding to the given name.
- * @return the value corresponding to the names user setting, or the default
- * value if there is no current user or matching user setting.
- */
- Serializable getUserSetting( String name, Serializable defaultValue );
-
- /**
- * Retrieves a user setting value for the given user and setting name. Returns
- * the given default value if the setting does not exist or the setting value
- * is null.
- *
- * @param name the setting name.
- * @param defaultValue the default value.
- * @param user the user.
- * @return a setting value.
- */
- Serializable getUserSetting( String name, Serializable defaultValue, User user );
-
- /**
- * Retrieves all UserSettings for the given User.
+ * @param key the user setting key.
+ * @param user the user.
+ * @return the value corresponding to the named user setting, or null if
+ * there is no match.
+ */
+ Serializable getUserSetting( UserSettingKey key, User user );
+
+ /**
+ * Retrieves UserSettings for the given User.
*
* @param user the User.
* @return a List of UserSettings.
*/
- List<UserSetting> getAllUserSettings( User user );
+ List<UserSetting> getUserSettings( User user );
/**
* Returns all user settings belonging to the current user.
*
* @return all user settings belonging to the current user.
- * @throws NoCurrentUserException if there is no current user.
*/
List<UserSetting> getAllUserSettings();
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java 2015-12-21 14:19:03 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java 2015-12-30 15:44:22 +0000
@@ -33,6 +33,7 @@
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.translation.Translation;
import org.hisp.dhis.translation.TranslationService;
+import org.hisp.dhis.user.UserSettingKey;
import org.hisp.dhis.user.UserSettingService;
import com.google.common.collect.Multimaps;
@@ -277,7 +278,7 @@
@Override
public Locale getCurrentLocale()
{
- return (Locale) userSettingService.getUserSetting( UserSettingService.KEY_DB_LOCALE );
+ return (Locale) userSettingService.getUserSetting( UserSettingKey.DB_LOCALE );
}
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/ui/locale/UserSettingLocaleManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/ui/locale/UserSettingLocaleManager.java 2015-10-19 11:25:31 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/ui/locale/UserSettingLocaleManager.java 2015-12-30 15:44:22 +0000
@@ -35,6 +35,7 @@
import org.hisp.dhis.i18n.locale.LocaleManager;
import org.hisp.dhis.i18n.ui.resourcebundle.ResourceBundleManager;
import org.hisp.dhis.i18n.ui.resourcebundle.ResourceBundleManagerException;
+import org.hisp.dhis.user.UserSettingKey;
import org.hisp.dhis.user.UserSettingService;
/**
@@ -83,7 +84,7 @@
@Override
public void setCurrentLocale( Locale locale )
{
- userSettingService.saveUserSetting( UserSettingService.KEY_UI_LOCALE, locale );
+ userSettingService.saveUserSetting( UserSettingKey.UI_LOCALE, locale );
}
@Override
@@ -105,7 +106,7 @@
private Locale getUserSelectedLocale()
{
- return (Locale) userSettingService.getUserSetting( UserSettingService.KEY_UI_LOCALE );
+ return (Locale) userSettingService.getUserSetting( UserSettingKey.UI_LOCALE );
}
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java 2015-12-11 11:21:38 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java 2015-12-30 15:44:22 +0000
@@ -42,12 +42,12 @@
import org.hisp.dhis.email.Email;
import org.hisp.dhis.email.EmailService;
import org.hisp.dhis.i18n.I18nManager;
-import org.hisp.dhis.i18n.locale.LocaleManager;
import org.hisp.dhis.setting.SystemSettingManager;
import org.hisp.dhis.system.velocity.VelocityManager;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserGroup;
+import org.hisp.dhis.user.UserSettingKey;
import org.hisp.dhis.user.UserSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
@@ -428,8 +428,7 @@
values.put( "responseUrl",
baseUrl + "/dhis-web-dashboard-integration/readMessage.action?id=" + conversation.getUid() );
- Locale locale = (Locale) userSettingService.getUserSetting( UserSettingService.KEY_UI_LOCALE,
- LocaleManager.DEFAULT_LOCALE, conversation.getUser() );
+ Locale locale = (Locale) userSettingService.getUserSetting( UserSettingKey.UI_LOCALE, conversation.getUser() );
values.put( "i18n", i18nManager.getI18n( locale ) );
return new VelocityManager().render( values, MESSAGE_EMAIL_FOOTER_TEMPLATE );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/EmailMessageSender.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/EmailMessageSender.java 2015-12-08 19:33:06 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/EmailMessageSender.java 2015-12-30 15:44:22 +0000
@@ -29,7 +29,6 @@
*/
import static org.apache.commons.lang3.StringUtils.defaultIfEmpty;
-import static org.hisp.dhis.user.UserSettingService.KEY_MESSAGE_EMAIL_NOTIFICATION;
import java.util.HashMap;
import java.util.Set;
@@ -46,6 +45,7 @@
import org.hisp.dhis.setting.SystemSettingManager;
import org.hisp.dhis.system.velocity.VelocityManager;
import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserSettingKey;
import org.hisp.dhis.user.UserSettingService;
import org.springframework.scheduling.annotation.Async;
@@ -133,7 +133,7 @@
for ( User user : users )
{
- boolean doSend = forceSend || (Boolean) userSettingService.getUserSetting( KEY_MESSAGE_EMAIL_NOTIFICATION, false, user );
+ boolean doSend = forceSend || (Boolean) userSettingService.getUserSetting( UserSettingKey.MESSAGE_EMAIL_NOTIFICATION, user );
if ( doSend && user.getEmail() != null && !user.getEmail().trim().isEmpty() )
{
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultSecurityService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultSecurityService.java 2015-12-08 19:33:06 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultSecurityService.java 2015-12-30 15:44:22 +0000
@@ -35,7 +35,6 @@
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.i18n.I18n;
import org.hisp.dhis.i18n.I18nManager;
-import org.hisp.dhis.i18n.locale.LocaleManager;
import org.hisp.dhis.message.MessageSender;
import org.hisp.dhis.period.Cal;
import org.hisp.dhis.setting.SettingKey;
@@ -46,6 +45,7 @@
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserCredentials;
import org.hisp.dhis.user.UserService;
+import org.hisp.dhis.user.UserSettingKey;
import org.hisp.dhis.user.UserSettingService;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
@@ -230,7 +230,7 @@
vars.put( "username", credentials.getUsername() );
User user = credentials.getUserInfo();
- Locale locale = (Locale) userSettingService.getUserSetting( UserSettingService.KEY_UI_LOCALE, LocaleManager.DEFAULT_LOCALE, user );
+ Locale locale = (Locale) userSettingService.getUserSetting( UserSettingKey.UI_LOCALE, user );
I18n i18n = i18nManager.getI18n( locale );
vars.put( "i18n", i18n );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultStyleManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultStyleManager.java 2015-12-08 19:33:06 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultStyleManager.java 2015-12-30 15:44:22 +0000
@@ -35,6 +35,7 @@
import org.hisp.dhis.i18n.I18n;
import org.hisp.dhis.i18n.I18nManager;
+import org.hisp.dhis.user.UserSettingKey;
import org.hisp.dhis.user.UserSettingService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -94,13 +95,13 @@
@Override
public void setUserStyle( String style )
{
- userSettingService.saveUserSetting( SettingKey.STYLE.getName(), style );
+ userSettingService.saveUserSetting( UserSettingKey.STYLE, style );
}
@Override
public String getCurrentStyle()
{
- String style = (String) userSettingService.getUserSetting( SettingKey.STYLE.getName() );
+ String style = (String) userSettingService.getUserSetting( UserSettingKey.STYLE );
if ( style != null )
{
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsMessageSender.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsMessageSender.java 2015-12-18 11:04:05 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsMessageSender.java 2015-12-30 15:44:22 +0000
@@ -44,6 +44,7 @@
import org.hisp.dhis.system.util.SmsUtils;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserSettingKey;
import org.hisp.dhis.user.UserSettingService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -184,7 +185,7 @@
// Receiver is user
{
Serializable userSetting = userSettingService
- .getUserSetting( UserSettingService.KEY_MESSAGE_SMS_NOTIFICATION, null, user );
+ .getUserSetting( UserSettingKey.MESSAGE_SMS_NOTIFICATION, user );
return userSetting != null ? (Boolean) userSetting : false;
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java 2015-12-08 19:36:21 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java 2015-12-30 17:05:16 +0000
@@ -92,49 +92,41 @@
// -------------------------------------------------------------------------
@Override
- public void addUserSetting( UserSetting userSetting )
- {
- SETTING_CACHE.invalidate( getCacheKey( userSetting.getName(), userSetting.getUser().getUsername() ) );
-
- userSettingStore.addUserSetting( userSetting );
- }
-
- @Override
- public void saveUserSetting( String name, Serializable value, String username )
+ public void saveUserSetting( UserSettingKey key, Serializable value, String username )
{
UserCredentials credentials = userService.getUserCredentialsByUsername( username );
if ( credentials != null )
{
- saveUserSetting( name, value, credentials.getUserInfo() );
+ saveUserSetting( key, value, credentials.getUserInfo() );
}
}
@Override
- public void saveUserSetting( String name, Serializable value )
+ public void saveUserSetting( UserSettingKey key, Serializable value )
{
User currentUser = currentUserService.getCurrentUser();
- saveUserSetting( name, value, currentUser );
+ saveUserSetting( key, value, currentUser );
}
@Override
- public void saveUserSetting( String name, Serializable value, User user )
+ public void saveUserSetting( UserSettingKey key, Serializable value, User user )
{
if ( user == null )
{
return;
}
- SETTING_CACHE.invalidate( getCacheKey( name, user.getUsername() ) );
+ SETTING_CACHE.invalidate( getCacheKey( key.getName(), user.getUsername() ) );
- UserSetting userSetting = userSettingStore.getUserSetting( user, name );
+ UserSetting userSetting = userSettingStore.getUserSetting( user, key.getName() );
if ( userSetting == null )
{
- userSetting = new UserSetting( user, name, value );
+ userSetting = new UserSetting( user, key.getName(), value );
- addUserSetting( userSetting );
+ userSettingStore.addUserSetting( userSetting );
}
else
{
@@ -153,13 +145,13 @@
}
@Override
- public void deleteUserSetting( String name )
+ public void deleteUserSetting( UserSettingKey key )
{
User currentUser = currentUserService.getCurrentUser();
if ( currentUser != null )
{
- UserSetting setting = userSettingStore.getUserSetting( currentUser, name );
+ UserSetting setting = userSettingStore.getUserSetting( currentUser, key.getName() );
if ( setting != null )
{
@@ -169,9 +161,9 @@
}
@Override
- public void deleteUserSetting( String name, User user )
+ public void deleteUserSetting( UserSettingKey key, User user )
{
- UserSetting setting = userSettingStore.getUserSetting( user, name );
+ UserSetting setting = userSettingStore.getUserSetting( user, key.getName() );
if ( setting != null )
{
@@ -180,26 +172,20 @@
}
@Override
- public Serializable getUserSetting( String name )
- {
- return getUserSetting( name, Optional.empty() ).orElse( null );
- }
-
- @Override
- public Serializable getUserSetting( String name, Serializable defaultValue )
- {
- return getUserSetting( name, Optional.empty() ).orElse( defaultValue );
- }
-
- @Override
- public Serializable getUserSetting( String name, Serializable defaultValue, User user )
- {
- return getUserSetting( name, Optional.ofNullable( user ) ).orElse( defaultValue );
- }
-
- private Optional<Serializable> getUserSetting( String name, Optional<User> user )
- {
- if ( name == null )
+ public Serializable getUserSetting( UserSettingKey key )
+ {
+ return getUserSetting( key, Optional.empty() ).orElse( null );
+ }
+
+ @Override
+ public Serializable getUserSetting( UserSettingKey key, User user )
+ {
+ return getUserSetting( key, Optional.of( user ) ).orElse( null );
+ }
+
+ private Optional<Serializable> getUserSetting( UserSettingKey key, Optional<User> user )
+ {
+ if ( key == null )
{
return Optional.empty();
}
@@ -208,9 +194,9 @@
try
{
- String cacheKey = getCacheKey( name, username );
+ String cacheKey = getCacheKey( key.getName(), username );
- return SETTING_CACHE.get( cacheKey, () -> getUserSettingOptional( username, name ) );
+ return SETTING_CACHE.get( cacheKey, () -> getUserSettingOptional( key, username ) );
}
catch ( ExecutionException ignored )
{
@@ -218,7 +204,7 @@
}
}
- private Optional<Serializable> getUserSettingOptional( String username, String settingName )
+ private Optional<Serializable> getUserSettingOptional( UserSettingKey key, String username )
{
UserCredentials userCredentials = userService.getUserCredentialsByUsername( username );
@@ -227,9 +213,9 @@
return Optional.empty();
}
- UserSetting setting = userSettingStore.getUserSetting( userCredentials.getUserInfo(), settingName );
+ UserSetting setting = userSettingStore.getUserSetting( userCredentials.getUserInfo(), key.getName() );
- return setting != null ? Optional.ofNullable( setting.getValue() ) : Optional.empty();
+ return setting != null && setting.hasValue() ? Optional.of( setting.getValue() ) : Optional.ofNullable( key.getDefaultValue() );
}
@Override
@@ -237,11 +223,11 @@
{
User currentUser = currentUserService.getCurrentUser();
- return getAllUserSettings( currentUser );
+ return getUserSettings( currentUser );
}
-
+
@Override
- public List<UserSetting> getAllUserSettings( User user )
+ public List<UserSetting> getUserSettings( User user )
{
if ( user == null )
{
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/UserSettingDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/UserSettingDeletionHandler.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/UserSettingDeletionHandler.java 2015-12-30 17:05:16 +0000
@@ -57,7 +57,7 @@
@Override
public void deleteUser( User user )
{
- for ( UserSetting setting : userSettingService.getAllUserSettings( user ) )
+ for ( UserSetting setting : userSettingService.getUserSettings( user ) )
{
userSettingService.deleteUserSetting( setting );
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserSettingServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserSettingServiceTest.java 2015-10-14 17:36:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserSettingServiceTest.java 2015-12-30 17:05:16 +0000
@@ -32,10 +32,7 @@
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
-import static org.hisp.dhis.user.UserSettingService.KEY_ANALYSIS_DISPLAY_PROPERTY;
-import static org.hisp.dhis.user.UserSettingService.KEY_STYLE;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
/**
* @author Kiran Prakash
@@ -67,64 +64,48 @@
@Test
public void testSaveGetDeleteUserSetting()
{
- assertNull( userSettingService.getUserSetting( KEY_ANALYSIS_DISPLAY_PROPERTY, null, userA ) );
- assertNull( userSettingService.getUserSetting( KEY_STYLE, null, userA ) );
-
- userSettingService.saveUserSetting( KEY_ANALYSIS_DISPLAY_PROPERTY, "name", "usernameA" );
- userSettingService.saveUserSetting( KEY_STYLE, "blue", "usernameA" );
-
- assertEquals( "name", userSettingService.getUserSetting( KEY_ANALYSIS_DISPLAY_PROPERTY, null, userA ) );
- assertEquals( "blue", userSettingService.getUserSetting( KEY_STYLE, null, userA ) );
-
- userSettingService.deleteUserSetting( KEY_ANALYSIS_DISPLAY_PROPERTY, userA );
-
- assertNull( userSettingService.getUserSetting( KEY_ANALYSIS_DISPLAY_PROPERTY, null, userA ) );
- assertEquals( "blue", userSettingService.getUserSetting( KEY_STYLE, null, userA ) );
-
- userSettingService.deleteUserSetting( KEY_STYLE, userA );
-
- assertNull( userSettingService.getUserSetting( KEY_ANALYSIS_DISPLAY_PROPERTY, null, userA ) );
- assertNull( userSettingService.getUserSetting( KEY_STYLE, null, userA ) );
+ assertEquals( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY.getDefaultValue(), userSettingService.getUserSetting( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY, userA ) );
+ assertEquals( UserSettingKey.STYLE.getDefaultValue(), userSettingService.getUserSetting( UserSettingKey.STYLE, userA ) );
+
+ userSettingService.saveUserSetting( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY, "shortName", "usernameA" );
+ userSettingService.saveUserSetting( UserSettingKey.STYLE, "blue", "usernameA" );
+
+ assertEquals( "shortName", userSettingService.getUserSetting( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY, userA ) );
+ assertEquals( "blue", userSettingService.getUserSetting( UserSettingKey.STYLE, userA ) );
+
+ userSettingService.deleteUserSetting( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY, userA );
+
+ assertEquals( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY.getDefaultValue(), userSettingService.getUserSetting( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY, userA ) );
+ assertEquals( "blue", userSettingService.getUserSetting( UserSettingKey.STYLE, userA ) );
+
+ userSettingService.deleteUserSetting( UserSettingKey.STYLE, userA );
+
+ assertEquals( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY.getDefaultValue(), userSettingService.getUserSetting( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY, userA ) );
+ assertEquals( UserSettingKey.STYLE.getDefaultValue(), userSettingService.getUserSetting( UserSettingKey.STYLE, userA ) );
}
@Test
public void testSaveOrUpdateUserSetting()
{
- userSettingService.saveUserSetting( KEY_ANALYSIS_DISPLAY_PROPERTY, "name", "usernameA" );
- userSettingService.saveUserSetting( KEY_STYLE, "blue", "usernameA" );
-
- assertEquals( "name", userSettingService.getUserSetting( KEY_ANALYSIS_DISPLAY_PROPERTY, null, userA ) );
- assertEquals( "blue", userSettingService.getUserSetting( KEY_STYLE, null, userA ) );
-
- userSettingService.saveUserSetting( KEY_ANALYSIS_DISPLAY_PROPERTY, "shortName", "usernameA" );
- userSettingService.saveUserSetting( KEY_STYLE, "green", "usernameA" );
-
- assertEquals( "shortName", userSettingService.getUserSetting( KEY_ANALYSIS_DISPLAY_PROPERTY, null, userA ) );
- assertEquals( "green", userSettingService.getUserSetting( KEY_STYLE, null, userA ) );
- }
-
- @Test
- public void testGetWithDefaultUserSetting()
- {
- assertNull( userSettingService.getUserSetting( KEY_ANALYSIS_DISPLAY_PROPERTY, null, userA ) );
- assertNull( userSettingService.getUserSetting( KEY_STYLE, null, userA ) );
-
- assertEquals( "shortName", userSettingService.getUserSetting( KEY_ANALYSIS_DISPLAY_PROPERTY, "shortName", userA ) );
- assertEquals( "yellow", userSettingService.getUserSetting( KEY_STYLE, "yellow", userA ) );
-
- userSettingService.saveUserSetting( KEY_ANALYSIS_DISPLAY_PROPERTY, "name", "usernameA" );
- userSettingService.saveUserSetting( KEY_STYLE, "blue", "usernameA" );
-
- assertEquals( "name", userSettingService.getUserSetting( KEY_ANALYSIS_DISPLAY_PROPERTY, null, userA ) );
- assertEquals( "blue", userSettingService.getUserSetting( KEY_STYLE, null, userA ) );
+ userSettingService.saveUserSetting( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY, "name", "usernameA" );
+ userSettingService.saveUserSetting( UserSettingKey.STYLE, "blue", "usernameA" );
+
+ assertEquals( "name", userSettingService.getUserSetting( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY, userA ) );
+ assertEquals( "blue", userSettingService.getUserSetting( UserSettingKey.STYLE, userA ) );
+
+ userSettingService.saveUserSetting( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY, "shortName", "usernameA" );
+ userSettingService.saveUserSetting( UserSettingKey.STYLE, "green", "usernameA" );
+
+ assertEquals( "shortName", userSettingService.getUserSetting( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY, userA ) );
+ assertEquals( "green", userSettingService.getUserSetting( UserSettingKey.STYLE, userA ) );
}
@Test
public void testGetUserSettingsByUser()
{
- userSettingService.saveUserSetting( KEY_ANALYSIS_DISPLAY_PROPERTY, "name", "usernameA" );
- userSettingService.saveUserSetting( KEY_STYLE, "blue", "usernameA" );
+ userSettingService.saveUserSetting( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY, "name", "usernameA" );
+ userSettingService.saveUserSetting( UserSettingKey.STYLE, "blue", "usernameA" );
- assertEquals( 2, userSettingService.getAllUserSettings( userA ).size() );
+ assertEquals( 2, userSettingService.getUserSettings( userA ).size() );
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/UserSettingController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/UserSettingController.java 2015-09-24 07:21:57 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/UserSettingController.java 2015-12-30 17:05:16 +0000
@@ -1,5 +1,7 @@
package org.hisp.dhis.webapi.controller;
+import org.hisp.dhis.dxf2.render.RenderService;
+
/*
* Copyright (c) 2004-2015, University of Oslo
* All rights reserved.
@@ -29,9 +31,16 @@
*/
import org.hisp.dhis.dxf2.webmessage.WebMessageException;
-import org.hisp.dhis.system.util.LocaleUtils;
+import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserCredentials;
+import org.hisp.dhis.user.UserService;
+import org.hisp.dhis.user.UserSetting;
+import org.hisp.dhis.user.UserSettingKey;
import org.hisp.dhis.user.UserSettingService;
+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;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
@@ -44,11 +53,13 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
import java.io.IOException;
import java.io.Serializable;
-import java.util.Locale;
-
-import static org.hisp.dhis.user.UserSettingService.*;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
/**
* @author Lars Helge Overland
@@ -59,13 +70,26 @@
{
@Autowired
private UserSettingService userSettingService;
+
+ @Autowired
+ private UserService userService;
+
+ @Autowired
+ private CurrentUserService currentUserService;
@Autowired
private WebMessageService webMessageService;
+
+ @Autowired
+ private RenderService renderService;
+
+ // -------------------------------------------------------------------------
+ // Resources
+ // -------------------------------------------------------------------------
@RequestMapping( value = "/{key}", method = RequestMethod.POST )
public void setUserSetting(
- @PathVariable String key,
+ @PathVariable( value = "key" ) String key,
@RequestParam( value = "user", required = false ) String username,
@RequestParam( value = "value", required = false ) String value,
@RequestBody( required = false ) String valuePayload,
@@ -81,43 +105,66 @@
throw new WebMessageException( WebMessageUtils.conflict( "Value must be specified as query param or as payload" ) );
}
- value = value != null ? value : valuePayload;
+ value = ObjectUtils.firstNonNull( value, valuePayload );
+ Optional<UserSettingKey> keyEnum = UserSettingKey.getByName( key );
+
+ if ( !keyEnum.isPresent() )
+ {
+ throw new WebMessageException( WebMessageUtils.conflict( "Key is not supported: " + key ) );
+ }
+
+ Serializable valueObject = UserSettingKey.getAsRealClass( key, value );
+
if ( username == null )
{
- userSettingService.saveUserSetting( key, valueToSet( key, value ) );
-
+ userSettingService.saveUserSetting( keyEnum.get(), valueObject );
}
else
{
- userSettingService.saveUserSetting( key, valueToSet( key, value ), username );
+ userSettingService.saveUserSetting( keyEnum.get(), valueObject, username );
}
webMessageService.send( WebMessageUtils.ok( "User setting saved" ), response, request );
}
@RequestMapping( value = "/{key}", method = RequestMethod.GET )
- public void getUserSetting( @PathVariable( "key" ) String key,
+ public void getUserSetting(
+ @PathVariable( "key" ) String key,
@RequestParam( value = "user", required = false ) String username,
HttpServletRequest request, HttpServletResponse response ) throws IOException, WebMessageException
{
+ Optional<UserSettingKey> keyEnum = UserSettingKey.getByName( key );
+
+ if ( !keyEnum.isPresent() )
+ {
+ throw new WebMessageException( WebMessageUtils.conflict( "Key is not supported: " + key ) );
+ }
+
+ UserCredentials credentials = userService.getUserCredentialsByUsername( username );
+
+ if ( credentials == null )
+ {
+ throw new WebMessageException( WebMessageUtils.conflict( "User does not exist: " + username ) );
+ }
+
Serializable value;
if ( username == null )
{
- value = userSettingService.getUserSetting( key );
+ value = userSettingService.getUserSetting( keyEnum.get() );
}
else
{
- value = userSettingService.getUserSetting( key, username );
+ value = userSettingService.getUserSetting( keyEnum.get(), credentials.getUser() );
}
if ( value == null )
{
- throw new WebMessageException( WebMessageUtils.notFound( "User setting not found." ) );
+ throw new WebMessageException( WebMessageUtils.notFound( "User setting not found for key: " + key ) );
}
- String stringVal = getStringValue( key, value );
+ String stringVal = String.valueOf( value );
String contentType = null;
@@ -133,34 +180,50 @@
response.setContentType( contentType );
response.getWriter().println( stringVal );
}
+
+ @RequestMapping( method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON )
+ public void getUserSettingsByUser( @RequestParam( required = false ) String user,
+ HttpServletRequest request, HttpServletResponse response )
+ throws WebMessageException, IOException
+ {
+ UserCredentials credentials = userService.getUserCredentialsByUsername( user );
+ User us = credentials != null ? credentials.getUser() : null;
+
+ if ( us == null )
+ {
+ us = currentUserService.getCurrentUser();
+ }
+
+ List<UserSetting> settings = userSettingService.getUserSettings( us );
+
+ Map<String, Serializable> map = asMap( settings );
+
+ renderService.toJson( response.getOutputStream(), map );
+ }
+
@RequestMapping( value = "/{key}", method = RequestMethod.DELETE )
public void removeSystemSetting( @PathVariable( "key" ) String key )
- {
- userSettingService.deleteUserSetting( key );
- }
-
- private Serializable valueToSet( String key, String value )
- {
- if ( KEY_UI_LOCALE.equals( key ) || KEY_DB_LOCALE.equals( key ) )
- {
- return LocaleUtils.getLocale( value );
- }
- else
- {
- return value;
- }
- }
-
- private String getStringValue( String key, Serializable value )
- {
- if ( KEY_UI_LOCALE.equals( key ) || KEY_DB_LOCALE.equals( key ) )
- {
- return ((Locale) value).getLanguage();
- }
- else
- {
- return String.valueOf( value );
- }
+ throws WebMessageException
+ {
+ Optional<UserSettingKey> keyEnum = UserSettingKey.getByName( key );
+
+ if ( !keyEnum.isPresent() )
+ {
+ throw new WebMessageException( WebMessageUtils.conflict( "Key is not supported: " + key ) );
+ }
+
+ userSettingService.deleteUserSetting( keyEnum.get() );
+ }
+
+ // -------------------------------------------------------------------------
+ // Supportive methods
+ // -------------------------------------------------------------------------
+
+ private Map<String, Serializable> asMap( List<UserSetting> settings )
+ {
+ return settings.stream().
+ filter( s -> s.getName() != null && s.getValue() != null ).
+ collect( Collectors.toMap( UserSetting::getName, UserSetting::getValue ) );
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/CurrentUserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/CurrentUserController.java 2015-11-18 16:46:20 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/CurrentUserController.java 2015-12-30 15:44:22 +0000
@@ -60,6 +60,7 @@
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserGroupService;
import org.hisp.dhis.user.UserService;
+import org.hisp.dhis.user.UserSettingKey;
import org.hisp.dhis.user.UserSettingService;
import org.hisp.dhis.webapi.controller.exception.FilterTooShortException;
import org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException;
@@ -99,8 +100,6 @@
import java.util.Map;
import java.util.Set;
-import static org.hisp.dhis.user.UserSettingService.*;
-
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@@ -358,11 +357,11 @@
userAccount.setInterests( currentUser.getInterests() );
userAccount.setLanguages( currentUser.getLanguages() );
- userAccount.getSettings().put( KEY_UI_LOCALE, TextUtils.toString( userSettingService.getUserSetting( KEY_UI_LOCALE ) ) );
- userAccount.getSettings().put( KEY_DB_LOCALE, TextUtils.toString( userSettingService.getUserSetting( KEY_DB_LOCALE ) ) );
- userAccount.getSettings().put( KEY_MESSAGE_EMAIL_NOTIFICATION, TextUtils.toString( userSettingService.getUserSetting( KEY_MESSAGE_EMAIL_NOTIFICATION ) ) );
- userAccount.getSettings().put( KEY_MESSAGE_SMS_NOTIFICATION, TextUtils.toString( userSettingService.getUserSetting( KEY_MESSAGE_SMS_NOTIFICATION ) ) );
- userAccount.getSettings().put( KEY_ANALYSIS_DISPLAY_PROPERTY, TextUtils.toString( userSettingService.getUserSetting( KEY_ANALYSIS_DISPLAY_PROPERTY ) ) );
+ userAccount.getSettings().put( UserSettingKey.UI_LOCALE.getName(), TextUtils.toString( userSettingService.getUserSetting( UserSettingKey.UI_LOCALE ) ) );
+ userAccount.getSettings().put( UserSettingKey.DB_LOCALE.getName(), TextUtils.toString( userSettingService.getUserSetting( UserSettingKey.DB_LOCALE ) ) );
+ userAccount.getSettings().put( UserSettingKey.MESSAGE_EMAIL_NOTIFICATION.getName(), TextUtils.toString( userSettingService.getUserSetting( UserSettingKey.MESSAGE_EMAIL_NOTIFICATION ) ) );
+ userAccount.getSettings().put( UserSettingKey.MESSAGE_SMS_NOTIFICATION.getName(), TextUtils.toString( userSettingService.getUserSetting( UserSettingKey.MESSAGE_SMS_NOTIFICATION ) ) );
+ userAccount.getSettings().put( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY.getName(), TextUtils.toString( userSettingService.getUserSetting( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY ) ) );
return userAccount;
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/UserSettingInterceptor.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/UserSettingInterceptor.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/UserSettingInterceptor.java 2015-12-30 15:44:22 +0000
@@ -28,13 +28,11 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.user.UserSettingService.KEY_STYLE;
-import static org.hisp.dhis.user.UserSettingService.KEY_STYLE_DIRECTORY;
-
import java.util.HashMap;
import java.util.Map;
import org.hisp.dhis.setting.StyleManager;
+import org.hisp.dhis.user.UserSettingKey;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
@@ -76,8 +74,8 @@
{
Map<String, Object> map = new HashMap<>();
- map.put( KEY_STYLE, styleManager.getCurrentStyle() );
- map.put( KEY_STYLE_DIRECTORY, styleManager.getCurrentStyleDirectory() );
+ map.put( UserSettingKey.STYLE.getName(), styleManager.getCurrentStyle() );
+ map.put( UserSettingKey.STYLE_DIRECTORY.getName(), styleManager.getCurrentStyleDirectory() );
invocation.getStack().push( map );
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/GetGeneralSettingsAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/GetGeneralSettingsAction.java 2015-10-16 20:17:09 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/GetGeneralSettingsAction.java 2015-12-30 15:44:22 +0000
@@ -28,20 +28,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.user.UserSettingService.DEFAULT_ANALYSIS_DISPLAY_PROPERTY;
-import static org.hisp.dhis.user.UserSettingService.KEY_ANALYSIS_DISPLAY_PROPERTY;
-import static org.hisp.dhis.user.UserSettingService.KEY_MESSAGE_EMAIL_NOTIFICATION;
-import static org.hisp.dhis.user.UserSettingService.KEY_MESSAGE_SMS_NOTIFICATION;
-
import java.util.List;
import java.util.Locale;
-import java.io.Serializable;
-
import org.hisp.dhis.i18n.I18nService;
import org.hisp.dhis.i18n.locale.LocaleManager;
import org.hisp.dhis.setting.StyleManager;
import org.hisp.dhis.setting.StyleObject;
+import org.hisp.dhis.user.UserSettingKey;
import org.hisp.dhis.user.UserSettingService;
import com.opensymphony.xwork2.Action;
@@ -183,12 +177,11 @@
currentStyle = styleManager.getCurrentStyle();
- analysisDisplayProperty = (String) userSettingService.getUserSetting( KEY_ANALYSIS_DISPLAY_PROPERTY,
- (Serializable) DEFAULT_ANALYSIS_DISPLAY_PROPERTY );
-
- messageEmailNotification = (Boolean) userSettingService.getUserSetting( KEY_MESSAGE_EMAIL_NOTIFICATION, false );
-
- messageSmsNotification = (Boolean) userSettingService.getUserSetting( KEY_MESSAGE_SMS_NOTIFICATION, false );
+ analysisDisplayProperty = (String) userSettingService.getUserSetting( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY );
+
+ messageEmailNotification = (Boolean) userSettingService.getUserSetting( UserSettingKey.MESSAGE_EMAIL_NOTIFICATION );
+
+ messageSmsNotification = (Boolean) userSettingService.getUserSetting( UserSettingKey.MESSAGE_SMS_NOTIFICATION );
return SUCCESS;
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/SetGeneralSettingsAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/SetGeneralSettingsAction.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/SetGeneralSettingsAction.java 2015-12-30 15:44:22 +0000
@@ -28,15 +28,11 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.user.UserSettingService.KEY_DB_LOCALE;
-import static org.hisp.dhis.user.UserSettingService.KEY_MESSAGE_EMAIL_NOTIFICATION;
-import static org.hisp.dhis.user.UserSettingService.KEY_MESSAGE_SMS_NOTIFICATION;
-import static org.hisp.dhis.user.UserSettingService.KEY_ANALYSIS_DISPLAY_PROPERTY;
-
import org.hisp.dhis.i18n.I18n;
import org.hisp.dhis.i18n.locale.LocaleManager;
import org.hisp.dhis.setting.StyleManager;
import org.hisp.dhis.system.util.LocaleUtils;
+import org.hisp.dhis.user.UserSettingKey;
import org.hisp.dhis.user.UserSettingService;
import com.opensymphony.xwork2.Action;
@@ -143,15 +139,13 @@
{
localeManager.setCurrentLocale( LocaleUtils.getLocale( currentLocale ) );
- userSettingService.saveUserSetting( KEY_DB_LOCALE, LocaleUtils.getLocale( currentLocaleDb ) );
+ userSettingService.saveUserSetting( UserSettingKey.DB_LOCALE, LocaleUtils.getLocale( currentLocaleDb ) );
styleManager.setUserStyle( currentStyle );
- userSettingService.saveUserSetting( KEY_MESSAGE_EMAIL_NOTIFICATION, messageEmailNotification );
-
- userSettingService.saveUserSetting( KEY_MESSAGE_SMS_NOTIFICATION, messageSmsNotification );
-
- userSettingService.saveUserSetting( KEY_ANALYSIS_DISPLAY_PROPERTY, analysisDisplayProperty );
+ userSettingService.saveUserSetting( UserSettingKey.MESSAGE_EMAIL_NOTIFICATION, messageEmailNotification );
+ userSettingService.saveUserSetting( UserSettingKey.MESSAGE_SMS_NOTIFICATION, messageSmsNotification );
+ userSettingService.saveUserSetting( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY, analysisDisplayProperty );
message = i18n.getString( "settings_updated" );
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/GetDataElementListAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/GetDataElementListAction.java 2015-06-11 12:24:58 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/GetDataElementListAction.java 2015-12-30 15:44:22 +0000
@@ -29,7 +29,6 @@
*/
import static org.apache.commons.lang3.StringUtils.isNotBlank;
-import static org.hisp.dhis.user.UserSettingService.KEY_CURRENT_DOMAIN_TYPE;
import java.util.Collections;
import java.util.List;
@@ -39,6 +38,7 @@
import org.hisp.dhis.dataelement.DataElementDomain;
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.paging.ActionPagingSupport;
+import org.hisp.dhis.user.UserSettingKey;
import org.hisp.dhis.user.UserSettingService;
/**
@@ -113,17 +113,17 @@
{
if ( domainType == null ) // None, get current domain type
{
- domainType = (String) userSettingService.getUserSetting( KEY_CURRENT_DOMAIN_TYPE );
+ domainType = (String) userSettingService.getUserSetting( UserSettingKey.CURRENT_DOMAIN_TYPE );
}
else if ( "all".equals( domainType ) ) // All, reset current domain type
{
- userSettingService.saveUserSetting( KEY_CURRENT_DOMAIN_TYPE, null );
+ userSettingService.deleteUserSetting( UserSettingKey.CURRENT_DOMAIN_TYPE );
domainType = null;
}
else // Specified, set current domain type
{
- userSettingService.saveUserSetting( KEY_CURRENT_DOMAIN_TYPE, domainType );
+ userSettingService.saveUserSetting( UserSettingKey.CURRENT_DOMAIN_TYPE, domainType );
}
// ---------------------------------------------------------------------
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/SetAutoSaveSettingAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/SetAutoSaveSettingAction.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/SetAutoSaveSettingAction.java 2015-12-30 15:44:22 +0000
@@ -1,5 +1,7 @@
package org.hisp.dhis.dataset.action.dataentryform;
+import org.hisp.dhis.user.UserSettingKey;
+
/*
* Copyright (c) 2004-2015, University of Oslo
* All rights reserved.
@@ -70,7 +72,7 @@
public String execute()
throws Exception
{
- userSettingService.saveUserSetting( UserSettingService.AUTO_SAVE_DATA_ENTRY_FORM, autoSave );
+ userSettingService.saveUserSetting( UserSettingKey.AUTO_SAVE_DATA_ENTRY_FORM, autoSave );
return SUCCESS;
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/ViewDataEntryFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/ViewDataEntryFormAction.java 2015-03-19 12:47:13 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/ViewDataEntryFormAction.java 2015-12-30 15:44:22 +0000
@@ -42,6 +42,7 @@
import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.i18n.I18n;
import org.hisp.dhis.setting.SystemSettingManager;
+import org.hisp.dhis.user.UserSettingKey;
import org.hisp.dhis.user.UserSettingService;
import com.opensymphony.xwork2.Action;
@@ -173,7 +174,7 @@
dataEntryValue = dataEntryForm != null ? dataEntryFormService.prepareDataEntryFormForEdit( dataEntryForm, dataSet, i18n ) : "";
- autoSave = (Boolean) userSettingService.getUserSetting( UserSettingService.AUTO_SAVE_DATA_ENTRY_FORM, false );
+ autoSave = (Boolean) userSettingService.getUserSetting( UserSettingKey.AUTO_SAVE_DATA_ENTRY_FORM );
dataElementList = new ArrayList<>( dataSet.getDataElements() );
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/dataentryform/SetAutoSaveDataEntrySettingAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/dataentryform/SetAutoSaveDataEntrySettingAction.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/dataentryform/SetAutoSaveDataEntrySettingAction.java 2015-12-30 15:44:22 +0000
@@ -1,5 +1,7 @@
package org.hisp.dhis.trackedentity.action.dataentryform;
+import org.hisp.dhis.user.UserSettingKey;
+
/*
* Copyright (c) 2004-2015, University of Oslo
* All rights reserved.
@@ -70,7 +72,7 @@
public String execute()
throws Exception
{
- userSettingService.saveUserSetting( UserSettingService.AUTO_SAVE_CASE_ENTRY_FORM, autoSave );
+ userSettingService.saveUserSetting( UserSettingKey.AUTO_SAVE_CASE_ENTRY_FORM, autoSave );
return SUCCESS;
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/dataentryform/SetAutoSaveProgramEntryFormSettingAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/dataentryform/SetAutoSaveProgramEntryFormSettingAction.java 2015-06-19 07:35:50 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/dataentryform/SetAutoSaveProgramEntryFormSettingAction.java 2015-12-30 15:44:22 +0000
@@ -1,5 +1,7 @@
package org.hisp.dhis.trackedentity.action.dataentryform;
+import org.hisp.dhis.user.UserSettingKey;
+
/*
* Copyright (c) 2004-2015, University of Oslo
* All rights reserved.
@@ -70,7 +72,7 @@
public String execute()
throws Exception
{
- userSettingService.saveUserSetting( UserSettingService.AUTO_SAVE_TRACKED_ENTITY_REGISTRATION_ENTRY_FORM, autoSave );
+ userSettingService.saveUserSetting( UserSettingKey.AUTO_SAVE_TRACKED_ENTITY_REGISTRATION_ENTRY_FORM, autoSave );
return SUCCESS;
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/dataentryform/ViewDataEntryFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/dataentryform/ViewDataEntryFormAction.java 2015-06-16 13:17:59 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/dataentryform/ViewDataEntryFormAction.java 2015-12-30 15:44:22 +0000
@@ -40,6 +40,7 @@
import org.hisp.dhis.program.ProgramStage;
import org.hisp.dhis.program.ProgramStageService;
import org.hisp.dhis.setting.SystemSettingManager;
+import org.hisp.dhis.user.UserSettingKey;
import org.hisp.dhis.user.UserSettingService;
import com.opensymphony.xwork2.Action;
@@ -219,7 +220,7 @@
flags = systemSettingManager.getFlags();
- autoSave = (Boolean) userSettingService.getUserSetting( UserSettingService.AUTO_SAVE_CASE_ENTRY_FORM, false );
+ autoSave = (Boolean) userSettingService.getUserSetting( UserSettingKey.AUTO_SAVE_CASE_ENTRY_FORM );
return SUCCESS;
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/dataentryform/ViewProgramEntryFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/dataentryform/ViewProgramEntryFormAction.java 2015-07-02 07:05:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/dataentryform/ViewProgramEntryFormAction.java 2015-12-30 15:44:22 +0000
@@ -40,6 +40,7 @@
import org.hisp.dhis.program.ProgramType;
import org.hisp.dhis.setting.SystemSettingManager;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
+import org.hisp.dhis.user.UserSettingKey;
import org.hisp.dhis.user.UserSettingService;
import com.opensymphony.xwork2.Action;
@@ -153,7 +154,7 @@
flags = systemSettingManager.getFlags();
autoSave = (Boolean) userSettingService.getUserSetting(
- UserSettingService.AUTO_SAVE_TRACKED_ENTITY_REGISTRATION_ENTRY_FORM, false );
+ UserSettingKey.AUTO_SAVE_TRACKED_ENTITY_REGISTRATION_ENTRY_FORM );
return SUCCESS;
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserAction.java 2015-11-23 06:52:49 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserAction.java 2015-12-30 15:44:22 +0000
@@ -50,7 +50,7 @@
import org.hisp.dhis.user.UserGroup;
import org.hisp.dhis.user.UserGroupService;
import org.hisp.dhis.user.UserService;
-import org.hisp.dhis.user.UserSetting;
+import org.hisp.dhis.user.UserSettingKey;
import org.hisp.dhis.user.UserSettingService;
import org.hisp.dhis.webapi.utils.ContextUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -396,9 +396,9 @@
// User settings
// ---------------------------------------------------------------------
- userSettingService.addUserSetting( new UserSetting( user, UserSettingService.KEY_UI_LOCALE, LocaleUtils.getLocale( localeUi ) ) );
- userSettingService.addUserSetting( new UserSetting( user, UserSettingService.KEY_DB_LOCALE, LocaleUtils.getLocale( localeDb ) ) );
-
+ userSettingService.saveUserSetting( UserSettingKey.UI_LOCALE, LocaleUtils.getLocale( localeUi ), user );
+ userSettingService.saveUserSetting( UserSettingKey.DB_LOCALE, LocaleUtils.getLocale( localeDb ), user );
+
if ( ACCOUNT_ACTION_INVITE.equals( accountAction ) )
{
RestoreOptions restoreOptions = inviteUsername == null || inviteUsername.isEmpty() ? RestoreOptions.INVITE_WITH_USERNAME_CHOICE : RestoreOptions.INVITE_WITH_DEFINED_USERNAME;
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/SetupTreeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/SetupTreeAction.java 2015-11-23 09:06:48 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/SetupTreeAction.java 2015-12-30 15:44:22 +0000
@@ -44,6 +44,7 @@
import org.hisp.dhis.user.UserCredentials;
import org.hisp.dhis.user.UserGroup;
import org.hisp.dhis.user.UserService;
+import org.hisp.dhis.user.UserSettingKey;
import org.hisp.dhis.user.UserSettingService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -54,9 +55,6 @@
import java.util.Locale;
import java.util.Map;
-import static org.hisp.dhis.user.UserSettingService.KEY_DB_LOCALE;
-import static org.hisp.dhis.user.UserSettingService.KEY_UI_LOCALE;
-
/**
* @author Nguyen Hong Duc
* @version $Id: SetupTreeAction.java 5556 2008-08-20 11:36:20Z abyot $
@@ -255,9 +253,9 @@
attributeValues = AttributeUtils.getAttributeValueMap( user.getAttributeValues() );
- currentLocale = (Locale) userSettingService.getUserSetting( KEY_UI_LOCALE, LocaleManager.DEFAULT_LOCALE, user );
+ currentLocale = (Locale) userSettingService.getUserSetting( UserSettingKey.UI_LOCALE, user );
- currentLocaleDb = (Locale) userSettingService.getUserSetting( KEY_DB_LOCALE, null, user );
+ currentLocaleDb = (Locale) userSettingService.getUserSetting( UserSettingKey.DB_LOCALE, user );
}
else
{
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java 2015-11-23 06:52:49 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java 2015-12-30 15:44:22 +0000
@@ -47,6 +47,7 @@
import org.hisp.dhis.user.UserGroup;
import org.hisp.dhis.user.UserGroupService;
import org.hisp.dhis.user.UserService;
+import org.hisp.dhis.user.UserSettingKey;
import org.hisp.dhis.user.UserSettingService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -369,8 +370,8 @@
// User settings
// ---------------------------------------------------------------------
- userSettingService.saveUserSetting( UserSettingService.KEY_UI_LOCALE, LocaleUtils.getLocale( localeUi ), user );
- userSettingService.saveUserSetting( UserSettingService.KEY_DB_LOCALE, LocaleUtils.getLocale( localeDb ), user );
+ userSettingService.saveUserSetting( UserSettingKey.UI_LOCALE, LocaleUtils.getLocale( localeUi ), user );
+ userSettingService.saveUserSetting( UserSettingKey.DB_LOCALE, LocaleUtils.getLocale( localeDb ), user );
// ---------------------------------------------------------------------
// User groups