dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21193
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9960: FRED-API: set default paging to 25, support limit=off
------------------------------------------------------------
revno: 9960
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-03-04 13:58:36 +0300
message:
FRED-API: set default paging to 25, support limit=off
modified:
dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.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-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 <mortenoh@xxxxxxxxx>
*/
-@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<OrganisationUnit> 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<OrganisationUnit>( organisationUnitService.getOrganisationUnitsBetween( offset, limit ) );
+ allOrganisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitsBetween( offset, limitValue ) );
}
else
{
@@ -266,7 +283,7 @@
if ( limit != null )
{
allOrganisationUnits = new ArrayList<OrganisationUnit>( 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<OrganisationUnit>( organisationUnitService.getOrganisationUnitsBetweenByStatus( active, offset, limit ) );
+ allOrganisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitsBetweenByStatus( active, offset, limitValue ) );
}
else
{
@@ -289,7 +306,7 @@
if ( limit != null )
{
allOrganisationUnits = new ArrayList<OrganisationUnit>( 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<String> 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<String> 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<Void> 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<String> exceptionHandler( Exception ex )
{
return new ResponseEntity<String>( ex.getMessage(), HttpStatus.FORBIDDEN );