=== 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-11-01 11:49:05 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java 2013-11-01 13:59:33 +0000 @@ -94,9 +94,9 @@ /** * @author Morten Olav Hansen */ -@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,36 +245,21 @@ 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( 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(); List allOrganisationUnits; - Integer limitValue = 25; - - if ( limit.equalsIgnoreCase( "off" ) ) - { - limitValue = null; - } - else - { - try - { - limitValue = Integer.parseInt( limit ); - } - catch ( NumberFormatException ignored ) - { - } - } - - if ( active == null && lastUpdated == null ) + Integer limitValue = getLimitValue( limit, 25 ); + + if ( lastUpdated == null ) { if ( limitValue != null ) { @@ -285,7 +270,7 @@ allOrganisationUnits = new ArrayList( organisationUnitService.getAllOrganisationUnits() ); } } - else if ( active == null ) + else { if ( limitValue != null ) { @@ -297,29 +282,6 @@ allOrganisationUnits = new ArrayList( organisationUnitService.getAllOrganisationUnitsByLastUpdated( lastUpdated ) ); } } - else if ( lastUpdated == null ) - { - if ( limitValue != null ) - { - allOrganisationUnits = new ArrayList( organisationUnitService.getOrganisationUnitsBetweenByStatus( active, offset, limitValue ) ); - } - else - { - allOrganisationUnits = new ArrayList( organisationUnitService.getAllOrganisationUnitsByStatus( active ) ); - } - } - else - { - if ( limitValue != null ) - { - allOrganisationUnits = new ArrayList( organisationUnitService. - getOrganisationUnitsBetweenByStatusLastUpdated( active, lastUpdated, offset, limitValue ) ); - } - else - { - allOrganisationUnits = new ArrayList( organisationUnitService.getAllOrganisationUnitsByStatusLastUpdated( active, lastUpdated ) ); - } - } facilities.getMeta().put( "limit", limitValue ); facilities.getMeta().put( "offset", offset ); @@ -364,10 +326,33 @@ return FredController.PREFIX + "/layout"; } - @RequestMapping(value = "/{id}", method = RequestMethod.GET) + private Integer getLimitValue( String limit, int defaultValue ) + { + Integer limitValue; + + if ( limit.equalsIgnoreCase( "off" ) ) + { + limitValue = null; + } + else + { + try + { + limitValue = Integer.parseInt( limit ); + } + catch ( NumberFormatException ignored ) + { + limitValue = defaultValue; + } + } + + return limitValue; + } + + @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, + @RequestParam( value = "allProperties", required = false, defaultValue = "true" ) Boolean allProperties, + @RequestParam( value = "fields", required = false ) String fields, HttpServletRequest request ) throws FacilityNotFoundException { OrganisationUnit organisationUnit = getOrganisationUnit( id ); @@ -459,8 +444,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 createFacility( @RequestBody Facility facility ) throws Exception { if ( facility.getUuid() == null ) @@ -532,8 +517,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 updateFacility( @PathVariable String id, @RequestBody Facility facility, HttpServletRequest request ) throws Exception { HttpHeaders headers = new HttpHeaders(); @@ -629,8 +614,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 deleteFacility( @PathVariable String id ) throws HierarchyViolationException, IOException, FacilityNotFoundException { OrganisationUnit organisationUnit = getOrganisationUnit( id );