← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18251: Program, moved code from store to service layer

 

------------------------------------------------------------
revno: 18251
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-02-13 09:50:17 +0100
message:
  Program, moved code from store to service layer
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStore.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageDataElementStore.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStore.java
  dhis-2/dhis-services/dhis-service-tracker/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/program/ProgramService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramService.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramService.java	2015-02-13 08:50:17 +0000
@@ -200,4 +200,21 @@
      * there are no Program.
      */
     Collection<Program> getProgramsBetween( int min, int max );
+
+    /**
+     * Get {@link Program} by the current user.
+     *
+     * @return The program list the current user
+     */
+    Collection<Program> getByCurrentUser();
+
+    /**
+     * Get {@link Program} by the current user and a certain type
+     *
+     * @param type The type of program. There are three types, include Multi
+     *             events with registration, Single event with registration and
+     *             Single event without registration.
+     * @return Program list by a type specified
+     */
+    Collection<Program> getByCurrentUser( int type );
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStore.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStore.java	2015-02-13 08:50:17 +0000
@@ -73,23 +73,6 @@
     Collection<Program> get( int type, OrganisationUnit orgunit );
 
     /**
-     * Get {@link Program} by the current user.
-     *
-     * @return The program list the current user
-     */
-    Collection<Program> getByCurrentUser();
-
-    /**
-     * Get {@link Program} by the current user and a certain type
-     *
-     * @param type The type of program. There are three types, include Multi
-     *             events with registration, Single event with registration and
-     *             Single event without registration.
-     * @return Program list by a type specified
-     */
-    Collection<Program> getByCurrentUser( int type );
-    
-    /**
      * Get {@link Program} by TrackedEntity
      *
      * @param trackedEntity {@link TrackedEntity}

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java	2015-02-13 08:50:17 +0000
@@ -37,7 +37,11 @@
 
 import org.hisp.dhis.i18n.I18nService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.system.util.CollectionUtils;
 import org.hisp.dhis.trackedentity.TrackedEntity;
+import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.user.UserAuthorityGroup;
+import org.hisp.dhis.user.UserService;
 import org.hisp.dhis.validation.ValidationCriteria;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -67,6 +71,20 @@
         i18nService = service;
     }
 
+    private CurrentUserService currentUserService;
+
+    public void setCurrentUserService( CurrentUserService currentUserService )
+    {
+        this.currentUserService = currentUserService;
+    }
+
+    private UserService userService;
+
+    public void setUserService( UserService userService )
+    {
+        this.userService = userService;
+    }
+
     // -------------------------------------------------------------------------
     // Implementation methods
     // -------------------------------------------------------------------------
@@ -144,13 +162,13 @@
     @Override
     public Collection<Program> getProgramsByCurrentUser()
     {
-        return i18n( i18nService, programStore.getByCurrentUser() );
+        return i18n( i18nService, getByCurrentUser() );
     }
 
     @Override
     public Collection<Program> getProgramsByCurrentUser( int type )
     {
-        return i18n( i18nService, programStore.getByCurrentUser( type ) );
+        return i18n( i18nService, getByCurrentUser( type ) );
     }
 
     @Override
@@ -197,5 +215,56 @@
     {
         return i18n( i18nService, programStore.getAllOrderedName( min, max ) );
     }
-
+    
+    @Override
+    public Collection<Program> getByCurrentUser()
+    {
+        Collection<Program> programs = new HashSet<>();
+
+        if ( currentUserService.getCurrentUser() != null && !currentUserService.currentUserIsSuper() )
+        {
+            Set<UserAuthorityGroup> userRoles = userService.getUserCredentials( currentUserService.getCurrentUser() )
+                .getUserAuthorityGroups();
+
+            for ( Program program : programStore.getAll() )
+            {
+                if ( CollectionUtils.intersection( program.getUserRoles(), userRoles ).size() > 0 )
+                {
+                    programs.add( program );
+                }
+            }
+        }
+        else
+        {
+            programs = programStore.getAll();
+        }
+
+        return programs;
+    }
+
+    @Override
+    public Collection<Program> getByCurrentUser( int type )
+    {
+        Collection<Program> programs = new HashSet<>();
+
+        if ( currentUserService.getCurrentUser() != null && !currentUserService.currentUserIsSuper() )
+        {
+            Set<UserAuthorityGroup> userRoles = userService.getUserCredentials( currentUserService.getCurrentUser() )
+                .getUserAuthorityGroups();
+
+            for ( Program program : programStore.getByType( type ) )
+            {
+                if ( CollectionUtils.intersection( program.getUserRoles(), userRoles ).size() > 0 )
+                {
+                    programs.add( program );
+                }
+            }
+        }
+        else
+        {
+            programs = programStore.getByType( type );
+        }
+
+        return programs;
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageDataElementStore.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageDataElementStore.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageDataElementStore.java	2015-02-13 08:50:17 +0000
@@ -118,5 +118,4 @@
         criteria.setProjection( Projections.property( "dataElement" ) );
         return criteria.list();
     }
-
 }

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStore.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStore.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStore.java	2015-02-13 08:50:17 +0000
@@ -29,8 +29,6 @@
  */
 
 import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
 
 import org.hibernate.Criteria;
 import org.hibernate.criterion.Restrictions;
@@ -38,11 +36,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramStore;
-import org.hisp.dhis.system.util.CollectionUtils;
 import org.hisp.dhis.trackedentity.TrackedEntity;
-import org.hisp.dhis.user.CurrentUserService;
-import org.hisp.dhis.user.UserAuthorityGroup;
-import org.hisp.dhis.user.UserService;
 
 /**
  * @author Chau Thu Tran
@@ -52,24 +46,6 @@
     implements ProgramStore
 {
     // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-
-    private CurrentUserService currentUserService;
-
-    public void setCurrentUserService( CurrentUserService currentUserService )
-    {
-        this.currentUserService = currentUserService;
-    }
-
-    private UserService userService;
-
-    public void setUserService( UserService userService )
-    {
-        this.userService = userService;
-    }
-
-    // -------------------------------------------------------------------------
     // Implemented methods
     // -------------------------------------------------------------------------
 
@@ -102,62 +78,9 @@
     }
 
     @Override
-    public Collection<Program> getByCurrentUser()
-    {
-        Collection<Program> programs = new HashSet<>();
-
-        if ( currentUserService.getCurrentUser() != null && !currentUserService.currentUserIsSuper() )
-        {
-            Set<UserAuthorityGroup> userRoles = userService.getUserCredentials( currentUserService.getCurrentUser() )
-                .getUserAuthorityGroups();
-
-            for ( Program program : getAll() )
-            {
-                if ( CollectionUtils.intersection( program.getUserRoles(), userRoles ).size() > 0 )
-                {
-                    programs.add( program );
-                }
-            }
-        }
-        else
-        {
-            programs = getAll();
-        }
-
-        return programs;
-    }
-
-    @Override
-    public Collection<Program> getByCurrentUser( int type )
-    {
-        Collection<Program> programs = new HashSet<>();
-
-        if ( currentUserService.getCurrentUser() != null && !currentUserService.currentUserIsSuper() )
-        {
-            Set<UserAuthorityGroup> userRoles = userService.getUserCredentials( currentUserService.getCurrentUser() )
-                .getUserAuthorityGroups();
-
-            for ( Program program : getByType( type ) )
-            {
-                if ( CollectionUtils.intersection( program.getUserRoles(), userRoles ).size() > 0 )
-                {
-                    programs.add( program );
-                }
-            }
-        }
-        else
-        {
-            programs = getByType( type );
-        }
-
-        return programs;
-    }
-
-    @Override
     @SuppressWarnings( "unchecked" )
     public Collection<Program> getByTrackedEntity( TrackedEntity trackedEntity )
     {
         return getCriteria( Restrictions.eq( "trackedEntity", trackedEntity ) ).list();
     }
-
 }

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml	2014-12-04 06:39:46 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml	2015-02-13 08:50:17 +0000
@@ -56,8 +56,6 @@
 		<property name="clazz" value="org.hisp.dhis.program.Program" />
 		<property name="sessionFactory" ref="sessionFactory" />
 		<property name="cacheable" value="true" />
-		<property name="userService" ref="org.hisp.dhis.user.UserService" />
-		<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
 	</bean>
 
 	<bean id="org.hisp.dhis.program.ProgramValidationStore"
@@ -226,6 +224,8 @@
 	<bean id="org.hisp.dhis.program.ProgramService" class="org.hisp.dhis.program.DefaultProgramService">
 		<property name="programStore" ref="org.hisp.dhis.program.ProgramStore" />
 		<property name="i18nService" ref="org.hisp.dhis.i18n.I18nService" />
+		<property name="userService" ref="org.hisp.dhis.user.UserService" />
+		<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
 	</bean>
 
 	<bean id="org.hisp.dhis.program.ProgramValidationService" class="org.hisp.dhis.program.DefaultProgramValidationService">