=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java 2014-12-19 11:18:40 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java 2014-12-19 13:27:39 +0000 @@ -176,24 +176,14 @@ private boolean nullable; /** - * Maximum length of this property. - */ - private Integer maxLength; - - /** - * Minimum length of this property. - */ - private Integer minLength; - - /** - * If type is numeric (or collection), this is the maximum value (or size) - */ - private Integer maxValue; - - /** - * If type is numeric (or collection), this is the minimum value (or size) - */ - private Integer minValue; + * Maximum length/size/value of this property. + */ + private Integer max; + + /** + * Minimum length/size/value of this property. + */ + private Integer min; /** * Cascading used when doing CRUD operations. @@ -492,50 +482,26 @@ @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) - public Integer getMaxLength() - { - return maxLength; - } - - public void setMaxLength( Integer maxLength ) - { - this.maxLength = maxLength; - } - - @JsonProperty - @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) - public Integer getMinLength() - { - return minLength; - } - - public void setMinLength( Integer minLength ) - { - this.minLength = minLength; - } - - @JsonProperty - @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) - public Integer getMaxValue() - { - return maxValue; - } - - public void setMaxValue( Integer maxValue ) - { - this.maxValue = maxValue; - } - - @JsonProperty - @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) - public Integer getMinValue() - { - return minValue; - } - - public void setMinValue( Integer minValue ) - { - this.minValue = minValue; + public Integer getMax() + { + return max; + } + + public void setMax( Integer max ) + { + this.max = max; + } + + @JsonProperty + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + public Integer getMin() + { + return min; + } + + public void setMin( Integer min ) + { + this.min = min; } @JsonProperty === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/SchemaUtils.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/SchemaUtils.java 2014-12-19 11:18:40 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/SchemaUtils.java 2014-12-19 13:27:39 +0000 @@ -30,6 +30,7 @@ import com.google.common.primitives.Primitives; import org.hisp.dhis.common.IdentifiableObject; +import org.hisp.dhis.schema.annotation.PropertyRange; import org.springframework.util.Assert; import java.util.Collection; @@ -51,6 +52,32 @@ { property.setItemPropertyType( getPropertyType( property.getItemKlass() ) ); } + + if ( property.getGetterMethod() != null ) + { + if ( property.getGetterMethod().isAnnotationPresent( org.hisp.dhis.schema.annotation.Property.class ) ) + { + property.setPropertyType( property.getGetterMethod().getAnnotation( org.hisp.dhis.schema.annotation.Property.class ).value() ); + } + + if ( property.getGetterMethod().isAnnotationPresent( PropertyRange.class ) ) + { + PropertyRange propertyRange = property.getGetterMethod().getAnnotation( PropertyRange.class ); + + int propertyMax = property.getMax() != null ? property.getMax() : Integer.MAX_VALUE; + int propertyMin = property.getMin() != null ? property.getMin() : 0; + + if ( propertyRange.max() >= 0 && propertyRange.max() <= propertyMax ) + { + property.setMax( propertyRange.max() ); + } + + if ( propertyRange.min() >= 0 && propertyRange.min() <= propertyMax ) + { + property.setMin( propertyRange.min() > property.getMax() ? property.getMax() : propertyRange.min() ); + } + } + } } private static PropertyType getPropertyType( Class klass ) === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/AbstractPropertyIntrospectorService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/AbstractPropertyIntrospectorService.java 2014-12-05 15:27:18 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/AbstractPropertyIntrospectorService.java 2014-12-19 13:27:39 +0000 @@ -187,8 +187,8 @@ property.setUnique( column.isUnique() ); property.setNullable( column.isNullable() ); - property.setMaxLength( column.getLength() ); - property.setMinLength( 0 ); + property.setMax( column.getLength() ); + property.setMin( 0 ); } properties.put( property.getName(), property ); === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/Jackson2PropertyIntrospectorService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/Jackson2PropertyIntrospectorService.java 2014-12-19 11:18:40 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/Jackson2PropertyIntrospectorService.java 2014-12-19 13:27:39 +0000 @@ -108,8 +108,8 @@ property.setWritable( true ); property.setUnique( hibernateProperty.isUnique() ); property.setNullable( hibernateProperty.isNullable() ); - property.setMaxLength( hibernateProperty.getMaxLength() ); - property.setMinLength( hibernateProperty.getMinLength() ); + property.setMax( hibernateProperty.getMax() ); + property.setMin( hibernateProperty.getMin() ); property.setCollection( hibernateProperty.isCollection() ); property.setCascade( hibernateProperty.getCascade() ); property.setOwner( hibernateProperty.isOwner() ); === modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaValidator.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaValidator.java 2014-12-12 18:51:13 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaValidator.java 2014-12-19 13:27:39 +0000 @@ -76,10 +76,10 @@ continue; } - if ( String.class.isInstance( value ) && property.getMaxLength() < ((String) value).length() ) + if ( String.class.isInstance( value ) && property.getMax() < ((String) value).length() ) { validationViolations.getValidationViolations().add( new ValidationViolation( "Property '" + property.getName() + "' is too long (" - + ((String) value).length() + "), maximum length is " + property.getMaxLength() ) ); + + ((String) value).length() + "), maximum length is " + property.getMax() ) ); continue; } }