=== 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-07 09:24:35 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java 2013-03-07 12:59:06 +0000 @@ -549,6 +549,23 @@ HttpHeaders headers = new HttpHeaders(); headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE ); + OrganisationUnit organisationUnit; + + if ( id.length() == 11 ) + { + organisationUnit = organisationUnitService.getOrganisationUnit( id ); + } + else + { + organisationUnit = organisationUnitService.getOrganisationUnitByUuid( id ); + } + + if ( organisationUnit == null ) + { + return new ResponseEntity( MessageResponseUtils.jsonMessage( HttpStatus.NOT_FOUND.toString(), + "Facility with that ID not found" ), headers, HttpStatus.NOT_FOUND ); + } + // getId == null is not legal, but will be catched by bean validation if ( facility.getId() != null ) { @@ -572,23 +589,6 @@ if ( constraintViolations.isEmpty() ) { OrganisationUnit organisationUnitUpdate = conversionService.convert( facility, OrganisationUnit.class ); - OrganisationUnit organisationUnit; - - if ( id.length() == 11 ) - { - organisationUnit = organisationUnitService.getOrganisationUnit( id ); - } - else - { - organisationUnit = organisationUnitService.getOrganisationUnitByUuid( id ); - } - - if ( organisationUnit == null ) - { - return new ResponseEntity( MessageResponseUtils.jsonMessage( HttpStatus.NOT_FOUND.toString(), - "Facility with that ID not found" ), headers, HttpStatus.NOT_FOUND ); - } - checkIdentifier( facility, organisationUnit.getUid() ); if ( request.getHeader( "If-Match" ) != null ) === 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-07 09:31:13 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/web/webapi/v1/controller/FacilityControllerTest.java 2013-03-07 12:59:06 +0000 @@ -137,4 +137,13 @@ .andExpect( jsonPath( "$.name" ).value( "OrgUnitA" ) ) .andExpect( status().isOk() ); } + + @Test + public void testPutFacility404() throws Exception + { + MockHttpSession session = getSession( "ALL" ); + + mvc.perform( put( "/v1/facilities/abc123" ).content( "{}" ).session( session ).contentType( MediaType.APPLICATION_JSON ) ) + .andExpect( status().isNotFound() ); + } }