← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20757: minor, add mergeWith to TEI

 

------------------------------------------------------------
revno: 20757
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-10-19 16:38:54 +0700
message:
  minor, add mergeWith to TEI
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstance.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/AddProgramAction.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/trackedentity/TrackedEntityInstance.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstance.java	2015-10-09 09:15:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstance.java	2015-10-19 09:38:54 +0000
@@ -36,6 +36,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.view.DetailedView;
 import org.hisp.dhis.common.view.ExportView;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -63,7 +65,7 @@
     private TrackedEntityInstance representative;
 
     private TrackedEntity trackedEntity;
-    
+
     private Boolean inactive = false;
 
     // -------------------------------------------------------------------------
@@ -177,4 +179,36 @@
     {
         this.inactive = inactive;
     }
+
+    @Override
+    public void mergeWith( IdentifiableObject other, MergeStrategy strategy )
+    {
+        super.mergeWith( other, strategy );
+
+        if ( other.getClass().isInstance( this ) )
+        {
+            TrackedEntityInstance trackedEntityInstance = (TrackedEntityInstance) other;
+
+            if ( strategy.isReplace() )
+            {
+                organisationUnit = trackedEntityInstance.getOrganisationUnit();
+                inactive = trackedEntityInstance.isInactive();
+                trackedEntity = trackedEntityInstance.getTrackedEntity();
+                representative = trackedEntityInstance.getRepresentative();
+            }
+            else if ( strategy.isMerge() )
+            {
+                organisationUnit = trackedEntityInstance.getOrganisationUnit() == null ? organisationUnit : trackedEntityInstance.getOrganisationUnit();
+                inactive = trackedEntityInstance.isInactive() == null ? inactive : trackedEntityInstance.isInactive();
+                trackedEntity = trackedEntityInstance.getTrackedEntity() == null ? trackedEntity : trackedEntityInstance.getTrackedEntity();
+                representative = trackedEntityInstance.getRepresentative() == null ? representative : trackedEntityInstance.getRepresentative();
+            }
+
+            attributeValues.clear();
+            attributeValues.addAll( trackedEntityInstance.getAttributeValues() );
+
+            programInstances.clear();
+            programInstances.addAll( trackedEntityInstance.getProgramInstances() );
+        }
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/AddProgramAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/AddProgramAction.java	2015-10-15 04:13:01 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/AddProgramAction.java	2015-10-19 09:38:54 +0000
@@ -326,8 +326,8 @@
 
             if ( ids[0].equals( TrackedEntityInstance.PREFIX_TRACKED_ENTITY_ATTRIBUTE ) )
             {
-                TrackedEntityAttribute attribute = trackedEntityAttributeService.getTrackedEntityAttribute( Integer
-                    .parseInt( ids[1] ) );
+                TrackedEntityAttribute attribute = trackedEntityAttributeService.getTrackedEntityAttribute(
+                    Integer.parseInt( ids[1] ) );
 
                 ProgramTrackedEntityAttribute programAttribute = new ProgramTrackedEntityAttribute( attribute,
                     personDisplayNames.get( index ), mandatory.get( index ), allowFutureDate.get( index ) );