=== modified file 'dhis-2/dhis-web/dhis-web-api/pom.xml' --- dhis-2/dhis-web/dhis-web-api/pom.xml 2010-11-15 18:00:33 +0000 +++ dhis-2/dhis-web/dhis-web-api/pom.xml 2010-12-08 05:45:56 +0000 @@ -45,6 +45,11 @@ 1.4 + com.sun.jersey + jersey-json + 1.4 + + com.sun.jersey.contribs jersey-spring 1.4 @@ -83,7 +88,7 @@ dhis-web-commons-resources war - + org.hisp.dhis dhis-api === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnits.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnits.java 2010-11-26 11:00:40 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnits.java 2010-12-08 05:45:56 +0000 @@ -9,17 +9,27 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; - @XmlRootElement -public class OrgUnits implements DataStreamSerializable +public class OrgUnits + implements DataStreamSerializable { private List orgUnits = new ArrayList(); - - @XmlElement(name="orgUnit") - public List getOrgUnits() { + + public OrgUnits() + { + } + + public OrgUnits( List unitList ) + { + this.orgUnits = unitList; + } + + @XmlElement( name = "orgUnit" ) + public List getOrgUnits() + { return orgUnits; } - + public void setOrgUnits( List orgUnits ) { this.orgUnits = orgUnits; === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResource.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResource.java 2010-11-26 11:00:40 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResource.java 2010-12-08 05:45:56 +0000 @@ -45,12 +45,13 @@ import org.hisp.dhis.user.User; import org.hisp.dhis.web.api.model.OrgUnit; import org.hisp.dhis.web.api.model.OrgUnits; +import org.hisp.dhis.web.api.service.NotAllowedException; import org.springframework.beans.factory.annotation.Required; import com.sun.jersey.api.core.ResourceContext; @Path( "/" ) -@Produces( { DhisMediaType.MOBILE_SERIALIZED, MediaType.APPLICATION_XML } ) +@Produces( { DhisMediaType.MOBILE_SERIALIZED, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) public class MobileResource { @@ -66,60 +67,61 @@ @Context private ResourceContext rc; + /** + * Get the units associated with the currently logged in user + * + * @throws NotAllowedException if no user is logged in + */ @GET @Path( "mobile" ) public OrgUnits getOrgUnitsForUser() + throws NotAllowedException { User user = currentUserService.getCurrentUser(); + if ( user == null ) + { + throw new NotAllowedException( "NO_USER", "No user is logged in." ); + } + Collection units = user.getOrganisationUnits(); - OrgUnits orgUnits = new OrgUnits(); - List unitList = new ArrayList(); - for ( OrganisationUnit unit : units ) { unitList.add( getOrgUnit( unit ) ); } - orgUnits.setOrgUnits( unitList ); - - return orgUnits; + return new OrgUnits( unitList ); } @Path( "orgUnits/{id}" ) public OrgUnitResource getOrgUnit( @PathParam( "id" ) int id ) { - OrgUnitResource resource = rc.getResource( OrgUnitResource.class ); - resource.setOrgUnit( organisationUnitService.getOrganisationUnit( id ) ); - return resource; } private OrgUnit getOrgUnit( OrganisationUnit unit ) { - OrgUnit m = new OrgUnit(); - - m.setId( unit.getId() ); - m.setName( unit.getShortName() ); - - m.setDownloadAllUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "all" ).build( unit.getId() ) + OrgUnit orgUnit = new OrgUnit(); + + orgUnit.setId( unit.getId() ); + orgUnit.setName( unit.getShortName() ); + + orgUnit.setDownloadAllUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "all" ).build( unit.getId() ) .toString() ); - m.setDownloadActivityPlanUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "activitiyplan" ) - .build( unit.getId() ).toString() ); - m.setUploadFacilityReportUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "dataSets" ) - .build( unit.getId() ).toString() ); - m.setUploadActivityReportUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "activities" ) + orgUnit.setDownloadActivityPlanUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "activitiyplan" ) + .build( unit.getId() ).toString() ); + orgUnit.setUploadFacilityReportUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "dataSets" ) + .build( unit.getId() ).toString() ); + orgUnit.setUploadActivityReportUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "activities" ) .build( unit.getId() ).toString() ); - return m; + return orgUnit; } - // Setters... - @Required public void setCurrentUserService( CurrentUserService currentUserService ) { === 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-12-02 10:53:14 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java 2010-12-08 05:45:56 +0000 @@ -22,8 +22,8 @@ import org.hisp.dhis.web.api.service.NotAllowedException; import org.springframework.beans.factory.annotation.Required; -@Produces( { DhisMediaType.MOBILE_SERIALIZED, MediaType.APPLICATION_XML } ) -@Consumes( { DhisMediaType.MOBILE_SERIALIZED, MediaType.APPLICATION_XML } ) +@Produces( { DhisMediaType.MOBILE_SERIALIZED, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) +@Consumes( { DhisMediaType.MOBILE_SERIALIZED, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) public class OrgUnitResource { @@ -45,9 +45,12 @@ this.unit = unit; } + /** Get activity plan, program forms and facility forms wrapped in a {@link MobileModel} + * @param locale - localize for the given locale + */ @GET @Path( "all" ) - public MobileModel getAllDataForUser( @HeaderParam( "accept-language" ) String locale ) + public MobileModel getAllDataForOrgUnit( @HeaderParam( "accept-language" ) String locale ) { MobileModel mobileModel = new MobileModel(); @@ -61,6 +64,9 @@ return mobileModel; } + /** + * Get a localized representation of the current activity plan + */ @GET @Path( "activitiyplan" ) public ActivityPlan getCurrentActivityPlan( @HeaderParam( "accept-language" ) String locale ) @@ -68,6 +74,11 @@ return activityReportingService.getCurrentActivityPlan( unit, locale ); } + /** + * Save a facility report for unit + * @param dataSetValue - the report to save + * @throws NotAllowedException if the {@link DataSetValue} is invalid + */ @POST @Path( "dataSets" ) public void saveDataSetValues( DataSetValue dataSetValue ) throws NotAllowedException @@ -75,6 +86,11 @@ facilityReportingService.saveDataSetValues( unit, dataSetValue ); } + /** + * Save activity report for unit + * @param activityValue - the report to save + * @throws NotAllowedException if the {@link ActivityValue activity value} is invalid + */ @POST @Path( "activities" ) public void saveActivityReport( ActivityValue activityValue ) throws NotAllowedException @@ -82,8 +98,6 @@ activityReportingService.saveActivityReport( unit, activityValue ); } - // Setters... - @Required public void setProgramService( IProgramService programService ) { === 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-12-02 10:53:14 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml 2010-12-08 05:45:56 +0000 @@ -44,7 +44,7 @@ - + @@ -55,9 +55,10 @@ - +