=== 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-04-07 16:50:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceQueryParams.java 2014-04-08 14:44:25 +0000 @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Set; @@ -131,6 +132,43 @@ // ------------------------------------------------------------------------- /** + * Performs a set of operations on this params. + * + * + */ + public void conform() + { + Iterator filterIter = filters.iterator(); + + while ( filterIter.hasNext() ) + { + QueryItem filter = filterIter.next(); + + int index = attributes.indexOf( filter ); // Filter present as attr + + if ( index >= 0 ) + { + QueryItem attribute = attributes.get( index ); + + if ( !attribute.hasFilter() ) + { + attribute.setOperator( filter.getOperator() ); + attribute.setFilter( filter.getFilter() ); + } + + filterIter.remove(); + } + } + } + + /** * Returns a mapping between level and organisation units. */ public SetMap getLevelOrgUnitMap() @@ -176,25 +214,43 @@ } /** - * Returns a list of query items which appear more than once as attributes - * or filters. - */ - public List getDuplicateAttributesAndFilters() - { - Set items = new HashSet(); - List duplicates = new ArrayList(); - - for ( QueryItem item : getAttributesAndFilters() ) - { - if ( !items.add( item ) ) - { - duplicates.add( item ); - } - } - - return duplicates; - } - + * Returns a list of attributes which appear more than once. + */ + public List getDuplicateAttributes() + { + Set items = new HashSet(); + List duplicates = new ArrayList(); + + for ( QueryItem item : getAttributes() ) + { + if ( !items.add( item ) ) + { + duplicates.add( item ); + } + } + + return duplicates; + } + + /** + * Returns a list of attributes which appear more than once. + */ + public List getDuplicateFilters() + { + Set items = new HashSet(); + List duplicates = new ArrayList(); + + for ( QueryItem item : getFilters() ) + { + if ( !items.add( item ) ) + { + duplicates.add( item ); + } + } + + return duplicates; + } + /** * Indicates whether this params specifies any attributes and/or filters. */ === 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-04-08 10:06:11 +0000 +++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java 2014-04-08 14:44:25 +0000 @@ -147,12 +147,16 @@ // Implementation methods // ------------------------------------------------------------------------- - //TODO queries with multiple words //TODO lower index on attribute value? @Override public Grid getTrackedEntityInstances( TrackedEntityInstanceQueryParams params ) { + if ( params != null ) + { + params.conform(); + } + validate( params ); // --------------------------------------------------------------------- @@ -290,11 +294,16 @@ violation = "Program must be defined when program dates are specified"; } - if ( !params.getDuplicateAttributesAndFilters().isEmpty() ) + if ( !params.getDuplicateAttributes().isEmpty() ) { - violation = "Attributes and filters cannot be specified more than once: " + params.getDuplicateAttributesAndFilters(); + violation = "Attributes cannot be specified more than once: " + params.getDuplicateAttributes(); } + if ( !params.getDuplicateFilters().isEmpty() ) + { + violation = "Filters cannot be specified more than once: " + params.getDuplicateFilters(); + } + if ( violation != null ) { log.warn( "Validation failed: " + violation );