← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19569: adds validation for PI query, also switches to @Autowired for IOC

 

------------------------------------------------------------
revno: 19569
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-07-08 10:38:42 +0700
message:
  adds validation for PI query, also switches to @Autowired for IOC
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.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-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java	2015-07-08 03:26:22 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java	2015-07-08 03:38:42 +0000
@@ -28,6 +28,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.common.CodeGenerator;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.common.GridHeader;
@@ -73,7 +75,7 @@
 import java.util.List;
 import java.util.Set;
 
-import static org.hisp.dhis.common.OrganisationUnitSelectionMode.CHILDREN;
+import static org.hisp.dhis.common.OrganisationUnitSelectionMode.*;
 
 /**
  * @author Abyot Asalefew
@@ -82,93 +84,51 @@
 public class DefaultProgramInstanceService
     implements ProgramInstanceService
 {
+    private static final Log log = LogFactory.getLog( DefaultProgramInstanceService.class );
+
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
 
+    @Autowired
     private ProgramInstanceStore programInstanceStore;
 
-    public void setProgramInstanceStore( ProgramInstanceStore programInstanceStore )
-    {
-        this.programInstanceStore = programInstanceStore;
-    }
-
+    @Autowired
     private TrackedEntityAttributeValueService attributeValueService;
 
-    public void setAttributeValueService( TrackedEntityAttributeValueService attributeValueService )
-    {
-        this.attributeValueService = attributeValueService;
-    }
-
-    public void setDataValueService( TrackedEntityDataValueService dataValueService )
-    {
-        this.dataValueService = dataValueService;
-    }
-
+    @Autowired
     private TrackedEntityDataValueService dataValueService;
 
+    @Autowired
     private ProgramService programService;
 
-    public void setProgramService( ProgramService programService )
-    {
-        this.programService = programService;
-    }
-
+    @Autowired
     private SmsSender smsSender;
 
-    public void setSmsSender( SmsSender smsSender )
-    {
-        this.smsSender = smsSender;
-    }
-
+    @Autowired
     private CurrentUserService currentUserService;
 
-    public void setCurrentUserService( CurrentUserService currentUserService )
-    {
-        this.currentUserService = currentUserService;
-    }
-
+    @Autowired
     private TrackedEntityInstanceReminderService reminderService;
 
-    public void setReminderService( TrackedEntityInstanceReminderService reminderService )
-    {
-        this.reminderService = reminderService;
-    }
-
+    @Autowired
     private MessageService messageService;
 
-    public void setMessageService( MessageService messageService )
-    {
-        this.messageService = messageService;
-    }
-
+    @Autowired
     private ProgramStageInstanceService programStageInstanceService;
 
-    public void setProgramStageInstanceService( ProgramStageInstanceService programStageInstanceService )
-    {
-        this.programStageInstanceService = programStageInstanceService;
-    }
-
+    @Autowired
     private TrackedEntityInstanceService trackedEntityInstanceService;
 
-    public void setTrackedEntityInstanceService( TrackedEntityInstanceService trackedEntityInstanceService )
-    {
-        this.trackedEntityInstanceService = trackedEntityInstanceService;
-    }
-
     @Autowired
     private OrganisationUnitService organisationUnitService;
 
     @Autowired
     private TrackedEntityService trackedEntityService;
 
+    @Autowired
     private I18nManager i18nManager;
 
-    public void setI18nManager( I18nManager i18nManager )
-    {
-        this.i18nManager = i18nManager;
-    }
-
     // -------------------------------------------------------------------------
     // Implementation methods
     // -------------------------------------------------------------------------
@@ -353,7 +313,56 @@
     @Override
     public void validate( ProgramInstanceQueryParams params ) throws IllegalQueryException
     {
-
+        String violation = null;
+
+        if ( params == null )
+        {
+            throw new IllegalQueryException( "Params cannot be null" );
+        }
+
+        User user = currentUserService.getCurrentUser();
+
+        if ( !params.hasOrganisationUnits() && !(params.isOrganisationUnitMode( ALL ) || params.isOrganisationUnitMode( ACCESSIBLE )) )
+        {
+            violation = "At least one organisation unit must be specified";
+        }
+
+        if ( params.isOrganisationUnitMode( ACCESSIBLE ) && (user == null || !user.hasDataViewOrganisationUnitWithFallback()) )
+        {
+            violation = "Current user must be associated with at least one organisation unit when selection mode is ACCESSIBLE";
+        }
+
+        if ( params.hasProgram() && params.hasTrackedEntity() )
+        {
+            violation = "Program and tracked entity cannot be specified simultaneously";
+        }
+
+        if ( params.hasProgramStatus() && !params.hasProgram() )
+        {
+            violation = "Program must be defined when program status is defined";
+        }
+
+        if ( params.hasFollowUp() && !params.hasProgram() )
+        {
+            violation = "Program must be defined when follow up status is defined";
+        }
+
+        if ( params.hasProgramStartDate() && !params.hasProgram() )
+        {
+            violation = "Program must be defined when program start date is specified";
+        }
+
+        if ( params.hasProgramEndDate() && !params.hasProgram() )
+        {
+            violation = "Program must be defined when program end date is specified";
+        }
+
+        if ( violation != null )
+        {
+            log.warn( "Validation failed: " + violation );
+
+            throw new IllegalQueryException( violation );
+        }
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java	2015-07-08 03:26:22 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java	2015-07-08 03:38:42 +0000
@@ -56,6 +56,7 @@
 import org.hisp.dhis.user.CurrentUserService;
 import org.hisp.dhis.user.User;
 import org.hisp.dhis.validation.ValidationCriteria;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.Collection;
@@ -82,74 +83,37 @@
     // Dependencies
     // -------------------------------------------------------------------------
 
+    @Autowired
     private TrackedEntityInstanceStore trackedEntityInstanceStore;
 
-    public void setTrackedEntityInstanceStore( TrackedEntityInstanceStore trackedEntityInstanceStore )
-    {
-        this.trackedEntityInstanceStore = trackedEntityInstanceStore;
-    }
-
+    @Autowired
     private TrackedEntityAttributeValueService attributeValueService;
 
-    public void setAttributeValueService( TrackedEntityAttributeValueService attributeValueService )
-    {
-        this.attributeValueService = attributeValueService;
-    }
-
+    @Autowired
     private TrackedEntityAttributeService attributeService;
 
-    public void setAttributeService( TrackedEntityAttributeService attributeService )
-    {
-        this.attributeService = attributeService;
-    }
-
+    @Autowired
     private TrackedEntityService trackedEntityService;
 
-    public void setTrackedEntityService( TrackedEntityService trackedEntityService )
-    {
-        this.trackedEntityService = trackedEntityService;
-    }
-
+    @Autowired
     private RelationshipService relationshipService;
 
-    public void setRelationshipService( RelationshipService relationshipService )
-    {
-        this.relationshipService = relationshipService;
-    }
-
+    @Autowired
     private RelationshipTypeService relationshipTypeService;
 
-    public void setRelationshipTypeService( RelationshipTypeService relationshipTypeService )
-    {
-        this.relationshipTypeService = relationshipTypeService;
-    }
-
+    @Autowired
     private ProgramService programService;
 
-    public void setProgramService( ProgramService programService )
-    {
-        this.programService = programService;
-    }
-
+    @Autowired
     private OrganisationUnitService organisationUnitService;
 
-    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
-    {
-        this.organisationUnitService = organisationUnitService;
-    }
-
+    @Autowired
     private CurrentUserService currentUserService;
 
-    public void setCurrentUserService( CurrentUserService currentUserService )
-    {
-        this.currentUserService = currentUserService;
-    }
-
     // -------------------------------------------------------------------------
     // Implementation methods
     // -------------------------------------------------------------------------
 
-
     @Override
     public int countTrackedEntityInstances( TrackedEntityInstanceQueryParams params )
     {

=== 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	2015-07-07 12:22:03 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2015-07-08 03:38:42 +0000
@@ -1106,19 +1106,7 @@
     <property name="messageService" ref="org.hisp.dhis.message.MessageService" />
   </bean>
 
-  <bean id="org.hisp.dhis.program.ProgramInstanceService" class="org.hisp.dhis.program.DefaultProgramInstanceService">
-    <property name="programInstanceStore" ref="org.hisp.dhis.program.ProgramInstanceStore" />
-    <property name="attributeValueService" ref="org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService" />
-    <property name="dataValueService" ref="org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueService" />
-    <property name="programService" ref="org.hisp.dhis.program.ProgramService" />
-    <property name="smsSender" ref="org.hisp.dhis.sms.SmsSender" />
-    <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
-    <property name="reminderService" ref="org.hisp.dhis.trackedentity.TrackedEntityInstanceReminderService" />
-    <property name="messageService" ref="org.hisp.dhis.message.MessageService" />
-    <property name="programStageInstanceService" ref="org.hisp.dhis.program.ProgramStageInstanceService" />
-    <property name="i18nManager" ref="org.hisp.dhis.i18n.I18nManager" />
-    <property name="trackedEntityInstanceService" ref="org.hisp.dhis.trackedentity.TrackedEntityInstanceService" />
-  </bean>
+  <bean id="org.hisp.dhis.program.ProgramInstanceService" class="org.hisp.dhis.program.DefaultProgramInstanceService" />
 
   <bean id="org.hisp.dhis.program.ProgramStageService" class="org.hisp.dhis.program.DefaultProgramStageService">
     <property name="programStageStore" ref="org.hisp.dhis.program.ProgramStageStore" />
@@ -1156,17 +1144,7 @@
   </bean>
 
   <bean id="org.hisp.dhis.trackedentity.TrackedEntityInstanceService"
-    class="org.hisp.dhis.trackedentity.DefaultTrackedEntityInstanceService">
-    <property name="trackedEntityInstanceStore" ref="org.hisp.dhis.trackedentity.TrackedEntityInstanceStore" />
-    <property name="attributeValueService" ref="org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService" />
-    <property name="attributeService" ref="org.hisp.dhis.trackedentity.TrackedEntityAttributeService" />
-    <property name="trackedEntityService" ref="org.hisp.dhis.trackedentity.TrackedEntityService" />
-    <property name="relationshipTypeService" ref="org.hisp.dhis.relationship.RelationshipTypeService" />
-    <property name="relationshipService" ref="org.hisp.dhis.relationship.RelationshipService" />
-    <property name="programService" ref="org.hisp.dhis.program.ProgramService" />
-    <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
-    <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
-  </bean>
+    class="org.hisp.dhis.trackedentity.DefaultTrackedEntityInstanceService" />
 
   <bean id="org.hisp.dhis.trackedentity.TrackedEntityAttributeService"
     class="org.hisp.dhis.trackedentity.DefaultTrackedEntityAttributeService">