← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9262: FRED-API: added filtering options active/updatedSince, full ISO not support yet.

 

------------------------------------------------------------
revno: 9262
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-12-11 12:10:56 +0300
message:
  FRED-API: added filtering options active/updatedSince, full ISO not support yet.
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/main/resources/META-INF/dhis/webapi-fred.xml


--
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	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<OrganisationUnit> allOrganisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.getAllOrganisationUnits() );
+        List<OrganisationUnit> allOrganisationUnits = null;
+
+        if ( active == null && lastUpdated == null )
+        {
+            allOrganisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.getAllOrganisationUnits() );
+        }
+        else if ( active == null )
+        {
+            allOrganisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.getAllOrganisationUnitsByLastUpdated( lastUpdated ) );
+        }
+        else if ( lastUpdated == null )
+        {
+            allOrganisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.getAllOrganisationUnitsByStatus( active ) );
+        }
+        else
+        {
+            allOrganisationUnits = new ArrayList<OrganisationUnit>( 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 @@
     </property>
   </bean>
 
+  <!-- TODO: doesn't seem to work right now, will investigate later
+  <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
+    <property name="converters">
+      <set>
+        <ref bean="toFacilityConverter" />
+        <ref bean="toOrganisationUnitConverter" />
+      </set>
+    </property>
+
+    <property name="formatterRegistrars">
+      <set>
+        <bean class="org.springframework.format.datetime.joda.JodaTimeFormatterRegistrar">
+          <property name="useIsoFormat" value="true" />
+        </bean>
+      </set>
+    </property>
+  </bean>
+    -->
+
   <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
 
   <mvc:annotation-driven conversion-service="conversionService" validator="validator" />