=== 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 15:37:24 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/ValidationViolation.java 2014-12-23 09:40:40 +0000 @@ -31,6 +31,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import org.hisp.dhis.common.DxfNamespaces; /** @@ -39,6 +40,7 @@ @JsonPropertyOrder( { "message" } ) +@JacksonXmlRootElement( localName = "validationViolation", namespace = DxfNamespaces.DXF_2_0 ) public class ValidationViolation { private String property; === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/ValidationViolations.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/ValidationViolations.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/ValidationViolations.java 2014-12-23 09:40:40 +0000 @@ -0,0 +1,71 @@ +package org.hisp.dhis.dxf2.schema; + +/* + * Copyright (c) 2004-2014, 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. + */ + +import com.fasterxml.jackson.annotation.JsonProperty; +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.common.DxfNamespaces; + +import java.util.ArrayList; +import java.util.List; + +/** + * Temporary wrapper for ValidationViolation + * + * @author Morten Olav Hansen + */ +@JacksonXmlRootElement( localName = "validationViolations", namespace = DxfNamespaces.DXF_2_0 ) +public class ValidationViolations +{ + private List validationViolations = new ArrayList<>(); + + public ValidationViolations() + { + } + + public ValidationViolations( List validationViolations ) + { + this.validationViolations = validationViolations; + } + + @JsonProperty + @JacksonXmlElementWrapper( localName = "validationViolations", namespace = DxfNamespaces.DXF_2_0, useWrapping = false ) + @JacksonXmlProperty( localName = "validationViolation", namespace = DxfNamespaces.DXF_2_0 ) + public List getValidationViolations() + { + return validationViolations; + } + + public void setValidationViolations( List validationViolations ) + { + this.validationViolations = validationViolations; + } +} === 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-22 13:52:51 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SchemaController.java 2014-12-23 09:40:40 +0000 @@ -31,6 +31,7 @@ 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.dxf2.schema.ValidationViolations; import org.hisp.dhis.schema.Property; import org.hisp.dhis.schema.Schema; import org.hisp.dhis.schema.SchemaService; @@ -86,7 +87,7 @@ } @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 + public void validateSchemaJson( @PathVariable String type, HttpServletRequest request, HttpServletResponse response ) throws IOException { Schema schema = getSchemaFromType( type ); @@ -101,6 +102,22 @@ renderService.toJson( response.getOutputStream(), validationViolations ); } + @RequestMapping( value = "/{type}", method = { RequestMethod.POST, RequestMethod.PUT }, consumes = MediaType.APPLICATION_XML_VALUE ) + public void validateSchemaXml( @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.fromXml( request.getInputStream(), schema.getKlass() ); + List validationViolations = schemaValidator.validate( object ); + + renderService.toXml( response.getOutputStream(), new ValidationViolations( validationViolations ) ); + } + @RequestMapping( value = "/{type}/{property}", method = RequestMethod.GET ) public @ResponseBody Property getSchemaProperty( @PathVariable String type, @PathVariable String property ) {