dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #40708
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20693: User settings. Included a cache for getting settings. Improves performance as this is called very...
------------------------------------------------------------
revno: 20693
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-10-14 11:35:22 +0200
message:
User settings. Included a cache for getting settings. Improves performance as this is called very frequently. Using Optional.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.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/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/DefaultSystemSettingManager.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/test/java/org/hisp/dhis/setting/SystemSettingManagerTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserSettingServiceTest.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/SetupTreeAction.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/SystemSettingManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java 2015-10-13 09:22:30 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java 2015-10-14 09:35:22 +0000
@@ -142,6 +142,8 @@
Map<String, Serializable> getSystemSettingsAsMap( Set<String> names );
+ void invalidateCache();
+
// -------------------------------------------------------------------------
// Specific methods
// -------------------------------------------------------------------------
=== 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-10-14 07:50:20 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingService.java 2015-10-14 09:35:22 +0000
@@ -36,7 +36,6 @@
* the current user from {@link CurrentUserService}.
*
* @author Torgeir Lorange Ostby
- * @version $Id: UserSettingService.java 2869 2007-02-20 14:26:09Z andegje $
*/
public interface UserSettingService
{
@@ -50,12 +49,14 @@
String KEY_MESSAGE_SMS_NOTIFICATION = "keyMessageSmsNotification";
String KEY_UI_LOCALE = "keyUiLocale";
String KEY_DB_LOCALE = "keyDbLocale";
- String KEY_GENERATE_REPORT_INTERFACE = "keyGenerateReportInterface";
String KEY_ANALYSIS_DISPLAY_PROPERTY = "keyAnalysisDisplayProperty";
String AUTO_SAVE_CASE_ENTRY_FORM = "autoSaveCaseEntryForm";
String AUTO_SAVE_TRACKED_ENTITY_REGISTRATION_ENTRY_FORM = "autoSavetTrackedEntityForm";
+
String DEFAULT_ANALYSIS_DISPLAY_PROPERTY = "name";
+ //TODO use enum for names
+
// -------------------------------------------------------------------------
// UserSettings
// -------------------------------------------------------------------------
@@ -99,13 +100,6 @@
void saveUserSetting( String name, Serializable value, User user );
/**
- * Updates a UserSetting.
- *
- * @param userSetting the UserSetting to update.
- */
- void updateUserSetting( UserSetting userSetting );
-
- /**
* Deletes a UserSetting.
*
* @param userSetting the UserSetting to delete.
@@ -119,38 +113,16 @@
* @throws NoCurrentUserException if there is no current user.
*/
void deleteUserSetting( String name );
+
+ /**
+ * Deletes the user setting with the given name for the given user.
+ *
+ * @param name the name of the user setting to delete.
+ * @user the user.
+ */
+ void deleteUserSetting( String name, User user );
/**
- * Retrieves the UserSetting associated with the given User for the given
- * UserSetting name.
- *
- * @param user the User.
- * @param name the name of the UserSetting.
- * @return the UserSetting.
- */
- UserSetting getUserSetting( User user, String name );
-
- /**
- * 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 user the user.
- * @param name the setting name.
- * @param defaultValue the default value.
- * @return a setting value.
- */
- Serializable getUserSettingValue( User user, String name, Serializable defaultValue );
-
- /**
- * Retrieves all UserSettings for the given User.
- *
- * @param user the User.
- * @return a List of UserSettings.
- */
- List<UserSetting> getAllUserSettings( User user );
-
- /**
* Returns the value of the user setting specified by the given name.
*
* @param name the name of the user setting.
@@ -174,10 +146,35 @@
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 user the User.
+ * @return a List of UserSettings.
+ */
+ List<UserSetting> getAllUserSettings( 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();
+
+ /**
+ * Invalidates in-memory caches.
+ */
+ void invalidateCache();
}
=== 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-06-16 05:11:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java 2015-10-14 09:35:22 +0000
@@ -419,7 +419,7 @@
values.put( "responseUrl", baseUrl + "/dhis-web-dashboard-integration/readMessage.action?id=" + conversation.getUid() );
- Locale locale = (Locale) userSettingService.getUserSettingValue( conversation.getUser(), UserSettingService.KEY_UI_LOCALE, LocaleManager.DHIS_STANDARD_LOCALE );
+ Locale locale = (Locale) userSettingService.getUserSetting( UserSettingService.KEY_UI_LOCALE, LocaleManager.DHIS_STANDARD_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-10-06 18:24:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/EmailMessageSender.java 2015-10-14 09:35:22 +0000
@@ -133,7 +133,7 @@
for ( User user : users )
{
- boolean doSend = forceSend || (Boolean) userSettingService.getUserSettingValue( user, KEY_MESSAGE_EMAIL_NOTIFICATION, false );
+ boolean doSend = forceSend || (Boolean) userSettingService.getUserSetting( KEY_MESSAGE_EMAIL_NOTIFICATION, false, 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-10-06 18:24:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultSecurityService.java 2015-10-14 09:35:22 +0000
@@ -238,7 +238,7 @@
vars.put( "username", credentials.getUsername() );
User user = credentials.getUserInfo();
- Locale locale = (Locale) userSettingService.getUserSettingValue( user, UserSettingService.KEY_UI_LOCALE, LocaleManager.DHIS_STANDARD_LOCALE );
+ Locale locale = (Locale) userSettingService.getUserSetting( UserSettingService.KEY_UI_LOCALE, LocaleManager.DHIS_STANDARD_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/DefaultSystemSettingManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java 2015-10-13 09:22:30 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java 2015-10-14 09:35:22 +0000
@@ -58,7 +58,7 @@
* Cache for system settings. Does not accept nulls.
*/
private static Cache<String, Serializable> SETTING_CACHE = CacheBuilder.newBuilder()
- .expireAfterAccess( 5, TimeUnit.MINUTES )
+ .expireAfterAccess( 15, TimeUnit.MINUTES )
.initialCapacity( 200 )
.maximumSize( 400 )
.build();
@@ -111,9 +111,7 @@
@Override
public void saveSystemSetting( Setting setting, Serializable value )
- {
- SETTING_CACHE.invalidate( setting.getName() );
-
+ {
saveSystemSetting( setting.getName(), value );
}
@@ -238,6 +236,12 @@
return map;
}
+ @Override
+ public void invalidateCache()
+ {
+ SETTING_CACHE.invalidateAll();
+ }
+
// -------------------------------------------------------------------------
// Specific methods
// -------------------------------------------------------------------------
=== 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-09-13 17:45:53 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsMessageSender.java 2015-10-14 09:35:22 +0000
@@ -43,10 +43,11 @@
import org.hisp.dhis.sms.outbound.OutboundSmsTransportService;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
-import org.hisp.dhis.user.UserSetting;
import org.hisp.dhis.user.UserSettingService;
import org.springframework.beans.factory.annotation.Autowired;
+import java.io.Serializable;
+
/**
* @author Nguyen Kim Lai
*/
@@ -181,9 +182,9 @@
else
// Receiver is user
{
- UserSetting userSetting = userSettingService.getUserSetting( user, UserSettingService.KEY_MESSAGE_SMS_NOTIFICATION );
+ Serializable userSetting = userSettingService.getUserSetting( UserSettingService.KEY_MESSAGE_SMS_NOTIFICATION, null, user );
- return (userSetting != null && userSetting.getValue() != null) ? (Boolean) userSetting.getValue() : false;
+ 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-10-14 07:50:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java 2015-10-14 09:35:22 +0000
@@ -31,9 +31,16 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import org.hisp.dhis.common.DimensionalObject;
import org.springframework.transaction.annotation.Transactional;
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+
/**
* @author Torgeir Lorange Ostby
*/
@@ -41,6 +48,20 @@
public class DefaultUserSettingService
implements UserSettingService
{
+ /**
+ * Cache for user settings. Does not accept nulls. Key is name + username.
+ */
+ private static Cache<String, Optional<Serializable>> SETTING_CACHE = CacheBuilder.newBuilder()
+ .expireAfterAccess( 15, TimeUnit.MINUTES )
+ .initialCapacity( 200 )
+ .maximumSize( 10000 )
+ .build();
+
+ private String getCacheKey( String settingName, String username )
+ {
+ return settingName + DimensionalObject.ITEM_SEP + username;
+ }
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -73,6 +94,8 @@
@Override
public void addUserSetting( UserSetting userSetting )
{
+ SETTING_CACHE.invalidate( getCacheKey( userSetting.getName(), userSetting.getUser().getUsername() ) );
+
userSettingStore.addUserSetting( userSetting );
}
@@ -103,7 +126,9 @@
return;
}
- UserSetting userSetting = getUserSetting( user, name );
+ SETTING_CACHE.invalidate( getCacheKey( name, user.getUsername() ) );
+
+ UserSetting userSetting = userSettingStore.getUserSetting( user, name );
if ( userSetting == null )
{
@@ -118,22 +143,18 @@
{
userSetting.setValue( value );
- updateUserSetting( userSetting );
+ userSettingStore.updateUserSetting( userSetting );
}
}
@Override
- public void updateUserSetting( UserSetting userSetting )
- {
- userSettingStore.updateUserSetting( userSetting );
- }
-
- @Override
public void deleteUserSetting( UserSetting userSetting )
{
+ SETTING_CACHE.invalidate( getCacheKey( userSetting.getName(), userSetting.getUser().getUsername() ) );
+
userSettingStore.deleteUserSetting( userSetting );
}
-
+
@Override
public void deleteUserSetting( String name )
{
@@ -141,69 +162,87 @@
if ( currentUser != null )
{
- deleteUserSetting( getUserSetting( currentUser, name ) );
+ UserSetting setting = userSettingStore.getUserSetting( currentUser, name );
+
+ if ( setting != null )
+ {
+ deleteUserSetting( setting );
+ }
}
}
@Override
- public UserSetting getUserSetting( User user, String name )
+ public void deleteUserSetting( String name, User user )
{
- return userSettingStore.getUserSetting( user, name );
+ UserSetting setting = userSettingStore.getUserSetting( user, name );
+
+ if ( setting != null )
+ {
+ deleteUserSetting( setting );
+ }
}
-
+
@Override
public Serializable getUserSetting( String name, Serializable defaultValue )
{
- User currentUser = currentUserService.getCurrentUser();
+ User user = currentUserService.getCurrentUser();
- if ( currentUser == null )
+ if ( user == null )
{
return defaultValue;
}
- UserSetting userSetting = getUserSetting( currentUser, name );
-
- if ( userSetting != null )
- {
- return userSetting.getValue();
- }
-
- return defaultValue;
+ Optional<Serializable> userSetting = getUserSetting( name, user );
+
+ return userSetting.orElse( defaultValue );
}
@Override
public Serializable getUserSetting( String name )
{
- User currentUser = currentUserService.getCurrentUser();
+ User user = currentUserService.getCurrentUser();
- return getUserSetting( name, currentUser );
- }
-
- private Serializable getUserSetting( String name, User currentUser )
- {
- if ( currentUser == null )
+ if ( user == null )
{
return null;
}
- UserSetting userSetting = getUserSetting( currentUser, name );
-
- if ( userSetting != null )
- {
- return userSetting.getValue();
- }
-
- return null;
+ Optional<Serializable> setting = getUserSetting( name, user );
+
+ return setting.orElse( null );
}
@Override
- public Serializable getUserSettingValue( User user, String name, Serializable defaultValue )
- {
- UserSetting setting = getUserSetting( user, name );
-
- return setting != null && setting.getValue() != null ? setting.getValue() : defaultValue;
- }
-
+ public Serializable getUserSetting( String name, Serializable defaultValue, User user )
+ {
+ Optional<Serializable> setting = getUserSetting( name, user );
+
+ return setting.orElse( defaultValue );
+ }
+
+ private Optional<Serializable> getUserSetting( String name, User user )
+ {
+ try
+ {
+ String cacheKey = getCacheKey( name, user.getUsername() );
+
+ Optional<Serializable> setting = SETTING_CACHE.get( cacheKey, () -> getUserSettingOptional( user, name ) );
+
+ return setting;
+ }
+ catch ( ExecutionException ignored )
+ {
+ return Optional.empty();
+ }
+ }
+
+ private Optional<Serializable> getUserSettingOptional( User user, String name )
+ {
+ UserSetting setting = userSettingStore.getUserSetting( user, name );
+
+ return setting != null && setting.getValue() != null ? Optional.of( setting.getValue() ) : Optional.empty();
+ }
+
@Override
public List<UserSetting> getAllUserSettings()
{
@@ -222,4 +261,10 @@
{
return userSettingStore.getAllUserSettings( user );
}
+
+ @Override
+ public void invalidateCache()
+ {
+ SETTING_CACHE.invalidateAll();
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/setting/SystemSettingManagerTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/setting/SystemSettingManagerTest.java 2015-10-13 09:22:30 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/setting/SystemSettingManagerTest.java 2015-10-14 09:35:22 +0000
@@ -51,6 +51,12 @@
@Autowired
private SystemSettingManager systemSettingManager;
+ @Override
+ public void setUpTest()
+ {
+ systemSettingManager.invalidateCache();
+ }
+
@Test
public void testSaveGetSystemSetting()
{
=== 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-05 07:55:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserSettingServiceTest.java 2015-10-14 09:35:22 +0000
@@ -29,18 +29,17 @@
*/
import org.hisp.dhis.DhisSpringTest;
-import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
-import java.io.Serializable;
-
+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
*/
-@Ignore
public class UserSettingServiceTest
extends DhisSpringTest
{
@@ -50,27 +49,82 @@
@Autowired
private UserService userService;
- private User testUser;
+ private User userA;
@Override
protected void setUpTest()
- throws Exception
- {
- testUser = createUser( 'D' );
- userService.addUser( testUser );
- UserCredentials userCredentials = testUser.getUserCredentials();
- userCredentials.setUserInfo( testUser );
- userService.addUserCredentials( userCredentials );
- }
-
- @Test
- public void testShouldGetUserSettings()
- {
- UserCredentials userCredentials = testUser.getUserCredentials();
- userCredentials.setUserInfo( testUser );
- userService.addUserCredentials( userCredentials );
- userSettingService.saveUserSetting( "mykey", "value", "username" );
- Serializable preference = userSettingService.getUserSetting( "mykey", "username" );
- assertEquals( preference, "value" );
+ {
+ userSettingService.invalidateCache();
+
+ userA = createUser( 'A' );
+ userService.addUser( userA );
+ UserCredentials userCredentials = userA.getUserCredentials();
+ userCredentials.setUsername( "usernameA" );
+ userCredentials.setUserInfo( userA );
+ userService.addUserCredentials( userCredentials );
+ }
+
+ @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 ) );
+ }
+
+ @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 ) );
+ }
+
+ @Test
+ public void testGetUserSettingsByUser()
+ {
+ userSettingService.saveUserSetting( KEY_ANALYSIS_DISPLAY_PROPERTY, "name", "usernameA" );
+ userSettingService.saveUserSetting( KEY_STYLE, "blue", "usernameA" );
+
+ assertEquals( 2, userSettingService.getAllUserSettings( userA ).size() );
}
}
=== 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-06-17 13:37:50 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/SetupTreeAction.java 2015-10-14 09:35:22 +0000
@@ -256,9 +256,9 @@
attributeValues = AttributeUtils.getAttributeValueMap( user.getAttributeValues() );
- currentLocale = (Locale) userSettingService.getUserSettingValue( user, KEY_UI_LOCALE, LocaleManager.DHIS_STANDARD_LOCALE );
+ currentLocale = (Locale) userSettingService.getUserSetting( KEY_UI_LOCALE, LocaleManager.DHIS_STANDARD_LOCALE, user );
- currentLocaleDb = (Locale) userSettingService.getUserSettingValue( user, KEY_DB_LOCALE, null );
+ currentLocaleDb = (Locale) userSettingService.getUserSetting( KEY_DB_LOCALE, null, user );
}
else
{