dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #08187
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1931: Add ActivityWrapper class and other related classes
------------------------------------------------------------
revno: 1931
committer: Tran Ng Minh Luan <Luan@MinhLuan-PC>
branch nick: cbhis-mobile
timestamp: Wed 2010-10-20 23:19:40 +0700
message:
Add ActivityWrapper class and other related classes
added:
DHISMobile/src/org/hisp/dhis/mobile/reporting/model/ActivityWrapper.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityWrapper.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/ActivityWrapperProvider.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ActivityWrapperResource.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
=== added file 'DHISMobile/src/org/hisp/dhis/mobile/reporting/model/ActivityWrapper.java'
--- DHISMobile/src/org/hisp/dhis/mobile/reporting/model/ActivityWrapper.java 1970-01-01 00:00:00 +0000
+++ DHISMobile/src/org/hisp/dhis/mobile/reporting/model/ActivityWrapper.java 2010-10-20 16:19:40 +0000
@@ -0,0 +1,56 @@
+package org.hisp.dhis.mobile.reporting.model;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.util.Date;
+import java.util.Vector;
+
+/**
+ * @author Tran Ng Minh Luan
+ *
+ */
+public class ActivityWrapper {
+ private Vector programs;
+ private ActivityPlan activityPlan;
+
+ public ActivityWrapper() {
+ }
+
+ public Vector getPrograms() {
+ return programs;
+ }
+
+ public void setPrograms(Vector programs) {
+ this.programs = programs;
+ }
+
+ public ActivityPlan getActivityPlan() {
+ return activityPlan;
+ }
+
+ public void setActivityPlan(ActivityPlan activityPlan) {
+ this.activityPlan = activityPlan;
+ }
+
+
+
+
+ public void deSerialize(DataInputStream din) throws IOException {
+ this.activityPlan = new ActivityPlan();
+ this.programs = new Vector();
+
+ int numbProgram = din.readInt();
+ System.out.println("Deserialize of ActivityWrapper - Number of Programs:"+numbProgram);
+ activityPlan.deSerialize(din);
+
+ for(int i=0; i<numbProgram;i++){
+ Program program = new Program();
+ program.deSerialize(din);
+ }
+ }
+
+
+
+
+}
+
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityWrapper.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityWrapper.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityWrapper.java 2010-10-20 16:19:40 +0000
@@ -0,0 +1,79 @@
+package org.hisp.dhis.web.api.model;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.List;
+
+/**
+ * @author Tran Ng Minh Luan
+ *
+ */
+public class ActivityWrapper implements ISerializable
+{
+ private ActivityPlan activityPlan;
+ private List<Program> programs;
+
+
+
+ public ActivityPlan getActivityPlan()
+ {
+ return activityPlan;
+ }
+
+ public void setActivityPlan( ActivityPlan activityPlan )
+ {
+ this.activityPlan = activityPlan;
+ }
+
+ public List<Program> getPrograms()
+ {
+ return programs;
+ }
+
+ public void setPrograms( List<Program> programs )
+ {
+ this.programs = programs;
+ }
+
+ public ActivityWrapper()
+ {
+
+ }
+
+ public void serialize(OutputStream out) throws IOException
+ {
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ DataOutputStream dout = new DataOutputStream(bout);
+
+ dout.writeInt(programs.size());
+
+ this.activityPlan.serialize( dout );
+
+ for(Program each : programs){
+ each.serialize( dout );
+ }
+ bout.flush();
+ bout.writeTo(out);
+ }
+
+ @Override
+ public byte[] serialize()
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void deSerialize( byte[] data )
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+
+}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/ActivityWrapperProvider.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/ActivityWrapperProvider.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/ActivityWrapperProvider.java 2010-10-20 16:19:40 +0000
@@ -0,0 +1,78 @@
+package org.hisp.dhis.web.api.provider;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+import org.hisp.dhis.web.api.model.ActivityWrapper;
+
+import com.jcraft.jzlib.JZlib;
+import com.jcraft.jzlib.ZOutputStream;
+import com.sun.jersey.spi.resource.Singleton;
+
+@Provider
+@Singleton
+@Produces( "application/vnd.org.dhis2.activitywrapper+serialized" )
+public class ActivityWrapperProvider implements MessageBodyWriter<ActivityWrapper>
+{
+ @Override
+ public long getSize(ActivityWrapper arg0, Class<?> arg1, Type arg2,
+ Annotation[] arg3, MediaType arg4) {
+ return -1;
+ }
+
+ @Override
+ public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2,
+ MediaType arg3) {
+ return true;
+ }
+
+ @Override
+ public void writeTo(ActivityWrapper activityWrapper, Class<?> arg1, Type arg2,
+ Annotation[] arg3, MediaType arg4,
+ MultivaluedMap<String, Object> arg5, OutputStream stream)
+ throws IOException, WebApplicationException {
+
+ //activityPlan.serialize( stream );
+ serializeZipped(activityWrapper, stream);
+ }
+
+ public void serializeZipped( ActivityWrapper activityWrapper, OutputStream os ) throws IOException
+ {
+ ByteArrayOutputStream baos = serializePersistent( activityWrapper );
+ ZOutputStream gzip = new ZOutputStream( os, JZlib.Z_BEST_COMPRESSION );
+ DataOutputStream dos = new DataOutputStream( gzip );
+
+ try
+ {
+ byte[] res = baos.toByteArray();
+ dos.write( res );
+ }
+ finally
+ {
+ dos.flush();
+ gzip.finish();
+ }
+ }
+
+ public ByteArrayOutputStream serializePersistent( ActivityWrapper activityWrapper ) throws IOException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DataOutputStream out = new DataOutputStream( baos );
+ activityWrapper.serialize(out);
+ out.flush();
+ return baos;
+ }
+
+
+}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ActivityWrapperResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ActivityWrapperResource.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ActivityWrapperResource.java 2010-10-20 16:19:40 +0000
@@ -0,0 +1,33 @@
+package org.hisp.dhis.web.api.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import org.hisp.dhis.web.api.model.ActivityWrapper;
+import org.hisp.dhis.web.api.service.IActivityPlanService;
+import org.hisp.dhis.web.api.service.IActivityValueService;
+import org.hisp.dhis.web.api.service.IProgramService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+@Path("/download")
+public class ActivityWrapperResource
+{
+ @Autowired
+ private IProgramService programService;
+
+ @Autowired
+ private IActivityPlanService activityPlanService;
+
+
+ @GET
+ @Produces( "application/vnd.org.dhis2.activitywrapper+serialized" )
+ public ActivityWrapper getCurrentActivityPlan(@HeaderParam("accept-language") String locale)
+ {
+ ActivityWrapper activityWrapper = new ActivityWrapper();
+ activityWrapper.setActivityPlan( activityPlanService.getCurrentActivityPlan( locale ) );
+ activityWrapper.setPrograms( programService.getAllProgramsForLocale( locale ) );
+ return activityWrapper;
+ }
+}