dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #08323
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1991: Small refactoring of mobile service (more to come):
------------------------------------------------------------
revno: 1991
committer: Jo Størset <storset@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2010-11-03 12:58:12 +0530
message:
Small refactoring of mobile service (more to come):
- Removed initial redirect
- Merged UserResource into MobileResource
removed:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/UserResource.java
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResouce.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java
dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.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/src/main/java/org/hisp/dhis/web/api/resources/MobileResouce.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResouce.java 2010-10-28 09:25:22 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResouce.java 2010-11-03 07:28:12 +0000
@@ -1,20 +1,29 @@
package org.hisp.dhis.web.api.resources;
+import java.net.URI;
+import java.util.Collection;
+
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.UriInfo;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.web.api.model.Link;
import org.hisp.dhis.web.api.model.MobileWrapper;
+import org.hisp.dhis.web.api.model.OrgUnit;
import org.hisp.dhis.web.api.service.IActivityPlanService;
import org.hisp.dhis.web.api.service.IDataSetService;
import org.hisp.dhis.web.api.service.IProgramService;
import org.springframework.beans.factory.annotation.Autowired;
-/**
- * @author Tran Ng Minh Luan
- *
- */
@Path("/mobile")
public class MobileResouce {
@Autowired
@@ -26,10 +35,49 @@
@Autowired
private IDataSetService idataSetService;
+ @Autowired
+ private CurrentUserService currentUserService;
+
+ @Context
+ private UriInfo uriInfo;
+
+ @GET
+ @Produces( MediaType.APPLICATION_XML )
+ public Response getOrgUnitForUser()
+ {
+ User user = currentUserService.getCurrentUser();
+
+ Collection<OrganisationUnit> units = user.getOrganisationUnits();
+
+ if ( units.isEmpty() )
+ {
+ return Response.status( Status.CONFLICT ).entity( "User is not registered to a unit." ).build();
+ }
+ else if ( units.size() > 1 )
+ {
+ StringBuilder sb = new StringBuilder("User is registered to more than one unit: ");
+
+ int i = units.size();
+ for ( OrganisationUnit unit : units )
+ {
+ sb.append( unit.getName() );
+ if (i-- > 1)
+ sb.append( ", " );
+ }
+
+ return Response.status( Status.CONFLICT ).entity( sb.toString() ).build();
+ }
+
+ OrganisationUnit unit = units.iterator().next();
+ return Response.ok(getOrgUnit(unit)).build();
+ }
+
+
@GET
+ @Path("all")
@Produces( "application/vnd.org.dhis2.mobileresource+serialized" )
- public MobileWrapper getMobileResource(@HeaderParam("accept-language") String locale)
+ public MobileWrapper getAllDataForUser(@HeaderParam("accept-language") String locale)
{
MobileWrapper mobileWrapper = new MobileWrapper();
mobileWrapper.setActivityPlan(activityPlanService.getCurrentActivityPlan( locale ));
@@ -44,4 +92,17 @@
// activityWrapper.setPrograms( programService.getAllProgramsForLocale( locale ) );
return mobileWrapper;
}
+
+ private OrgUnit getOrgUnit(OrganisationUnit unit)
+ {
+ OrgUnit m = new OrgUnit();
+
+ m.setId( unit.getId() );
+ m.setName( unit.getShortName() );
+ m.setProgramFormsLink( new Link( uriInfo.getRequestUriBuilder().path( "programforms" ).build().toString() ) );
+ m.setActivitiesLink( new Link( uriInfo.getRequestUriBuilder().path( "activityplan/current" ).build().toString() ) );
+
+ return m;
+ }
+
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java 2010-08-25 17:40:56 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java 2010-11-03 07:28:12 +0000
@@ -6,16 +6,11 @@
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;
-import javax.ws.rs.core.UriInfo;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.web.api.model.ActivityPlan;
import org.hisp.dhis.web.api.model.Form;
-import org.hisp.dhis.web.api.model.Link;
-import org.hisp.dhis.web.api.model.OrgUnit;
import org.hisp.dhis.web.api.service.ActivityPlanModelService;
import org.hisp.dhis.web.api.service.ProgramStageService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -33,40 +28,16 @@
@Autowired
private ProgramStageService programStageService;
- @Context
- private UriInfo uriInfo;
-
@PathParam( "id" )
private int unitId;
@GET
- public OrgUnit getOrgUnit( )
- {
- OrganisationUnit unit = getUnit();
-
- OrgUnit m = new OrgUnit();
-
- m.setId( unit.getId() );
- m.setName( unit.getShortName() );
- m.setProgramFormsLink( new Link( uriInfo.getRequestUriBuilder().path( "programforms" ).build().toString() ) );
- m.setActivitiesLink( new Link( uriInfo.getRequestUriBuilder().path( "activityplan/current" ).build().toString() ) );
-
- return m;
- }
-
- @GET
@Path( "activityplan/current" )
@Produces( MediaType.APPLICATION_XML )
public ActivityPlan getCurrentActivityPlan()
{
- return service.getCurrentActivityPlan( getUnit() );
- }
-
- private OrganisationUnit getUnit( )
- {
- return organisationUnitService.getOrganisationUnit( unitId );
- }
-
+ return service.getCurrentActivityPlan( organisationUnitService.getOrganisationUnit( unitId ) );
+ }
@GET
@Path("programforms")
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/UserResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/UserResource.java 2010-10-05 09:14:30 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/UserResource.java 1970-01-01 00:00:00 +0000
@@ -1,73 +0,0 @@
-package org.hisp.dhis.web.api.resources;
-
-import java.net.URI;
-import java.util.Collection;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-import javax.ws.rs.core.UriInfo;
-
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-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;
-
-/**
- * This resource redirects the logged in user to the OrgUnit it is assigned to.
- * <p>It is possible to be assigned to more than one org unit, and in that case
- * a 409 will be sent back.
- */
-@Path( "user" )
-public class UserResource
-{
-
- @Autowired
- private CurrentUserService currentUserService;
-
- @Context
- private UriInfo uriInfo;
-
- @Context
- private ResourceContext rc;
-
- @GET
- @Produces( MediaType.APPLICATION_XML )
- public Response getOrgUnitForUser()
- {
- User user = currentUserService.getCurrentUser();
-
- Collection<OrganisationUnit> units = user.getOrganisationUnits();
-
- if ( units.isEmpty() )
- {
- return Response.status( Status.NO_CONTENT ).build();
- }
- else if ( units.size() > 1 )
- {
- StringBuilder sb = new StringBuilder("User is registered to more than one unit: ");
-
- int i = units.size();
- for ( OrganisationUnit unit : units )
- {
- sb.append( unit.getName() );
- if (i-- > 1)
- sb.append( ", " );
- }
-
- return Response.status( Status.CONFLICT ).entity( sb.toString() ).build();
- }
-
- OrganisationUnit unit = units.iterator().next();
- URI uri = uriInfo.getBaseUriBuilder().path( "orgUnits/{id}" ).build( unit.getId() );
-
- return Response.seeOther( uri ).build();
- }
-
-}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml 2010-11-03 03:08:11 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml 2010-11-03 07:28:12 +0000
@@ -6,18 +6,6 @@
<!-- Providers -->
- <!--<bean id="org.hisp.dhis.web.api.provider.ActivityPlanProvider"
- class="org.hisp.dhis.web.api.provider.ActivityPlanProvider" scope="singleton"/>-->
-
- <!--<bean id="org.hisp.dhis.web.api.provider.ActivityWrapperProvider"
- class="org.hisp.dhis.web.api.provider.ActivityWrapperProvider" scope="singleton"/>-->
-
- <!--<bean id="org.hisp.dhis.web.api.provider.ProgramProvider"
- class="org.hisp.dhis.web.api.provider.ProgramProvider" scope="singleton"/>-->
-
- <!--<bean id="org.hisp.dhis.web.api.provider.DataSetProvider"
- class="org.hisp.dhis.web.api.provider.DataSetProvider" scope="singleton"/>-->
-
<bean id="org.hisp.dhis.web.api.provider.AbstractModelListProvider"
class="org.hisp.dhis.web.api.provider.AbstractModelListProvider" scope="singleton"/>
@@ -36,30 +24,19 @@
<!-- Resources -->
- <bean id="org.hisp.dhis.web.api.resources.UserResource"
- class="org.hisp.dhis.web.api.resources.UserResource" scope="prototype"/>
-
+ <bean id="org.hisp.dhis.web.api.resources.MobileResouce"
+ class="org.hisp.dhis.web.api.resources.MobileResouce" scope="prototype"/>
+
<bean id="org.hisp.dhis.web.api.resources.OrgUnitResource"
class="org.hisp.dhis.web.api.resources.OrgUnitResource"
scope="prototype"/>
- <!--<bean id="org.hisp.dhis.web.api.resources.FormResource"
- class="org.hisp.dhis.web.api.resources.FormResource" scope="prototype"/>-->
-
<bean id="org.hisp.dhis.web.api.resources.DataSetResource"
class="org.hisp.dhis.web.api.resources.DataSetResource" scope="prototype"/>
- <!--<bean id="org.hisp.dhis.web.api.resources.ProgramResource"
- class="org.hisp.dhis.web.api.resources.ProgramResource" scope="prototype"/>-->
-
<bean id="org.hisp.dhis.web.api.resources.ActivityPlanResource"
class="org.hisp.dhis.web.api.resources.ActivityPlanResource" scope="prototype"/>
- <!--<bean id="org.hisp.dhis.web.api.resources.ActivityWrapperResource"
- class="org.hisp.dhis.web.api.resources.ActivityWrapperResource" scope="prototype"/>-->
-
- <bean id="org.hisp.dhis.web.api.resources.MobileResouce"
- class="org.hisp.dhis.web.api.resources.MobileResouce" scope="prototype"/>
<!-- Services -->