← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20464: minor fixes, use lambda in enrollment-service

 

------------------------------------------------------------
revno: 20464
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-10-02 15:39:24 +0700
message:
  minor fixes, use lambda in enrollment-service
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.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-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-09-30 08:57:38 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java	2015-10-02 08:39:24 +0000
@@ -444,8 +444,8 @@
         List<ImportConflict> importConflicts = new ArrayList<>();
 
         Program program = getProgram( enrollment.getProgram() );
-        org.hisp.dhis.trackedentity.TrackedEntityInstance trackedEntityInstance = teiService
-            .getTrackedEntityInstance( enrollment.getTrackedEntityInstance() );
+        org.hisp.dhis.trackedentity.TrackedEntityInstance trackedEntityInstance = teiService.getTrackedEntityInstance(
+            enrollment.getTrackedEntityInstance() );
 
         Map<TrackedEntityAttribute, Boolean> mandatoryMap = Maps.newHashMap();
         Map<String, String> attributeValueMap = Maps.newHashMap();
@@ -455,14 +455,10 @@
             mandatoryMap.put( programTrackedEntityAttribute.getAttribute(), programTrackedEntityAttribute.isMandatory() );
         }
 
-        for ( TrackedEntityAttributeValue value : trackedEntityInstance.getAttributeValues() )
-        {
-            // ignore attributes which do not belong to this program
-            if ( mandatoryMap.containsKey( value.getAttribute() ) )
-            {
-                attributeValueMap.put( value.getAttribute().getUid(), value.getValue() );
-            }
-        }
+        // ignore attributes which do not belong to this program
+        trackedEntityInstance.getAttributeValues().stream()
+            .filter( value -> mandatoryMap.containsKey( value.getAttribute() ) )
+            .forEach( value -> attributeValueMap.put( value.getAttribute().getUid(), value.getValue() ) );
 
         for ( Attribute attribute : enrollment.getAttributes() )
         {
@@ -470,8 +466,7 @@
             importConflicts.addAll( validateAttributeType( attribute ) );
         }
 
-        TrackedEntityInstance instance = trackedEntityInstanceService.getTrackedEntityInstance( enrollment
-            .getTrackedEntityInstance() );
+        TrackedEntityInstance instance = trackedEntityInstanceService.getTrackedEntityInstance( enrollment.getTrackedEntityInstance() );
 
         for ( TrackedEntityAttribute trackedEntityAttribute : mandatoryMap.keySet() )
         {
@@ -536,18 +531,16 @@
             attributeValueMap.put( attribute.getAttribute(), attribute.getValue() );
         }
 
-        for ( TrackedEntityAttributeValue value : trackedEntityInstance.getAttributeValues() )
-        {
-            if ( attributeValueMap.containsKey( value.getAttribute().getUid() ) )
-            {
+        trackedEntityInstance.getAttributeValues().stream()
+            .filter( value -> attributeValueMap.containsKey( value.getAttribute().getUid() ) )
+            .forEach( value -> {
                 String newValue = attributeValueMap.get( value.getAttribute().getUid() );
                 value.setValue( newValue );
 
                 trackedEntityAttributeValueService.updateTrackedEntityAttributeValue( value );
 
                 attributeValueMap.remove( value.getAttribute().getUid() );
-            }
-        }
+            } );
 
         for ( String key : attributeValueMap.keySet() )
         {