← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20548: minor fixes in program/programStage mergeWith

 

------------------------------------------------------------
revno: 20548
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-10-07 10:23:23 +0700
message:
  minor fixes in program/programStage mergeWith
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStage.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/program/Program.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2015-10-05 17:45:17 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2015-10-07 03:23:23 +0000
@@ -28,11 +28,13 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonView;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import com.google.common.collect.Sets;
 import org.hisp.dhis.attribute.AttributeValue;
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.DxfNamespaces;
@@ -54,13 +56,10 @@
 import org.hisp.dhis.user.UserAuthorityGroup;
 import org.hisp.dhis.validation.ValidationCriteria;
 
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonView;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-import com.google.common.collect.Sets;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 /**
  * @author Abyot Asalefew
@@ -127,12 +126,12 @@
     private Set<AttributeValue> attributeValues = new HashSet<>();
 
     private DataEntryForm dataEntryForm;
-    
+
     /**
      * The CategoryCombo used for data attributes.
      */
     private DataElementCategoryCombo categoryCombo;
-    
+
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
@@ -157,25 +156,25 @@
         organisationUnits.add( organisationUnit );
         organisationUnit.getPrograms().add( this );
     }
-    
+
     public void removeOrganisationUnit( OrganisationUnit organisationUnit )
     {
         organisationUnits.remove( organisationUnit );
         organisationUnit.getPrograms().remove( this );
     }
-    
+
     public void updateOrganisationUnits( Set<OrganisationUnit> updates )
     {
         Set<OrganisationUnit> toRemove = Sets.difference( organisationUnits, updates );
         Set<OrganisationUnit> toAdd = Sets.difference( updates, organisationUnits );
-        
+
         toRemove.parallelStream().forEach( u -> u.getPrograms().remove( this ) );
         toAdd.parallelStream().forEach( u -> u.getPrograms().add( this ) );
-        
+
         organisationUnits.clear();
         organisationUnits.addAll( updates );
     }
-    
+
     /**
      * Returns the ProgramTrackedEntityAttribute of this Program which contains
      * the given TrackedEntityAttribute.
@@ -278,7 +277,7 @@
 
         return null;
     }
-    
+
     public boolean isSingleProgramStage()
     {
         return programStages != null && programStages.size() == 1;
@@ -393,7 +392,7 @@
     {
         this.programType = programType;
     }
-    
+
     @JsonProperty( "validationCriterias" )
     @JsonSerialize( contentAs = BaseIdentifiableObject.class )
     @JsonView( { DetailedView.class, ExportView.class } )
@@ -450,7 +449,7 @@
     {
         return programType.equals( ProgramType.WITHOUT_REGISTRATION );
     }
-    
+
     @JsonProperty
     @JsonSerialize( contentAs = BaseIdentifiableObject.class )
     @JsonView( { DetailedView.class, ExportView.class } )
@@ -654,7 +653,7 @@
     {
         this.dataEntryForm = dataEntryForm;
     }
-    
+
     @JsonProperty
     @JsonSerialize( as = BaseIdentifiableObject.class )
     @JsonView( { DetailedView.class, ExportView.class } )
@@ -668,7 +667,7 @@
     {
         this.categoryCombo = categoryCombo;
     }
-    
+
     /**
      * Indicates whether this program has a category combination which is different
      * from the default category combination.
@@ -677,7 +676,7 @@
     {
         return categoryCombo != null && !DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME.equals( categoryCombo.getName() );
     }
-    
+
     @Override
     public void mergeWith( IdentifiableObject other, MergeStrategy strategy )
     {
@@ -730,7 +729,12 @@
             organisationUnits.addAll( program.getOrganisationUnits() );
 
             programStages.clear();
-            programStages.addAll( program.getProgramStages() );
+
+            for ( ProgramStage programStage : program.getProgramStages() )
+            {
+                programStages.add( programStage );
+                programStage.setProgram( this );
+            }
 
             validationCriteria.clear();
             validationCriteria.addAll( program.getValidationCriteria() );

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStage.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStage.java	2015-10-06 09:33:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStage.java	2015-10-07 03:23:23 +0000
@@ -575,10 +575,20 @@
             }
 
             programStageDataElements.clear();
-            programStageDataElements.addAll( programStage.getProgramStageDataElements() );
+
+            for ( ProgramStageDataElement programStageDataElement : programStage.getProgramStageDataElements() )
+            {
+                programStageDataElements.add( programStageDataElement );
+                programStageDataElement.setProgramStage( this );
+            }
 
             programStageSections.clear();
-            programStageSections.addAll( programStage.getProgramStageSections() );
+
+            for ( ProgramStageSection programStageSection : programStage.getProgramStageSections() )
+            {
+                programStageSections.add( programStageSection );
+                programStageSection.setProgramStage( this );
+            }
 
             reminders.clear();
             reminders.addAll( programStage.getReminders() );