← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17782: Cleanup

 

------------------------------------------------------------
revno: 17782
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-12-23 10:38:34 +0100
message:
  Cleanup
modified:
  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


--
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/UserService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java	2014-12-22 11:16:13 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java	2014-12-23 09:38:34 +0000
@@ -40,20 +40,11 @@
 
 /**
  * @author Chau Thu Tran
- * @version $Id$
  */
 public interface UserService
 {
     String ID = UserService.class.getName();
 
-    boolean isSuperUser( UserCredentials userCredentials );
-
-    boolean isLastSuperUser( UserCredentials userCredentials );
-
-    boolean isSuperRole( UserAuthorityGroup userAuthorityGroup );
-
-    boolean isLastSuperRole( UserAuthorityGroup userAuthorityGroup );
-
     // -------------------------------------------------------------------------
     // User
     // -------------------------------------------------------------------------
@@ -169,6 +160,20 @@
      */
     public Set<DataElementCategoryOption> getCoDimensionConstraints( UserCredentials userCredentials );
 
+    boolean isSuperUser( UserCredentials userCredentials );
+
+    boolean isLastSuperUser( UserCredentials userCredentials );
+
+    boolean isSuperRole( UserAuthorityGroup userAuthorityGroup );
+
+    boolean isLastSuperRole( UserAuthorityGroup userAuthorityGroup );
+
+    Collection<User> getUsersByName( String name );
+
+    Collection<String> getUsernames( String query, Integer max );
+
+    int countDataSetUserAuthorityGroups( DataSet dataSet );
+
     // -------------------------------------------------------------------------
     // UserCredentials
     // -------------------------------------------------------------------------
@@ -308,7 +313,9 @@
      * @return true if current user can update this user, else false.
      */
     boolean canUpdate( UserCredentials userCredentials );
-
+    
+    boolean credentialsNonExpired( UserCredentials credentials );
+    
     // -------------------------------------------------------------------------
     // UserAuthorityGroup
     // -------------------------------------------------------------------------
@@ -401,12 +408,4 @@
      * @param userRoles the collection of user roles.
      */
     void canIssueFilter( Collection<UserAuthorityGroup> userRoles );
-    
-    Collection<User> getUsersByName( String name );
-
-    Collection<String> getUsernames( String query, Integer max );
-
-    int countDataSetUserAuthorityGroups( DataSet dataSet );
-
-    boolean credentialsNonExpired( UserCredentials credentials );
 }

=== 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-12-22 11:16:13 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java	2014-12-23 09:38:34 +0000
@@ -121,75 +121,8 @@
     }
 
     // -------------------------------------------------------------------------
-    // Implementing methods
+    // UserService implementation
     // -------------------------------------------------------------------------
-
-    @Override
-    public boolean isSuperUser( UserCredentials userCredentials )
-    {
-        if ( userCredentials == null )
-        {
-            return false;
-        }
-
-        for ( UserAuthorityGroup group : userCredentials.getUserAuthorityGroups() )
-        {
-            if ( group.getAuthorities().contains( "ALL" ) )
-            {
-                return true;
-            }
-        }
-
-        return false;
-    }
-
-    @Override
-    public boolean isLastSuperUser( UserCredentials userCredentials )
-    {
-        if ( !isSuperUser( userCredentials ) )
-        {
-            return false; // Cannot be last if not super user
-        }
-
-        Collection<UserCredentials> users = userCredentialsStore.getAllUserCredentials();
-
-        for ( UserCredentials user : users )
-        {
-            if ( isSuperUser( user ) && !user.equals( userCredentials ) )
-            {
-                return false;
-            }
-        }
-
-        return true;
-    }
-
-    @Override
-    public boolean isSuperRole( UserAuthorityGroup userAuthorityGroup )
-    {
-        if ( userAuthorityGroup == null )
-        {
-            return false;
-        }
-
-        return ( userAuthorityGroup.getAuthorities().contains( "ALL" ) );
-    }
-
-    @Override
-    public boolean isLastSuperRole( UserAuthorityGroup userAuthorityGroup )
-    {
-        Collection<UserAuthorityGroup> groups = userAuthorityGroupStore.getAll();
-
-        for ( UserAuthorityGroup group : groups )
-        {
-            if ( isSuperRole( group ) && group.getId() != userAuthorityGroup.getId() )
-            {
-                return false;
-            }
-        }
-
-        return true;
-    }
 
     // -------------------------------------------------------------------------
     // User
@@ -389,6 +322,91 @@
         return options;
     }
 
+    @Override
+    public Collection<User> getUsersByOrganisationUnits( Collection<OrganisationUnit> units )
+    {
+        return userStore.getUsersByOrganisationUnits( units );
+    }
+
+    @Override
+    public Collection<String> getUsernames( String query, Integer max )
+    {
+        return userCredentialsStore.getUsernames( query, max );
+    }
+
+    @Override
+    public int countDataSetUserAuthorityGroups( DataSet dataSet )
+    {
+        return userAuthorityGroupStore.countDataSetUserAuthorityGroups( dataSet );
+    }
+
+    @Override
+    public boolean isSuperUser( UserCredentials userCredentials )
+    {
+        if ( userCredentials == null )
+        {
+            return false;
+        }
+
+        for ( UserAuthorityGroup group : userCredentials.getUserAuthorityGroups() )
+        {
+            if ( group.getAuthorities().contains( "ALL" ) )
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    @Override
+    public boolean isLastSuperUser( UserCredentials userCredentials )
+    {
+        if ( !isSuperUser( userCredentials ) )
+        {
+            return false; // Cannot be last if not super user
+        }
+
+        Collection<UserCredentials> users = userCredentialsStore.getAllUserCredentials();
+
+        for ( UserCredentials user : users )
+        {
+            if ( isSuperUser( user ) && !user.equals( userCredentials ) )
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    @Override
+    public boolean isSuperRole( UserAuthorityGroup userAuthorityGroup )
+    {
+        if ( userAuthorityGroup == null )
+        {
+            return false;
+        }
+
+        return ( userAuthorityGroup.getAuthorities().contains( "ALL" ) );
+    }
+
+    @Override
+    public boolean isLastSuperRole( UserAuthorityGroup userAuthorityGroup )
+    {
+        Collection<UserAuthorityGroup> groups = userAuthorityGroupStore.getAll();
+
+        for ( UserAuthorityGroup group : groups )
+        {
+            if ( isSuperRole( group ) && group.getId() != userAuthorityGroup.getId() )
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
     // -------------------------------------------------------------------------
     // UserAuthorityGroup
     // -------------------------------------------------------------------------
@@ -699,28 +717,6 @@
         return hasAuthorityToUpdateUser( userCredentials );
     }
 
-    // -------------------------------------------------------------------------
-    // UserSettings
-    // -------------------------------------------------------------------------
-
-    @Override
-    public Collection<User> getUsersByOrganisationUnits( Collection<OrganisationUnit> units )
-    {
-        return userStore.getUsersByOrganisationUnits( units );
-    }
-
-    @Override
-    public Collection<String> getUsernames( String query, Integer max )
-    {
-        return userCredentialsStore.getUsernames( query, max );
-    }
-
-    @Override
-    public int countDataSetUserAuthorityGroups( DataSet dataSet )
-    {
-        return userAuthorityGroupStore.countDataSetUserAuthorityGroups( dataSet );
-    }
-
     @Override
     public boolean credentialsNonExpired( UserCredentials credentials )
     {