← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22201: Data element will prefer data sets with a data approval workflow when determining which data set ...

 

------------------------------------------------------------
revno: 22201
committer: jimgrace@xxxxxxxxx
branch nick: dhis2
timestamp: Tue 2016-03-08 16:17:58 -0500
message:
  Data element will prefer data sets with a data approval workflow when determining which data set it is a member of in the situation where it has multiple memberships.
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/comparator/DataSetApprovalFrequencyComparator.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataset/comparator/DataSetApprovalFrequencyComparatorTest.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/DataElementResourceTable.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.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	2016-03-03 15:12:09 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java	2016-03-08 21:17:58 +0000
@@ -46,6 +46,7 @@
 import org.hisp.dhis.common.view.DimensionalView;
 import org.hisp.dhis.common.view.ExportView;
 import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.comparator.DataSetApprovalFrequencyComparator;
 import org.hisp.dhis.dataset.comparator.DataSetFrequencyComparator;
 import org.hisp.dhis.option.OptionSet;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -233,6 +234,13 @@
         return !list.isEmpty() ? list.get( 0 ) : null;
     }
 
+    public DataSet getApprovalDataSet()
+    {
+        List<DataSet> list = new ArrayList<>( dataSets );
+        Collections.sort( list, DataSetApprovalFrequencyComparator.INSTANCE );
+        return !list.isEmpty() ? list.get( 0 ) : null;
+    }
+    
     /**
      * Returns the category combinations associated with the data sets of this
      * data element.

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/comparator/DataSetApprovalFrequencyComparator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/comparator/DataSetApprovalFrequencyComparator.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/comparator/DataSetApprovalFrequencyComparator.java	2016-03-08 21:17:58 +0000
@@ -0,0 +1,72 @@
+package org.hisp.dhis.dataset.comparator;
+
+/*
+ * 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.Comparator;
+
+import org.hisp.dhis.dataset.DataSet;
+
+public class DataSetApprovalFrequencyComparator
+    implements Comparator<DataSet>
+{
+    public static final DataSetApprovalFrequencyComparator INSTANCE = new DataSetApprovalFrequencyComparator();
+    
+    @Override
+    public int compare( DataSet d1, DataSet d2 )
+    {
+        if ( d1 == null )
+        {
+            return -1;
+        }
+        
+        if ( d2 == null )
+        {
+            return 1;
+        }
+        
+        if ( d1.getWorkflow() != null && d2.getWorkflow() == null)
+        {
+            return -1;
+        }
+        
+        if ( d1.getWorkflow() == null && d2.getWorkflow() != null )
+        {
+            return 1;
+        }
+        
+        int frequencyOrder = Integer.valueOf( d1.getPeriodType().getFrequencyOrder() ).compareTo( Integer.valueOf( d2.getPeriodType().getFrequencyOrder() ) );
+        
+        if ( frequencyOrder != 0 )
+        {
+            return frequencyOrder;
+        }
+        
+        return d1.compareTo( d2 );
+    }
+}

=== added file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataset/comparator/DataSetApprovalFrequencyComparatorTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataset/comparator/DataSetApprovalFrequencyComparatorTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataset/comparator/DataSetApprovalFrequencyComparatorTest.java	2016-03-08 21:17:58 +0000
@@ -0,0 +1,103 @@
+package org.hisp.dhis.dataset.comparator;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.hisp.dhis.dataapproval.DataApprovalWorkflow;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.period.MonthlyPeriodType;
+import org.hisp.dhis.period.QuarterlyPeriodType;
+import org.hisp.dhis.period.YearlyPeriodType;
+import org.junit.Test;
+
+import com.google.common.collect.Lists;
+
+public class DataSetApprovalFrequencyComparatorTest
+{
+    @Test
+    public void testA()
+    {
+        DataSet dsA = new DataSet( "DataSetA", new YearlyPeriodType() );
+        DataSet dsB = new DataSet( "DataSetB", new YearlyPeriodType() );
+        DataSet dsC = new DataSet( "DataSetC", new MonthlyPeriodType() );
+        DataSet dsD = new DataSet( "DataSetD", new QuarterlyPeriodType() );
+
+        DataApprovalWorkflow workflow = new DataApprovalWorkflow( "Workflow A", new QuarterlyPeriodType(), null );
+
+        dsA.setWorkflow( workflow );
+        dsD.setWorkflow( workflow );
+        
+        List<DataSet> list = Lists.newArrayList( dsA, dsC, dsB, dsD );
+        
+        Collections.sort( list, DataSetApprovalFrequencyComparator.INSTANCE );
+
+        assertEquals( dsD, list.get( 0 ) );
+        assertEquals( dsA, list.get( 1 ) );
+        assertEquals( dsC, list.get( 2 ) );
+        assertEquals( dsB, list.get( 3 ) );
+    }
+    
+    @Test
+    public void testB()
+    {
+        DataSet dsA = new DataSet( "EA: Expenditures Site Level", new QuarterlyPeriodType() );
+        DataSet dsB = new DataSet( "MER Results: Facility Based", new QuarterlyPeriodType() );
+        DataSet dsC = new DataSet( "MER Results: Facility Based - DoD ONLY", new QuarterlyPeriodType() );
+
+        DataApprovalWorkflow workflow = new DataApprovalWorkflow( "Workflow A", new QuarterlyPeriodType(), null );
+
+        dsB.setWorkflow( workflow );
+        
+        List<DataSet> list = Lists.newArrayList( dsB, dsC, dsA );
+        
+        Collections.sort( list, DataSetApprovalFrequencyComparator.INSTANCE );
+
+        assertEquals( dsB, list.get( 0 ) );
+        assertEquals( dsA, list.get( 1 ) );
+        assertEquals( dsC, list.get( 2 ) );
+    }
+    
+    @Test
+    public void testC()
+    {
+        DataSet dsA = new DataSet( "DataSetA", new YearlyPeriodType() );
+        DataSet dsB = new DataSet( "DataSetB", new YearlyPeriodType() );
+        DataSet dsC = new DataSet( "DataSetC", new MonthlyPeriodType() );
+        DataSet dsD = new DataSet( "DataSetD", new QuarterlyPeriodType() );
+
+        DataApprovalWorkflow workflow = new DataApprovalWorkflow( "Workflow A", new QuarterlyPeriodType(), null );
+
+        dsA.setWorkflow( workflow );
+        dsD.setWorkflow( workflow );
+        
+        DataElement deA = new DataElement();
+        deA.addDataSet( dsA );
+        deA.addDataSet( dsB );
+        deA.addDataSet( dsC );
+        deA.addDataSet( dsD );
+        
+        assertEquals( dsD, deA.getApprovalDataSet() );
+    }
+    
+    @Test
+    public void testD()
+    {
+        DataSet dsA = new DataSet( "EA: Expenditures Site Level", new QuarterlyPeriodType() );
+        DataSet dsB = new DataSet( "MER Results: Facility Based", new QuarterlyPeriodType() );
+        DataSet dsC = new DataSet( "MER Results: Facility Based - DoD ONLY", new QuarterlyPeriodType() );
+
+        DataApprovalWorkflow workflow = new DataApprovalWorkflow( "Workflow A", new QuarterlyPeriodType(), null );
+
+        dsB.setWorkflow( workflow );
+
+        DataElement deA = new DataElement();
+        deA.addDataSet( dsA );
+        deA.addDataSet( dsB );
+        deA.addDataSet( dsC );
+        
+        assertEquals( dsB, deA.getApprovalDataSet() );        
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/DataElementResourceTable.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/DataElementResourceTable.java	2016-01-05 14:55:10 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/DataElementResourceTable.java	2016-03-08 21:17:58 +0000
@@ -91,7 +91,7 @@
         {
             List<Object> values = new ArrayList<>();
 
-            final DataSet dataSet = dataElement.getDataSet();
+            final DataSet dataSet = dataElement.getApprovalDataSet();
             final PeriodType periodType = dataElement.getPeriodType();
 
             // -----------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java	2016-03-08 17:02:03 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java	2016-03-08 21:17:58 +0000
@@ -431,7 +431,7 @@
             return true;
         }
 
-        DataSet dataSet = dataElement.getDataSet();
+        DataSet dataSet = dataElement.getApprovalDataSet();
 
         if ( dataSet == null || dataSet.getWorkflow() == null )
         {