=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseIdentifiableObject.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseIdentifiableObject.java 2014-12-22 10:28:42 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseIdentifiableObject.java 2014-12-22 13:52:51 +0000 @@ -37,6 +37,7 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import org.apache.commons.lang.Validate; import org.hisp.dhis.acl.Access; +import org.hisp.dhis.acl.AccessStringHelper; import org.hisp.dhis.common.annotation.Description; import org.hisp.dhis.common.view.DimensionalView; import org.hisp.dhis.common.view.SharingBasicView; @@ -106,7 +107,7 @@ /** * Access string for public access. */ - protected String publicAccess; + protected String publicAccess = AccessStringHelper.DEFAULT; /** * Owner of this object. === 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 13:43:08 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java 2014-12-22 13:52:51 +0000 @@ -173,7 +173,7 @@ /** * Nullability of this property. */ - private boolean nullable; + private boolean required; /** * Maximum length/size/value of this property. @@ -470,14 +470,14 @@ @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) - public boolean isNullable() + public boolean isRequired() { - return nullable; + return required; } - public void setNullable( boolean nullable ) + public void setRequired( boolean required ) { - this.nullable = nullable; + this.required = required; } @JsonProperty === 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-22 11:16:13 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/AbstractPropertyIntrospectorService.java 2014-12-22 13:52:51 +0000 @@ -147,7 +147,7 @@ while ( propertyIterator.hasNext() ) { Property property = new Property( klass ); - property.setNullable( true ); + property.setRequired( false ); property.setPersisted( true ); property.setOwner( true ); @@ -186,7 +186,7 @@ Column column = (Column) hibernateProperty.getColumnIterator().next(); property.setUnique( column.isUnique() ); - property.setNullable( column.isNullable() ); + property.setRequired( !column.isNullable() ); property.setMax( column.getLength() ); property.setMin( 0 ); === 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 13:27:39 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/Jackson2PropertyIntrospectorService.java 2014-12-22 13:52:51 +0000 @@ -107,7 +107,7 @@ property.setPersisted( true ); property.setWritable( true ); property.setUnique( hibernateProperty.isUnique() ); - property.setNullable( hibernateProperty.isNullable() ); + property.setRequired( hibernateProperty.isRequired() ); property.setMax( hibernateProperty.getMax() ); property.setMin( hibernateProperty.getMin() ); property.setCollection( hibernateProperty.isCollection() ); === 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-22 09:52:13 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaValidator.java 2014-12-22 13:52:51 +0000 @@ -29,7 +29,6 @@ */ import org.apache.commons.validator.GenericValidator; -import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.schema.Property; import org.hisp.dhis.schema.PropertyType; import org.hisp.dhis.schema.Schema; @@ -51,7 +50,7 @@ private SchemaService schemaService; @Override - public List validate( T object ) + public List validate( Object object ) { if ( object == null || schemaService.getSchema( object.getClass() ) == null ) { @@ -68,7 +67,7 @@ if ( value == null ) { - if ( !property.isNullable() ) + if ( !property.isRequired() ) { validationViolations.add( new ValidationViolation( "Property '" + property.getName() + "' can not be null." ) ); } === modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/SchemaValidator.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/SchemaValidator.java 2014-12-22 08:04:25 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/SchemaValidator.java 2014-12-22 13:52:51 +0000 @@ -28,9 +28,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import org.hisp.dhis.common.IdentifiableObject; -import org.hisp.dhis.dxf2.webmessage.WebMessage; - import java.util.List; /** @@ -44,5 +41,5 @@ * @param object Object to validate * @return WebMessage containing validation response */ - List validate( T object ); + List validate( Object object ); } === 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-22 08:04:25 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/ValidationViolation.java 2014-12-22 13:52:51 +0000 @@ -59,4 +59,13 @@ { this.message = message; } + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder( "ValidationViolation{" ); + sb.append( "message='" ).append( message ).append( '\'' ); + sb.append( '}' ); + return sb.toString(); + } } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SchemaController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SchemaController.java 2014-12-19 11:37:11 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SchemaController.java 2014-12-22 13:52:51 +0000 @@ -28,12 +28,16 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.hisp.dhis.dxf2.render.RenderService; +import org.hisp.dhis.dxf2.schema.SchemaValidator; +import org.hisp.dhis.dxf2.schema.ValidationViolation; import org.hisp.dhis.schema.Property; import org.hisp.dhis.schema.Schema; import org.hisp.dhis.schema.SchemaService; import org.hisp.dhis.schema.Schemas; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -41,6 +45,11 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.client.HttpClientErrorException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.List; + /** * @author Morten Olav Hansen */ @@ -51,13 +60,19 @@ @Autowired private SchemaService schemaService; + @Autowired + private SchemaValidator schemaValidator; + + @Autowired + private RenderService renderService; + @RequestMapping public @ResponseBody Schemas getSchemas() { return new Schemas( schemaService.getSortedSchemas() ); } - @RequestMapping( value = "/{type}" ) + @RequestMapping( value = "/{type}", method = RequestMethod.GET ) public @ResponseBody Schema getSchema( @PathVariable String type ) { Schema schema = getSchemaFromType( type ); @@ -70,7 +85,23 @@ throw new HttpClientErrorException( HttpStatus.NOT_FOUND, "Type " + type + " does not exist." ); } - @RequestMapping( value = "/{type}/{property}" ) + @RequestMapping( value = "/{type}", method = { RequestMethod.POST, RequestMethod.PUT }, consumes = MediaType.APPLICATION_JSON_VALUE ) + public void validateSchema( @PathVariable String type, HttpServletRequest request, HttpServletResponse response ) throws IOException + { + Schema schema = getSchemaFromType( type ); + + if ( schema == null ) + { + throw new HttpClientErrorException( HttpStatus.NOT_FOUND, "Type " + type + " does not exist." ); + } + + Object object = renderService.fromJson( request.getInputStream(), schema.getKlass() ); + List validationViolations = schemaValidator.validate( object ); + + renderService.toJson( response.getOutputStream(), validationViolations ); + } + + @RequestMapping( value = "/{type}/{property}", method = RequestMethod.GET ) public @ResponseBody Property getSchemaProperty( @PathVariable String type, @PathVariable String property ) { Schema schema = getSchemaFromType( type );