← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21536: add mergeWith to DataApprovalWorkflow

 

------------------------------------------------------------
revno: 21536
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-12-28 15:54:00 +0100
message:
  add mergeWith to DataApprovalWorkflow
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalWorkflow.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/dataapproval/DataApprovalWorkflow.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalWorkflow.java	2015-12-01 17:19:15 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalWorkflow.java	2015-12-28 14:54:00 +0000
@@ -37,6 +37,8 @@
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.MergeStrategy;
 import org.hisp.dhis.common.adapter.JacksonPeriodTypeDeserializer;
 import org.hisp.dhis.common.adapter.JacksonPeriodTypeSerializer;
 import org.hisp.dhis.common.annotation.Scanned;
@@ -54,7 +56,7 @@
 /**
  * Identifies types of data to be approved, and the set of approval levels
  * by which it is approved.
- *
+ * <p>
  * The types of data to be approved are identified by data sets (for aggregate
  * data) and or programs (for event/tracker data) that are related to a
  * workflow.
@@ -84,12 +86,12 @@
     {
     }
 
-    public DataApprovalWorkflow(String name)
+    public DataApprovalWorkflow( String name )
     {
         this.name = name;
     }
 
-    public DataApprovalWorkflow(String name, PeriodType periodType, Set<DataApprovalLevel> levels)
+    public DataApprovalWorkflow( String name, PeriodType periodType, Set<DataApprovalLevel> levels )
     {
         this.name = name;
         this.periodType = periodType;
@@ -150,4 +152,27 @@
     {
         this.levels = levels;
     }
-}
+
+    @Override
+    public void mergeWith( IdentifiableObject other, MergeStrategy strategy )
+    {
+        super.mergeWith( other, strategy );
+
+        if ( other.getClass().isInstance( this ) )
+        {
+            DataApprovalWorkflow dataApprovalWorkflow = (DataApprovalWorkflow) other;
+
+            if ( strategy.isReplace() )
+            {
+                periodType = dataApprovalWorkflow.getPeriodType();
+            }
+            else if ( strategy.isMerge() )
+            {
+                periodType = dataApprovalWorkflow.getPeriodType() == null ? periodType : dataApprovalWorkflow.getPeriodType();
+            }
+
+            levels.clear();
+            levels.addAll( dataApprovalWorkflow.getLevels() );
+        }
+    }
+}
\ No newline at end of file