← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21531: Data value import, fixed bug with check for open future periods

 

------------------------------------------------------------
revno: 21531
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-12-28 12:17:59 +0100
message:
  Data value import, fixed bug with check for open future periods
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataelement/DataElementTest.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/dataelement/DataElement.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java	2015-12-01 19:58:55 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java	2015-12-28 11:17:59 +0000
@@ -58,7 +58,6 @@
 import org.hisp.dhis.schema.PropertyType;
 import org.hisp.dhis.schema.annotation.Property;
 import org.hisp.dhis.schema.annotation.PropertyRange;
-import org.hisp.dhis.util.ObjectUtils;
 import org.joda.time.DateTime;
 
 import com.fasterxml.jackson.annotation.JsonProperty;
@@ -331,14 +330,14 @@
      */
     public int getOpenFuturePeriods()
     {
-        Set<Integer> openPeriods = new HashSet<>();
+        int maxOpenPeriods = 0;
 
         for ( DataSet dataSet : dataSets )
-        {
-            openPeriods.add( dataSet.getOpenFuturePeriods() );
+        {            
+            maxOpenPeriods = Math.max( maxOpenPeriods, dataSet.getOpenFuturePeriods() );
         }
 
-        return ObjectUtils.firstNonNull( Collections.max( openPeriods ), 0 );
+        return maxOpenPeriods;
     }
 
     /**

=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataelement/DataElementTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataelement/DataElementTest.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataelement/DataElementTest.java	2015-12-28 11:17:59 +0000
@@ -45,7 +45,7 @@
 public class DataElementTest
 {
     @Test
-    public void getPeriodType()
+    public void testGetPeriodType()
     {
         PeriodType periodType = new MonthlyPeriodType();
         
@@ -63,7 +63,7 @@
     }
 
     @Test
-    public void periodTypeIsValid()
+    public void testPeriodTypeIsValid()
     {
         DataElement element = new DataElement();
         
@@ -80,4 +80,26 @@
         
         assertFalse( element.periodTypeIsValid() );
     }
+    
+    @Test
+    public void testGetOpenFuturePeriods()
+    {
+        DataElement deA = new DataElement( "A" );
+        
+        assertEquals( 0, deA.getOpenFuturePeriods() );
+        
+        DataSet dsA = new DataSet( "A" );
+        DataSet dsB = new DataSet( "B" );
+        
+        dsA.setOpenFuturePeriods( 0 );
+        dsB.setOpenFuturePeriods( 3 );
+        
+        dsA.addDataElement( deA );        
+        
+        assertEquals( 0, deA.getOpenFuturePeriods() );
+        
+        dsB.addDataElement( deA );
+        
+        assertEquals( 3, deA.getOpenFuturePeriods() );
+    }
 }