← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18218: Event analytics, impl better dimension value type info in response

 

------------------------------------------------------------
revno: 18218
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-02-10 19:40:27 +0100
message:
  Event analytics, impl better dimension value type info in response
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/util/ObjectUtils.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryItem.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-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.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/QueryItem.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryItem.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryItem.java	2015-02-10 18:40:27 +0000
@@ -32,6 +32,8 @@
 import java.util.Collection;
 import java.util.List;
 
+import org.hisp.dhis.util.ObjectUtils;
+
 /**
  * Class which encapsulates a query parameter and value. Operator and filter 
  * are inherited from QueryFilter.
@@ -44,7 +46,7 @@
 
     private List<QueryFilter> filters = new ArrayList<>();
     
-    private boolean numeric;
+    private String valueType;
     
     private String optionSet;
 
@@ -57,17 +59,17 @@
         this.item = item;
     }
 
-    public QueryItem( NameableObject item, boolean numeric, String optionSet )
+    public QueryItem( NameableObject item, String valueType, String optionSet )
     {
         this.item = item;
-        this.numeric = numeric;
+        this.valueType = valueType;
         this.optionSet = optionSet;
     }
     
-    public QueryItem( NameableObject item, QueryOperator operator, String filter, boolean numeric, String optionSet )
+    public QueryItem( NameableObject item, QueryOperator operator, String filter, String valueType, String optionSet )
     {
         this.item = item;
-        this.numeric = numeric;
+        this.valueType = valueType;
         this.optionSet = optionSet;
         
         if ( operator != null && filter != null )
@@ -76,11 +78,11 @@
         }
     }
     
-    public QueryItem( NameableObject item, List<QueryFilter> filters, boolean numeric, String optionSet )
+    public QueryItem( NameableObject item, List<QueryFilter> filters, String valueType, String optionSet )
     {
         this.item = item;
         this.filters = filters;
-        this.numeric = numeric;
+        this.valueType = valueType;
         this.optionSet = optionSet;
     }
     
@@ -95,7 +97,12 @@
     
     public String getTypeAsString()
     {
-        return isNumeric() ? Double.class.getName() : String.class.getName();
+        return ObjectUtils.VALUE_TYPE_JAVA_CLASS_MAP.get( valueType ).getName();
+    }
+    
+    public boolean isNumeric()
+    {
+        return Double.class.equals( getTypeAsString() );
     }
     
     public boolean hasFilter()
@@ -109,7 +116,7 @@
         
         for ( NameableObject object : objects )
         {
-            queryItems.add( new QueryItem( object, false, null ) );
+            queryItems.add( new QueryItem( object, null, null ) );
         }
         
         return queryItems;
@@ -151,7 +158,7 @@
     @Override
     public String toString()
     {
-        return "[Item: " + item + ", filters: " + filters + ", numeric: " + numeric + ", optionSet: " + optionSet + "]";
+        return "[Item: " + item + ", filters: " + filters + ", value type: " + valueType + ", optionSet: " + optionSet + "]";
     }
     
     // -------------------------------------------------------------------------
@@ -178,14 +185,14 @@
         this.filters = filters;
     }
 
-    public boolean isNumeric()
+    public String getValueType()
     {
-        return numeric;
+        return valueType;
     }
 
-    public void setNumeric( boolean numeric )
+    public void setValueType( String valueType )
     {
-        this.numeric = numeric;
+        this.valueType = valueType;
     }
 
     public String getOptionSet()

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/util/ObjectUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/util/ObjectUtils.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/util/ObjectUtils.java	2015-02-10 18:40:27 +0000
@@ -0,0 +1,53 @@
+package org.hisp.dhis.util;
+
+/*
+ * Copyright (c) 2004-2015, 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 java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
+
+public class ObjectUtils
+{
+    public static final Map<String, Class<?>> VALUE_TYPE_JAVA_CLASS_MAP = new HashMap<String, Class<?>>() { {
+        put( DataElement.VALUE_TYPE_INT, Double.class );
+        put( DataElement.VALUE_TYPE_STRING, String.class );
+        put( DataElement.VALUE_TYPE_BOOL, Boolean.class );
+        put( DataElement.VALUE_TYPE_TRUE_ONLY, Boolean.class );
+        put( DataElement.VALUE_TYPE_DATE, Date.class );
+        put( DataElement.VALUE_TYPE_UNIT_INTERVAL, Double.class );
+        put( DataElement.VALUE_TYPE_PERCENTAGE, Double.class );
+        put( TrackedEntityAttribute.TYPE_NUMBER, Double.class );
+        put( TrackedEntityAttribute.TYPE_LETTER, String.class );
+        put( TrackedEntityAttribute.TYPE_OPTION_SET, String.class );
+        put( TrackedEntityAttribute.TYPE_EMAIL, String.class );
+    } };
+}

=== 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	2015-02-05 18:58:22 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java	2015-02-10 18:40:27 +0000
@@ -649,14 +649,14 @@
 
         if ( de != null ) //TODO check if part of program
         {
-            return new QueryItem( de, de.isNumericType(), de.hasOptionSet() ? de.getOptionSet().getUid() : null );
+            return new QueryItem( de, de.getType(), de.hasOptionSet() ? de.getOptionSet().getUid() : null );
         }
 
         TrackedEntityAttribute at = attributeService.getTrackedEntityAttribute( item );
 
         if ( at != null )
         {
-            return new QueryItem( at, at.isNumericType(), at.hasOptionSet() ? at.getOptionSet().getUid() : null );
+            return new QueryItem( at, at.getValueType(), at.hasOptionSet() ? at.getOptionSet().getUid() : null );
         }
 
         throw new IllegalQueryException( "Item identifier does not reference any item part of the program: " + item );

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java	2015-02-10 18:40:27 +0000
@@ -580,7 +580,7 @@
 
         TrackedEntityInstanceQueryParams params = new TrackedEntityInstanceQueryParams();
 
-        QueryItem queryItem = new QueryItem( attribute, QueryOperator.EQ, value, attribute.isNumericType(), null );
+        QueryItem queryItem = new QueryItem( attribute, QueryOperator.EQ, value, attribute.getValueType(), null );
         params.addAttribute( queryItem );
 
         if ( attribute.getOrgunitScope() && attribute.getProgramScope() )

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java	2015-02-10 18:40:27 +0000
@@ -353,7 +353,7 @@
 
         TrackedEntityInstanceQueryParams params = new TrackedEntityInstanceQueryParams();
 
-        QueryItem queryItem = new QueryItem( attribute, QueryOperator.EQ, value, attribute.isNumericType(), null );
+        QueryItem queryItem = new QueryItem( attribute, QueryOperator.EQ, value, attribute.getValueType(), null );
         params.addAttribute( queryItem );
 
         if ( attribute.getOrgunitScope() )

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java	2015-02-09 14:06:32 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java	2015-02-10 18:40:27 +0000
@@ -1738,7 +1738,7 @@
             else
             {
                 TrackedEntityAttribute at = attributeService.getTrackedEntityAttributeByName( split[0] );
-                QueryItem queryItem = new QueryItem( at, at.isNumericType(), null );
+                QueryItem queryItem = new QueryItem( at, at.getValueType(), null );
                 QueryOperator operator = QueryOperator.fromString( split[1] );
                 queryItem.getFilters().add( new QueryFilter( operator, split[2] ) );
                 param.getFilters().add( queryItem );

=== 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	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java	2015-02-10 18:40:27 +0000
@@ -492,7 +492,7 @@
             throw new IllegalQueryException( "Attribute does not exist: " + item );
         }
         
-        return new QueryItem( at, at.isNumericType(), at.hasOptionSet() ? at.getOptionSet().getUid() : null );
+        return new QueryItem( at, at.getValueType(), at.hasOptionSet() ? at.getOptionSet().getUid() : null );
     }
     
     /**