=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityAdvice.java' --- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityAdvice.java 2013-11-01 10:15:04 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityAdvice.java 2013-11-01 11:24:53 +0000 @@ -37,19 +37,30 @@ import org.hisp.dhis.web.webapi.v1.exception.FacilityNotFoundException; import org.hisp.dhis.web.webapi.v1.exception.UuidFormatException; import org.hisp.dhis.web.webapi.v1.utils.MessageUtils; +import org.springframework.beans.ConversionNotSupportedException; +import org.springframework.beans.TypeMismatchException; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.http.converter.HttpMessageNotWritableException; +import org.springframework.validation.BindException; import org.springframework.web.HttpMediaTypeNotAcceptableException; import org.springframework.web.HttpMediaTypeNotSupportedException; +import org.springframework.web.HttpRequestMethodNotSupportedException; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.MissingServletRequestParameterException; +import org.springframework.web.bind.ServletRequestBindingException; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.HttpServerErrorException; import org.springframework.web.client.HttpStatusCodeException; import org.springframework.web.context.request.WebRequest; +import org.springframework.web.multipart.support.MissingServletRequestPartException; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; +import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException; import java.io.IOException; @@ -130,4 +141,112 @@ return new ResponseEntity( MessageUtils.jsonMessage( Integer.toString( status.value() ), ex.getMessage() ), status ); } + + @Override + protected ResponseEntity handleExceptionInternal( Exception ex, Object body, HttpHeaders headers, HttpStatus status, WebRequest request ) + { + headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE ); + + return new ResponseEntity( MessageUtils.jsonMessage( + Integer.toString( status.value() ), ex.getMessage() ), status ); + } + + @Override + protected ResponseEntity handleNoSuchRequestHandlingMethod( NoSuchRequestHandlingMethodException ex, HttpHeaders headers, HttpStatus status, WebRequest request ) + { + headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE ); + + return new ResponseEntity( MessageUtils.jsonMessage( + Integer.toString( status.value() ), ex.getMessage() ), status ); + } + + @Override + protected ResponseEntity handleHttpRequestMethodNotSupported( HttpRequestMethodNotSupportedException ex, HttpHeaders headers, HttpStatus status, WebRequest request ) + { + headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE ); + + return new ResponseEntity( MessageUtils.jsonMessage( + Integer.toString( status.value() ), ex.getMessage() ), status ); + } + + @Override + protected ResponseEntity handleMissingServletRequestParameter( MissingServletRequestParameterException ex, HttpHeaders headers, HttpStatus status, WebRequest request ) + { + headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE ); + + return new ResponseEntity( MessageUtils.jsonMessage( + Integer.toString( status.value() ), ex.getMessage() ), status ); + } + + @Override + protected ResponseEntity handleServletRequestBindingException( ServletRequestBindingException ex, HttpHeaders headers, HttpStatus status, WebRequest request ) + { + headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE ); + + return new ResponseEntity( MessageUtils.jsonMessage( + Integer.toString( status.value() ), ex.getMessage() ), status ); + } + + @Override + protected ResponseEntity handleConversionNotSupported( ConversionNotSupportedException ex, HttpHeaders headers, HttpStatus status, WebRequest request ) + { + headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE ); + + return new ResponseEntity( MessageUtils.jsonMessage( + Integer.toString( status.value() ), ex.getMessage() ), status ); + } + + @Override + protected ResponseEntity handleTypeMismatch( TypeMismatchException ex, HttpHeaders headers, HttpStatus status, WebRequest request ) + { + headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE ); + + return new ResponseEntity( MessageUtils.jsonMessage( + Integer.toString( status.value() ), ex.getMessage() ), status ); + } + + @Override + protected ResponseEntity handleHttpMessageNotReadable( HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatus status, WebRequest request ) + { + headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE ); + + return new ResponseEntity( MessageUtils.jsonMessage( + Integer.toString( status.value() ), ex.getMessage() ), status ); + } + + @Override + protected ResponseEntity handleHttpMessageNotWritable( HttpMessageNotWritableException ex, HttpHeaders headers, HttpStatus status, WebRequest request ) + { + headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE ); + + return new ResponseEntity( MessageUtils.jsonMessage( + Integer.toString( status.value() ), ex.getMessage() ), status ); + } + + @Override + protected ResponseEntity handleMethodArgumentNotValid( MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request ) + { + headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE ); + + return new ResponseEntity( MessageUtils.jsonMessage( + Integer.toString( status.value() ), ex.getMessage() ), status ); + } + + @Override + protected ResponseEntity handleMissingServletRequestPart( MissingServletRequestPartException ex, HttpHeaders headers, HttpStatus status, WebRequest request ) + { + headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE ); + + return new ResponseEntity( MessageUtils.jsonMessage( + Integer.toString( status.value() ), ex.getMessage() ), status ); + } + + @Override + protected ResponseEntity handleBindException( BindException ex, HttpHeaders headers, HttpStatus status, WebRequest request ) + { + headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE ); + + return new ResponseEntity( MessageUtils.jsonMessage( + Integer.toString( status.value() ), ex.getMessage() ), status ); + } } === modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/domain/Facility.java' --- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/domain/Facility.java 2013-08-23 16:05:01 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/domain/Facility.java 2013-11-01 11:24:53 +0000 @@ -53,7 +53,7 @@ // Name of the facility @NotNull - @Length(min = 2, max = 160) + @Length( min = 2, max = 160 ) private String name; // Active = true/false indicates whether the facility is active or not