=== 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-03-09 15:32:50 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityAdvice.java 2013-03-09 16:14:46 +0000 @@ -36,7 +36,9 @@ 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.http.HttpHeaders; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; @@ -59,35 +61,50 @@ @ExceptionHandler( { HttpClientErrorException.class, HttpServerErrorException.class } ) public ResponseEntity statusCodeExceptionHandler( HttpStatusCodeException ex ) throws IOException { + HttpHeaders headers = new HttpHeaders(); + headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE ); + return new ResponseEntity( MessageUtils.jsonMessage( ex.getStatusText(), - ex.getMessage() ), ex.getStatusCode() ); + ex.getMessage() ), headers, ex.getStatusCode() ); } @ExceptionHandler( { DeleteNotAllowedException.class, HierarchyViolationException.class } ) public ResponseEntity handleForbidden( Exception ex ) throws IOException { + HttpHeaders headers = new HttpHeaders(); + headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE ); + return new ResponseEntity( MessageUtils.jsonMessage( HttpStatus.FORBIDDEN.toString(), - ex.getMessage() ), HttpStatus.FORBIDDEN ); + ex.getMessage() ), headers, HttpStatus.FORBIDDEN ); } @ExceptionHandler( { ETagVerificationException.class, UuidFormatException.class } ) public ResponseEntity handlePreconditionFailed( Exception ex ) throws IOException { + HttpHeaders headers = new HttpHeaders(); + headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE ); + return new ResponseEntity( MessageUtils.jsonMessage( HttpStatus.PRECONDITION_FAILED.toString(), - ex.getMessage() ), HttpStatus.PRECONDITION_FAILED ); + ex.getMessage() ), headers, HttpStatus.PRECONDITION_FAILED ); } @ExceptionHandler( { FacilityNotFoundException.class } ) public ResponseEntity handleNotFound( Exception ex ) throws IOException { + HttpHeaders headers = new HttpHeaders(); + headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE ); + return new ResponseEntity( MessageUtils.jsonMessage( HttpStatus.NOT_FOUND.toString(), - ex.getMessage() ), HttpStatus.NOT_FOUND ); + ex.getMessage() ), headers, HttpStatus.NOT_FOUND ); } @ExceptionHandler( { DuplicateCodeException.class, DuplicateUidException.class, DuplicateUuidException.class } ) public ResponseEntity handleConflict( Exception ex ) throws IOException { + HttpHeaders headers = new HttpHeaders(); + headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE ); + return new ResponseEntity( MessageUtils.jsonMessage( HttpStatus.CONFLICT.toString(), - ex.getMessage() ), HttpStatus.CONFLICT ); + ex.getMessage() ), headers, HttpStatus.CONFLICT ); } } === modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java' --- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java 2013-03-09 15:32:50 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java 2013-03-09 16:14:46 +0000 @@ -48,6 +48,7 @@ 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.ContextUtils; +import org.hisp.dhis.web.webapi.v1.utils.MessageUtils; import org.hisp.dhis.web.webapi.v1.utils.ValidationUtils; import org.hisp.dhis.web.webapi.v1.validation.group.Create; import org.hisp.dhis.web.webapi.v1.validation.group.Update; @@ -618,7 +619,7 @@ // DELETE JSON //-------------------------------------------------------------------------- - @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) + @RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) @PreAuthorize("hasRole('F_FRED_DELETE') or hasRole('ALL')") public ResponseEntity deleteFacility( @PathVariable String id ) throws HierarchyViolationException, IOException, FacilityNotFoundException { @@ -631,7 +632,8 @@ organisationUnitService.deleteOrganisationUnit( organisationUnit ); - return new ResponseEntity( HttpStatus.OK ); + return new ResponseEntity( MessageUtils.jsonMessage( HttpStatus.OK.toString(), + "{}" ), HttpStatus.OK ); } //-------------------------------------------------------------------------- === modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/web/webapi/v1/controller/FacilityControllerTest.java' --- dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/web/webapi/v1/controller/FacilityControllerTest.java 2013-03-09 08:30:36 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/web/webapi/v1/controller/FacilityControllerTest.java 2013-03-09 16:14:46 +0000 @@ -114,6 +114,7 @@ MockHttpSession session = getSession( "ALL" ); mvc.perform( get( "/v1/facilities/abc123" ).session( session ).accept( MediaType.APPLICATION_JSON ) ) + .andExpect( content().contentType( MediaType.APPLICATION_JSON ) ) .andExpect( status().isNotFound() ); } @@ -127,6 +128,7 @@ mvc.perform( get( "/v1/facilities/" + organisationUnit.getUid() ).session( session ).accept( MediaType.APPLICATION_JSON ) ) .andExpect( header().string( "ETag", Matchers.notNullValue() ) ) + .andExpect( content().contentType( MediaType.APPLICATION_JSON ) ) .andExpect( status().isOk() ); } @@ -178,6 +180,7 @@ MockHttpSession session = getSession( "ALL" ); mvc.perform( put( "/v1/facilities/INVALID_IDENTIFIER" ).content( "{}" ).session( session ).contentType( MediaType.APPLICATION_JSON ) ) + .andExpect( content().contentType( MediaType.APPLICATION_JSON ) ) .andExpect( status().isNotFound() ); } @@ -294,6 +297,7 @@ mvc.perform( put( "/v1/facilities/" + organisationUnit.getUuid() ).content( objectMapper.writeValueAsString( facility ) ) .session( session ).contentType( MediaType.APPLICATION_JSON ) ) + .andExpect( content().contentType( MediaType.APPLICATION_JSON ) ) .andExpect( status().isPreconditionFailed() ); } @@ -326,6 +330,7 @@ mvc.perform( post( "/v1/facilities" ).content( "{}" ) .session( session ).contentType( MediaType.APPLICATION_JSON ) ) + .andExpect( content().contentType( MediaType.APPLICATION_JSON ) ) .andExpect( status().isUnprocessableEntity() ); } @@ -339,6 +344,7 @@ mvc.perform( post( "/v1/facilities" ).content( objectMapper.writeValueAsString( facility ) ) .session( session ).contentType( MediaType.APPLICATION_JSON ) ) + .andExpect( content().contentType( MediaType.APPLICATION_JSON ) ) .andExpect( status().isPreconditionFailed() ); } @@ -449,6 +455,7 @@ MockHttpSession session = getSession( "ALL" ); mvc.perform( delete( "/v1/facilities/INVALID_IDENTIFIER" ).session( session ) ) + .andExpect( content().contentType( MediaType.APPLICATION_JSON ) ) .andExpect( status().isNotFound() ); } @@ -461,6 +468,7 @@ MockHttpSession session = getSession( "ALL" ); mvc.perform( delete( "/v1/facilities/" + organisationUnit.getUid() ).session( session ) ) + .andExpect( content().contentType( MediaType.APPLICATION_JSON ) ) .andExpect( status().isOk() ); } @@ -473,6 +481,7 @@ MockHttpSession session = getSession( "ALL" ); mvc.perform( delete( "/v1/facilities/" + organisationUnit.getUuid() ).session( session ) ) + .andExpect( content().contentType( MediaType.APPLICATION_JSON ) ) .andExpect( status().isOk() ); }