← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20695: User settings, null check

 

------------------------------------------------------------
revno: 20695
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-10-14 12:36:42 +0200
message:
  User settings, null check
modified:
  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-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 10:26:36 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java	2015-10-14 10:36:42 +0000
@@ -132,10 +132,7 @@
 
         if ( userSetting == null )
         {
-            userSetting = new UserSetting();
-            userSetting.setUser( user );
-            userSetting.setName( name );
-            userSetting.setValue( value );
+            userSetting = new UserSetting( user, name, value );
 
             addUserSetting( userSetting );
         }
@@ -181,47 +178,36 @@
             deleteUserSetting( setting );
         }
     }
-    
+
+    @Override
+    public Serializable getUserSetting( String name )
+    {
+        User user = currentUserService.getCurrentUser();
+        
+        return getUserSetting( name, user ).orElse( null );
+    }
+
     @Override
     public Serializable getUserSetting( String name, Serializable defaultValue )
     {
         User user = currentUserService.getCurrentUser();
 
-        if ( user == null )
-        {
-            return defaultValue;
-        }
-
-        Optional<Serializable> userSetting = getUserSetting( name, user );
-
-        return userSetting.orElse( defaultValue );
-    }
-
-    @Override
-    public Serializable getUserSetting( String name )
-    {
-        User user = currentUserService.getCurrentUser();
-        
-        if ( user == null )
-        {
-            return null;
-        }
-
-        Optional<Serializable> setting = getUserSetting( name, user );
-        
-        return setting.orElse( null );
+        return getUserSetting( name, user ).orElse( defaultValue );
     }
 
     @Override
     public Serializable getUserSetting( String name, Serializable defaultValue, User user )
     {
-        Optional<Serializable> setting = getUserSetting( name, user );
-
-        return setting.orElse( defaultValue );
+        return getUserSetting( name, user ).orElse( defaultValue );
     }
 
     private Optional<Serializable> getUserSetting( String name, User user )
     {
+        if ( name == null || user == null )
+        {
+            return Optional.empty();
+        }
+        
         try
         {
             String cacheKey = getCacheKey( name, user.getUsername() );
@@ -246,17 +232,17 @@
     {
         User currentUser = currentUserService.getCurrentUser();
 
-        if ( currentUser == null )
-        {
-            return new ArrayList<>();
-        }
-
         return getAllUserSettings( currentUser );
     }
     
     @Override
     public List<UserSetting> getAllUserSettings( User user )
     {
+        if ( user == null )
+        {
+            return new ArrayList<>();
+        }
+
         return userSettingStore.getAllUserSettings( user );
     }