=== 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 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. - *

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 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 @@ - - - - - - - - @@ -36,30 +24,19 @@ - - + + - - - - - - -