← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2100: [DHIS Mobile] Add ActivityPlanProvider

 

------------------------------------------------------------
revno: 2100
committer: Long <thanhlongngo1988>
branch nick: dhis2
timestamp: Thu 2010-11-18 16:29:24 +0700
message:
  [DHIS Mobile] Add ActivityPlanProvider
added:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/ActivityPlanProvider.java
modified:
  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
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/ActivityPlanProvider.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/ActivityPlanProvider.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/ActivityPlanProvider.java	2010-11-18 09:29:24 +0000
@@ -0,0 +1,77 @@
+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.ActivityPlan;
+import com.jcraft.jzlib.JZlib;
+import com.jcraft.jzlib.ZOutputStream;
+import com.sun.jersey.spi.resource.Singleton;
+
+@Provider
+@Singleton
+@Produces( "application/vnd.org.dhis2.activityplan+serialized" )
+public class ActivityPlanProvider
+    implements MessageBodyWriter<ActivityPlan>
+{
+    @Override
+    public long getSize( ActivityPlan 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( ActivityPlan arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4,
+        MultivaluedMap<String, Object> arg5, OutputStream stream )
+        throws IOException, WebApplicationException
+    {
+        serializeZipped( arg0, stream );
+    }
+
+    public void serializeZipped( ActivityPlan activityPlan, OutputStream os )
+        throws IOException
+    {
+        ByteArrayOutputStream baos = serializePersistent( activityPlan );
+        ZOutputStream gzip = new ZOutputStream( os, JZlib.Z_BEST_COMPRESSION );
+        DataOutputStream dos = new DataOutputStream( gzip );
+
+        try
+        {
+            dos.write( baos.toByteArray() );
+        }
+        finally
+        {
+            dos.flush();
+            gzip.finish();
+        }
+    }
+
+    public ByteArrayOutputStream serializePersistent( ActivityPlan activityPlan )
+        throws IOException
+
+    {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        DataOutputStream out = new DataOutputStream( baos );
+
+        activityPlan.serialize( out );
+        out.flush();
+
+        return baos;
+    }
+
+}
\ No newline at end of file

=== 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-18 06:08:29 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml	2010-11-18 09:29:24 +0000
@@ -48,6 +48,9 @@
   <bean id="org.hisp.dhis.web.api.provider.DataSerializableProvider" class="org.hisp.dhis.web.api.provider.DataStreamSerializableProvider"
     scope="singleton" />
 	
+	<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.consumer.DataSetValueConsumer" class="org.hisp.dhis.web.api.provider.DataSetValueConsumer"
     scope="singleton" />