=== 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 2014-12-19 15:36:44 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorType.java 2015-01-15 09:50:45 +0000 @@ -79,7 +79,6 @@ @JsonProperty @JsonView( { DetailedView.class, ExportView.class } ) @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) - @PropertyRange( min = 1, max = 10 ) public int getFactor() { return factor; === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/UserCredentialsSchemaDescriptor.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/UserCredentialsSchemaDescriptor.java 2014-06-10 16:59:51 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/UserCredentialsSchemaDescriptor.java 2015-01-15 09:50:45 +0000 @@ -47,6 +47,7 @@ public Schema getSchema() { Schema schema = new Schema( UserCredentials.class, SINGULAR, PLURAL ); + schema.setMetadata( false ); schema.setOrder( 2000 ); return schema; === 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 2015-01-09 13:25:59 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/AbstractPropertyIntrospectorService.java 2015-01-15 09:50:45 +0000 @@ -28,11 +28,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import org.hibernate.SessionFactory; import org.hibernate.mapping.Collection; import org.hibernate.mapping.Column; @@ -55,9 +53,10 @@ import org.springframework.context.ApplicationContext; import org.springframework.orm.hibernate4.LocalSessionFactoryBean; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; /** * @author Morten Olav Hansen @@ -127,7 +126,7 @@ return (LocalSessionFactoryBean) context.getBean( "&sessionFactory" ); } - @SuppressWarnings("unused") + @SuppressWarnings( "unused" ) protected Map getPropertiesFromHibernate( Class klass ) { ClassMetadata classMetadata = sessionFactory.getClassMetadata( klass ); @@ -182,7 +181,8 @@ { AnyType anyType = (AnyType) type; } - else + + if ( hibernateProperty.getColumnSpan() > 0 ) { Column column = (Column) hibernateProperty.getColumnIterator().next(); @@ -191,9 +191,9 @@ property.setMax( column.getLength() ); property.setMin( 0 ); + + properties.put( property.getName(), property ); } - - properties.put( property.getName(), property ); } return properties; === modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2014-12-30 13:05:45 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2015-01-15 09:50:45 +0000 @@ -58,10 +58,13 @@ import org.hisp.dhis.dxf2.metadata.ObjectBridge; import org.hisp.dhis.dxf2.metadata.handlers.ObjectHandler; import org.hisp.dhis.dxf2.metadata.handlers.ObjectHandlerUtils; +import org.hisp.dhis.dxf2.schema.SchemaValidator; +import org.hisp.dhis.dxf2.schema.ValidationViolation; import org.hisp.dhis.eventchart.EventChart; import org.hisp.dhis.eventreport.EventReport; import org.hisp.dhis.expression.Expression; import org.hisp.dhis.expression.ExpressionService; +import org.hisp.dhis.indicator.Indicator; import org.hisp.dhis.period.Period; import org.hisp.dhis.period.PeriodService; import org.hisp.dhis.period.PeriodType; @@ -137,6 +140,9 @@ private SchemaService schemaService; @Autowired + private SchemaValidator schemaValidator; + + @Autowired private UserService userService; @Autowired( required = false ) @@ -284,10 +290,17 @@ return false; } + List validate = schemaValidator.validate( object ); + + if ( !validate.isEmpty() ) + { + return false; + } + // make sure that the internalId is 0, so that the system will generate a ID object.setId( 0 ); // object.setUser( user ); - object.setUser( null ); + // object.setUser( null ); NonIdentifiableObjects nonIdentifiableObjects = new NonIdentifiableObjects( user ); nonIdentifiableObjects.extract( object ); @@ -385,6 +398,13 @@ return true; } + List validate = schemaValidator.validate( object ); + + if ( !validate.isEmpty() ) + { + return false; + } + NonIdentifiableObjects nonIdentifiableObjects = new NonIdentifiableObjects( user ); nonIdentifiableObjects.extract( object ); nonIdentifiableObjects.delete( persistedObject ); === 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 2015-01-03 10:01:31 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaValidator.java 2015-01-15 09:50:45 +0000 @@ -36,6 +36,7 @@ import org.hisp.dhis.system.util.ReflectionUtils; import org.hisp.dhis.system.util.ValidationUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.StringUtils; import java.util.ArrayList; import java.util.Collection; @@ -89,7 +90,8 @@ { List validationViolations = new ArrayList<>(); - if ( !String.class.isInstance( object ) ) + // TODO How should empty strings be handled? they are not valid color, password, url, etc of course. + if ( !String.class.isInstance( object ) || StringUtils.isEmpty( object ) ) { return validationViolations; } @@ -99,27 +101,27 @@ if ( value.length() < property.getMin() || value.length() > property.getMax() ) { validationViolations.add( new ValidationViolation( property.getName(), "Allowed range for length [" - + property.getMin() + ", " + property.getMax() + "], length is " + value.length() ) ); + + property.getMin() + ", " + property.getMax() + "], length is " + value.length(), value ) ); } if ( PropertyType.EMAIL == property.getPropertyType() && !GenericValidator.isEmail( value ) ) { - validationViolations.add( new ValidationViolation( property.getName(), "Not a valid email." ) ); + validationViolations.add( new ValidationViolation( property.getName(), "Not a valid email.", value ) ); } if ( PropertyType.URL == property.getPropertyType() && !GenericValidator.isUrl( value ) ) { - validationViolations.add( new ValidationViolation( property.getName(), "Not a valid URL." ) ); + validationViolations.add( new ValidationViolation( property.getName(), "Not a valid URL.", value ) ); } if ( PropertyType.PASSWORD == property.getPropertyType() && !ValidationUtils.passwordIsValid( value ) ) { - validationViolations.add( new ValidationViolation( property.getName(), "Not a valid password." ) ); + validationViolations.add( new ValidationViolation( property.getName(), "Not a valid password.", value ) ); } if ( PropertyType.COLOR == property.getPropertyType() && !ValidationUtils.isValidHexColor( value ) ) { - validationViolations.add( new ValidationViolation( property.getName(), "Not a valid color (in hex format)." ) ); + validationViolations.add( new ValidationViolation( property.getName(), "Not a valid color (in hex format).", value ) ); } /* TODO add proper validation for both Points and Polygons, ValidationUtils only supports points at this time @@ -146,7 +148,7 @@ if ( value.size() < property.getMin() || value.size() > property.getMax() ) { validationViolations.add( new ValidationViolation( property.getName(), "Invalid range for size [" - + property.getMin() + ", " + property.getMax() + "], size is " + value.size() ) ); + + property.getMin() + ", " + property.getMax() + "], size is " + value.size(), value ) ); } return validationViolations; @@ -166,7 +168,7 @@ if ( !GenericValidator.isInRange( value, property.getMin(), property.getMax() ) ) { validationViolations.add( new ValidationViolation( property.getName(), "Invalid range for value [" - + property.getMin() + ", " + property.getMax() + "], value is " + value ) ); + + property.getMin() + ", " + property.getMax() + "], value is " + value, value ) ); } return validationViolations; @@ -186,7 +188,7 @@ if ( !GenericValidator.isInRange( value, property.getMin(), property.getMax() ) ) { validationViolations.add( new ValidationViolation( property.getName(), "Invalid range for value [" - + property.getMin() + ", " + property.getMax() + "], value is " + value ) ); + + property.getMin() + ", " + property.getMax() + "], value is " + value, value ) ); } return validationViolations; @@ -206,7 +208,7 @@ if ( !GenericValidator.isInRange( value, property.getMin(), property.getMax() ) ) { validationViolations.add( new ValidationViolation( property.getName(), "Invalid range for value [" - + property.getMin() + ", " + property.getMax() + "], value is " + value ) ); + + property.getMin() + ", " + property.getMax() + "], value is " + value, value ) ); } return validationViolations; === modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/ValidationViolation.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/ValidationViolation.java 2014-12-23 09:40:40 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/ValidationViolation.java 2015-01-15 09:50:45 +0000 @@ -47,12 +47,21 @@ private String message; + private Object value; + public ValidationViolation( String property, String message ) { this.property = property; this.message = message; } + public ValidationViolation( String property, String message, Object value ) + { + this.property = property; + this.message = message; + this.value = value; + } + @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) public String getProperty() @@ -77,12 +86,24 @@ this.message = message; } - @Override - public String toString() + @JsonProperty + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + public Object getValue() + { + return value; + } + + public void setValue( Object value ) + { + this.value = value; + } + + @Override public String toString() { final StringBuilder sb = new StringBuilder( "ValidationViolation{" ); sb.append( "property='" ).append( property ).append( '\'' ); sb.append( ", message='" ).append( message ).append( '\'' ); + sb.append( ", value=" ).append( value ); sb.append( '}' ); return sb.toString(); }