=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java 2012-03-27 17:38:48 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java 2012-04-10 21:41:34 +0000 @@ -37,6 +37,7 @@ import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.BaseNameableObject; import org.hisp.dhis.common.Dxf2Namespace; +import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.adapter.JacksonPeriodTypeDeserializer; import org.hisp.dhis.common.adapter.JacksonPeriodTypeSerializer; import org.hisp.dhis.common.view.DetailedView; @@ -223,6 +224,18 @@ } } + public void addIndicator( Indicator indicator ) + { + indicators.add( indicator ); + indicator.getDataSets().add( this ); + } + + public void removeIndicator( Indicator indicator ) + { + indicators.remove( indicator ); + indicator.getDataSets().remove( this ); + } + public boolean hasDataEntryForm() { return dataEntryForm != null; @@ -457,4 +470,52 @@ { this.expiryDays = expiryDays; } + + @Override + public void mergeWith( IdentifiableObject other ) + { + super.mergeWith( other ); + + if ( other.getClass().isInstance( this ) ) + { + DataSet dataSet = (DataSet) other; + + periodType = periodType != null ? periodType : dataSet.getPeriodType(); + sortOrder = sortOrder != null ? sortOrder : dataSet.getSortOrder(); + mobile = dataSet.isMobile(); + dataEntryForm = dataEntryForm != null ? dataEntryForm : dataSet.getDataEntryForm(); + version = version != null ? version : dataSet.getVersion(); + expiryDays = dataSet.getExpiryDays(); + + for ( DataElement dataElement : dataSet.getDataElements() ) + { + addDataElement( dataElement ); + } + + for ( Indicator indicator : dataSet.getIndicators() ) + { + addIndicator( indicator ); + } + + for ( DataElementOperand dataElementOperand : dataSet.getCompulsoryDataElementOperands() ) + { + compulsoryDataElementOperands.add( dataElementOperand ); + } + + for ( OrganisationUnit organisationUnit : dataSet.getSources() ) + { + addOrganisationUnit( organisationUnit ); + } + + for ( Section section : dataSet.getSections() ) + { + sections.add( section ); + + if ( section.getDataSet() == null ) + { + section.setDataSet( this ); + } + } + } + } } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java 2012-03-27 17:38:48 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java 2012-04-10 21:41:34 +0000 @@ -37,6 +37,7 @@ import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.BaseNameableObject; import org.hisp.dhis.common.Dxf2Namespace; +import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.view.DetailedView; import org.hisp.dhis.common.view.ExportView; import org.hisp.dhis.dataset.DataSet; @@ -117,6 +118,18 @@ } } + public void addDataSet( DataSet dataSet ) + { + this.dataSets.add( dataSet ); + dataSet.getIndicators().add( this ); + } + + public void removeDataSet( DataSet dataSet ) + { + this.dataSets.remove( dataSet ); + dataSet.getIndicators().remove( this ); + } + // ------------------------------------------------------------------------- // hashCode and equals // ------------------------------------------------------------------------- @@ -331,4 +344,39 @@ { this.attributeValues = attributeValues; } + + @Override + public void mergeWith( IdentifiableObject other ) + { + super.mergeWith( other ); + + if ( other.getClass().isInstance( this ) ) + { + Indicator indicator = (Indicator) other; + + annualized = indicator.isAnnualized(); + denominator = denominator != null ? denominator : indicator.getDenominator(); + denominatorDescription = denominatorDescription != null ? denominatorDescription : indicator.getDenominatorDescription(); + numerator = numerator != null ? numerator : indicator.getNumerator(); + numeratorDescription = numeratorDescription != null ? numeratorDescription : indicator.getNumeratorDescription(); + explodedNumerator = explodedNumerator != null ? explodedNumerator : indicator.getExplodedNumerator(); + explodedDenominator = explodedDenominator != null ? explodedDenominator : indicator.getExplodedDenominator(); + indicatorType = indicatorType != null ? indicatorType : indicator.getIndicatorType(); + + for ( DataSet dataSet : indicator.getDataSets() ) + { + addDataSet( dataSet ); + } + + for ( IndicatorGroup indicatorGroup : indicator.getGroups() ) + { + addIndicatorGroup( indicatorGroup ); + } + + for ( AttributeValue attributeValue : indicator.getAttributeValues() ) + { + attributeValues.add( attributeValue ); + } + } + } } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorGroup.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorGroup.java 2012-04-10 13:20:37 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorGroup.java 2012-04-10 21:41:34 +0000 @@ -35,6 +35,7 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.Dxf2Namespace; +import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.view.DetailedView; import org.hisp.dhis.common.view.ExportView; @@ -173,4 +174,22 @@ { this.groupSet = groupSet; } + + @Override + public void mergeWith( IdentifiableObject other ) + { + super.mergeWith( other ); + + if ( other.getClass().isInstance( this ) ) + { + IndicatorGroup indicatorGroup = (IndicatorGroup) other; + + groupSet = groupSet != null ? groupSet : indicatorGroup.getGroupSet(); + + for ( Indicator indicator : indicatorGroup.getMembers() ) + { + addIndicator( indicator ); + } + } + } } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorGroupSet.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorGroupSet.java 2012-03-27 17:38:48 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorGroupSet.java 2012-04-10 21:41:34 +0000 @@ -35,6 +35,7 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.Dxf2Namespace; +import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator; import org.hisp.dhis.common.view.DetailedView; import org.hisp.dhis.common.view.ExportView; @@ -189,6 +190,20 @@ } // ------------------------------------------------------------------------- + // Logic + // ------------------------------------------------------------------------- + + public void addIndicatorGroup( IndicatorGroup indicatorGroup ) + { + if ( !members.contains( indicatorGroup ) ) + { + this.members.add( indicatorGroup ); + } + + indicatorGroup.setGroupSet( this ); + } + + // ------------------------------------------------------------------------- // Getters and setters // ------------------------------------------------------------------------- @@ -237,4 +252,31 @@ { this.members = members; } + + @Override + public void mergeWith( IdentifiableObject other ) + { + super.mergeWith( other ); + + if ( other.getClass().isInstance( this ) ) + { + IndicatorGroupSet indicatorGroupSet = (IndicatorGroupSet) other; + + compulsory = compulsory != null ? compulsory : indicatorGroupSet.isCompulsory(); + description = description != null ? description : indicatorGroupSet.getDescription(); + + for ( IndicatorGroup indicatorGroup : indicatorGroupSet.getMembers() ) + { + if ( !members.contains( indicatorGroup ) ) + { + members.add( indicatorGroup ); + } + + if ( indicatorGroup.getGroupSet() == null ) + { + indicatorGroup.setGroupSet( this ); + } + } + } + } } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorType.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorType.java 2012-03-27 17:38:48 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorType.java 2012-04-10 21:41:34 +0000 @@ -33,6 +33,7 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.Dxf2Namespace; +import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.view.DetailedView; import org.hisp.dhis.common.view.ExportView; @@ -135,4 +136,18 @@ { this.number = number; } + + @Override + public void mergeWith( IdentifiableObject other ) + { + super.mergeWith( other ); + + if(other.getClass().isInstance( this )) + { + IndicatorType indicatorType = (IndicatorType) other; + + factor = indicatorType.getFactor(); + number = indicatorType.isNumber(); + } + } } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java 2012-03-27 17:38:48 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java 2012-04-10 21:41:34 +0000 @@ -230,6 +230,18 @@ } } + public void addUser( User user ) + { + user.getOrganisationUnits().add( this ); + users.add( user ); + } + + public void removeUser( User user ) + { + user.getOrganisationUnits().remove( this ); + users.remove( user ); + } + public List getSortedChildren() { List sortedChildren = new ArrayList( children ); @@ -845,4 +857,45 @@ { this.currentParent = currentParent; } + + @Override + public void mergeWith( IdentifiableObject other ) + { + super.mergeWith( other ); + + if ( other.getClass().isInstance( this ) ) + { + OrganisationUnit organisationUnit = (OrganisationUnit) other; + + openingDate = openingDate != null ? openingDate : organisationUnit.getOpeningDate(); + closedDate = closedDate != null ? closedDate : organisationUnit.getClosedDate(); + active = organisationUnit.isActive(); + comment = comment != null ? comment : organisationUnit.getComment(); + geoCode = geoCode != null ? geoCode : organisationUnit.getGeoCode(); + featureType = featureType != null ? featureType : organisationUnit.getFeatureType(); + coordinates = coordinates != null ? coordinates : organisationUnit.getCoordinates(); + url = url != null ? url : organisationUnit.getUrl(); + contactPerson = contactPerson != null ? contactPerson : organisationUnit.getContactPerson(); + address = address != null ? address : organisationUnit.getAddress(); + email = email != null ? email : organisationUnit.getEmail(); + phoneNumber = phoneNumber != null ? phoneNumber : organisationUnit.getPhoneNumber(); + hasPatients = organisationUnit.isHasPatients(); + parent = parent != null ? parent : organisationUnit.getParent(); + + for ( DataSet dataSet : organisationUnit.getDataSets() ) + { + addDataSet( dataSet ); + } + + for ( OrganisationUnitGroup organisationUnitGroup : organisationUnit.getGroups() ) + { + addOrganisationUnitGroup( organisationUnitGroup ); + } + + for ( User user : organisationUnit.getUsers() ) + { + addUser( user ); + } + } + } } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroup.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroup.java 2012-04-03 10:52:58 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroup.java 2012-04-10 21:41:34 +0000 @@ -36,6 +36,7 @@ import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.BaseNameableObject; import org.hisp.dhis.common.Dxf2Namespace; +import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.view.DetailedView; import org.hisp.dhis.common.view.ExportView; @@ -160,7 +161,7 @@ @JsonProperty( value = "organisationUnits" ) @JsonSerialize( contentAs = BaseIdentifiableObject.class ) - @JsonView( { DetailedView.class, ExportView.class } ) + @JsonView( {DetailedView.class, ExportView.class} ) @JacksonXmlElementWrapper( localName = "organisationUnits", namespace = Dxf2Namespace.NAMESPACE ) @JacksonXmlProperty( localName = "organisationUnit", namespace = Dxf2Namespace.NAMESPACE ) public Set getMembers() @@ -175,7 +176,7 @@ @JsonProperty( value = "organisationUnitGroupSet" ) @JsonSerialize( as = BaseIdentifiableObject.class ) - @JsonView( { DetailedView.class, ExportView.class } ) + @JsonView( {DetailedView.class, ExportView.class} ) @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE ) public OrganisationUnitGroupSet getGroupSet() { @@ -186,4 +187,22 @@ { this.groupSet = groupSet; } + + @Override + public void mergeWith( IdentifiableObject other ) + { + super.mergeWith( other ); + + if ( other.getClass().isInstance( this ) ) + { + OrganisationUnitGroup organisationUnitGroup = (OrganisationUnitGroup) other; + + groupSet = groupSet != null ? groupSet : organisationUnitGroup.getGroupSet(); + + for ( OrganisationUnit organisationUnit : organisationUnitGroup.getMembers() ) + { + addOrganisationUnit( organisationUnit ); + } + } + } } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupSet.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupSet.java 2012-03-27 17:38:48 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupSet.java 2012-04-10 21:41:34 +0000 @@ -228,4 +228,28 @@ { this.organisationUnitGroups = organisationUnitGroups; } + + @Override + public void mergeWith( IdentifiableObject other ) + { + super.mergeWith( other ); + + if ( other.getClass().isInstance( this ) ) + { + OrganisationUnitGroupSet organisationUnitGroupSet = (OrganisationUnitGroupSet) other; + + compulsory = organisationUnitGroupSet.isCompulsory(); + description = description != null ? description : organisationUnitGroupSet.getDescription(); + + for ( OrganisationUnitGroup organisationUnitGroup : organisationUnitGroupSet.getOrganisationUnitGroups() ) + { + organisationUnitGroups.add( organisationUnitGroup ); + + if ( organisationUnitGroup.getGroupSet() == null ) + { + organisationUnitGroup.setGroupSet( this ); + } + } + } + } } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitLevel.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitLevel.java 2012-03-27 17:38:48 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitLevel.java 2012-04-10 21:41:34 +0000 @@ -33,6 +33,7 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.Dxf2Namespace; +import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.view.DetailedView; import org.hisp.dhis.common.view.ExportView; @@ -126,4 +127,17 @@ { this.level = level; } + + @Override + public void mergeWith( IdentifiableObject other ) + { + super.mergeWith( other ); + + if ( other.getClass().isInstance( this ) ) + { + OrganisationUnitLevel organisationUnitLevel = (OrganisationUnitLevel) other; + + level = organisationUnitLevel.getLevel(); + } + } }