← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14236: Moved IllegalQueryException to api

 

------------------------------------------------------------
revno: 14236
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-03-17 11:04:44 +0100
message:
  Moved IllegalQueryException to api
renamed:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/IllegalQueryException.java => dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IllegalQueryException.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObject.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceQueryParams.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/QueryPlanner.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryPlanner.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java
  dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java
  dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.java
  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/hibernate/HibernateTrackedEntityInstanceStore.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/EventAnalyticsController.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IllegalQueryException.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/common/DimensionalObject.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObject.java	2014-02-04 08:24:06 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObject.java	2014-03-17 10:04:44 +0000
@@ -48,6 +48,11 @@
     final String ORGUNIT_DIM_ID = "ou";
     final String ORGUNIT_GROUP_DIM_ID = "oug"; // Used for org unit target
     final String ITEM_DIM_ID = "item";
+
+    final String OU_MODE_SELECTED = "selected";
+    final String OU_MODE_CHILDREN = "children";
+    final String OU_MODE_DESCENDANTS = "descendants";
+    final String OU_MODE_ALL = "all";
     
     final String DIMENSION_SEP = "-";
 

=== renamed file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/IllegalQueryException.java' => 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IllegalQueryException.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/IllegalQueryException.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IllegalQueryException.java	2014-03-17 10:04:44 +0000
@@ -1,4 +1,4 @@
-package org.hisp.dhis.analytics;
+package org.hisp.dhis.common;
 
 /*
  * Copyright (c) 2004-2013, University of Oslo

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceQueryParams.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceQueryParams.java	2014-03-16 23:07:04 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceQueryParams.java	2014-03-17 10:04:44 +0000
@@ -29,9 +29,12 @@
  */
 
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.hisp.dhis.common.QueryItem;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.program.Program;
 
 /**
@@ -51,7 +54,7 @@
     
     private TrackedEntity trackedEntity;
     
-    private List<String> organisationUnits = new ArrayList<String>();
+    private Set<OrganisationUnit> organisationUnits = new HashSet<OrganisationUnit>();
     
     private String organisationUnitMode;
 
@@ -76,6 +79,16 @@
         return program != null;
     }
     
+    public boolean hasTrackedEntity()
+    {
+        return trackedEntity != null;
+    }
+    
+    public boolean isOrganisationUnitMode( String mode )
+    {
+        return organisationUnitMode != null && organisationUnitMode.equals( mode );
+    }
+    
     // -------------------------------------------------------------------------
     // Getters and setters
     // -------------------------------------------------------------------------
@@ -110,12 +123,12 @@
         this.trackedEntity = trackedEntity;
     }
 
-    public List<String> getOrganisationUnits()
+    public Set<OrganisationUnit> getOrganisationUnits()
     {
         return organisationUnits;
     }
 
-    public void setOrganisationUnits( List<String> organisationUnits )
+    public void setOrganisationUnits( Set<OrganisationUnit> organisationUnits )
     {
         this.organisationUnits = organisationUnits;
     }

=== 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-02-26 15:09:48 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.java	2014-03-17 10:04:44 +0000
@@ -50,11 +50,14 @@
     String ID = TrackedEntityInstanceService.class.getName();
 
     public static final int ERROR_NONE = 0;
-
     public static final int ERROR_DUPLICATE_IDENTIFIER = 1;
-
     public static final int ERROR_ENROLLMENT = 2;
 
+    Grid getTrackedEntityInstances( TrackedEntityInstanceQueryParams params );
+    
+    TrackedEntityInstanceQueryParams getFromUrl( Set<String> items, String program, String trackedEntity, 
+        Set<String> organisationUnits, String ouMode, Integer page, Integer pageSize );
+    
     /**
      * Adds an {@link TrackedEntityInstance}
      * 

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/QueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/QueryPlanner.java	2013-09-29 17:20:53 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/QueryPlanner.java	2014-03-17 10:04:44 +0000
@@ -30,6 +30,8 @@
 
 import java.util.List;
 
+import org.hisp.dhis.common.IllegalQueryException;
+
 /**
  * @author Lars Helge Overland
  */

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2014-02-21 13:44:04 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2014-03-17 10:04:44 +0000
@@ -84,7 +84,6 @@
 import org.hisp.dhis.analytics.DataQueryGroups;
 import org.hisp.dhis.analytics.DataQueryParams;
 import org.hisp.dhis.analytics.DimensionItem;
-import org.hisp.dhis.analytics.IllegalQueryException;
 import org.hisp.dhis.analytics.QueryPlanner;
 import org.hisp.dhis.common.BaseAnalyticalObject;
 import org.hisp.dhis.common.BaseDimensionalObject;
@@ -96,6 +95,7 @@
 import org.hisp.dhis.common.GridHeader;
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.common.IdentifiableObjectUtils;
+import org.hisp.dhis.common.IllegalQueryException;
 import org.hisp.dhis.common.NameableObject;
 import org.hisp.dhis.common.NameableObjectUtils;
 import org.hisp.dhis.constant.ConstantService;

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java	2013-11-27 19:02:17 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java	2014-03-17 10:04:44 +0000
@@ -53,13 +53,13 @@
 import org.hisp.dhis.analytics.AggregationType;
 import org.hisp.dhis.analytics.DataQueryGroups;
 import org.hisp.dhis.analytics.DataQueryParams;
-import org.hisp.dhis.analytics.IllegalQueryException;
 import org.hisp.dhis.analytics.Partitions;
 import org.hisp.dhis.analytics.QueryPlanner;
 import org.hisp.dhis.analytics.table.PartitionUtils;
 import org.hisp.dhis.common.BaseDimensionalObject;
 import org.hisp.dhis.common.DimensionType;
 import org.hisp.dhis.common.DimensionalObject;
+import org.hisp.dhis.common.IllegalQueryException;
 import org.hisp.dhis.common.ListMap;
 import org.hisp.dhis.common.NameableObject;
 import org.hisp.dhis.dataelement.DataElement;

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java	2014-03-10 13:26:01 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java	2014-03-17 10:04:44 +0000
@@ -51,10 +51,6 @@
 public class EventQueryParams
     extends DataQueryParams
 {
-    public static final String OU_MODE_SELECTED = "selected";
-    public static final String OU_MODE_CHILDREN = "children";
-    public static final String OU_MODE_DESCENDANTS = "descendants";
-    
     private Program program;
     
     private ProgramStage programStage;

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryPlanner.java	2014-02-13 14:40:12 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryPlanner.java	2014-03-17 10:04:44 +0000
@@ -30,7 +30,7 @@
 
 import java.util.List;
 
-import org.hisp.dhis.analytics.IllegalQueryException;
+import org.hisp.dhis.common.IllegalQueryException;
 
 /**
  * @author Lars Helge Overland

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java	2014-03-10 16:40:11 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java	2014-03-17 10:04:44 +0000
@@ -47,7 +47,6 @@
 
 import org.hisp.dhis.analytics.AnalyticsService;
 import org.hisp.dhis.analytics.DataQueryParams;
-import org.hisp.dhis.analytics.IllegalQueryException;
 import org.hisp.dhis.analytics.SortOrder;
 import org.hisp.dhis.analytics.event.EventAnalyticsManager;
 import org.hisp.dhis.analytics.event.EventAnalyticsService;
@@ -59,6 +58,7 @@
 import org.hisp.dhis.common.GridHeader;
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.common.IdentifiableObjectUtils;
+import org.hisp.dhis.common.IllegalQueryException;
 import org.hisp.dhis.common.NameableObject;
 import org.hisp.dhis.common.Pager;
 import org.hisp.dhis.common.QueryItem;
@@ -93,8 +93,8 @@
     private static final String ITEM_ORG_UNIT_CODE = "oucode";
     private static final String COL_NAME_EVENTDATE = "executiondate";
 
-    private static final List<String> SORTABLE_ITEMS = Arrays.asList( ITEM_EXECUTION_DATE, ITEM_ORG_UNIT_NAME,
-        ITEM_ORG_UNIT_CODE );
+    private static final List<String> SORTABLE_ITEMS = Arrays.asList( 
+        ITEM_EXECUTION_DATE, ITEM_ORG_UNIT_NAME, ITEM_ORG_UNIT_CODE );
 
     @Autowired
     private ProgramService programService;

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java	2014-02-13 14:40:12 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java	2014-03-17 10:04:44 +0000
@@ -37,12 +37,12 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.analytics.DataQueryParams;
-import org.hisp.dhis.analytics.IllegalQueryException;
 import org.hisp.dhis.analytics.Partitions;
 import org.hisp.dhis.analytics.QueryPlanner;
 import org.hisp.dhis.analytics.event.EventQueryParams;
 import org.hisp.dhis.analytics.event.EventQueryPlanner;
 import org.hisp.dhis.analytics.table.PartitionUtils;
+import org.hisp.dhis.common.IllegalQueryException;
 import org.hisp.dhis.common.ListMap;
 import org.hisp.dhis.common.NameableObject;
 import org.hisp.dhis.period.Cal;

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java	2014-03-10 13:26:01 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java	2014-03-17 10:04:44 +0000
@@ -363,11 +363,11 @@
             sql += "where " + params.getPeriodType() + " in (" + getQuotedCommaDelimitedString( getUids( params.getDimensionOrFilter( PERIOD_DIM_ID ) ) ) + ") ";
         }
         
-        if ( params.isOrganisationUnitMode( EventQueryParams.OU_MODE_SELECTED ) )
+        if ( params.isOrganisationUnitMode( DimensionalObject.OU_MODE_SELECTED ) )
         {
             sql += "and ou in (" + getQuotedCommaDelimitedString( getUids( params.getDimensionOrFilter( ORGUNIT_DIM_ID ) ) ) + ") ";
         }
-        else if ( params.isOrganisationUnitMode( EventQueryParams.OU_MODE_CHILDREN ) )
+        else if ( params.isOrganisationUnitMode( DimensionalObject.OU_MODE_CHILDREN ) )
         {
             sql += "and ou in (" + getQuotedCommaDelimitedString( getUids( params.getOrganisationUnitChildren() ) ) + ") ";
         }

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java	2014-01-07 15:52:34 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java	2014-03-17 10:04:44 +0000
@@ -37,9 +37,9 @@
 import org.hisp.dhis.DhisSpringTest;
 import org.hisp.dhis.analytics.AnalyticsService;
 import org.hisp.dhis.analytics.DataQueryParams;
-import org.hisp.dhis.analytics.IllegalQueryException;
 import org.hisp.dhis.chart.Chart;
 import org.hisp.dhis.common.DimensionalObject;
+import org.hisp.dhis.common.IllegalQueryException;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.mock.MockCurrentUserService;

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.java	2013-09-29 15:24:12 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.java	2014-03-17 10:04:44 +0000
@@ -29,12 +29,14 @@
  */
 
 import static org.hisp.dhis.analytics.AnalyticsTableManager.ANALYTICS_TABLE_NAME;
+import static org.hisp.dhis.common.DimensionalObject.DATA_X_DIM_ID;
 import static org.hisp.dhis.common.DimensionalObject.DIMENSION_SEP;
-import static org.hisp.dhis.common.DimensionalObject.DATA_X_DIM_ID;
 import static org.hisp.dhis.common.DimensionalObject.ORGUNIT_DIM_ID;
 import static org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID;
 import static org.hisp.dhis.common.NameableObjectUtils.getList;
-import static org.hisp.dhis.dataelement.DataElement.*;
+import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_AVERAGE;
+import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_SUM;
+import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_INT;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
@@ -49,10 +51,10 @@
 import org.hisp.dhis.analytics.DataQueryGroups;
 import org.hisp.dhis.analytics.DataQueryParams;
 import org.hisp.dhis.analytics.DimensionItem;
-import org.hisp.dhis.analytics.IllegalQueryException;
 import org.hisp.dhis.analytics.QueryPlanner;
 import org.hisp.dhis.common.BaseDimensionalObject;
 import org.hisp.dhis.common.DimensionalObject;
+import org.hisp.dhis.common.IllegalQueryException;
 import org.hisp.dhis.common.ListMap;
 import org.hisp.dhis.common.NameableObject;
 import org.hisp.dhis.dataelement.DataElement;

=== 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-16 23:07:04 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java	2014-03-17 10:04:44 +0000
@@ -39,20 +39,17 @@
 import org.apache.commons.lang.StringUtils;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.common.GridHeader;
+import org.hisp.dhis.common.IllegalQueryException;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramService;
 import org.hisp.dhis.relationship.Relationship;
 import org.hisp.dhis.relationship.RelationshipService;
 import org.hisp.dhis.relationship.RelationshipType;
 import org.hisp.dhis.relationship.RelationshipTypeService;
 import org.hisp.dhis.system.grid.ListGrid;
-import org.hisp.dhis.trackedentity.TrackedEntityInstance;
-import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
-import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
-import org.hisp.dhis.trackedentity.TrackedEntityInstanceService;
-import org.hisp.dhis.trackedentity.TrackedEntityInstanceStore;
 import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
 import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService;
 import org.hisp.dhis.validation.ValidationCriteria;
@@ -60,7 +57,6 @@
 
 /**
  * @author Abyot Asalefew Gizaw
- * @version $Id$
  */
 @Transactional
 public class DefaultTrackedEntityInstanceService
@@ -70,11 +66,11 @@
     // Dependencies
     // -------------------------------------------------------------------------
 
-    private TrackedEntityInstanceStore entityInstanceStore;
+    private TrackedEntityInstanceStore trackedEntityInstanceStore;
 
-    public void setEntityInstanceStore( TrackedEntityInstanceStore entityInstanceStore )
+    public void setTrackedEntityInstanceStore( TrackedEntityInstanceStore trackedEntityInstanceStore )
     {
-        this.entityInstanceStore = entityInstanceStore;
+        this.trackedEntityInstanceStore = trackedEntityInstanceStore;
     }
 
     private TrackedEntityAttributeValueService attributeValueService;
@@ -104,15 +100,42 @@
     {
         this.relationshipTypeService = relationshipTypeService;
     }
+    
+    private ProgramService programService;
+
+    public void setProgramService( ProgramService programService )
+    {
+        this.programService = programService;
+    }
 
     // -------------------------------------------------------------------------
     // Implementation methods
     // -------------------------------------------------------------------------
 
+    public Grid getTrackedEntityInstances( TrackedEntityInstanceQueryParams params )
+    {
+        return trackedEntityInstanceStore.getTrackedEntityInstances( params );
+    }
+    
+    public TrackedEntityInstanceQueryParams getFromUrl( Set<String> items, String program, String trackedEntity, 
+        Set<String> organisationUnits, String ouMode, Integer page, Integer pageSize )
+    {
+        TrackedEntityInstanceQueryParams params = new TrackedEntityInstanceQueryParams();
+
+        Program pr = programService.getProgram( program );
+
+        if ( pr == null )
+        {
+            throw new IllegalQueryException( "Program does not exist: " + program );
+        }
+        
+        return params;
+    }
+    
     @Override
     public int saveTrackedEntityInstance( TrackedEntityInstance instance )
     {
-        return entityInstanceStore.save( instance );
+        return trackedEntityInstanceStore.save( instance );
     }
 
     @Override
@@ -133,7 +156,7 @@
 
         if ( representativeId != null )
         {
-            TrackedEntityInstance representative = entityInstanceStore.get( representativeId );
+            TrackedEntityInstance representative = trackedEntityInstanceStore.get( representativeId );
             if ( representative != null )
             {
                 instance.setRepresentative( representative );
@@ -163,31 +186,31 @@
     @Override
     public void updateTrackedEntityInstance( TrackedEntityInstance instance )
     {
-        entityInstanceStore.update( instance );
+        trackedEntityInstanceStore.update( instance );
     }
 
     @Override
     public void deleteTrackedEntityInstance( TrackedEntityInstance instance )
     {
-        entityInstanceStore.delete( instance );
+        trackedEntityInstanceStore.delete( instance );
     }
 
     @Override
     public TrackedEntityInstance getTrackedEntityInstance( int id )
     {
-        return entityInstanceStore.get( id );
+        return trackedEntityInstanceStore.get( id );
     }
 
     @Override
     public TrackedEntityInstance getTrackedEntityInstance( String uid )
     {
-        return entityInstanceStore.getByUid( uid );
+        return trackedEntityInstanceStore.getByUid( uid );
     }
 
     @Override
     public Collection<TrackedEntityInstance> getAllTrackedEntityInstances()
     {
-        return entityInstanceStore.getAll();
+        return trackedEntityInstanceStore.getAll();
     }
 
     @Override
@@ -221,20 +244,20 @@
     public Collection<TrackedEntityInstance> getTrackedEntityInstances( OrganisationUnit organisationUnit, Integer min,
         Integer max )
     {
-        return entityInstanceStore.getByOrgUnit( organisationUnit, min, max );
+        return trackedEntityInstanceStore.getByOrgUnit( organisationUnit, min, max );
     }
 
     @Override
     public Collection<TrackedEntityInstance> getTrackedEntityInstances( Program program )
     {
-        return entityInstanceStore.getByProgram( program, 0, Integer.MAX_VALUE );
+        return trackedEntityInstanceStore.getByProgram( program, 0, Integer.MAX_VALUE );
     }
 
     @Override
     public Collection<TrackedEntityInstance> getTrackedEntityInstances( OrganisationUnit organisationUnit,
         Program program )
     {
-        return entityInstanceStore.getByOrgUnitProgram( organisationUnit, program, 0, Integer.MAX_VALUE );
+        return trackedEntityInstanceStore.getByOrgUnitProgram( organisationUnit, program, 0, Integer.MAX_VALUE );
     }
 
     @Override
@@ -288,7 +311,7 @@
     @Override
     public int countGetTrackedEntityInstancesByOrgUnit( OrganisationUnit organisationUnit )
     {
-        return entityInstanceStore.countListTrackedEntityInstanceByOrgunit( organisationUnit );
+        return trackedEntityInstanceStore.countListTrackedEntityInstanceByOrgunit( organisationUnit );
     }
 
     @Override
@@ -296,7 +319,7 @@
         Integer relationshipTypeId, List<TrackedEntityAttributeValue> valuesForSave,
         List<TrackedEntityAttributeValue> valuesForUpdate, Collection<TrackedEntityAttributeValue> valuesForDelete )
     {
-        entityInstanceStore.update( instance );
+        trackedEntityInstanceStore.update( instance );
 
         for ( TrackedEntityAttributeValue av : valuesForSave )
         {
@@ -315,7 +338,7 @@
 
         if ( shouldSaveRepresentativeInformation( instance, representativeId ) )
         {
-            TrackedEntityInstance representative = entityInstanceStore.get( representativeId );
+            TrackedEntityInstance representative = trackedEntityInstanceStore.get( representativeId );
 
             if ( representative != null )
             {
@@ -352,13 +375,13 @@
     public Collection<TrackedEntityInstance> getTrackedEntityInstances( OrganisationUnit organisationUnit,
         Program program, Integer min, Integer max )
     {
-        return entityInstanceStore.getByOrgUnitProgram( organisationUnit, program, min, max );
+        return trackedEntityInstanceStore.getByOrgUnitProgram( organisationUnit, program, min, max );
     }
 
     @Override
     public int countGetTrackedEntityInstancesByOrgUnitProgram( OrganisationUnit organisationUnit, Program program )
     {
-        return entityInstanceStore.countGetTrackedEntityInstancesByOrgUnitProgram( organisationUnit, program );
+        return trackedEntityInstanceStore.countGetTrackedEntityInstancesByOrgUnitProgram( organisationUnit, program );
     }
 
     @Override
@@ -399,7 +422,7 @@
     @Override
     public Collection<TrackedEntityInstance> getRepresentatives( TrackedEntityInstance instance )
     {
-        return entityInstanceStore.getRepresentatives( instance );
+        return trackedEntityInstanceStore.getRepresentatives( instance );
     }
 
     @Override
@@ -407,21 +430,21 @@
         Collection<OrganisationUnit> orgunits, Boolean followup, Collection<TrackedEntityAttribute> attributes,
         Integer statusEnrollment, Integer min, Integer max )
     {
-        return entityInstanceStore.search( searchKeys, orgunits, followup, attributes, statusEnrollment, min, max );
+        return trackedEntityInstanceStore.search( searchKeys, orgunits, followup, attributes, statusEnrollment, min, max );
     }
 
     @Override
     public int countSearchTrackedEntityInstances( List<String> searchKeys, Collection<OrganisationUnit> orgunits,
         Boolean followup, Integer statusEnrollment )
     {
-        return entityInstanceStore.countSearch( searchKeys, orgunits, followup, statusEnrollment );
+        return trackedEntityInstanceStore.countSearch( searchKeys, orgunits, followup, statusEnrollment );
     }
 
     @Override
     public Collection<String> getTrackedEntityInstancePhoneNumbers( List<String> searchKeys,
         Collection<OrganisationUnit> orgunits, Boolean followup, Integer statusEnrollment, Integer min, Integer max )
     {
-        Collection<TrackedEntityInstance> entityInstances = entityInstanceStore.search( searchKeys, orgunits, followup,
+        Collection<TrackedEntityInstance> entityInstances = trackedEntityInstanceStore.search( searchKeys, orgunits, followup,
             null, statusEnrollment, min, max );
         Set<String> phoneNumbers = new HashSet<String>();
 
@@ -447,7 +470,7 @@
     public List<Integer> getProgramStageInstances( List<String> searchKeys, Collection<OrganisationUnit> orgunits,
         Boolean followup, Integer statusEnrollment, Integer min, Integer max )
     {
-        return entityInstanceStore.getProgramStageInstances( searchKeys, orgunits, followup, null, statusEnrollment,
+        return trackedEntityInstanceStore.getProgramStageInstances( searchKeys, orgunits, followup, null, statusEnrollment,
             min, max );
     }
 
@@ -455,7 +478,7 @@
     public Collection<TrackedEntityInstance> getTrackedEntityInstancesByPhone( String phoneNumber, Integer min,
         Integer max )
     {
-        return entityInstanceStore.getByPhoneNumber( phoneNumber, min, max );
+        return trackedEntityInstanceStore.getByPhoneNumber( phoneNumber, min, max );
     }
 
     @Override
@@ -499,7 +522,7 @@
         grid.addHeader( new GridHeader( i18n.getString( "program_stage" ), false, true ) );
         grid.addHeader( new GridHeader( i18n.getString( "due_date" ), false, true ) );
 
-        return entityInstanceStore.getTrackedEntityInstanceEventReport( grid, searchKeys, orgunits, followup,
+        return trackedEntityInstanceStore.getTrackedEntityInstanceEventReport( grid, searchKeys, orgunits, followup,
             attributes, statusEnrollment, min, max );
     }
 
@@ -545,20 +568,20 @@
         grid.addHeader( new GridHeader( i18n.getString( "due_date" ), false, true ) );
         grid.addHeader( new GridHeader( i18n.getString( "risk" ), false, true ) );
 
-        return entityInstanceStore.getTrackedEntityInstanceEventReport( grid, searchKeys, orgunits, followup,
+        return trackedEntityInstanceStore.getTrackedEntityInstanceEventReport( grid, searchKeys, orgunits, followup,
             attributes, statusEnrollment, null, null );
     }
 
     @Override
     public int validateTrackedEntityInstance( TrackedEntityInstance instance, Program program, I18nFormat format )
     {
-        return entityInstanceStore.validate( instance, program, format );
+        return trackedEntityInstanceStore.validate( instance, program, format );
     }
 
     @Override
     public ValidationCriteria validateEnrollment( TrackedEntityInstance instance, Program program, I18nFormat format )
     {
-        return entityInstanceStore.validateEnrollment( instance, program, format );
+        return trackedEntityInstanceStore.validateEnrollment( instance, program, format );
     }
 
     @Override
@@ -595,6 +618,6 @@
     public Collection<TrackedEntityInstance> getTrackedEntityInstancesByAttributeValue( String searchText,
         int attributeId, Integer min, Integer max )
     {
-        return entityInstanceStore.getByAttributeValue( searchText, attributeId, min, max );
+        return trackedEntityInstanceStore.getByAttributeValue( searchText, attributeId, min, max );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java	2014-03-16 23:07:04 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java	2014-03-17 10:04:44 +0000
@@ -28,6 +28,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
+import static org.hisp.dhis.system.util.TextUtils.getQuotedCommaDelimitedString;
 import static org.hisp.dhis.trackedentity.TrackedEntityInstance.PREFIX_PROGRAM;
 import static org.hisp.dhis.trackedentity.TrackedEntityInstance.PREFIX_PROGRAM_EVENT_BY_STATUS;
 import static org.hisp.dhis.trackedentity.TrackedEntityInstance.PREFIX_PROGRAM_INSTANCE;
@@ -57,11 +59,13 @@
 import org.hibernate.criterion.Disjunction;
 import org.hibernate.criterion.Projections;
 import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.common.DimensionalObject;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.common.GridHeader;
 import org.hisp.dhis.common.QueryItem;
 import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
 import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.jdbc.StatementBuilder;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.Period;
@@ -106,6 +110,13 @@
     {
         this.organisationUnitService = organisationUnitService;
     }
+    
+    private StatementBuilder statementBuilder;
+
+    public void setStatementBuilder( StatementBuilder statementBuilder )
+    {
+        this.statementBuilder = statementBuilder;
+    }
 
     // -------------------------------------------------------------------------
     // Implementation methods
@@ -132,7 +143,6 @@
         for ( Map<String, String> entity : entities )
         {
             grid.addValue( entity.get( TRACKED_ENTITY_INSTANCE_ID ) );
-            grid.addValue( entity.get( CREATED_ID ) );
             grid.addValue( entity.get( LAST_UPDATED_ID ) );
             grid.addValue( entity.get( TRACKED_ENTITY_ID ) );
             grid.addValue( entity.get( ORG_UNIT_ID ) );
@@ -143,16 +153,51 @@
     
     private Collection<Map<String, String>> getEntities( TrackedEntityInstanceQueryParams params )
     {
+        SqlHelper hlp = new SqlHelper();
+        
         String sql = 
             "select tei.uid, tei.created, tei.lastupdated, te.uid, ou.uid, tav.value, ta.uid " +
             "from trackedentityinstance tei " +
-            "left join trackedentity te on tei.trackedentityid=te.trackedentityid " +
-            "left join organisationunit ou on tei.organisationunitid=ou.organisationunitid " +
-            "left join trackedentityattributevalue tav on tei.trackedentityinstanceid=tav.trackedentityinstanceid " +
-            "left join trackedentityattribute ta on tav.trackedentityattributeid=ta.trackedentityattributeid";
+            "left join trackedentity te on tei.trackedentityid = te.trackedentityid " +
+            "left join organisationunit ou on tei.organisationunitid = ou.organisationunitid " +
+            "left join trackedentityattributevalue tav on tei.trackedentityinstanceid = tav.trackedentityinstanceid " +
+            "left join trackedentityattribute ta on tav.trackedentityattributeid = ta.trackedentityattributeid ";
+        
+        if ( !params.isOrganisationUnitMode( DimensionalObject.OU_MODE_SELECTED ) )
+        {
+            sql += "left join _orgunitstructure ous using tei.organisationunitid=ous.organisationunitid ";
+        }
+        
+        if ( params.hasTrackedEntity() )
+        {
+            sql += hlp.whereAnd() + " tei.trackedentityid = " + params.getTrackedEntity().getId();
+        }
+        
+        if ( params.isOrganisationUnitMode( DimensionalObject.OU_MODE_SELECTED ) )
+        {
+            sql += hlp.whereAnd() + " tei.organisationunitid in (" + getQuotedCommaDelimitedString( getUids( params.getOrganisationUnits() ) ) + ") ";
+        }
+        
+        for ( QueryItem item : params.getItems() )
+        {
+            String filter = statementBuilder.encode( item.getFilter(), false );
+            
+            String valClause = "tav.value " + item.getSqlOperator() + " " + item.getSqlFilter( filter );
+            
+            if ( item.hasFilter() )
+            {
+                sql += hlp.whereAnd() + " (ta.uid = " + item.getItemId() + " and " + valClause + ") ";
+            }
+            else
+            {
+                sql += hlp.whereAnd() + " (" + valClause + ") ";
+            }
+        }
         
         MapMap<String, String, String> entityMap = new MapMap<String, String, String>();
 
+        log.info( "Tracked entity instance query SQL: " + sql );
+        
         SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
         
         while ( rowSet.next() )

=== 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-02-17 15:00:27 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml	2014-03-17 10:04:44 +0000
@@ -74,12 +74,11 @@
 
 	<bean id="org.hisp.dhis.trackedentity.TrackedEntityInstanceStore"
 		class="org.hisp.dhis.trackedentity.hibernate.HibernateTrackedEntityInstanceStore">
-		<property name="clazz"
-			value="org.hisp.dhis.trackedentity.TrackedEntityInstance" />
+		<property name="clazz" value="org.hisp.dhis.trackedentity.TrackedEntityInstance" />
 		<property name="sessionFactory" ref="sessionFactory" />
-		<property name="organisationUnitService"
-			ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+		<property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
 		<property name="jdbcTemplate" ref="jdbcTemplate" />
+		<property name="statementBuilder" ref="statementBuilder" />
 	</bean>
 
 	<bean id="org.hisp.dhis.trackedentity.TrackedEntityAttributeStore"
@@ -237,7 +236,7 @@
 
 	<bean id="org.hisp.dhis.trackedentity.TrackedEntityInstanceService"
 		class="org.hisp.dhis.trackedentity.DefaultTrackedEntityInstanceService">
-		<property name="entityInstanceStore"
+		<property name="trackedEntityInstanceStore"
 			ref="org.hisp.dhis.trackedentity.TrackedEntityInstanceStore" />
 		<property name="attributeValueService"
 			ref="org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService" />
@@ -247,6 +246,8 @@
 			ref="org.hisp.dhis.relationship.RelationshipTypeService" />
 		<property name="relationshipService"
 			ref="org.hisp.dhis.relationship.RelationshipService" />
+	    <property name="programService"
+	        ref="org.hisp.dhis.program.ProgramService" />
 	</bean>
 
 	<bean id="org.hisp.dhis.trackedentity.TrackedEntityAttributeService"

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java	2014-01-20 13:42:55 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java	2014-03-17 10:04:44 +0000
@@ -39,10 +39,10 @@
 import org.hisp.dhis.analytics.AggregationType;
 import org.hisp.dhis.analytics.AnalyticsService;
 import org.hisp.dhis.analytics.DataQueryParams;
-import org.hisp.dhis.analytics.IllegalQueryException;
 import org.hisp.dhis.api.utils.ContextUtils;
 import org.hisp.dhis.api.utils.ContextUtils.CacheStrategy;
 import org.hisp.dhis.common.Grid;
+import org.hisp.dhis.common.IllegalQueryException;
 import org.hisp.dhis.i18n.I18nManager;
 import org.hisp.dhis.system.grid.GridUtils;
 import org.springframework.beans.factory.annotation.Autowired;

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/EventAnalyticsController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/EventAnalyticsController.java	2014-02-14 13:48:40 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/EventAnalyticsController.java	2014-03-17 10:04:44 +0000
@@ -35,13 +35,13 @@
 
 import javax.servlet.http.HttpServletResponse;
 
-import org.hisp.dhis.analytics.IllegalQueryException;
 import org.hisp.dhis.analytics.SortOrder;
 import org.hisp.dhis.analytics.event.EventAnalyticsService;
 import org.hisp.dhis.analytics.event.EventQueryParams;
 import org.hisp.dhis.api.utils.ContextUtils;
 import org.hisp.dhis.api.utils.ContextUtils.CacheStrategy;
 import org.hisp.dhis.common.Grid;
+import org.hisp.dhis.common.IllegalQueryException;
 import org.hisp.dhis.i18n.I18nManager;
 import org.hisp.dhis.system.grid.GridUtils;
 import org.springframework.beans.factory.annotation.Autowired;