=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ValueType.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ValueType.java 2015-08-31 02:55:58 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ValueType.java 2015-08-31 04:36:39 +0000 @@ -28,10 +28,12 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.util.Date; - import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.option.OptionSet; import org.hisp.dhis.trackedentity.TrackedEntityAttribute; +import org.hisp.dhis.trackedentity.TrackedEntityInstance; + +import java.util.Date; /** * @author Lars Helge Overland @@ -41,7 +43,7 @@ TEXT( String.class ), LONG_TEXT( String.class ), LETTER( String.class ), - TYPE_PHONE_NUMBER( String.class ), + PHONE_NUMBER( String.class ), EMAIL( String.class ), BOOLEAN( Boolean.class ), TRUE_ONLY( Boolean.class ), @@ -53,31 +55,44 @@ INTEGER( Integer.class ), INTEGER_POSITIVE( Integer.class ), INTEGER_NEGATIVE( Integer.class ), - INTEGER_ZERO_OR_POSITIVE( Integer.class ); + INTEGER_ZERO_OR_POSITIVE( Integer.class ), + TRACKER_ASSOCIATE( TrackedEntityInstance.class ), + OPTION_SET( OptionSet.class ), + USERNAME( String.class ); private final Class javaClass; - + ValueType() { this.javaClass = null; } - + ValueType( Class javaClass ) { this.javaClass = javaClass; } - + public Class getJavaClass() { return javaClass; } + public boolean isInteger() + { + return this == INTEGER || this == INTEGER_POSITIVE || this == INTEGER_NEGATIVE || this == INTEGER_ZERO_OR_POSITIVE; + } + + public boolean isText() + { + return this == TEXT || this == LONG_TEXT; + } + /** * TODO replace string value type on data element with ValueType and remove * this method. */ public static ValueType getFromDataElement( DataElement dataElement ) - { + { if ( DataElement.VALUE_TYPE_STRING.equals( dataElement.getType() ) ) { if ( DataElement.VALUE_TYPE_LONG_TEXT.equals( dataElement.getTextType() ) ) @@ -136,6 +151,10 @@ { return ValueType.DATETIME; } + else if ( DataElement.VALUE_TYPE_USER_NAME.equals( dataElement.getType() ) ) + { + return ValueType.USERNAME; + } return ValueType.TEXT; // Fall back } @@ -158,7 +177,15 @@ { return ValueType.DATE; } - + else if ( TrackedEntityAttribute.TYPE_TRACKER_ASSOCIATE.equals( attribute.getValueType() ) ) + { + return ValueType.TRACKER_ASSOCIATE; + } + else if ( TrackedEntityAttribute.TYPE_USERS.equals( attribute.getValueType() ) ) + { + return ValueType.USERNAME; + } + return ValueType.TEXT; // Fall back - } + } } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2015-08-30 18:24:11 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2015-08-31 04:36:39 +0000 @@ -28,15 +28,13 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import static org.hisp.dhis.dataset.DataSet.NO_EXPIRY; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - +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.analytics.AggregationType; import org.hisp.dhis.attribute.AttributeValue; import org.hisp.dhis.common.BaseDimensionalObject; @@ -44,6 +42,7 @@ import org.hisp.dhis.common.DxfNamespaces; import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.MergeStrategy; +import org.hisp.dhis.common.ValueType; import org.hisp.dhis.common.view.DetailedView; import org.hisp.dhis.common.view.DimensionalView; import org.hisp.dhis.common.view.ExportView; @@ -57,13 +56,14 @@ import org.hisp.dhis.schema.annotation.PropertyRange; import org.hisp.dhis.util.ObjectUtils; -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.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import static org.hisp.dhis.dataset.DataSet.NO_EXPIRY; /** * A DataElement is a definition (meta-information about) of the entities that @@ -74,7 +74,7 @@ * children. The sum of the children represent the same entity as the parent. * Hierarchies of DataElements are used to give more fine- or course-grained * representations of the entities. - *

+ *

* DataElement acts as a DimensionSet in the dynamic dimensional model, and as a * DimensionOption in the static DataElement dimension. * @@ -119,6 +119,11 @@ public static final String AGGREGATION_OPERATOR_NONE = "none"; /** + * Data element value type (int, boolean, etc) + */ + private ValueType valueType; + + /** * The name to appear in forms. */ private String formName; @@ -129,7 +134,7 @@ protected transient String displayFormName; /** - * The domain of this DataElement; e.g. DataElementDomainType.aggregate or + * The domain of this DataElement; e.g. DataElementDomainType.AGGREGATE or * DataElementDomainType.TRACKER. */ private DataElementDomain domainType; @@ -276,7 +281,7 @@ { return VALUE_TYPE_DATE.equals( type ) || VALUE_TYPE_DATETIME.equals( type ); } - + /** * Returns the value type. If value type is int and the number type exists, * the number type is returned, otherwise the type is returned. @@ -338,7 +343,7 @@ Collections.sort( list, DataSetFrequencyComparator.INSTANCE ); return !list.isEmpty() ? list.get( 0 ) : null; } - + /** * Returns the category combinations associated with the data sets of this * data element. @@ -346,12 +351,12 @@ public Set getDataSetCategoryCombos() { Set categoryCombos = new HashSet<>(); - + for ( DataSet dataSet : dataSets ) { categoryCombos.add( dataSet.getCategoryCombo() ); } - + return categoryCombos; } @@ -362,12 +367,12 @@ public Set getDataSetCategoryOptionCombos() { Set categoryOptionCombos = new HashSet<>(); - + for ( DataSet dataSet : dataSets ) { categoryOptionCombos.addAll( dataSet.getCategoryCombo().getOptionCombos() ); } - + return categoryOptionCombos; } @@ -383,7 +388,7 @@ return dataSet != null ? dataSet.getPeriodType() : null; } - + /** * Returns the PeriodTypes of the DataElement, based on the PeriodType of the * DataSets which the DataElement is associated with. @@ -415,16 +420,16 @@ * Number of periods in the future to open for data capture, 0 means capture * not allowed for current period. Based on the data sets of which this data * element is a member. - */ + */ public int getOpenFuturePeriods() { Set openPeriods = new HashSet<>(); - + for ( DataSet dataSet : dataSets ) { openPeriods.add( dataSet.getOpenFuturePeriods() ); } - + return ObjectUtils.firstNonNull( Collections.max( openPeriods ), 0 ); } @@ -473,7 +478,7 @@ { return categoryCombo != null; } - + /** * Tests whether the DataElement is associated with a * DataElementCategoryCombo with more than one DataElementCategory, or any @@ -574,7 +579,7 @@ { return aggregationOperator != null ? AggregationType.fromValue( aggregationOperator ) : null; } - + // ------------------------------------------------------------------------- // Helper getters // ------------------------------------------------------------------------- @@ -585,7 +590,7 @@ { return optionSet != null; } - + // ------------------------------------------------------------------------- // Getters and setters // ------------------------------------------------------------------------- @@ -593,6 +598,19 @@ @JsonProperty @JsonView( { DetailedView.class, ExportView.class } ) @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + public ValueType getValueType() + { + return ValueType.getFromDataElement( this ); + } + + public void setValueType( ValueType valueType ) + { + this.valueType = valueType; + } + + @JsonProperty + @JsonView( { DetailedView.class, ExportView.class } ) + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) @PropertyRange( min = 2 ) public String getFormName() {