← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20688: User settings, cleanup

 

------------------------------------------------------------
revno: 20688
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-10-14 09:45:12 +0200
message:
  User settings, cleanup
modified:
  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/user/DefaultUserSettingService.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.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/UserSettingService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingService.java	2015-10-14 07:31:34 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingService.java	2015-10-14 07:45:12 +0000
@@ -67,15 +67,7 @@
      * @param userSetting the UserSetting to add.
      */
     void addUserSetting( UserSetting userSetting );
-
-    /**
-     * If a matching UserSetting exists, based on its user and name, it will be
-     * updated, if not, the given UserSetting will be added.
-     *
-     * @param userSetting the UserSetting.
-     */
-    void addOrUpdateUserSetting( UserSetting userSetting );
-
+    
     /**
      * Saves the name/value pair as a user setting connected to the currently
      * logged in user.
@@ -87,7 +79,8 @@
     void saveUserSetting( String name, Serializable value );
 
     /**
-     * Saves the name/value pair as a user setting connected to user identified by username
+     * Saves the name/value pair as a user setting connected to user identified 
+     * by username.
      *
      * @param name the name/handle of the value.
      * @param value the value to store.
@@ -97,6 +90,16 @@
     void saveUserSetting( String name, Serializable value, String username );
 
     /**
+     * Saves the name/value pair as a user setting connected to user.
+     *
+     * @param name the name/handle of the value.
+     * @param value the value to store.
+     * @param username the user.
+     * @throws NoCurrentUserException if there is no user.
+     */
+    void saveUserSetting( String name, Serializable value, User user );
+
+    /**
      * Updates a UserSetting.
      *
      * @param userSetting the UserSetting to update.
@@ -213,5 +216,4 @@
      * @throws NoCurrentUserException if there is no current user.
      */
     List<UserSetting> getAllUserSettings();
-
 }

=== 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:31:34 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java	2015-10-14 07:45:12 +0000
@@ -80,29 +80,13 @@
     }
 
     @Override
-    public void addOrUpdateUserSetting( UserSetting userSetting )
-    {
-        UserSetting setting = getUserSetting( userSetting.getUser(), userSetting.getName() );
-
-        if ( setting != null )
-        {
-            setting.mergeWith( userSetting );
-            updateUserSetting( setting );
-        }
-        else
-        {
-            addUserSetting( userSetting );
-        }
-    }
-
-    @Override
     public void saveUserSetting( String name, Serializable value, String username )
     {
         UserCredentials credentials = userService.getUserCredentialsByUsername( username );
         
         if ( credentials != null )
         {        
-            save( name, value, credentials.getUserInfo() );
+            saveUserSetting( name, value, credentials.getUserInfo() );
         }
     }
 
@@ -111,10 +95,11 @@
     {
         User currentUser = currentUserService.getCurrentUser();
         
-        save( name, value, currentUser );
+        saveUserSetting( name, value, currentUser );
     }
 
-    private void save( String name, Serializable value, User user )
+    @Override
+    public void saveUserSetting( String name, Serializable value, User user )
     {
         if ( user == null )
         {

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java	2015-10-08 13:50:01 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java	2015-10-14 07:45:12 +0000
@@ -51,7 +51,6 @@
 import org.hisp.dhis.user.UserGroup;
 import org.hisp.dhis.user.UserGroupService;
 import org.hisp.dhis.user.UserService;
-import org.hisp.dhis.user.UserSetting;
 import org.hisp.dhis.user.UserSettingService;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -367,8 +366,8 @@
         // User settings
         // ---------------------------------------------------------------------
 
-        userSettingService.addOrUpdateUserSetting( new UserSetting( user, UserSettingService.KEY_UI_LOCALE, LocaleUtils.getLocale( localeUi ) ) );
-        userSettingService.addOrUpdateUserSetting( new UserSetting( user, UserSettingService.KEY_DB_LOCALE, LocaleUtils.getLocale( localeDb ) ) );
+        userSettingService.saveUserSetting( UserSettingService.KEY_UI_LOCALE, LocaleUtils.getLocale( localeUi ), user );
+        userSettingService.saveUserSetting( UserSettingService.KEY_DB_LOCALE, LocaleUtils.getLocale( localeDb ), user );
 
         // ---------------------------------------------------------------------
         // User groups