=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/VersionedObject.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/VersionedObject.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/VersionedObject.java 2015-02-18 13:39:52 +0000 @@ -0,0 +1,45 @@ +package org.hisp.dhis.common; + +/* + * Copyright (c) 2004-2015, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Lars Helge Overland + */ +public interface VersionedObject +{ + /** + * Returns the current version. + */ + int getVersion(); + + /** + * Increases the version and returns its new version. + */ + int increaseVersion(); +} === 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 2015-02-05 06:53:38 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java 2015-02-18 13:39:52 +0000 @@ -35,12 +35,14 @@ 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.attribute.AttributeValue; 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.MergeStrategy; +import org.hisp.dhis.common.VersionedObject; import org.hisp.dhis.common.adapter.JacksonPeriodTypeDeserializer; import org.hisp.dhis.common.adapter.JacksonPeriodTypeSerializer; import org.hisp.dhis.common.annotation.Scanned; @@ -72,6 +74,7 @@ @JacksonXmlRootElement( localName = "dataSet", namespace = DxfNamespaces.DXF_2_0 ) public class DataSet extends BaseNameableObject + implements VersionedObject { public static final String TYPE_DEFAULT = "default"; public static final String TYPE_SECTION = "section"; @@ -139,7 +142,7 @@ /** * Indicating version number. */ - private Integer version; + private int version; /** * How many days after period is over will this dataSet auto-lock @@ -397,10 +400,9 @@ return dataElements; } - public DataSet increaseVersion() + public int increaseVersion() { - version = version != null ? version + 1 : 1; - return this; + return ++version; } /** @@ -576,12 +578,12 @@ @JsonProperty @JsonView( { DetailedView.class, ExportView.class, WithoutOrganisationUnitsView.class } ) @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) - public Integer getVersion() + public int getVersion() { return version; } - public void setVersion( Integer version ) + public void setVersion( int version ) { this.version = version; } @@ -815,12 +817,12 @@ fieldCombinationRequired = dataSet.isFieldCombinationRequired(); mobile = dataSet.isMobile(); validCompleteOnly = dataSet.isValidCompleteOnly(); + version = dataSet.getVersion(); if ( MergeStrategy.MERGE_ALWAYS.equals( strategy ) ) { periodType = dataSet.getPeriodType(); dataEntryForm = dataSet.getDataEntryForm(); - version = dataSet.getVersion(); legendSet = dataSet.getLegendSet(); notificationRecipients = dataSet.getNotificationRecipients(); } @@ -828,7 +830,6 @@ { periodType = dataSet.getPeriodType() == null ? periodType : dataSet.getPeriodType(); dataEntryForm = dataSet.getDataEntryForm() == null ? dataEntryForm : dataSet.getDataEntryForm(); - version = dataSet.getVersion() == null ? version : dataSet.getVersion(); legendSet = dataSet.getLegendSet() == null ? legendSet : dataSet.getLegendSet(); notificationRecipients = dataSet.getNotificationRecipients() == null ? notificationRecipients : dataSet.getNotificationRecipients(); } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionSet.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionSet.java 2015-02-05 06:53:38 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionSet.java 2015-02-18 13:39:52 +0000 @@ -28,24 +28,26 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -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.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + 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.VersionedObject; import org.hisp.dhis.common.annotation.Scanned; import org.hisp.dhis.common.view.DetailedView; import org.hisp.dhis.common.view.ExportView; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +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; /** * @author Lars Helge Overland @@ -53,16 +55,18 @@ @JacksonXmlRootElement( localName = "optionSet", namespace = DxfNamespaces.DXF_2_0 ) public class OptionSet extends BaseIdentifiableObject + implements VersionedObject { private static final Pattern OPTION_PATTERN = Pattern.compile( "\\[(.*)\\]" ); @Scanned private List