------------------------------------------------------------ revno: 10120 committer: Morten Olav Hansen <[email protected]> branch nick: dhis2 timestamp: Sun 2013-03-10 18:28:06 +0300 message: FRED-API: check error code modified: 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/test/java/org/hisp/dhis/web/webapi/v1/controller/FacilityControllerTest.java
-- lp:dhis2 https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk Your team DHIS 2 developers is subscribed to branch lp:dhis2. To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== 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 16:14:46 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java 2013-03-10 15:28:06 +0000 @@ -69,7 +69,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.client.HttpClientErrorException; import javax.servlet.http.HttpServletRequest; import javax.validation.ConstraintViolation; @@ -94,9 +93,9 @@ /** * @author Morten Olav Hansen <[email protected]> */ -@Controller(value = "facility-controller-" + FredController.PREFIX) -@RequestMapping(FacilityController.RESOURCE_PATH) -@PreAuthorize("hasRole('M_dhis-web-api-fred') or hasRole('ALL')") +@Controller( value = "facility-controller-" + FredController.PREFIX ) +@RequestMapping( FacilityController.RESOURCE_PATH ) +@PreAuthorize( "hasRole('M_dhis-web-api-fred') or hasRole('ALL')" ) public class FacilityController { public static final String RESOURCE_PATH = "/" + FredController.PREFIX + "/facilities"; @@ -245,13 +244,13 @@ return facility; } - @RequestMapping(value = "", method = RequestMethod.GET) - public String readFacilities( Model model, @RequestParam(required = false) Boolean active, - @RequestParam(value = "updatedSince", required = false) Date lastUpdated, - @RequestParam(value = "allProperties", required = false, defaultValue = "true") Boolean allProperties, - @RequestParam(value = "fields", required = false) String fields, - @RequestParam(value = "limit", required = false, defaultValue = "25") String limit, - @RequestParam(value = "offset", required = false, defaultValue = "0") Integer offset, + @RequestMapping( value = "", method = RequestMethod.GET ) + public String readFacilities( Model model, @RequestParam( required = false ) Boolean active, + @RequestParam( value = "updatedSince", required = false ) Date lastUpdated, + @RequestParam( value = "allProperties", required = false, defaultValue = "true" ) Boolean allProperties, + @RequestParam( value = "fields", required = false ) String fields, + @RequestParam( value = "limit", required = false, defaultValue = "25" ) String limit, + @RequestParam( value = "offset", required = false, defaultValue = "0" ) Integer offset, HttpServletRequest request ) { Facilities facilities = new Facilities(); @@ -359,17 +358,17 @@ return FredController.PREFIX + "/layout"; } - @RequestMapping(value = "/{id}", method = RequestMethod.GET) + @RequestMapping( value = "/{id}", method = RequestMethod.GET ) public String readFacility( Model model, @PathVariable String id, - @RequestParam(value = "allProperties", required = false, defaultValue = "true") Boolean allProperties, - @RequestParam(value = "fields", required = false) String fields, - HttpServletRequest request ) + @RequestParam( value = "allProperties", required = false, defaultValue = "true" ) Boolean allProperties, + @RequestParam( value = "fields", required = false ) String fields, + HttpServletRequest request ) throws FacilityNotFoundException { OrganisationUnit organisationUnit = getOrganisationUnit( id ); if ( organisationUnit == null ) { - throw new HttpClientErrorException( HttpStatus.NOT_FOUND ); + throw new FacilityNotFoundException(); } List<OrganisationUnitLevel> organisationUnitLevels = organisationUnitService.getOrganisationUnitLevels(); @@ -449,8 +448,8 @@ // POST JSON //-------------------------------------------------------------------------- - @RequestMapping(value = "", method = RequestMethod.POST) - @PreAuthorize("hasRole('F_FRED_CREATE') or hasRole('ALL')") + @RequestMapping( value = "", method = RequestMethod.POST ) + @PreAuthorize( "hasRole('F_FRED_CREATE') or hasRole('ALL')" ) public ResponseEntity<String> createFacility( @RequestBody Facility facility ) throws Exception { if ( facility.getUuid() == null ) @@ -522,8 +521,8 @@ // PUT JSON //-------------------------------------------------------------------------- - @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE) - @PreAuthorize("hasRole('F_FRED_UPDATE') or hasRole('ALL')") + @RequestMapping( value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE ) + @PreAuthorize( "hasRole('F_FRED_UPDATE') or hasRole('ALL')" ) public ResponseEntity<String> updateFacility( @PathVariable String id, @RequestBody Facility facility, HttpServletRequest request ) throws Exception { HttpHeaders headers = new HttpHeaders(); @@ -619,8 +618,8 @@ // DELETE JSON //-------------------------------------------------------------------------- - @RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) - @PreAuthorize("hasRole('F_FRED_DELETE') or hasRole('ALL')") + @RequestMapping( value = "/{id}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE ) + @PreAuthorize( "hasRole('F_FRED_DELETE') or hasRole('ALL')" ) public ResponseEntity<String> deleteFacility( @PathVariable String id ) throws HierarchyViolationException, IOException, FacilityNotFoundException { OrganisationUnit organisationUnit = getOrganisationUnit( id ); === 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 16:14:46 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/web/webapi/v1/controller/FacilityControllerTest.java 2013-03-10 15:28:06 +0000 @@ -35,8 +35,10 @@ import org.hisp.dhis.web.webapi.v1.utils.OrganisationUnitToFacilityConverter; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.mock.web.MockHttpSession; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; @@ -115,6 +117,7 @@ mvc.perform( get( "/v1/facilities/abc123" ).session( session ).accept( MediaType.APPLICATION_JSON ) ) .andExpect( content().contentType( MediaType.APPLICATION_JSON ) ) + .andExpect( jsonPath( "$.code" ).value( HttpStatus.NOT_FOUND.toString() ) ) .andExpect( status().isNotFound() ); } @@ -181,6 +184,7 @@ mvc.perform( put( "/v1/facilities/INVALID_IDENTIFIER" ).content( "{}" ).session( session ).contentType( MediaType.APPLICATION_JSON ) ) .andExpect( content().contentType( MediaType.APPLICATION_JSON ) ) + .andExpect( jsonPath( "$.code" ).value( HttpStatus.NOT_FOUND.toString() ) ) .andExpect( status().isNotFound() ); } @@ -456,6 +460,7 @@ mvc.perform( delete( "/v1/facilities/INVALID_IDENTIFIER" ).session( session ) ) .andExpect( content().contentType( MediaType.APPLICATION_JSON ) ) + .andExpect( jsonPath( "$.code" ).value( HttpStatus.NOT_FOUND.toString() ) ) .andExpect( status().isNotFound() ); }
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : [email protected] Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp

