← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1893: Trying to clean up somewhat.

 

------------------------------------------------------------
revno: 1893
committer: Jo Størset <storset@xxxxxxxxx>
branch nick: cbhis-mobile
timestamp: Tue 2010-08-10 00:50:29 +0200
message:
  Trying to clean up somewhat.
removed:
  dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/resources/ActivityPlanResource.java
added:
  dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/resources/ActivitiesResource.java
  dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/OrgUnitsMapper.java
modified:
  dhis-2/dhis-web/dhis-web-cbhis-api/pom.xml
  dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/model/Link.java
  dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/model/OrgUnit.java
  dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/model/OrgUnits.java
  dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/resources/DhisMediaType.java
  dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/resources/MobileUserResource.java
  dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/resources/OrgUnitResource.java
  dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/ActivityPlanModelService.java
  dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/MappingFactory.java
  dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/ActivityPlanItemMapper.java
  dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/ActivityPlanMapper.java
  dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/BeanMapper.java
  dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/BeneficiaryMapper.java
  dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/TaskMapper.java
  dhis-2/dhis-web/dhis-web-cbhis-api/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-cbhis-api/src/test/java/org/hisp/dhis/patient/api/service/ActivityPlanModelServiceTest.java
  dhis-2/dhis-web/dhis-web-cbhis-api/src/test/java/org/hisp/dhis/patient/api/service/ModelMapperTest.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-cbhis-api/pom.xml'
--- dhis-2/dhis-web/dhis-web-cbhis-api/pom.xml	2010-08-09 11:40:55 +0000
+++ dhis-2/dhis-web/dhis-web-cbhis-api/pom.xml	2010-08-09 22:50:29 +0000
@@ -38,11 +38,8 @@
       <artifactId>jersey-server</artifactId>
       <version>1.3</version>
     </dependency>
-<!--    <dependency>
-      <groupId>com.sun.jersey</groupId>
-      <artifactId>jersey-json</artifactId>
-      <version>1.3</version>
-    </dependency>-->
+    <!-- <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-json</artifactId> 
+      <version>1.3</version> </dependency> -->
     <dependency>
       <groupId>com.sun.jersey.contribs</groupId>
       <artifactId>jersey-spring</artifactId>
@@ -70,7 +67,11 @@
         </exclusion>
       </exclusions>
     </dependency>
-
+    <!-- dependency>
+      <groupId>net.sf.dozer</groupId>
+      <artifactId>dozer</artifactId>
+      <version>5.2.2</version>
+    </dependency> -->
     <!-- DHIS -->
 
     <dependency>

=== modified file 'dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/model/Link.java'
--- dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/model/Link.java	2010-08-09 19:43:12 +0000
+++ dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/model/Link.java	2010-08-09 22:50:29 +0000
@@ -20,12 +20,10 @@
         this.url = url;
     }
 
-    public static Link create( UriInfo uriInfo, Class<?> clazz, int id )
+    public void setUrl( String url )
     {
-        Link l = new Link();
-        l.url = uriInfo.getBaseUriBuilder().path( clazz ).build( id ).toString();
-        
-        return l;
+        this.url = url;
     }
-    
+
+
 }

=== modified file 'dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/model/OrgUnit.java'
--- dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/model/OrgUnit.java	2010-08-09 11:40:55 +0000
+++ dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/model/OrgUnit.java	2010-08-09 22:50:29 +0000
@@ -1,14 +1,9 @@
 package org.hisp.dhis.patient.api.model;
 
-import javax.ws.rs.core.UriInfo;
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.patient.api.resources.ActivityPlanResource;
-import org.hisp.dhis.patient.api.resources.ProgramFormsResource;
-
 @XmlRootElement(name="orgUnit")
 public class OrgUnit {
 
@@ -22,15 +17,26 @@
     
     @XmlElement(name="currentActivities")
     private Link activitiesLink;
+
+    public void setId( int id )
+    {
+        this.id = id;
+    }
+
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+
+    public void setProgramFormsLink( Link programFormsLink )
+    {
+        this.programFormsLink = programFormsLink;
+    }
+
+    public void setActivitiesLink( Link activitiesLink )
+    {
+        this.activitiesLink = activitiesLink;
+    }
+ 
     
-    public static OrgUnit create(OrganisationUnit unit, UriInfo uriInfo) {
-        OrgUnit m = new OrgUnit();
-        m.id = unit.getId();
-        m.name = unit.getShortName();
-        m.programFormsLink = Link.create(uriInfo, ProgramFormsResource.class, m.id);
-        m.activitiesLink = Link.create(uriInfo, ActivityPlanResource.class, m.id);
-
-        
-        return m;
-    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/model/OrgUnits.java'
--- dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/model/OrgUnits.java	2010-08-09 11:40:55 +0000
+++ dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/model/OrgUnits.java	2010-08-09 22:50:29 +0000
@@ -26,17 +26,4 @@
         this.orgUnitList = orgUnitList;
     }
 
-    public static OrgUnits create( Collection<OrganisationUnit> units, UriInfo uriInfo )
-    {
-        OrgUnits o = new OrgUnits();
-        
-        o.orgUnitList = new ArrayList<OrgUnit>();
-        for ( OrganisationUnit unit : units )
-        {
-            o.orgUnitList.add( OrgUnit.create( unit, uriInfo ) );
-        }
-        
-        return o;
-    }
-
 }

=== added file 'dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/resources/ActivitiesResource.java'
--- dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/resources/ActivitiesResource.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/resources/ActivitiesResource.java	2010-08-09 22:50:29 +0000
@@ -0,0 +1,48 @@
+package org.hisp.dhis.patient.api.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.patient.api.model.ActivityPlan;
+import org.hisp.dhis.patient.api.service.ActivityPlanModelService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+
+public class ActivitiesResource
+{
+
+    private static final Log LOG = LogFactory.getLog( OrgUnitResource.class );
+
+    @Autowired
+    private ActivityPlanModelService service;
+
+    private OrganisationUnit organisationUnit;
+
+    @GET
+    @Path("plan/current")
+    @Produces( { MediaType.APPLICATION_XML, DhisMediaType.ACTIVITYPLAN_SERIALIZED } )
+    public ActivityPlan getCurrentActivityPlan()
+    {
+        return service.getCurrentActivityPlan( organisationUnit );
+    }
+
+    @GET
+    @Path("all")
+    @Produces( { MediaType.APPLICATION_XML, DhisMediaType.ACTIVITYPLAN_SERIALIZED } )
+    public ActivityPlan getOrgUnitActivityPlan()
+    {
+        return service.getAllActivities( organisationUnit );
+    }
+
+    public void setOrganisationUnit( OrganisationUnit organisationUnit )
+    {
+        this.organisationUnit = organisationUnit;
+    }
+
+}

=== removed file 'dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/resources/ActivityPlanResource.java'
--- dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/resources/ActivityPlanResource.java	2010-08-09 19:43:12 +0000
+++ dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/resources/ActivityPlanResource.java	1970-01-01 00:00:00 +0000
@@ -1,31 +0,0 @@
-package org.hisp.dhis.patient.api.resources;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hisp.dhis.patient.api.model.ActivityPlan;
-import org.hisp.dhis.patient.api.service.ActivityPlanModelService;
-import org.springframework.beans.factory.annotation.Autowired;
-
-@Path( "v0.1/orgunits/{id}/activityplan" )
-public class ActivityPlanResource
-{
-
-    private static final Log LOG = LogFactory.getLog( OrgUnitResource.class );
-
-    @Autowired
-    private ActivityPlanModelService service;
-
-    @GET
-    @Produces( { MediaType.APPLICATION_XML, DhisMediaType.ACTIVITYPLAN_SERIALIZED } )
-    public ActivityPlan getOrgUnitActivityPlan( @PathParam( "id" ) int id )
-    {
-        return service.getActivityPlan( id );
-    }
-
-}

=== modified file 'dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/resources/DhisMediaType.java'
--- dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/resources/DhisMediaType.java	2010-08-09 11:40:55 +0000
+++ dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/resources/DhisMediaType.java	2010-08-09 22:50:29 +0000
@@ -2,8 +2,9 @@
 
 public class DhisMediaType
 {
-    public static final String ACTIVITYPLAN_SERIALIZED = "application/vnd.org.dhis2.casebased.v0.1.activityplan+serialized";
-    public static final String ORG_UNITS_XML = "application/vnd.org.dhis2.casebased.v0.1.OrgUnits+xml";
-    public static final String ORG_UNITS_SERIALIZED = "application/vnd.org.dhis2.casebased.v0.1.OrgUnits+serialized";
+    public static final String ACTIVITYPLAN_SERIALIZED = "application/vnd.org.dhis2.cbhis.v0.1.activityplan+serialized";
+
+    public static final String ORG_UNITS_XML = "application/vnd.org.dhis2.cbhis.v0.1.OrgUnits+xml";
+    public static final String ORG_UNITS_SERIALIZED = "application/vnd.org.dhis2.cbhis.v0.1.OrgUnits+serialized";
 
 }

=== modified file 'dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/resources/MobileUserResource.java'
--- dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/resources/MobileUserResource.java	2010-08-09 11:40:55 +0000
+++ dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/resources/MobileUserResource.java	2010-08-09 22:50:29 +0000
@@ -4,6 +4,7 @@
 
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
@@ -14,10 +15,13 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.patient.api.model.OrgUnits;
+import org.hisp.dhis.patient.api.service.MappingFactory;
 import org.hisp.dhis.user.CurrentUserService;
 import org.hisp.dhis.user.User;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import com.sun.jersey.api.core.ResourceContext;
+
 @Path( "v0.1" )
 public class MobileUserResource
 {
@@ -30,9 +34,15 @@
     @Autowired
     private CurrentUserService currentUserService;
 
+    @Autowired
+    private MappingFactory mappingFactory;
+
     @Context
     private UriInfo uriInfo;
 
+    @Context
+    private ResourceContext rc;
+    
     @GET
     @Produces( { MediaType.APPLICATION_XML, DhisMediaType.ORG_UNITS_XML } )
     public OrgUnits getOrgUnitsForUser()
@@ -46,10 +56,13 @@
             return null;
         }
 
-        OrgUnits orgUnits = OrgUnits.create( units, uriInfo );
-
-        return orgUnits;
-
-    }
-
+        return mappingFactory.getBeanMapper( units, OrgUnits.class ).getModel( units, mappingFactory, uriInfo );
+    }
+
+    @Path("orgUnits/{id}")
+    public OrgUnitResource getOrgUnitResource(@PathParam("id") int id) {
+        OrgUnitResource subResource = rc.getResource(OrgUnitResource.class);
+        subResource.setOrganisationUnit(organisationUnitService.getOrganisationUnit( id ));
+        return subResource;
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/resources/OrgUnitResource.java'
--- dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/resources/OrgUnitResource.java	2010-08-09 11:40:55 +0000
+++ dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/resources/OrgUnitResource.java	2010-08-09 22:50:29 +0000
@@ -1,14 +1,33 @@
 package org.hisp.dhis.patient.api.resources;
 
 import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
-@Path("v0.1/orgunits/{id}")
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+
+import com.sun.jersey.api.core.ResourceContext;
+
 public class OrgUnitResource {
 
     private static final Log LOG = LogFactory.getLog( OrgUnitResource.class );
 
+    @Context ResourceContext rc;
     
+    private OrganisationUnit organisationUnit;
+
+    public void setOrganisationUnit( OrganisationUnit organisationUnit )
+    {
+        this.organisationUnit = organisationUnit;
+    }
+
+    @Path( "activities" )
+    public ActivitiesResource getActivitiesResource() {
+        ActivitiesResource subResource = rc.getResource( ActivitiesResource.class );
+        subResource.setOrganisationUnit(organisationUnit);
+        
+        return subResource;
+    }
+
 }

=== modified file 'dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/ActivityPlanModelService.java'
--- dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/ActivityPlanModelService.java	2010-08-09 19:43:12 +0000
+++ dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/ActivityPlanModelService.java	2010-08-09 22:50:29 +0000
@@ -1,12 +1,21 @@
 package org.hisp.dhis.patient.api.service;
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.SortedSet;
+
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
 
 import org.hisp.dhis.activityplan.Activity;
 import org.hisp.dhis.activityplan.ActivityPlanService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.patient.api.model.ActivityPlan;
+import org.hisp.dhis.patient.api.model.ActivityPlanItem;
+import org.joda.time.DateTime;
 import org.springframework.beans.factory.annotation.Autowired;
 
 public class ActivityPlanModelService
@@ -20,14 +29,37 @@
     @Autowired
     private OrganisationUnitService organisationUnitService;
 
-    public ActivityPlan getActivityPlan( int orgUnitId )
-    {
-        OrganisationUnit unit = organisationUnitService.getOrganisationUnit( orgUnitId );
+    @Context
+    private UriInfo uriInfo;
+
+    public ActivityPlan getCurrentActivityPlan( OrganisationUnit unit )
+    {
+        DateTime dt = new DateTime();
+        Date from = dt.withDayOfMonth( 1 ).toDateMidnight().toDate();
+        Date to = dt.plusMonths( 1 ).withDayOfMonth( 1 ).toDate();
+        
+        final Collection<Activity> allActivities = activityPlanService.getActivitiesWithInDate( from, to );
+        Collection<Activity> activities = new ArrayList<Activity>();
+        for ( Activity activity : allActivities )
+        {
+            if (activity.getProvider().getId() == unit.getId()) {
+                activities.add( activity );
+            }
+        }
+        
+        ActivityPlan plan = mappingFactory.getBeanMapper(Collection.class, ActivityPlan.class).getModel( activities, mappingFactory, uriInfo );
+
+        return plan;
+    }
+
+    public ActivityPlan getAllActivities( OrganisationUnit unit )
+    {
         final Collection<Activity> activities = activityPlanService.getActivitiesByProvider( unit );
         
-        return mappingFactory.getBeanMapper(Collection.class, ActivityPlan.class).getModel( activities, mappingFactory );
+        return mappingFactory.getBeanMapper(activities, ActivityPlan.class).getModel( activities, mappingFactory, uriInfo );
     }
 
+    
     public void setActivityPlanService( ActivityPlanService activityPlanService )
     {
         this.activityPlanService = activityPlanService;
@@ -43,6 +75,7 @@
         this.mappingFactory = mappingFactory;
     }
 
+
     
     
 }

=== modified file 'dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/MappingFactory.java'
--- dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/MappingFactory.java	2010-08-09 19:43:12 +0000
+++ dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/MappingFactory.java	2010-08-09 22:50:29 +0000
@@ -1,5 +1,6 @@
 package org.hisp.dhis.patient.api.service;
 
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -10,6 +11,8 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.patient.api.model.OrgUnits;
 import org.hisp.dhis.patient.api.resources.OrgUnitResource;
 import org.hisp.dhis.patient.api.service.mapping.BeanMapper;
 import org.springframework.beans.factory.BeanInitializationException;
@@ -30,12 +33,12 @@
     public void setMappers( Set<BeanMapper<?, ?>> mappers )
     {
         this.mappers = mappers;
+        init();
     }
 
     Map<Class<?>, BeanMapper<?, ?>> mappingIndex = new HashMap<Class<?>, BeanMapper<?, ?>>();
 
-    @PostConstruct
-    public void init()
+    private void init()
     {
         if ( mappers == null || mappers.isEmpty() )
         {
@@ -75,6 +78,12 @@
         return beanMapper;
     }
 
+
+    public <S, T> BeanMapper<Collection<S>, T> getBeanMapper( Collection<S> entity, Class<T> destination )
+    {
+        return (BeanMapper<Collection<S>, T>) this.mappingIndex.get( destination );
+    }
+
     
     
 //    private <T> T map( Object entity, Class<T> destination )

=== modified file 'dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/ActivityPlanItemMapper.java'
--- dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/ActivityPlanItemMapper.java	2010-08-09 19:43:12 +0000
+++ dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/ActivityPlanItemMapper.java	2010-08-09 22:50:29 +0000
@@ -1,5 +1,7 @@
 package org.hisp.dhis.patient.api.service.mapping;
 
+import javax.ws.rs.core.UriInfo;
+
 import org.hisp.dhis.activityplan.Activity;
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.api.model.ActivityPlanItem;
@@ -13,7 +15,7 @@
 {
 
     @Override
-    public ActivityPlanItem getModel( Activity activity, MappingFactory mappingFactory )
+    public ActivityPlanItem getModel( Activity activity, MappingFactory mappingFactory, UriInfo uriInfo )
     {
         if ( activity == null )
         {
@@ -22,9 +24,9 @@
 
         ActivityPlanItem item = new ActivityPlanItem();
 
-        item.setBeneficiary( mappingFactory.getBeanMapper( Patient.class, Beneficiary.class ).getModel( activity.getBeneficiary(), mappingFactory ) );
+        item.setBeneficiary( mappingFactory.getBeanMapper( Patient.class, Beneficiary.class ).getModel( activity.getBeneficiary(), mappingFactory, uriInfo ) );
         item.setDueDate( activity.getDueDate() );
-        item.setTask( mappingFactory.getBeanMapper( ProgramStageInstance.class, Task.class ).getModel( activity.getTask(), mappingFactory ) );
+        item.setTask( mappingFactory.getBeanMapper( ProgramStageInstance.class, Task.class ).getModel( activity.getTask(), mappingFactory, uriInfo ) );
         return item;
     }
 

=== modified file 'dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/ActivityPlanMapper.java'
--- dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/ActivityPlanMapper.java	2010-08-09 19:43:12 +0000
+++ dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/ActivityPlanMapper.java	2010-08-09 22:50:29 +0000
@@ -4,6 +4,8 @@
 import java.util.Collection;
 import java.util.List;
 
+import javax.ws.rs.core.UriInfo;
+
 import org.hisp.dhis.activityplan.Activity;
 import org.hisp.dhis.patient.api.model.ActivityPlan;
 import org.hisp.dhis.patient.api.model.ActivityPlanItem;
@@ -13,7 +15,7 @@
 {
 
     @Override
-    public ActivityPlan getModel( Collection<Activity> activities, MappingFactory mappingFactory )
+    public ActivityPlan getModel( Collection<Activity> activities, MappingFactory mappingFactory, UriInfo uriInfo )
     {
         ActivityPlan plan = new ActivityPlan();
 
@@ -27,7 +29,7 @@
 
         for ( Activity activity : activities )
         {
-            items.add(mappingFactory.getBeanMapper( Activity.class, ActivityPlanItem.class ).getModel( activity, mappingFactory ));
+            items.add(mappingFactory.getBeanMapper( Activity.class, ActivityPlanItem.class ).getModel( activity, mappingFactory, uriInfo ));
         }
         
         return plan;

=== modified file 'dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/BeanMapper.java'
--- dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/BeanMapper.java	2010-08-09 19:43:12 +0000
+++ dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/BeanMapper.java	2010-08-09 22:50:29 +0000
@@ -1,9 +1,11 @@
 package org.hisp.dhis.patient.api.service.mapping;
 
+import javax.ws.rs.core.UriInfo;
+
 import org.hisp.dhis.patient.api.service.MappingFactory;
 
 
 public interface BeanMapper<S, T>
 {
-    public T getModel( S entity, MappingFactory mappingFactory );
+    public T getModel( S entity, MappingFactory mappingFactory, UriInfo uriInfo );
 }

=== modified file 'dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/BeneficiaryMapper.java'
--- dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/BeneficiaryMapper.java	2010-08-09 19:43:12 +0000
+++ dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/BeneficiaryMapper.java	2010-08-09 22:50:29 +0000
@@ -1,5 +1,7 @@
 package org.hisp.dhis.patient.api.service.mapping;
 
+import javax.ws.rs.core.UriInfo;
+
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.api.model.Beneficiary;
 import org.hisp.dhis.patient.api.service.MappingFactory;
@@ -9,12 +11,12 @@
 {
 
     @Override
-    public Beneficiary getModel( Patient patient, MappingFactory mappingFactory )
+    public Beneficiary getModel( Patient patient, MappingFactory mappingFactory, UriInfo uriInfo )
     {
         if (patient == null) {
             return null;
         }
-        
+
         Beneficiary beneficiary = new Beneficiary();
         
         beneficiary.setId( patient.getId() );

=== added file 'dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/OrgUnitsMapper.java'
--- dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/OrgUnitsMapper.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/OrgUnitsMapper.java	2010-08-09 22:50:29 +0000
@@ -0,0 +1,47 @@
+package org.hisp.dhis.patient.api.service.mapping;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.ws.rs.core.UriInfo;
+
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.patient.api.model.Link;
+import org.hisp.dhis.patient.api.model.OrgUnit;
+import org.hisp.dhis.patient.api.model.OrgUnits;
+import org.hisp.dhis.patient.api.resources.ProgramFormsResource;
+import org.hisp.dhis.patient.api.service.MappingFactory;
+
+public class OrgUnitsMapper
+    implements BeanMapper<Collection<OrganisationUnit>, OrgUnits>
+{
+
+    @Override
+    public OrgUnits getModel( Collection<OrganisationUnit> units, MappingFactory mappingFactory, UriInfo uriInfo )
+    {
+        OrgUnits o = new OrgUnits();
+        
+        List<OrgUnit> orgUnitList = new ArrayList<OrgUnit>();
+        o.setOrgUnitList( orgUnitList );
+        
+        for ( OrganisationUnit unit : units )
+        {
+            orgUnitList.add( create( unit, uriInfo ) );
+        }
+        
+        return o;
+
+    }
+
+    private OrgUnit create(OrganisationUnit unit, UriInfo uriInfo) {
+        OrgUnit m = new OrgUnit();
+        m.setId(unit.getId());
+        m.setName(unit.getShortName());
+        m.setProgramFormsLink( new Link(uriInfo.getBaseUriBuilder().fromResource( ProgramFormsResource.class).build( unit.getId()).toString()));
+        m.setActivitiesLink( new Link(uriInfo.getBaseUriBuilder().path( "v0.1/orgUnits/{id}/activities/plan/current" ).build( unit.getId() ).toString()));
+        
+        return m;
+    }
+
+}

=== modified file 'dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/TaskMapper.java'
--- dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/TaskMapper.java	2010-08-09 19:43:12 +0000
+++ dhis-2/dhis-web/dhis-web-cbhis-api/src/main/java/org/hisp/dhis/patient/api/service/mapping/TaskMapper.java	2010-08-09 22:50:29 +0000
@@ -1,5 +1,7 @@
 package org.hisp.dhis.patient.api.service.mapping;
 
+import javax.ws.rs.core.UriInfo;
+
 import org.hisp.dhis.patient.api.model.Task;
 import org.hisp.dhis.patient.api.service.MappingFactory;
 import org.hisp.dhis.program.ProgramStageInstance;
@@ -9,7 +11,7 @@
 {
 
     @Override
-    public Task getModel( ProgramStageInstance stageInstance, MappingFactory mappingManager )
+    public Task getModel( ProgramStageInstance stageInstance, MappingFactory mappingFactory, UriInfo uriInfo )
     {
         if (stageInstance == null) {
             return null;

=== modified file 'dhis-2/dhis-web/dhis-web-cbhis-api/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-cbhis-api/src/main/resources/META-INF/dhis/beans.xml	2010-08-09 19:43:12 +0000
+++ dhis-2/dhis-web/dhis-web-cbhis-api/src/main/resources/META-INF/dhis/beans.xml	2010-08-09 22:50:29 +0000
@@ -1,53 +1,60 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans";
-	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-	xsi:schemaLocation="
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xsi:schemaLocation="
 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd";>
 
-	<!-- Resources -->
-
-	<bean id="case.api.ProgramForms"
-		class="org.hisp.dhis.patient.api.resources.ProgramFormsResource" />
-
-	<bean id="case.api.OrgUnit" class="org.hisp.dhis.patient.api.resources.OrgUnitResource" />
-
-	<bean id="case.api.MobileUser" class="org.hisp.dhis.patient.api.resources.MobileUserResource" />
-
-	<bean id="case.api.ActivityPlan"
-		class="org.hisp.dhis.patient.api.resources.ActivityPlanResource" />
-
-	<!-- Web service layer -->
-
-	<bean id="org.hisp.dhis.patient.api.service.ActivityPlanModelService"
-		class="org.hisp.dhis.patient.api.service.ActivityPlanModelService" />
-
-
-	<!-- Entity bean mapping -->
-
-	<bean id="mappingFactory" class="org.hisp.dhis.patient.api.service.MappingFactory">
-		<property name="mappers">
-			<set>
-				<bean id="activityPlanMapper"
-					class="org.hisp.dhis.patient.api.service.mapping.ActivityPlanMapper" />
-				<bean id="activityPlanItemMapper"
-					class="org.hisp.dhis.patient.api.service.mapping.ActivityPlanItemMapper" />
-				<bean id="beneficiaryMapper"
-					class="org.hisp.dhis.patient.api.service.mapping.BeneficiaryMapper" />
-				<bean id="taskMapper" class="org.hisp.dhis.patient.api.service.mapping.TaskMapper" />
-			</set>
-		</property>
-	</bean>
-	
-	<!-- Response writers -->
-
-	<bean id="activityPlanSerializingWriter"
-		class="org.hisp.dhis.patient.api.support.ActivityPlanSerializingWriter"
-		scope="singleton" />
-
-	<!-- Object serializers -->
-
-	<bean id="activitySerializer"
-		class="org.hisp.dhis.patient.api.serialization.ActivityListSerializer" />
+  <!-- Resources -->
+
+  <bean id="case.api.MobileUser" 
+    class="org.hisp.dhis.patient.api.resources.MobileUserResource" scope="prototype" />
+
+  <bean id="case.api.OrgUnit" 
+    class="org.hisp.dhis.patient.api.resources.OrgUnitResource" scope="prototype" />
+
+  <bean id="case.api.ActivityPlan"
+    class="org.hisp.dhis.patient.api.resources.ActivitiesResource" scope="prototype" />
+
+  <bean id="case.api.ProgramForms"
+    class="org.hisp.dhis.patient.api.resources.ProgramFormsResource" scope="prototype" />
+
+  <!-- Web service layer -->
+
+  <bean id="org.hisp.dhis.patient.api.service.ActivityPlanModelService"
+    class="org.hisp.dhis.patient.api.service.ActivityPlanModelService" />
+
+
+  <!-- Entity bean mapping -->
+
+  <!-- bean id="org.dozer.Mapper" class="org.dozer.DozerBeanMapper" /> -->
+
+  <bean id="mappingFactory" class="org.hisp.dhis.patient.api.service.MappingFactory">
+    <property name="mappers">
+      <set>
+        <bean id="orgUnitsMapper"
+          class="org.hisp.dhis.patient.api.service.mapping.OrgUnitsMapper" />
+        <bean id="activityPlanMapper"
+          class="org.hisp.dhis.patient.api.service.mapping.ActivityPlanMapper" />
+        <bean id="activityPlanItemMapper"
+          class="org.hisp.dhis.patient.api.service.mapping.ActivityPlanItemMapper" />
+        <bean id="beneficiaryMapper"
+          class="org.hisp.dhis.patient.api.service.mapping.BeneficiaryMapper" />
+        <bean id="taskMapper"
+          class="org.hisp.dhis.patient.api.service.mapping.TaskMapper" />
+      </set>
+    </property>
+  </bean>
+
+  <!-- Response writers -->
+
+  <bean id="activityPlanSerializingWriter"
+    class="org.hisp.dhis.patient.api.support.ActivityPlanSerializingWriter"
+    scope="singleton" />
+
+  <!-- Object serializers -->
+
+  <bean id="activitySerializer"
+    class="org.hisp.dhis.patient.api.serialization.ActivityListSerializer" />
 
 
 </beans>

=== modified file 'dhis-2/dhis-web/dhis-web-cbhis-api/src/test/java/org/hisp/dhis/patient/api/service/ActivityPlanModelServiceTest.java'
--- dhis-2/dhis-web/dhis-web-cbhis-api/src/test/java/org/hisp/dhis/patient/api/service/ActivityPlanModelServiceTest.java	2010-08-09 19:43:12 +0000
+++ dhis-2/dhis-web/dhis-web-cbhis-api/src/test/java/org/hisp/dhis/patient/api/service/ActivityPlanModelServiceTest.java	2010-08-09 22:50:29 +0000
@@ -68,7 +68,6 @@
         mappers.add( new BeneficiaryMapper() );
         mappers.add( new TaskMapper() );
         mapper.setMappers( mappers );
-        mapper.init();
 
         service = new ActivityPlanModelService();
         service.setActivityPlanService( mockedActivityPlanService );
@@ -79,7 +78,7 @@
     @Test
     public void getActivityPlan()
     {
-        ActivityPlan activityPlan = service.getActivityPlan( 1 );
+        ActivityPlan activityPlan = service.getCurrentActivityPlan( orgUnit );
 
         assertNotNull( activityPlan );
         List<ActivityPlanItem> activities = activityPlan.getActivitiesList();

=== modified file 'dhis-2/dhis-web/dhis-web-cbhis-api/src/test/java/org/hisp/dhis/patient/api/service/ModelMapperTest.java'
--- dhis-2/dhis-web/dhis-web-cbhis-api/src/test/java/org/hisp/dhis/patient/api/service/ModelMapperTest.java	2010-08-09 19:43:12 +0000
+++ dhis-2/dhis-web/dhis-web-cbhis-api/src/test/java/org/hisp/dhis/patient/api/service/ModelMapperTest.java	2010-08-09 22:50:29 +0000
@@ -8,9 +8,12 @@
 import java.util.Set;
 
 import org.hisp.dhis.activityplan.Activity;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patient.api.model.ActivityPlan;
+import org.hisp.dhis.patient.api.model.OrgUnits;
 import org.hisp.dhis.patient.api.service.mapping.ActivityPlanMapper;
 import org.hisp.dhis.patient.api.service.mapping.BeanMapper;
+import org.hisp.dhis.patient.api.service.mapping.OrgUnitsMapper;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -33,18 +36,22 @@
     
     @Test
     public void testInitialization() {
-        MappingFactory manager = new MappingFactory();
+        MappingFactory factory = new MappingFactory();
         
         BeanMapper activityPlanMapper = new ActivityPlanMapper();
 
         Set<BeanMapper<?,?>> mappers = new HashSet<BeanMapper<?,?>>();
         mappers.add( activityPlanMapper );
-        
-        manager.setMappers( mappers );
-        
-        manager.init();
-        
-        assertEquals( activityPlanMapper, manager.mappingIndex.get( ActivityPlan.class ) );
+        OrgUnitsMapper orgUnitsMapper = new OrgUnitsMapper();
+        mappers.add( orgUnitsMapper );
+        
+        factory.setMappers( mappers );
+        
+        assertEquals( activityPlanMapper, factory.mappingIndex.get( ActivityPlan.class ) );
+        assertEquals( activityPlanMapper, factory.getBeanMapper( new ArrayList<Activity>(), ActivityPlan.class ));
+
+        assertEquals( orgUnitsMapper, factory.getBeanMapper( new ArrayList<OrganisationUnit>(), OrgUnits.class ));
+
     }
     
 }