=== 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-02-07 12:57:52 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java 2013-03-04 10:58:36 +0000 @@ -90,9 +90,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"; @@ -238,23 +238,40 @@ 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) Integer 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(); 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 ) { - if ( limit != null ) + if ( limitValue != null ) { - allOrganisationUnits = new ArrayList( organisationUnitService.getOrganisationUnitsBetween( offset, limit ) ); + allOrganisationUnits = new ArrayList( organisationUnitService.getOrganisationUnitsBetween( offset, limitValue ) ); } else { @@ -266,7 +283,7 @@ if ( limit != null ) { allOrganisationUnits = new ArrayList( organisationUnitService. - getOrganisationUnitsBetweenByLastUpdated( lastUpdated, offset, limit ) ); + getOrganisationUnitsBetweenByLastUpdated( lastUpdated, offset, limitValue ) ); } else { @@ -275,9 +292,9 @@ } else if ( lastUpdated == null ) { - if ( limit != null ) + if ( limitValue != null ) { - allOrganisationUnits = new ArrayList( organisationUnitService.getOrganisationUnitsBetweenByStatus( active, offset, limit ) ); + allOrganisationUnits = new ArrayList( organisationUnitService.getOrganisationUnitsBetweenByStatus( active, offset, limitValue ) ); } else { @@ -289,7 +306,7 @@ if ( limit != null ) { allOrganisationUnits = new ArrayList( organisationUnitService. - getOrganisationUnitsBetweenByStatusLastUpdated( active, lastUpdated, offset, limit ) ); + getOrganisationUnitsBetweenByStatusLastUpdated( active, lastUpdated, offset, limitValue ) ); } else { @@ -321,10 +338,10 @@ 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, + @RequestParam( value = "allProperties", required = false, defaultValue = "true" ) Boolean allProperties, + @RequestParam( value = "fields", required = false ) String fields, HttpServletRequest request ) { OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( id ); @@ -400,8 +417,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.getId() == null ) @@ -500,8 +517,8 @@ } } - @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(); @@ -599,8 +616,8 @@ // DELETE JSON //-------------------------------------------------------------------------- - @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) - @PreAuthorize("hasRole('F_FRED_DELETE') or hasRole('ALL')") + @RequestMapping( value = "/{id}", method = RequestMethod.DELETE ) + @PreAuthorize( "hasRole('F_FRED_DELETE') or hasRole('ALL')" ) public ResponseEntity deleteFacility( @PathVariable String id ) throws HierarchyViolationException { OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( id ); @@ -619,7 +636,7 @@ // EXCEPTION HANDLERS //-------------------------------------------------------------------------- - @ExceptionHandler({ DeleteNotAllowedException.class, HierarchyViolationException.class }) + @ExceptionHandler( { DeleteNotAllowedException.class, HierarchyViolationException.class } ) public ResponseEntity exceptionHandler( Exception ex ) { return new ResponseEntity( ex.getMessage(), HttpStatus.FORBIDDEN );