← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16911: Changed return type on HibernateUserCredentialsStore from User to int

 

------------------------------------------------------------
revno: 16911
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-10-01 15:56:33 +0200
message:
  Changed return type on HibernateUserCredentialsStore from User to int
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentialsStore.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserCredentialsStore.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserStoreTest.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/UserCredentialsStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentialsStore.java	2014-10-01 10:19:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentialsStore.java	2014-10-01 13:56:33 +0000
@@ -50,7 +50,7 @@
      * @param userCredentials the UserCredentials to add.
      * @return the User which the UserCredentials is associated with.
      */
-    User addUserCredentials( UserCredentials userCredentials );
+   int addUserCredentials( UserCredentials userCredentials );
 
     /**
      * Updates a UserCredentials.
@@ -66,6 +66,14 @@
      * @return the UserCredentials.
      */
     UserCredentials getUserCredentials( User user );
+
+    /**
+     * Retrieves the UserCredentials with given identifier.
+     *
+     * @param id the identifier.
+     * @return the UserCredentials.
+     */
+    UserCredentials getUserCredentials( int id );
     
     /**
      * Retrieves the UserCredentials associated with the User with the given

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java	2014-05-28 16:38:44 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java	2014-10-01 13:56:33 +0000
@@ -181,7 +181,7 @@
      * @param userCredentials the UserCredentials to add.
      * @return the User which the UserCredentials is associated with.
      */
-    User addUserCredentials( UserCredentials userCredentials );
+    int addUserCredentials( UserCredentials userCredentials );
 
     /**
      * Updates a UserCredentials.

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java	2014-10-01 10:19:12 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java	2014-10-01 13:56:33 +0000
@@ -468,7 +468,7 @@
     // UserCredentials
     // -------------------------------------------------------------------------
 
-    public User addUserCredentials( UserCredentials userCredentials )
+    public int addUserCredentials( UserCredentials userCredentials )
     {
         return userCredentialsStore.addUserCredentials( userCredentials );
     }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserCredentialsStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserCredentialsStore.java	2014-10-01 10:19:12 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserCredentialsStore.java	2014-10-01 13:56:33 +0000
@@ -77,13 +77,9 @@
     // UserCredentials
     // -------------------------------------------------------------------------
 
-    public User addUserCredentials( UserCredentials userCredentials )
+    public int addUserCredentials( UserCredentials userCredentials )
     {
-        Session session = sessionFactory.getCurrentSession();
-
-        int id = (Integer) session.save( userCredentials );
-
-        return userService.getUser( id );
+        return (Integer) sessionFactory.getCurrentSession().save( userCredentials );
     }
 
     public void updateUserCredentials( UserCredentials userCredentials )
@@ -114,6 +110,11 @@
 
         return (UserCredentials) session.get( UserCredentials.class, user.getId() );
     }
+    
+    public UserCredentials getUserCredentials( int id )
+    {
+        return (UserCredentials) sessionFactory.getCurrentSession().get( UserCredentials.class, id );
+    }
 
     public UserCredentials getUserCredentialsByUsername( String username )
     {

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserStoreTest.java	2014-10-01 09:50:38 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserStoreTest.java	2014-10-01 13:56:33 +0000
@@ -143,10 +143,10 @@
         UserCredentials credentialsA = createUserCredentials( 'A', userA );
         UserCredentials credentialsB = createUserCredentials( 'B', userB );
         
-        User user1 = userCredentialsStore.addUserCredentials( credentialsA );
-        User user2 = userCredentialsStore.addUserCredentials( credentialsB );
+        int idA = userCredentialsStore.addUserCredentials( credentialsA );
+        int idB = userCredentialsStore.addUserCredentials( credentialsB );
         
-        assertEquals( userA, user1 );
-        assertEquals( userB, user2 );
+        assertEquals( credentialsA, userCredentialsStore.getUserCredentials( idA ) );
+        assertEquals( credentialsB, userCredentialsStore.getUserCredentials( idB ) );
     }
 }