← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14369: TEI query, allow no org unit in java api

 

------------------------------------------------------------
revno: 14369
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-03-24 18:25:22 +0100
message:
  TEI query, allow no org unit in java api
added:
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentityinstance/
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentityinstance/TrackedEntityInstanceQueryTest.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.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/trackedentity/TrackedEntityInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.java	2014-03-24 14:16:32 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.java	2014-03-24 17:25:22 +0000
@@ -33,6 +33,7 @@
 import java.util.Set;
 
 import org.hisp.dhis.common.Grid;
+import org.hisp.dhis.common.IllegalQueryException;
 import org.hisp.dhis.common.OrganisationUnitSelectionMode;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.i18n.I18nFormat;
@@ -43,9 +44,7 @@
 
 /**
  * @author Abyot Asalefew Gizaw
- * @version $Id$
  */
-
 public interface TrackedEntityInstanceService
 {
     String ID = TrackedEntityInstanceService.class.getName();
@@ -54,12 +53,43 @@
     public static final int ERROR_DUPLICATE_IDENTIFIER = 1;
     public static final int ERROR_ENROLLMENT = 2;
 
+    /**
+     * Returns a grid with tracked entity instance values based on the given
+     * TrackedEntityInstanceQueryParams.
+     * 
+     * @param params the TrackedEntityInstanceQueryParams.
+     * @return a grid.
+     */
     Grid getTrackedEntityInstances( TrackedEntityInstanceQueryParams params );
     
+    /**
+     * Returns a TrackedEntityInstanceQueryParams based on the given input.
+     * 
+     * @param query the query string.
+     * @param attribute the set of attributes.
+     * @param filter the set of filters.
+     * @param ou the organisation unit string.
+     * @param ouMode the OrganisationUnitSelectionMode.
+     * @param program the Program uid.
+     * @param trackedEntity the TrackedEntity uid.
+     * @param page the page number.
+     * @param pageSize the page size.
+     * @return a TrackedEntityInstanceQueryParams.
+     */
     TrackedEntityInstanceQueryParams getFromUrl( String query, Set<String> attribute, Set<String> filter, 
         Set<String> ou, OrganisationUnitSelectionMode ouMode, String program, String trackedEntity, Integer page, Integer pageSize );
     
     /**
+     * Validates the given TrackedEntityInstanceQueryParams. The params is
+     * considered valid if no exception are thrown and the method returns normally.
+     * 
+     * @param params the TrackedEntityInstanceQueryParams.
+     * @throws IllegalQueryException if the given params is invalid.
+     */
+    void validate( TrackedEntityInstanceQueryParams params )
+        throws IllegalQueryException;
+    
+    /**
      * Adds an {@link TrackedEntityInstance}
      * 
      * @param entityInstance The to TrackedEntityInstance add.

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java	2014-03-24 14:49:29 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java	2014-03-24 17:25:22 +0000
@@ -225,7 +225,8 @@
         
         return grid;
     }
-    
+
+    @Override
     public void validate( TrackedEntityInstanceQueryParams params )
         throws IllegalQueryException
     {
@@ -236,7 +237,7 @@
             throw new IllegalQueryException( "Params cannot be null" );
         }
 
-        if ( !params.hasOrganisationUnits() )
+        if ( !params.hasOrganisationUnits() && !params.isOrganisationUnitMode( OrganisationUnitSelectionMode.ALL ) )
         {
             violation = "At least one organisation unit must be specified";
         }

=== added directory 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentityinstance'
=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentityinstance/TrackedEntityInstanceQueryTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentityinstance/TrackedEntityInstanceQueryTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentityinstance/TrackedEntityInstanceQueryTest.java	2014-03-24 17:25:22 +0000
@@ -0,0 +1,54 @@
+package org.hisp.dhis.trackedentityinstance;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.common.OrganisationUnitSelectionMode;
+import org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams;
+import org.hisp.dhis.trackedentity.TrackedEntityInstanceService;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class TrackedEntityInstanceQueryTest
+    extends DhisSpringTest
+{
+    @Autowired
+    private TrackedEntityInstanceService instanceService;
+    
+    @Test
+    public void testValidateNoOrgUnitsModeAll()
+    {
+        TrackedEntityInstanceQueryParams params = new TrackedEntityInstanceQueryParams();
+        params.setOrganisationUnitMode( OrganisationUnitSelectionMode.ALL );
+        instanceService.validate( params );
+    }
+}