dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #43914
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22277: User setting, tostring. Code style.
------------------------------------------------------------
revno: 22277
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2016-03-13 15:11:35 +0100
message:
User setting, tostring. Code style.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSetting.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.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/user/UserSetting.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSetting.java 2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSetting.java 2016-03-13 14:11:35 +0000
@@ -104,6 +104,16 @@
return result;
}
+
+ @Override
+ public String toString()
+ {
+ return "{" +
+ "\"user\":\"" + user.getUsername() + "\", " +
+ "\"name:\":\"" + name + "\", " +
+ "\"value\":\"" + value + "\" " +
+ "}";
+ }
public void mergeWith( UserSetting other )
{
=== 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 2016-03-07 15:28:25 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java 2016-03-13 14:11:35 +0000
@@ -200,6 +200,47 @@
return getUserSetting( key, Optional.ofNullable( user ) ).orElse( null );
}
+ @Override
+ public List<UserSetting> getAllUserSettings()
+ {
+ User currentUser = currentUserService.getCurrentUser();
+
+ return getUserSettings( currentUser );
+ }
+
+ @Override
+ public List<UserSetting> getUserSettings( User user )
+ {
+ if ( user == null )
+ {
+ return new ArrayList<>();
+ }
+
+ List<UserSetting> list = userSettingStore.getAllUserSettings( user );
+
+ return list.stream().map( userSetting -> {
+ if ( userSetting.getValue() == null )
+ {
+ return new UserSetting( userSetting.getUser(), userSetting.getName(),
+ systemSettingManager.getSystemSetting( NAME_SETTING_KEY_MAP.get( userSetting.getName() ) ) );
+ }
+ else
+ {
+ return userSetting;
+ }
+ } ).collect( Collectors.toList() );
+ }
+
+ @Override
+ public void invalidateCache()
+ {
+ SETTING_CACHE.invalidateAll();
+ }
+
+ // -------------------------------------------------------------------------
+ // Private methods
+ // -------------------------------------------------------------------------
+
private Optional<Serializable> getUserSetting( UserSettingKey key, Optional<User> user )
{
if ( key == null )
@@ -210,14 +251,16 @@
try
{
String username = user.isPresent() ? user.get().getUsername() : currentUserService.getCurrentUsername();
+
String cacheKey = getCacheKey( key.getName(), username );
- Optional<Serializable> result = SETTING_CACHE
- .get( cacheKey, () -> getUserSettingOptional( key, username ) );
+
+ Optional<Serializable> result = SETTING_CACHE.
+ get( cacheKey, () -> getUserSettingOptional( key, username ) );
if ( !result.isPresent() && NAME_SETTING_KEY_MAP.containsKey( key.getName() ) )
{
- return Optional
- .ofNullable( systemSettingManager.getSystemSetting( NAME_SETTING_KEY_MAP.get( key.getName() ) ) );
+ return Optional.ofNullable(
+ systemSettingManager.getSystemSetting( NAME_SETTING_KEY_MAP.get( key.getName() ) ) );
}
else
{
@@ -243,40 +286,6 @@
UserSetting setting = userSettingStore.getUserSetting( userCredentials.getUserInfo(), key.getName() );
return setting != null && setting.hasValue() ?
- Optional.of( setting.getValue() ) :
- Optional.empty();
- }
-
- @Override
- public List<UserSetting> getAllUserSettings()
- {
- User currentUser = currentUserService.getCurrentUser();
-
- return getUserSettings( currentUser );
- }
-
- @Override
- public List<UserSetting> getUserSettings( User user )
- {
- if ( user == null )
- {
- return new ArrayList<>();
- }
-
- List<UserSetting> list = userSettingStore.getAllUserSettings( user );
-
- return list.stream().map( userSetting -> {
- if ( userSetting.getValue() == null )
- return new UserSetting( userSetting.getUser(), userSetting.getName(),
- systemSettingManager.getSystemSetting( NAME_SETTING_KEY_MAP.get( userSetting.getName() ) ) );
- else
- return userSetting;
- } ).collect( Collectors.toList() );
- }
-
- @Override
- public void invalidateCache()
- {
- SETTING_CACHE.invalidateAll();
+ Optional.of( setting.getValue() ) : Optional.empty();
}
}