dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #08212
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1951: Merge Minh Luan's commit from branch:
------------------------------------------------------------
revno: 1951
author: Minh Luan
committer: Jo Størset <storset@xxxxxxxxx>
branch nick: trunk
timestamp: Mon 2010-10-25 17:54:24 +0530
message:
Merge Minh Luan's commit from branch:
Add DataSets and DataElements to download all stream (Facility Report)
URL for download all: <Tomcat Host><Tomcat Port>/dhis-web-api/api/mobile
added:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileWrapper.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/MobileWrapperProvider.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResouce.java
modified:
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/DataSet.java
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/DataSetResource.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultDataSetService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IDataSetService.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/model/ActivityWrapper.java'
--- 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
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityWrapper.java 2010-10-25 12:24:24 +0000
@@ -15,8 +15,6 @@
private ActivityPlan activityPlan;
private List<Program> programs;
-
-
public ActivityPlan getActivityPlan()
{
return activityPlan;
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataSet.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataSet.java 2010-09-24 11:12:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataSet.java 2010-10-25 12:24:24 +0000
@@ -104,7 +104,7 @@
dout.writeUTF( de.getType() );
}
- //bout.flush();
+ bout.flush();
bout.writeTo(out);
}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileWrapper.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileWrapper.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileWrapper.java 2010-10-25 12:24:24 +0000
@@ -0,0 +1,103 @@
+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 MobileWrapper implements ISerializable{
+ private ActivityPlan activityPlan;
+ private List<Program> programs;
+ private List<DataSet> datasets;
+
+ public MobileWrapper() {
+ }
+
+ 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 List<DataSet> getDatasets() {
+ return datasets;
+ }
+
+ public void setDatasets(List<DataSet> datasets) {
+ this.datasets = datasets;
+ }
+
+ public void serialize(OutputStream out) throws IOException
+ {
+ if(datasets == null){
+ System.out.println("Dataset list is null");
+ }
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ DataOutputStream dout = new DataOutputStream(bout);
+
+ dout.writeInt(programs.size());
+
+ if(this.activityPlan == null){
+ dout.writeInt(0);
+ }else{
+ this.activityPlan.serialize( dout );
+ }
+
+ if(programs.size() > 0){
+ dout.writeInt(programs.size());
+ }else{
+ for(Program prog : programs){
+ prog.serialize( dout );
+ }
+ }
+
+ if(datasets != null){
+ dout.writeInt(datasets.size());
+ }else{
+ dout.writeInt(0);
+ }
+ for(DataSet ds : datasets){
+ ds.serialize();
+ }
+
+
+ }
+
+ @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/MobileWrapperProvider.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/MobileWrapperProvider.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/MobileWrapperProvider.java 2010-10-25 12:24:24 +0000
@@ -0,0 +1,81 @@
+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 org.hisp.dhis.web.api.model.MobileWrapper;
+
+import com.jcraft.jzlib.JZlib;
+import com.jcraft.jzlib.ZOutputStream;
+import com.sun.jersey.spi.resource.Singleton;
+
+/**
+ * @author Tran Ng Minh Luan
+ *
+ */
+@Provider
+@Singleton
+@Produces( "application/vnd.org.dhis2.mobileresource+serialized" )
+public class MobileWrapperProvider implements MessageBodyWriter<MobileWrapper>{
+ @Override
+ public long getSize(MobileWrapper 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(MobileWrapper mobileWrapper, Class<?> arg1, Type arg2,
+ Annotation[] arg3, MediaType arg4,
+ MultivaluedMap<String, Object> arg5, OutputStream stream)
+ throws IOException, WebApplicationException {
+
+ //activityPlan.serialize( stream );
+ serializeZipped(mobileWrapper, stream);
+ }
+
+
+ public void serializeZipped( MobileWrapper mobileWrapper, OutputStream os ) throws IOException
+ {
+ ByteArrayOutputStream baos = serializePersistent( mobileWrapper );
+ 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( MobileWrapper mobileWrapper ) throws IOException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DataOutputStream out = new DataOutputStream( baos );
+ mobileWrapper.serialize(out);
+ out.flush();
+ return baos;
+ }
+}
=== modified 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 2010-10-20 16:19:40 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ActivityWrapperResource.java 2010-10-25 12:24:24 +0000
@@ -8,6 +8,8 @@
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.IDataSetService;
+import org.hisp.dhis.web.api.service.IDataValueService;
import org.hisp.dhis.web.api.service.IProgramService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -19,7 +21,7 @@
@Autowired
private IActivityPlanService activityPlanService;
-
+
@GET
@Produces( "application/vnd.org.dhis2.activitywrapper+serialized" )
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetResource.java 2010-09-24 11:12:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetResource.java 2010-10-25 12:24:24 +0000
@@ -38,7 +38,8 @@
@Produces( "application/vnd.org.dhis2.abstractmodellist+serialized" )
public AbstractModelList getAllMobileDataSets(@HeaderParam("accept-language") String locale)
{
- return idataSetService.getAllMobileDataSetsForLocale( locale );
+ return null;
+// return idataSetService.getAllMobileDataSetsForLocale( locale );
}
@GET
@@ -49,7 +50,8 @@
@HeaderParam("accept-language") String locale
)
{
- return idataSetService.getDataSetForLocale( datasetid, locale );
+ return null;
+// return idataSetService.getDataSetForLocale( datasetid, locale );
}
@POST
=== added 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 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResouce.java 2010-10-25 12:24:24 +0000
@@ -0,0 +1,45 @@
+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.model.MobileWrapper;
+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
+ private IProgramService programService;
+
+ @Autowired
+ private IActivityPlanService activityPlanService;
+
+ @Autowired
+ private IDataSetService idataSetService;
+
+
+ @GET
+ @Produces( "application/vnd.org.dhis2.mobileresource+serialized" )
+ public MobileWrapper getMobileResource(@HeaderParam("accept-language") String locale)
+ {
+ MobileWrapper mobileWrapper = new MobileWrapper();
+ mobileWrapper.setActivityPlan(activityPlanService.getCurrentActivityPlan( locale ));
+ mobileWrapper.setPrograms( programService.getAllProgramsForLocale( locale ) );
+ mobileWrapper.setDatasets(idataSetService.getAllMobileDataSetsForLocale(locale));
+
+// ActivityWrapper activityWrapper = new ActivityWrapper();
+// activityWrapper.setActivityPlan( activityPlanService.getCurrentActivityPlan( locale ) );
+// activityWrapper.setPrograms( programService.getAllProgramsForLocale( locale ) );
+ return mobileWrapper;
+ }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultDataSetService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultDataSetService.java 2010-09-24 11:12:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultDataSetService.java 2010-10-25 12:24:24 +0000
@@ -31,14 +31,14 @@
// MobileDataSetService
// -------------------------------------------------------------------------
- public AbstractModelList getAllMobileDataSetsForLocale(String localeString) {
-
- Locale locale = LocaleUtil.getLocale(localeString);
-
- AbstractModelList abstractModelList = new AbstractModelList();
-
- List<AbstractModel> abstractModels = new ArrayList<AbstractModel>();
-
+ public List<DataSet> getAllMobileDataSetsForLocale(String localeString) {
+
+ List<DataSet> datasets = new ArrayList<DataSet>();
+ Locale locale = LocaleUtil.getLocale(localeString);
+// AbstractModelList abstractModelList = new AbstractModelList();
+//
+// List<AbstractModel> abstractModels = new ArrayList<AbstractModel>();
+//
for (org.hisp.dhis.dataset.DataSet dataSet : dataSetService.getDataSetsForMobile())
{
if( dataSet.getPeriodType().getName().equals( "Daily") ||
@@ -46,27 +46,16 @@
dataSet.getPeriodType().getName().equals( "Monthly") ||
dataSet.getPeriodType().getName().equals( "Yearly") )
{
-
- dataSet = i18n( i18nService, locale, dataSet );
-
- AbstractModel abstractModel = new AbstractModel();
-
- abstractModel.setId( dataSet.getId());
- abstractModel.setName(dataSet.getName());
-
- abstractModels.add(abstractModel);
- }
+ datasets.add(getDataSetForLocale(dataSet.getId(),locale));
+ }
}
-
- abstractModelList.setAbstractModels(abstractModels);
-
- return abstractModelList;
+//
+// abstractModelList.setAbstractModels(abstractModels);
+
+ return datasets;
}
- public DataSet getDataSetForLocale(int dataSetId, String localeString) {
-
- Locale locale = LocaleUtil.getLocale(localeString);
-
+ public DataSet getDataSetForLocale(int dataSetId, Locale locale) {
org.hisp.dhis.dataset.DataSet dataSet = dataSetService.getDataSet( dataSetId );
dataSet = i18n( i18nService, locale, dataSet );
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IDataSetService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IDataSetService.java 2010-09-24 11:12:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IDataSetService.java 2010-10-25 12:24:24 +0000
@@ -1,11 +1,14 @@
package org.hisp.dhis.web.api.service;
+import java.util.List;
+import java.util.Locale;
+
import org.hisp.dhis.web.api.model.AbstractModelList;
import org.hisp.dhis.web.api.model.DataSet;
public interface IDataSetService {
- AbstractModelList getAllMobileDataSetsForLocale( String localeString );
+ List<DataSet> getAllMobileDataSetsForLocale( String localeString );
- DataSet getDataSetForLocale( int dataSetId, String localeString );
+ DataSet getDataSetForLocale( int dataSetId,Locale locale);
}
=== 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-10-20 15:56:07 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml 2010-10-25 12:24:24 +0000
@@ -17,6 +17,10 @@
<bean id="org.hisp.dhis.web.api.provider.AbstractModelListProvider"
class="org.hisp.dhis.web.api.provider.AbstractModelListProvider" scope="singleton"/>
+
+ <bean id="org.hisp.dhis.web.api.provider.MobileWrapperProvider"
+ class="org.hisp.dhis.web.api.provider.MobileWrapperProvider" scope="singleton"/>
+
<!-- Consumers -->
<bean id="org.hisp.dhis.web.api.consumer.DataSetValueConsumer"
@@ -27,6 +31,8 @@
<bean id="org.hisp.dhis.web.api.consumer.ActivityValueConsumer"
class="org.hisp.dhis.web.api.consumer.ActivityValueConsumer" scope="singleton"/>
+
+
<!-- Resources -->
<bean id="org.hisp.dhis.web.api.resources.UserResource"
@@ -50,6 +56,10 @@
<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 -->