=== 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 2012-12-10 13:53:34 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java 2012-12-11 09:10:56 +0000 @@ -50,16 +50,17 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.*; import javax.validation.ConstraintViolation; import javax.validation.Validator; import javax.validation.groups.Default; +import java.beans.PropertyEditorSupport; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; @@ -88,16 +89,69 @@ @Autowired private Validator validator; + @InitBinder + protected void initBinder( WebDataBinder binder ) + { + binder.registerCustomEditor( Date.class, new PropertyEditorSupport() + { + private SimpleDateFormat[] simpleDateFormats = new SimpleDateFormat[]{ + new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssZ" ), + new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss" ), + new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm" ), + new SimpleDateFormat( "yyyy-MM-dd'T'HH" ), + new SimpleDateFormat( "yyyy-MM-dd" ), + new SimpleDateFormat( "yyyy-MM" ), + new SimpleDateFormat( "yyyy" ) + }; + + @Override + public void setAsText( String value ) throws IllegalArgumentException + { + for ( SimpleDateFormat simpleDateFormat : simpleDateFormats ) + { + try + { + setValue( simpleDateFormat.parse( value ) ); + return; + } + catch ( ParseException ignored ) + { + } + } + + setValue( null ); + } + } ); + } + //-------------------------------------------------------------------------- // GET HTML //-------------------------------------------------------------------------- @RequestMapping( value = "", method = RequestMethod.GET ) - public String readFacilities( Model model ) + public String readFacilities( Model model, @RequestParam( required = false ) Boolean active, + @RequestParam( value = "updatedSince", required = false ) Date lastUpdated ) { Facilities facilities = new Facilities(); - - List allOrganisationUnits = new ArrayList( organisationUnitService.getAllOrganisationUnits() ); + List allOrganisationUnits = null; + + if ( active == null && lastUpdated == null ) + { + allOrganisationUnits = new ArrayList( organisationUnitService.getAllOrganisationUnits() ); + } + else if ( active == null ) + { + allOrganisationUnits = new ArrayList( organisationUnitService.getAllOrganisationUnitsByLastUpdated( lastUpdated ) ); + } + else if ( lastUpdated == null ) + { + allOrganisationUnits = new ArrayList( organisationUnitService.getAllOrganisationUnitsByStatus( active ) ); + } + else + { + allOrganisationUnits = new ArrayList( organisationUnitService.getAllOrganisationUnitsByStatusLastUpdated( active, lastUpdated ) ); + } + Collections.sort( allOrganisationUnits, IdentifiableObjectNameComparator.INSTANCE ); for ( OrganisationUnit organisationUnit : allOrganisationUnits ) === modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/resources/META-INF/dhis/webapi-fred.xml' --- dhis-2/dhis-web/dhis-web-api-fred/src/main/resources/META-INF/dhis/webapi-fred.xml 2012-12-10 13:53:34 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/main/resources/META-INF/dhis/webapi-fred.xml 2012-12-11 09:10:56 +0000 @@ -24,6 +24,25 @@ + +