← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21561: User setting controller, user fix

 

------------------------------------------------------------
revno: 21561
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2016-01-03 23:51:40 +0100
message:
  User setting controller, user fix
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/UserSettingController.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-12-30 17:05:16 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java	2016-01-03 22:51:40 +0000
@@ -180,7 +180,7 @@
     @Override
     public Serializable getUserSetting( UserSettingKey key, User user )
     {
-        return getUserSetting( key, Optional.of( user ) ).orElse( null );
+        return getUserSetting( key, Optional.ofNullable( user ) ).orElse( null );
     }
 
     private Optional<Serializable> getUserSetting( UserSettingKey key, Optional<User> user )

=== 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-12-30 17:05:16 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/UserSettingController.java	2016-01-03 22:51:40 +0000
@@ -141,23 +141,23 @@
             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( keyEnum.get() );
-        }
-        else
-        {
-            value = userSettingService.getUserSetting( keyEnum.get(), credentials.getUser() );
-        }
+        User user = null;
+        
+        if ( username != null )
+        {
+            UserCredentials credentials = userService.getUserCredentialsByUsername( username );
+            
+            if ( credentials != null )
+            {
+                user = credentials.getUser();
+            }
+            else
+            {
+                throw new WebMessageException( WebMessageUtils.conflict( "User does not exist: " + username ) );
+            }
+        }
+        
+        Serializable value = userSettingService.getUserSetting( keyEnum.get(), user );
 
         if ( value == null )
         {