← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4798: Cleaned up a bit in UserStore

 

------------------------------------------------------------
revno: 4798
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-10-03 11:15:35 +0200
message:
  Cleaned up a bit in UserStore
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.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/HibernateUserStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml


--
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/UserStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java	2011-09-09 06:18:32 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java	2011-10-03 09:15:35 +0000
@@ -231,20 +231,6 @@
      */
     Collection<UserAuthorityGroup> getAllUserAuthorityGroups();
 
-    /**
-     * Retrieves all UserAuthorityGroups.
-     * 
-     * @return a Collectio of UserAuthorityGroups.
-     */
-    Collection<UserAuthorityGroup> getUserRolesBetween( int first, int max );
-
-    /**
-     * Retrieves all UserAuthorityGroups.
-     * 
-     * @return a Collectio of UserAuthorityGroups.
-     */
-    Collection<UserAuthorityGroup> getUserRolesBetweenByName( String name, int first, int max );
-
     // -------------------------------------------------------------------------
     // UserSettings
     // -------------------------------------------------------------------------
@@ -287,13 +273,4 @@
      * @param userSetting the UserSetting to delete.
      */
     void deleteUserSetting( UserSetting userSetting );
-
-    // -------------------------------------------------------------------------
-    // UserRole
-    // -------------------------------------------------------------------------
-
-    int getUserRoleCount();
-
-    int getUserRoleCountByName( String name );
-
 }

=== 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	2011-09-09 06:18:32 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java	2011-10-03 09:15:35 +0000
@@ -6,6 +6,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.PeriodType;
@@ -56,6 +57,20 @@
     // Dependencies
     // -------------------------------------------------------------------------
 
+    private UserStore userStore;
+
+    public void setUserStore( UserStore userStore )
+    {
+        this.userStore = userStore;
+    }
+
+    private GenericIdentifiableObjectStore<UserAuthorityGroup> userRoleStore;
+
+    public void setUserRoleStore( GenericIdentifiableObjectStore<UserAuthorityGroup> userRoleStore )
+    {
+        this.userRoleStore = userRoleStore;
+    }
+
     private CurrentUserService currentUserService;
 
     public void setCurrentUserService( CurrentUserService currentUserService )
@@ -63,13 +78,6 @@
         this.currentUserService = currentUserService;
     }
 
-    private UserStore userStore;
-
-    public void setUserStore( UserStore userStore )
-    {
-        this.userStore = userStore;
-    }
-
     // -------------------------------------------------------------------------
     // Implementing methods
     // -------------------------------------------------------------------------
@@ -273,22 +281,22 @@
 
     public Collection<UserAuthorityGroup> getUserRolesBetween( int first, int max )
     {
-        return userStore.getUserRolesBetween( first, max );
+        return userRoleStore.getBetween( first, max );
     }
 
     public Collection<UserAuthorityGroup> getUserRolesBetweenByName( String name, int first, int max )
     {
-        return userStore.getUserRolesBetweenByName( name, first, max );
+        return userRoleStore.getBetweenByName( name, first, max );
     }
 
     public int getUserRoleCount()
     {
-        return userStore.getUserRoleCount();
+        return userRoleStore.getCount();
     }
 
     public int getUserRoleCountByName( String name )
     {
-        return userStore.getUserRoleCountByName( name );
+        return userRoleStore.getCountByName( name );
     }
 
     public void assignDataSetToUserRole( DataSet dataSet )

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java	2011-09-09 06:18:32 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java	2011-10-03 09:15:35 +0000
@@ -40,7 +40,6 @@
 import org.hibernate.criterion.Order;
 import org.hibernate.criterion.Projections;
 import org.hibernate.criterion.Restrictions;
-import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.user.User;
 import org.hisp.dhis.user.UserAuthorityGroup;
@@ -66,13 +65,6 @@
         this.sessionFactory = sessionFactory;
     }
 
-    private GenericIdentifiableObjectStore<UserAuthorityGroup> userRoleStore;
-
-    public void setUserRoleStore( GenericIdentifiableObjectStore<UserAuthorityGroup> userRoleStore )
-    {
-        this.userRoleStore = userRoleStore;
-    }
-
     // -------------------------------------------------------------------------
     // User
     // -------------------------------------------------------------------------
@@ -195,105 +187,15 @@
         session.delete( userCredentials );
     }
 
-    // -------------------------------------------------------------------------
-    // UserAuthorityGroup
-    // -------------------------------------------------------------------------
-
-    public int addUserAuthorityGroup( UserAuthorityGroup userAuthorityGroup )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        return (Integer) session.save( userAuthorityGroup );
-    }
-
-    public void updateUserAuthorityGroup( UserAuthorityGroup userAuthorityGroup )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        session.update( userAuthorityGroup );
-    }
-
-    public UserAuthorityGroup getUserAuthorityGroup( int id )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        return (UserAuthorityGroup) session.get( UserAuthorityGroup.class, id );
-    }
-
-    public UserAuthorityGroup getUserAuthorityGroupByName( String name )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        Criteria criteria = session.createCriteria( UserAuthorityGroup.class );
-
-        criteria.add( Restrictions.eq( "name", name ) );
-
-        return (UserAuthorityGroup) criteria.uniqueResult();
-    }
-
-    @SuppressWarnings( "unchecked" )
-    public Collection<UserAuthorityGroup> getAllUserAuthorityGroups()
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        return session.createQuery( "from UserAuthorityGroup" ).list();
-    }
-
-    public void deleteUserAuthorityGroup( UserAuthorityGroup userAuthorityGroup )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        session.delete( userAuthorityGroup );
-    }
-
-    // -------------------------------------------------------------------------
-    // UserSettings
-    // -------------------------------------------------------------------------
-
-    public void addUserSetting( UserSetting userSetting )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        session.save( userSetting );
-    }
-
-    public void updateUserSetting( UserSetting userSetting )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        session.update( userSetting );
-    }
-
-    public UserSetting getUserSetting( User user, String name )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        Query query = session.createQuery( "from UserSetting us where us.user = :user and us.name = :name" );
-
-        query.setEntity( "user", user );
-        query.setString( "name", name );
-        query.setCacheable( true );
-
-        return (UserSetting) query.uniqueResult();
-    }
-
-    @SuppressWarnings( "unchecked" )
-    public Collection<UserSetting> getAllUserSettings( User user )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        Query query = session.createQuery( "from UserSetting us where us.user = :user" );
-
-        query.setEntity( "user", user );
-
-        return query.list();
-    }
-
-    public void deleteUserSetting( UserSetting userSetting )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        session.delete( userSetting );
+    public int getUserCount()
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Query query = session.createQuery( "select count(*) from UserCredentials" );
+
+        Number rs = (Number) query.uniqueResult();
+
+        return rs != null ? rs.intValue() : 0;
     }
 
     @SuppressWarnings( "unchecked" )
@@ -309,17 +211,6 @@
         return criteria.list();
     }
 
-    public int getUserCount()
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        Query query = session.createQuery( "select count(*) from User" );
-
-        Number rs = (Number) query.uniqueResult();
-
-        return rs != null ? rs.intValue() : 0;
-    }
-
     public int getUserCountByName( String name )
     {
         Session session = sessionFactory.getCurrentSession();
@@ -359,26 +250,6 @@
         return criteria.list();
     }
 
-    public int getUserRoleCount()
-    {
-        return userRoleStore.getCount();
-    }
-
-    public int getUserRoleCountByName( String name )
-    {
-        return userRoleStore.getCountByName( name );
-    }
-
-    public Collection<UserAuthorityGroup> getUserRolesBetween( int first, int max )
-    {
-        return userRoleStore.getBetween( first, max );
-    }
-
-    public Collection<UserAuthorityGroup> getUserRolesBetweenByName( String name, int first, int max )
-    {
-        return userRoleStore.getBetweenByName( name, first, max );
-    }
-
     public Collection<UserCredentials> getUsersByOrganisationUnitBetween( OrganisationUnit orgUnit, int first, int max )
     {
         return getBlockUser( toUserCredentials( orgUnit.getUsers() ), first, max );
@@ -461,14 +332,112 @@
 
         return rs != null ? rs.intValue() : 0;
     }
+    
+    // -------------------------------------------------------------------------
+    // UserAuthorityGroup
+    // -------------------------------------------------------------------------
+
+    public int addUserAuthorityGroup( UserAuthorityGroup userAuthorityGroup )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        return (Integer) session.save( userAuthorityGroup );
+    }
+
+    public void updateUserAuthorityGroup( UserAuthorityGroup userAuthorityGroup )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        session.update( userAuthorityGroup );
+    }
+
+    public UserAuthorityGroup getUserAuthorityGroup( int id )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        return (UserAuthorityGroup) session.get( UserAuthorityGroup.class, id );
+    }
+
+    public UserAuthorityGroup getUserAuthorityGroupByName( String name )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Criteria criteria = session.createCriteria( UserAuthorityGroup.class );
+
+        criteria.add( Restrictions.eq( "name", name ) );
+
+        return (UserAuthorityGroup) criteria.uniqueResult();
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public Collection<UserAuthorityGroup> getAllUserAuthorityGroups()
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        return session.createQuery( "from UserAuthorityGroup" ).list();
+    }
+
+    public void deleteUserAuthorityGroup( UserAuthorityGroup userAuthorityGroup )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        session.delete( userAuthorityGroup );
+    }
+
+    // -------------------------------------------------------------------------
+    // UserSettings
+    // -------------------------------------------------------------------------
+
+    public void addUserSetting( UserSetting userSetting )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        session.save( userSetting );
+    }
+
+    public void updateUserSetting( UserSetting userSetting )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        session.update( userSetting );
+    }
+
+    public UserSetting getUserSetting( User user, String name )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Query query = session.createQuery( "from UserSetting us where us.user = :user and us.name = :name" );
+
+        query.setEntity( "user", user );
+        query.setString( "name", name );
+        query.setCacheable( true );
+
+        return (UserSetting) query.uniqueResult();
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public Collection<UserSetting> getAllUserSettings( User user )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Query query = session.createQuery( "from UserSetting us where us.user = :user" );
+
+        query.setEntity( "user", user );
+
+        return query.list();
+    }
+
+    public void deleteUserSetting( UserSetting userSetting )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        session.delete( userSetting );
+    }
 
     // -------------------------------------------------------------------------
     // Supportive methods
     // -------------------------------------------------------------------------
 
-    // TODO All this user / credentials search stuff is horrible and must be
-    // improved
-
     private Collection<UserCredentials> findByName( Collection<UserCredentials> users, String key )
     {
         List<UserCredentials> returnList = new ArrayList<UserCredentials>();

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2011-09-30 17:01:57 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2011-10-03 09:15:35 +0000
@@ -174,7 +174,6 @@
 
   <bean id="org.hisp.dhis.user.UserStore" class="org.hisp.dhis.user.hibernate.HibernateUserStore">
     <property name="sessionFactory" ref="sessionFactory" />
-    <property name="userRoleStore" ref="org.hisp.dhis.user.UserAuthorityGroupStore" />
   </bean>
 
   <bean id="org.hisp.dhis.user.UserGroupStore" class="org.hisp.dhis.hibernate.HibernateGenericStore">
@@ -417,6 +416,7 @@
 
   <bean id="org.hisp.dhis.user.UserService" class="org.hisp.dhis.user.DefaultUserService">
     <property name="userStore" ref="org.hisp.dhis.user.UserStore" />
+    <property name="userRoleStore" ref="org.hisp.dhis.user.UserAuthorityGroupStore" />
     <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
   </bean>