← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21570: Program, using streams and filters

 

------------------------------------------------------------
revno: 21570
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2016-01-04 11:49:18 +0100
message:
  Program, using streams and filters
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/caseaggregation/GetTrackedEntityDataElementsAction.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/program/Program.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2016-01-04 10:49:18 +0000
@@ -61,6 +61,7 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 /**
  * @author Abyot Asalefew
@@ -206,7 +207,7 @@
     /**
      * Returns all data elements which are part of the stages of this program.
      */
-    public Set<DataElement> getAllDataElements()
+    public Set<DataElement> getDataElements()
     {
         Set<DataElement> elements = new HashSet<>();
 
@@ -224,17 +225,7 @@
      */
     public Set<DataElement> getDataElementsWithLegendSet()
     {
-        Set<DataElement> elements = new HashSet<>();
-
-        for ( DataElement element : getAllDataElements() )
-        {
-            if ( element != null && element.hasLegendSet() && element.isNumericType() )
-            {
-                elements.add( element );
-            }
-        }
-
-        return elements;
+        return getDataElements().stream().filter( e -> e.hasLegendSet() && e.isNumericType() ).collect( Collectors.toSet() );
     }
 
     /**
@@ -243,33 +234,25 @@
      */
     public List<TrackedEntityAttribute> getTrackedEntityAttributes()
     {
-        List<TrackedEntityAttribute> attributes = new ArrayList<>();
-
-        for ( ProgramTrackedEntityAttribute programAttribute : programAttributes )
-        {
-            attributes.add( programAttribute.getAttribute() );
-        }
-
-        return attributes;
+        return programAttributes.stream().map( p -> p.getAttribute() ).collect( Collectors.toList() );
+    }
+
+    /**
+     * Returns non-confidential TrackedEntityAttributes from ProgramTrackedEntityAttributes. Use
+     * getAttributes() to access the persisted attribute list.
+     */
+    public List<TrackedEntityAttribute> getNonConfidentialTrackedEntityAttributes()
+    {
+        return programAttributes.stream().map( p -> p.getAttribute() ).filter( a -> a.isConfidential() ).collect( Collectors.toList() );
     }
 
     /**
      * Returns TrackedEntityAttributes from ProgramTrackedEntityAttributes which
      * have a legend set and is of numeric value type.
      */
-    public List<TrackedEntityAttribute> getTrackedEntityAttributesWithLegendSet()
+    public List<TrackedEntityAttribute> getNonConfidentialTrackedEntityAttributesWithLegendSet()
     {
-        List<TrackedEntityAttribute> attributes = new ArrayList<>();
-
-        for ( TrackedEntityAttribute attribute : getTrackedEntityAttributes() )
-        {
-            if ( attribute != null && attribute.hasLegendSet() && attribute.isNumericType() )
-            {
-                attributes.add( attribute );
-            }
-        }
-
-        return attributes;
+        return getTrackedEntityAttributes().stream().filter( a -> a.isConfidential() && a.hasLegendSet() && a.isNumericType() ).collect( Collectors.toList() );
     }
 
     public ProgramStage getProgramStageByStage( int stage )

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java	2016-01-04 10:49:18 +0000
@@ -1,5 +1,7 @@
 package org.hisp.dhis.trackedentity;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
 /*
  * Copyright (c) 2004-2016, University of Oslo
  * All rights reserved.
@@ -122,6 +124,15 @@
     {
         return valueType.isDate();
     }
+    
+    /**
+     * Indicates whether this attribute has confidential information.
+     */
+    @JsonIgnore
+    public boolean isConfidential()
+    {
+        return confidential != null && confidential;
+    }
 
     /**
      * Indicates whether this attribute has an option set.

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java	2016-01-04 10:49:18 +0000
@@ -259,7 +259,7 @@
             columns.add( col );
         }
 
-        for ( DataElement dataElement : table.getProgram().getAllDataElements() )
+        for ( DataElement dataElement : table.getProgram().getDataElements() )
         {
             ValueType valueType = dataElement.getValueType();
             String dataType = getColumnType( valueType );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramService.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramService.java	2016-01-04 10:49:18 +0000
@@ -289,7 +289,7 @@
             return programDataElements;
         }
         
-        for ( DataElement element : program.getAllDataElements() )
+        for ( DataElement element : program.getDataElements() )
         {
             programDataElements.add( new ProgramDataElement( program, element ) );
         }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java	2016-01-04 10:49:18 +0000
@@ -337,7 +337,7 @@
         {
             Map<String, String> dataElements = new HashMap<>();
 
-            for ( DataElement de : program.getAllDataElements() )
+            for ( DataElement de : program.getDataElements() )
             {
                 dataElements.put( de.getUid(), de.getDisplayName() );
             }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/caseaggregation/GetTrackedEntityDataElementsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/caseaggregation/GetTrackedEntityDataElementsAction.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/caseaggregation/GetTrackedEntityDataElementsAction.java	2016-01-04 10:49:18 +0000
@@ -122,7 +122,7 @@
         {
             Program program = programService.getProgram( programId );
             
-            dataElements = new ArrayList<>( program.getAllDataElements() );
+            dataElements = new ArrayList<>( program.getDataElements() );
         }
         
         Collections.sort( dataElements, IdentifiableObjectNameComparator.INSTANCE );