← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20770: Program indicator UI, attribute filter

 

------------------------------------------------------------
revno: 20770
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-10-19 16:29:04 +0200
message:
  Program indicator UI, attribute filter
added:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/predicate/
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/predicate/ArithmeticValueTypeTrackedEntityAttributeFilter.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObject.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programindicator/GetProgramIndicatorAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programIndicatorForm.vm


--
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	2015-09-21 13:36:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObject.java	2015-10-19 14:29:04 +0000
@@ -31,6 +31,7 @@
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.hisp.dhis.analytics.AggregationType;
 import org.hisp.dhis.dataelement.CategoryOptionGroup;
@@ -46,6 +47,7 @@
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Sets;
 
 /**
 * @author Lars Helge Overland
@@ -98,7 +100,13 @@
         put( DataElementGroupSet.class, DataElementGroup.class ).
         put( OrganisationUnitGroupSet.class, OrganisationUnitGroup.class ).
         put( CategoryOptionGroupSet.class, CategoryOptionGroup.class ).build();
-        
+    
+    Set<ValueType> ARITHMETIC_VALUE_TYPES = Sets.newHashSet(
+        ValueType.BOOLEAN, ValueType.TRUE_ONLY, ValueType.NUMBER, ValueType.INTEGER, 
+        ValueType.INTEGER_POSITIVE, ValueType.INTEGER_NEGATIVE, ValueType.INTEGER_ZERO_OR_POSITIVE, 
+        ValueType.UNIT_INTERVAL, ValueType.PERCENTAGE
+    );
+    
     /**
      * Gets the dimension identifier.
      */

=== added directory 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/predicate'
=== added file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/predicate/ArithmeticValueTypeTrackedEntityAttributeFilter.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/predicate/ArithmeticValueTypeTrackedEntityAttributeFilter.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/predicate/ArithmeticValueTypeTrackedEntityAttributeFilter.java	2015-10-19 14:29:04 +0000
@@ -0,0 +1,50 @@
+package org.hisp.dhis.system.predicate;
+
+/*
+ * 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.function.Predicate;
+
+import org.hisp.dhis.common.DimensionalObject;
+import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
+
+/**
+* @author Lars Helge Overland
+*/
+public class ArithmeticValueTypeTrackedEntityAttributeFilter
+    implements Predicate<TrackedEntityAttribute>
+{
+    public static final ArithmeticValueTypeTrackedEntityAttributeFilter INSTANCE = new ArithmeticValueTypeTrackedEntityAttributeFilter();
+    
+    @Override
+    public boolean test( TrackedEntityAttribute attribute )
+    {
+        return attribute != null && attribute.getValueType() != null && 
+            DimensionalObject.ARITHMETIC_VALUE_TYPES.contains( attribute.getValueType() );
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programindicator/GetProgramIndicatorAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programindicator/GetProgramIndicatorAction.java	2015-10-19 13:43:13 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programindicator/GetProgramIndicatorAction.java	2015-10-19 14:29:04 +0000
@@ -31,17 +31,16 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.stream.Collectors;
 
-import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
 import org.hisp.dhis.constant.Constant;
 import org.hisp.dhis.constant.ConstantService;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramIndicator;
 import org.hisp.dhis.program.ProgramIndicatorService;
 import org.hisp.dhis.program.ProgramService;
-import org.hisp.dhis.system.filter.AggregatableTrackedEntityAttributeValueFilter;
+import org.hisp.dhis.system.predicate.ArithmeticValueTypeTrackedEntityAttributeFilter;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
-import org.hisp.dhis.commons.filter.FilterUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import com.opensymphony.xwork2.Action;
@@ -122,13 +121,13 @@
         return filter;
     }
 
-    private List<TrackedEntityAttribute> attributes = new ArrayList<>();
-    
-    public List<TrackedEntityAttribute> getAttributes()
+    private List<TrackedEntityAttribute> expressionAttributes = new ArrayList<>();
+        
+    public List<TrackedEntityAttribute> getExpressionAttributes()
     {
-        return attributes;
+        return expressionAttributes;
     }
-    
+
     private List<Constant> constants = new ArrayList<>();
 
     public List<Constant> getConstants()
@@ -150,21 +149,21 @@
             program = programIndicator.getProgram();
             expressionDescription = programIndicatorService.getExpressionDescription( programIndicator.getExpression() );
             filterDescription = programIndicatorService.getExpressionDescription( programIndicator.getFilter() );
-            filter = programIndicatorService.getExpressionDescription( programIndicator.getFilter() );
-            attributes = new ArrayList<>( program.getTrackedEntityAttributes() );
+            filter = programIndicatorService.getExpressionDescription( programIndicator.getFilter() );            
         }
         else if ( programId != null )
         {            
             program = programService.getProgram( programId );
-            attributes = new ArrayList<>( program.getTrackedEntityAttributes() );
         }
         
+        expressionAttributes = new ArrayList<>( program.getTrackedEntityAttributes() );
         constants = new ArrayList<>( constantService.getAllConstants() );
 
-        FilterUtils.filter( attributes, AggregatableTrackedEntityAttributeValueFilter.INSTANCE );
-        Collections.sort( attributes, IdentifiableObjectNameComparator.INSTANCE );
-        Collections.sort( constants, IdentifiableObjectNameComparator.INSTANCE );
+        expressionAttributes = expressionAttributes.stream().filter( ArithmeticValueTypeTrackedEntityAttributeFilter.INSTANCE ).collect( Collectors.toList() );
         
+        Collections.sort( expressionAttributes );
+        Collections.sort( constants );
+                
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programIndicatorForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programIndicatorForm.vm	2015-09-18 12:51:09 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programIndicatorForm.vm	2015-10-19 14:29:04 +0000
@@ -56,7 +56,7 @@
 		        <tr>
 					<td>
 						<select multiple id="expression-attributes" name="expression-attributes" size="7" style="width:100%" ondblclick="insertAttribute('expression');">
-							#foreach( $programAttribute in $attributes )
+							#foreach( $programAttribute in $expressionAttributes )
 								<option value='$programAttribute.uid'>$encoder.htmlEncode($programAttribute.displayName)</option>
 							#end
 						</select>