------------------------------------------------------------ revno: 20703 committer: Lars Helge Overland <larshe...@gmail.com> branch nick: dhis2 timestamp: Wed 2015-10-14 19:36:42 +0200 message: User setting manager. Moved database call for getting current user behind cache. modified: 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/user/UserSettingServiceTest.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-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 11:29:47 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java 2015-10-14 17:36:42 +0000 @@ -182,37 +182,35 @@ @Override public Serializable getUserSetting( String name ) { - User user = currentUserService.getCurrentUser(); - - return getUserSetting( name, user ).orElse( null ); + return getUserSetting( name, Optional.empty() ).orElse( null ); } @Override public Serializable getUserSetting( String name, Serializable defaultValue ) { - User user = currentUserService.getCurrentUser(); - - return getUserSetting( name, user ).orElse( defaultValue ); + return getUserSetting( name, Optional.empty() ).orElse( defaultValue ); } @Override public Serializable getUserSetting( String name, Serializable defaultValue, User user ) { - return getUserSetting( name, user ).orElse( defaultValue ); + return getUserSetting( name, Optional.ofNullable( user ) ).orElse( defaultValue ); } - private Optional<Serializable> getUserSetting( String name, User user ) + private Optional<Serializable> getUserSetting( String name, Optional<User> user ) { - if ( name == null || user == null ) + if ( name == null ) { return Optional.empty(); } + String username = user.isPresent() ? user.get().getUsername() : currentUserService.getCurrentUsername(); + try { - String cacheKey = getCacheKey( name, user.getUsername() ); + String cacheKey = getCacheKey( name, username ); - return SETTING_CACHE.get( cacheKey, () -> getUserSettingOptional( user, name ) ); + return SETTING_CACHE.get( cacheKey, () -> getUserSettingOptional( username, name ) ); } catch ( ExecutionException ignored ) { @@ -220,9 +218,16 @@ } } - private Optional<Serializable> getUserSettingOptional( User user, String name ) + private Optional<Serializable> getUserSettingOptional( String username, String settingName ) { - UserSetting setting = userSettingStore.getUserSetting( user, name ); + UserCredentials userCredentials = userService.getUserCredentialsByUsername( username ); + + if ( userCredentials == null ) + { + return Optional.empty(); + } + + UserSetting setting = userSettingStore.getUserSetting( userCredentials.getUserInfo(), settingName ); return setting != null ? Optional.ofNullable( setting.getValue() ) : Optional.empty(); } === 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 09:35:22 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserSettingServiceTest.java 2015-10-14 17:36:42 +0000 @@ -58,10 +58,10 @@ userA = createUser( 'A' ); userService.addUser( userA ); - UserCredentials userCredentials = userA.getUserCredentials(); - userCredentials.setUsername( "usernameA" ); - userCredentials.setUserInfo( userA ); - userService.addUserCredentials( userCredentials ); + UserCredentials userCredentialsA = userA.getUserCredentials(); + userCredentialsA.setUsername( "usernameA" ); + userCredentialsA.setUserInfo( userA ); + userService.addUserCredentials( userCredentialsA ); } @Test
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp