← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14732: TEI query, prohibiting attributes and filters to be specified more than once

 

------------------------------------------------------------
revno: 14732
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-04-07 18:50:00 +0200
message:
  TEI query, prohibiting attributes and filters to be specified more than once
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryFilter.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryItem.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceQueryParams.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/common/QueryFilter.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryFilter.java	2014-04-04 12:15:25 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryFilter.java	2014-04-07 16:50:00 +0000
@@ -113,7 +113,74 @@
         
         return "'" + encodedFilter + "'";
     }
-    
+
+    // -------------------------------------------------------------------------
+    // hashCode, equals and toString
+    // -------------------------------------------------------------------------
+    
+    @Override
+    public String toString()
+    {
+        return "[Operator: " + operator + ", filter: " + filter + "]";
+    }
+    
+    @Override
+    public int hashCode()
+    {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ( ( filter == null) ? 0 : filter.hashCode() );
+        result = prime * result + ( ( operator == null) ? 0 : operator.hashCode() );
+        return result;
+    }
+
+    @Override
+    public boolean equals( Object object )
+    {
+        if ( this == object )
+        {
+            return true;
+        }
+        
+        if ( object == null )
+        {
+            return false;
+        }
+        
+        if ( getClass() != object.getClass() )
+        {
+            return false;
+        }
+        
+        QueryFilter other = (QueryFilter) object;
+        
+        if ( filter == null )
+        {
+            if ( other.filter != null )
+            {
+                return false;
+            }
+        }
+        else if ( !filter.equals( other.filter ) )
+        {
+            return false;
+        }
+        
+        if ( operator == null )
+        {
+            if ( other.operator != null )
+            {
+                return false;
+            }
+        }
+        else if ( !operator.equals( other.operator ) )
+        {
+            return false;
+        }
+        
+        return true;
+    }
+
     // -------------------------------------------------------------------------
     // Getters and setters
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryItem.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryItem.java	2014-04-04 11:54:42 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryItem.java	2014-04-07 16:50:00 +0000
@@ -89,8 +89,37 @@
     }
     
     // -------------------------------------------------------------------------
-    // toString
+    // hashCode, equals and toString
     // -------------------------------------------------------------------------
+    
+    @Override
+    public int hashCode()
+    {
+        return item.hashCode();
+    }
+
+    @Override
+    public boolean equals( Object object )
+    {
+        if ( this == object )
+        {
+            return true;
+        }
+        
+        if ( object == null )
+        {
+            return false;
+        }
+        
+        if ( getClass() != object.getClass() )
+        {
+            return false;
+        }
+        
+        final QueryItem other = (QueryItem) object;
+        
+        return item.equals( other.getItem() );
+    }
 
     @Override
     public String toString()

=== 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-04 17:20:41 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceQueryParams.java	2014-04-07 16:50:00 +0000
@@ -176,6 +176,26 @@
     }
 
     /**
+     * Returns a list of query items which appear more than once as attributes
+     * or filters.
+     */
+    public List<QueryItem> getDuplicateAttributesAndFilters()
+    {
+        Set<QueryItem> items = new HashSet<QueryItem>();
+        List<QueryItem> duplicates = new ArrayList<QueryItem>();
+        
+        for ( QueryItem item : getAttributesAndFilters() )
+        {
+            if ( !items.add( item ) )
+            {
+                duplicates.add( item );
+            }
+        }
+        
+        return duplicates;
+    }
+    
+    /**
      * Indicates whether this params specifies any attributes and/or filters.
      */
     public boolean hasAttributesOrFilters()

=== 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-04 17:35:02 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java	2014-04-07 16:50:00 +0000
@@ -290,6 +290,11 @@
             violation = "Program must be defined when program dates are specified";
         }
         
+        if ( !params.getDuplicateAttributesAndFilters().isEmpty() )
+        {
+            violation = "Attributes and filters cannot be specified more than once: " + params.getDuplicateAttributesAndFilters();
+        }
+        
         if ( violation != null )
         {
             log.warn( "Validation failed: " + violation );