← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9214: FRED-API: exposed facility-converter in conversionService

 

------------------------------------------------------------
revno: 9214
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-12-07 23:03:51 +0300
message:
  FRED-API: exposed facility-converter in conversionService
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/java/org/hisp/dhis/web/webapi/v1/utils/ToFacilityConverter.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-07 19:54:25 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java	2012-12-07 20:03:51 +0000
@@ -34,10 +34,9 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.web.webapi.v1.domain.Facilities;
 import org.hisp.dhis.web.webapi.v1.domain.Facility;
-import org.hisp.dhis.web.webapi.v1.utils.ToFacilityConverter;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.core.convert.converter.Converter;
+import org.springframework.core.convert.ConversionService;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Controller;
@@ -66,7 +65,9 @@
     @Qualifier( "org.hisp.dhis.organisationunit.OrganisationUnitService" )
     private OrganisationUnitService organisationUnitService;
 
-    private static Converter<OrganisationUnit, Facility> toFacility = new ToFacilityConverter();
+    @Autowired
+    @Qualifier( "fredConversionService" )
+    private ConversionService conversionService;
 
     //--------------------------------------------------------------------------
     // GET HTML
@@ -82,7 +83,7 @@
 
         for ( OrganisationUnit organisationUnit : allOrganisationUnits )
         {
-            Facility facility = toFacility.convert( organisationUnit );
+            Facility facility = conversionService.convert( organisationUnit, Facility.class );
 
             facilities.getFacilities().add( facility );
         }
@@ -100,7 +101,7 @@
     {
         OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( id );
 
-        Facility facility = toFacility.convert( organisationUnit );
+        Facility facility = conversionService.convert( organisationUnit, Facility.class );
 
         model.addAttribute( "entity", facility );
         model.addAttribute( "baseUrl", linkTo( FredController.class ).toString() );

=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/ToFacilityConverter.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/ToFacilityConverter.java	2012-12-07 19:54:25 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/ToFacilityConverter.java	2012-12-07 20:03:51 +0000
@@ -32,6 +32,7 @@
 import org.hisp.dhis.web.webapi.v1.controller.FacilityController;
 import org.hisp.dhis.web.webapi.v1.domain.Facility;
 import org.springframework.core.convert.converter.Converter;
+import org.springframework.stereotype.Component;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -43,6 +44,7 @@
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
+@Component
 public class ToFacilityConverter implements Converter<OrganisationUnit, Facility>
 {
     @Override

=== 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-07 16:00:59 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/resources/META-INF/dhis/webapi-fred.xml	2012-12-07 20:03:51 +0000
@@ -10,7 +10,16 @@
 
   <context:component-scan base-package="org.hisp.dhis.web.webapi" />
   <context:annotation-config />
-  <mvc:annotation-driven />
+
+  <bean id="fredConversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
+    <property name="converters">
+      <set>
+        <ref bean="toFacilityConverter" />
+      </set>
+    </property>
+  </bean>
+
+  <mvc:annotation-driven conversion-service="fredConversionService" />
 
   <bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
     <property name="resourceLoaderPath" value="/WEB-INF/api-fred-velocity/" />