=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOption.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOption.java 2014-11-24 20:52:55 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOption.java 2014-11-25 02:57:48 +0000 @@ -28,30 +28,30 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.util.Date; -import java.util.HashSet; -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 org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.BaseNameableObject; import org.hisp.dhis.common.DxfNamespaces; +import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.annotation.Scanned; import org.hisp.dhis.common.view.DetailedView; import org.hisp.dhis.common.view.ExportView; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.period.Period; -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 java.util.Date; +import java.util.HashSet; +import java.util.Set; /** * @author Abyot Asalefew */ -@JacksonXmlRootElement(localName = "categoryOption", namespace = DxfNamespaces.DXF_2_0) +@JacksonXmlRootElement( localName = "categoryOption", namespace = DxfNamespaces.DXF_2_0 ) public class DataElementCategoryOption extends BaseNameableObject { @@ -75,7 +75,7 @@ private Set categoryOptionCombos = new HashSet<>(); private Set groups = new HashSet<>(); - + // ------------------------------------------------------------------------- // Constructors // ------------------------------------------------------------------------- @@ -107,7 +107,7 @@ public Set getGroupSets() { Set groupSets = new HashSet<>(); - + if ( groups != null ) { for ( CategoryOptionGroup group : groups ) @@ -118,7 +118,7 @@ } } } - + return groupSets; } @@ -136,8 +136,8 @@ public boolean includes( Period period ) { - return ( startDate == null || !startDate.after( period.getEndDate() ) ) - && ( endDate == null || !endDate.before( period.getStartDate() ) ); + return (startDate == null || !startDate.after( period.getEndDate() )) + && (endDate == null || !endDate.before( period.getStartDate() )); } public boolean includes( OrganisationUnit ou ) @@ -154,7 +154,7 @@ return true; } } - + return false; } @@ -216,10 +216,10 @@ } @JsonProperty - @JsonSerialize(contentAs = BaseIdentifiableObject.class) - @JsonView({ DetailedView.class }) - @JacksonXmlElementWrapper(localName = "categories", namespace = DxfNamespaces.DXF_2_0) - @JacksonXmlProperty(localName = "category", namespace = DxfNamespaces.DXF_2_0) + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) + @JsonView( { DetailedView.class } ) + @JacksonXmlElementWrapper( localName = "categories", namespace = DxfNamespaces.DXF_2_0 ) + @JacksonXmlProperty( localName = "category", namespace = DxfNamespaces.DXF_2_0 ) public Set getCategories() { return categories; @@ -231,10 +231,10 @@ } @JsonProperty - @JsonSerialize(contentAs = BaseIdentifiableObject.class) - @JsonView({ DetailedView.class }) - @JacksonXmlElementWrapper(localName = "categoryOptionCombos", namespace = DxfNamespaces.DXF_2_0) - @JacksonXmlProperty(localName = "categoryOptionCombo", namespace = DxfNamespaces.DXF_2_0) + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) + @JsonView( { DetailedView.class } ) + @JacksonXmlElementWrapper( localName = "categoryOptionCombos", namespace = DxfNamespaces.DXF_2_0 ) + @JacksonXmlProperty( localName = "categoryOptionCombo", namespace = DxfNamespaces.DXF_2_0 ) public Set getCategoryOptionCombos() { return categoryOptionCombos; @@ -246,10 +246,10 @@ } @JsonProperty - @JsonSerialize(contentAs = BaseIdentifiableObject.class) - @JsonView({ DetailedView.class }) - @JacksonXmlElementWrapper(localName = "categoryOptionGroups", namespace = DxfNamespaces.DXF_2_0) - @JacksonXmlProperty(localName = "categoryOptionGroup", namespace = DxfNamespaces.DXF_2_0) + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) + @JsonView( { DetailedView.class } ) + @JacksonXmlElementWrapper( localName = "categoryOptionGroups", namespace = DxfNamespaces.DXF_2_0 ) + @JacksonXmlProperty( localName = "categoryOptionGroup", namespace = DxfNamespaces.DXF_2_0 ) public Set getGroups() { return groups; @@ -259,4 +259,28 @@ { this.groups = groups; } + + @Override + public void mergeWith( IdentifiableObject other ) + { + super.mergeWith( other ); + + if ( other.getClass().isInstance( this ) ) + { + DataElementCategoryOption dataElementCategoryOption = (DataElementCategoryOption) other; + + startDate = dataElementCategoryOption.getStartDate(); + endDate = dataElementCategoryOption.getEndDate(); + + organisationUnits.clear(); + categories.clear(); + groups.clear(); + categoryOptionCombos.clear(); + + organisationUnits.addAll( dataElementCategoryOption.getOrganisationUnits() ); + categories.addAll( dataElementCategoryOption.getCategories() ); + groups.addAll( dataElementCategoryOption.getGroups() ); + categoryOptionCombos.addAll( dataElementCategoryOption.getCategoryOptionCombos() ); + } + } }