dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #14969
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5234: Ported mobile client api to spring mvc, implemented in separate module dhis-web-mobile-api.
------------------------------------------------------------
revno: 5234
committer: Jo Størset <storset@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-11-29 13:06:35 +0100
message:
Ported mobile client api to spring mvc, implemented in separate module dhis-web-mobile-api.
added:
dhis-2/dhis-web/dhis-web-mobile-api/
dhis-2/dhis-web/dhis-web-mobile-api/pom.xml
dhis-2/dhis-web/dhis-web-mobile-api/src/
dhis-2/dhis-web/dhis-web-mobile-api/src/main/
dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/
dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/
dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/
dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/
dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/
dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/
dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/controller/
dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/controller/AbstractMobileController.java
dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java
dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java
dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/support/
dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/support/DataStreamSerializableMessageConverter.java
dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/support/DataStreamSerializer.java
dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/support/MediaTypes.java
dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/support/MessageConverterAddingPostProcessor.java
dhis-2/dhis-web/dhis-web-mobile-api/src/main/resources/
dhis-2/dhis-web/dhis-web-mobile-api/src/main/resources/META-INF/
dhis-2/dhis-web/dhis-web-mobile-api/src/main/resources/META-INF/dhis/
dhis-2/dhis-web/dhis-web-mobile-api/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-mobile-api/src/main/resources/META-INF/dhis/servlet.xml
dhis-2/dhis-web/dhis-web-mobile-api/src/main/resources/struts.xml
dhis-2/dhis-web/dhis-web-mobile-api/src/main/webapp/
dhis-2/dhis-web/dhis-web-mobile-api/src/main/webapp/WEB-INF/
dhis-2/dhis-web/dhis-web-mobile-api/src/main/webapp/WEB-INF/web.xml
dhis-2/dhis-web/dhis-web-mobile-api/src/test/
dhis-2/dhis-web/dhis-web-mobile-api/src/test/java/
dhis-2/dhis-web/dhis-web-mobile-api/src/test/java/org/
dhis-2/dhis-web/dhis-web-mobile-api/src/test/java/org/hisp/
dhis-2/dhis-web/dhis-web-mobile-api/src/test/java/org/hisp/dhis/
dhis-2/dhis-web/dhis-web-mobile-api/src/test/java/org/hisp/dhis/api/
dhis-2/dhis-web/dhis-web-mobile-api/src/test/java/org/hisp/dhis/api/mobile/
dhis-2/dhis-web/dhis-web-mobile-api/src/test/java/org/hisp/dhis/api/mobile/DataStreamSerializableMessageConverterTest.java
dhis-2/dhis-web/dhis-web-mobile-api/src/test/java/org/hisp/dhis/api/mobile/controller/
dhis-2/dhis-web/dhis-web-mobile-api/src/test/java/org/hisp/dhis/api/mobile/controller/ActivityPlanTest.java
modified:
dhis-2/dhis-web/dhis-web-api/pom.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/pom.xml
dhis-2/dhis-web/dhis-web-portal/pom.xml
dhis-2/dhis-web/dhis-web-portal/src/main/webapp/WEB-INF/web.xml
dhis-2/dhis-web/pom.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/pom.xml'
--- dhis-2/dhis-web/dhis-web-api/pom.xml 2011-11-21 12:41:53 +0000
+++ dhis-2/dhis-web/dhis-web-api/pom.xml 2011-11-29 12:06:35 +0000
@@ -20,7 +20,7 @@
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
- </dependency>
+ </dependency>
<dependency>
<groupId>org.hisp.dhis</groupId>
<artifactId>dhis-web-commons</artifactId>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/pom.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/pom.xml 2011-11-10 23:04:32 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/pom.xml 2011-11-29 12:06:35 +0000
@@ -49,7 +49,7 @@
</dependencies>
<properties>
- <rootDir>../../</rootDir>
+ <rootDir>../../../</rootDir>
</properties>
</project>
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api'
=== added file 'dhis-2/dhis-web/dhis-web-mobile-api/pom.xml'
--- dhis-2/dhis-web/dhis-web-mobile-api/pom.xml 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mobile-api/pom.xml 2011-11-29 12:06:35 +0000
@@ -0,0 +1,59 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.hisp.dhis</groupId>
+ <artifactId>dhis-web</artifactId>
+ <version>2.6-SNAPSHOT</version>
+ </parent>
+
+
+ <artifactId>dhis-web-api-mobile</artifactId>
+ <packaging>war</packaging>
+ <name>DHIS Mobile API</name>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
+
+ <!-- DHIS -->
+ <dependency>
+ <groupId>org.hisp.dhis</groupId>
+ <artifactId>dhis-web-commons</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hisp.dhis</groupId>
+ <artifactId>dhis-web-commons-resources</artifactId>
+ <type>war</type>
+ </dependency>
+ <dependency>
+ <groupId>org.hisp.dhis</groupId>
+ <artifactId>dhis-service-mobile</artifactId>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-oxm</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.jcraft</groupId>
+ <artifactId>jzlib</artifactId>
+ <version>1.0.7</version>
+ </dependency>
+ </dependencies>
+
+ <properties>
+ <rootDir>../../</rootDir>
+ </properties>
+</project>
+
+
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src'
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src/main'
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/java'
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org'
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp'
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis'
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api'
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile'
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/controller'
=== added file 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/controller/AbstractMobileController.java'
--- dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/controller/AbstractMobileController.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/controller/AbstractMobileController.java 2011-11-29 12:06:35 +0000
@@ -0,0 +1,20 @@
+package org.hisp.dhis.api.mobile.controller;
+
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.hisp.dhis.api.mobile.NotAllowedException;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+
+public class AbstractMobileController
+{
+ @ExceptionHandler
+ public void mapException(NotAllowedException exception, HttpServletResponse response ) throws IOException
+ {
+ response.setStatus( HttpServletResponse.SC_CONFLICT );
+ response.setContentType( "text/plain" );
+ response.getWriter().write( exception.getReason() );
+ }
+
+}
=== added file 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java'
--- dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java 2011-11-29 12:06:35 +0000
@@ -0,0 +1,81 @@
+package org.hisp.dhis.api.mobile.controller;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.hisp.dhis.api.mobile.NotAllowedException;
+import org.hisp.dhis.api.mobile.model.MobileOrgUnitLinks;
+import org.hisp.dhis.api.mobile.model.OrgUnits;
+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 org.springframework.security.web.util.UrlUtils;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+@Controller
+@RequestMapping( value = "/mobile" )
+public class MobileClientController extends AbstractMobileController
+{
+
+ @Autowired
+ private CurrentUserService currentUserService;
+
+ @RequestMapping( method = RequestMethod.GET )
+ @ResponseBody
+ public OrgUnits getOrgUnitsForUser( HttpServletRequest request )
+ throws NotAllowedException
+ {
+ User user = currentUserService.getCurrentUser();
+
+ if ( user == null )
+ {
+ throw NotAllowedException.NO_USER;
+ }
+
+ Collection<OrganisationUnit> units = user.getOrganisationUnits();
+
+ List<MobileOrgUnitLinks> unitList = new ArrayList<MobileOrgUnitLinks>();
+ for ( OrganisationUnit unit : units )
+ {
+ unitList.add( getOrgUnit( unit, request ) );
+ }
+
+ return new OrgUnits( unitList );
+ }
+
+ private MobileOrgUnitLinks getOrgUnit( OrganisationUnit unit, HttpServletRequest request )
+ {
+ MobileOrgUnitLinks orgUnit = new MobileOrgUnitLinks();
+
+ orgUnit.setId( unit.getId() );
+ orgUnit.setName( unit.getShortName() );
+
+ orgUnit.setDownloadAllUrl( getUrl( request, unit.getId(), "all" ) );
+ orgUnit.setUpdateActivityPlanUrl( getUrl( request, unit.getId(), "activitiyplan" ) );
+ orgUnit.setUploadFacilityReportUrl( getUrl( request, unit.getId(), "dataSets" ) );
+ orgUnit.setUploadActivityReportUrl( getUrl( request, unit.getId(), "activities" ) );
+ orgUnit.setUpdateDataSetUrl( getUrl( request, unit.getId(), "updateDataSets" ) );
+ orgUnit.setChangeUpdateDataSetLangUrl( getUrl( request, unit.getId(), "changeLanguageDataSet" ) );
+ orgUnit.setSearchUrl( getUrl( request, unit.getId(), "search" ) );
+
+ return orgUnit;
+ }
+
+ private static String getUrl( HttpServletRequest request, int id, String path )
+ {
+ String url = UrlUtils.buildFullRequestUrl( request );
+ String base = "/mobile";
+ url = url.substring( 0, url.indexOf( base ) + base.length() );
+
+ return url + "/orgUnits/" + id + "/" + path;
+
+ }
+
+}
=== added file 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java'
--- dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java 2011-11-29 12:06:35 +0000
@@ -0,0 +1,163 @@
+package org.hisp.dhis.api.mobile.controller;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Locale;
+
+import org.hisp.dhis.api.mobile.ActivityReportingService;
+import org.hisp.dhis.api.mobile.FacilityReportingService;
+import org.hisp.dhis.api.mobile.IProgramService;
+import org.hisp.dhis.api.mobile.NotAllowedException;
+import org.hisp.dhis.api.mobile.model.ActivityPlan;
+import org.hisp.dhis.api.mobile.model.ActivityValue;
+import org.hisp.dhis.api.mobile.model.DataSetList;
+import org.hisp.dhis.api.mobile.model.DataSetValue;
+import org.hisp.dhis.api.mobile.model.MobileModel;
+import org.hisp.dhis.api.mobile.model.ModelList;
+import org.hisp.dhis.i18n.I18nService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+@Controller
+@RequestMapping( value = "/mobile/orgUnits" )
+public class MobileOrganisationUnitController extends AbstractMobileController
+{
+
+ @Autowired
+ private ActivityReportingService activityReportingService;
+
+ @Autowired
+ private IProgramService programService;
+
+ @Autowired
+ private FacilityReportingService facilityReportingService;
+
+ @Autowired
+ private OrganisationUnitService organisationUnitService;
+
+ @Autowired
+ private I18nService i18nService;
+
+
+ @RequestMapping( method = RequestMethod.GET, value = "{id}/all" )
+ @ResponseBody
+ public MobileModel getAllDataForOrgUnit( @PathVariable int id, @RequestHeader( "accept-language" ) String locale )
+ {
+ MobileModel mobileModel = new MobileModel();
+
+ OrganisationUnit unit = getUnit( id );
+ mobileModel.setActivityPlan( activityReportingService.getCurrentActivityPlan( unit, locale ) );
+ mobileModel.setPrograms( programService.getPrograms( unit, locale ) );
+
+ mobileModel.setDatasets( facilityReportingService.getMobileDataSetsForUnit( unit, locale ) );
+ mobileModel.setServerCurrentDate( new Date() );
+ mobileModel.setLocales( getLocalStrings( i18nService.getAvailableLocales() ) );
+ return mobileModel;
+ }
+
+ @RequestMapping( method = RequestMethod.POST, value = "{id}/updateDataSets" )
+ @ResponseBody
+ public DataSetList checkUpdatedDataSet( @PathVariable
+ int id, @RequestBody
+ DataSetList dataSetList, @RequestHeader( "accept-language" )
+ String locale )
+ {
+ return facilityReportingService.getUpdatedDataSet( dataSetList, getUnit( id ), locale );
+ }
+
+ @RequestMapping( method = RequestMethod.GET, value = "{id}/changeLanguageDataSet" )
+ @ResponseBody
+ public DataSetList changeLanguageDataSet( @PathVariable
+ int id, @RequestHeader( "accept-language" )
+ String locale )
+ {
+ return facilityReportingService.getDataSetsForLocale( getUnit( id ), locale );
+ }
+
+ /**
+ * Save a facility report for unit
+ *
+ * @param dataSetValue - the report to save
+ * @throws NotAllowedException if the {@link DataSetValue} is invalid
+ */
+ @RequestMapping( method = RequestMethod.POST, value = " {id}/dataSets" )
+ public void saveDataSetValues( @PathVariable int id, @RequestBody DataSetValue dataSetValue )
+ throws NotAllowedException
+ {
+ facilityReportingService.saveDataSetValues( getUnit( id ), dataSetValue );
+ }
+
+ /**
+ * Save activity report for unit
+ *
+ * @param activityValue - the report to save
+ * @throws NotAllowedException if the {@link ActivityValue activity value}
+ * is invalid
+ */
+ @RequestMapping( method = RequestMethod.POST, value = "{id}/activities" )
+ public void saveActivityReport( @PathVariable
+ int id, @RequestBody
+ ActivityValue activityValue )
+ throws NotAllowedException
+ {
+ activityReportingService.saveActivityReport( getUnit( id ), activityValue );
+ }
+
+ @RequestMapping( method = RequestMethod.POST, value = "{id}/activitiyplan" )
+ @ResponseBody
+ public MobileModel updatePrograms( @PathVariable
+ int id, @RequestHeader( "accept-language" )
+ String locale, @RequestBody
+ ModelList programsFromClient )
+ {
+ MobileModel model = new MobileModel();
+ model.setPrograms( programService.updateProgram( programsFromClient, locale, getUnit( id ) ) );
+ model.setActivityPlan( activityReportingService.getCurrentActivityPlan( getUnit( id ), locale ) );
+ model.setServerCurrentDate( new Date() );
+ return model;
+ }
+
+ @RequestMapping( method = RequestMethod.GET, value = "{id}/search" )
+ @ResponseBody
+ public ActivityPlan search( @PathVariable
+ int id, @RequestHeader( "identifier" )
+ String identifier )
+ throws NotAllowedException
+ {
+ return activityReportingService.getActivitiesByIdentifier( identifier );
+ }
+
+
+ private Collection<String> getLocalStrings( Collection<Locale> locales )
+ {
+ if ( locales == null || locales.isEmpty() )
+ {
+ return null;
+ }
+ Collection<String> localeStrings = new ArrayList<String>();
+
+ for ( Locale locale : locales )
+ {
+ localeStrings.add( locale.getLanguage() + "-" + locale.getCountry() );
+ }
+ return localeStrings;
+ }
+
+
+ private OrganisationUnit getUnit( int id )
+ {
+ return organisationUnitService.getOrganisationUnit( id );
+ }
+
+
+
+}
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/support'
=== added file 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/support/DataStreamSerializableMessageConverter.java'
--- dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/support/DataStreamSerializableMessageConverter.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/support/DataStreamSerializableMessageConverter.java 2011-11-29 12:06:35 +0000
@@ -0,0 +1,54 @@
+package org.hisp.dhis.api.mobile.support;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.hisp.dhis.api.mobile.model.DataStreamSerializable;
+import org.springframework.http.HttpInputMessage;
+import org.springframework.http.HttpOutputMessage;
+import org.springframework.http.MediaType;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.HttpMessageNotReadableException;
+import org.springframework.http.converter.HttpMessageNotWritableException;
+
+public class DataStreamSerializableMessageConverter
+ implements HttpMessageConverter<DataStreamSerializable>
+{
+
+ @Override
+ public boolean canRead( Class<?> clazz, MediaType mediaType )
+ {
+ return MediaTypes.MEDIA_TYPES.contains( mediaType) && DataStreamSerializable.class.isAssignableFrom( clazz );
+ }
+
+
+ @Override
+ public boolean canWrite( Class<?> clazz, MediaType mediaType )
+ {
+ return MediaTypes.MEDIA_TYPES.contains( mediaType) && DataStreamSerializable.class.isAssignableFrom( clazz );
+ }
+
+ @Override
+ public List<MediaType> getSupportedMediaTypes()
+ {
+ return MediaTypes.MEDIA_TYPES;
+ }
+
+ @Override
+ public DataStreamSerializable read( Class<? extends DataStreamSerializable> clazz, HttpInputMessage inputMessage )
+ throws IOException, HttpMessageNotReadableException
+ {
+ return DataStreamSerializer.read( clazz, inputMessage.getBody() );
+
+ }
+
+ @Override
+ public void write( DataStreamSerializable entity, MediaType contentType, HttpOutputMessage outputMessage )
+ throws IOException, HttpMessageNotWritableException
+ {
+ outputMessage.getHeaders().setContentType( contentType );
+ DataStreamSerializer.write( entity, outputMessage.getBody() );
+
+ }
+
+}
=== added file 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/support/DataStreamSerializer.java'
--- dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/support/DataStreamSerializer.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/support/DataStreamSerializer.java 2011-11-29 12:06:35 +0000
@@ -0,0 +1,72 @@
+package org.hisp.dhis.api.mobile.support;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.hisp.dhis.api.mobile.model.DataStreamSerializable;
+
+import com.jcraft.jzlib.JZlib;
+import com.jcraft.jzlib.ZOutputStream;
+
+public class DataStreamSerializer
+{
+
+ public static DataStreamSerializable read( Class<? extends DataStreamSerializable> clazz, InputStream input )
+ throws IOException
+ {
+ DataStreamSerializable t;
+ try
+ {
+ t = clazz.newInstance();
+ t.deSerialize( new DataInputStream( input ) );
+ return t;
+ }
+ catch ( InstantiationException e )
+ {
+ throw new IOException( "Can't instantiate class " + clazz.getName(), e );
+ }
+ catch ( IllegalAccessException e )
+ {
+ throw new IOException( "Not allowed to instantiate class " + clazz.getName(), e );
+ }
+ }
+
+
+ public static void write( DataStreamSerializable entity, OutputStream out )
+ throws IOException
+ {
+ ByteArrayOutputStream baos = serializePersistent( entity );
+ ZOutputStream gzip = new ZOutputStream(out, JZlib.Z_BEST_COMPRESSION );
+ DataOutputStream dos = new DataOutputStream( gzip );
+
+ try
+ {
+ byte[] res = baos.toByteArray();
+ dos.write( res );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ dos.flush();
+ gzip.finish();
+ }
+ }
+
+ private static ByteArrayOutputStream serializePersistent( DataStreamSerializable entity )
+ throws IOException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DataOutputStream out = new DataOutputStream( baos );
+ entity.serialize( out );
+ out.flush();
+ return baos;
+ }
+
+}
=== added file 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/support/MediaTypes.java'
--- dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/support/MediaTypes.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/support/MediaTypes.java 2011-11-29 12:06:35 +0000
@@ -0,0 +1,26 @@
+package org.hisp.dhis.api.mobile.support;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.springframework.http.MediaType;
+
+public class MediaTypes
+{
+
+ public static String ACTIVITYVALUELIST_SERIALIZED = "application/vnd.org.dhis2.activityvaluelist+serialized";
+ public static MediaType ACTIVITYVALUELIST_SERIALIZED_TYPE =
+ MediaType.parseMediaType( ACTIVITYVALUELIST_SERIALIZED );
+
+ public static String DATASETVALUE_SERIALIZED = "application/vnd.org.dhis2.datasetvalue+serialized";
+ public static MediaType DATASETVALUE_SERIALIZED_TYPE =
+ MediaType.parseMediaType( DATASETVALUE_SERIALIZED );
+
+ public static String MOBILE_SERIALIZED = "application/vnd.org.dhis2.mobile+serialized";
+ public static MediaType MOBILE_SERIALIZED_TYPE =
+ MediaType.parseMediaType( MOBILE_SERIALIZED );
+
+ public static List<MediaType> MEDIA_TYPES = Arrays.asList( new MediaType[] { ACTIVITYVALUELIST_SERIALIZED_TYPE,
+ DATASETVALUE_SERIALIZED_TYPE, MOBILE_SERIALIZED_TYPE } );
+
+}
\ No newline at end of file
=== added file 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/support/MessageConverterAddingPostProcessor.java'
--- dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/support/MessageConverterAddingPostProcessor.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mobile-api/src/main/java/org/hisp/dhis/api/mobile/support/MessageConverterAddingPostProcessor.java 2011-11-29 12:06:35 +0000
@@ -0,0 +1,70 @@
+package org.hisp.dhis.api.mobile.support;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.config.BeanPostProcessor;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.stereotype.Component;
+import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter;
+
+@Component
+public class MessageConverterAddingPostProcessor
+ implements BeanPostProcessor
+{
+
+ private final static Log logger = LogFactory.getLog( MessageConverterAddingPostProcessor.class );
+
+ private HttpMessageConverter<?> messageConverter = new DataStreamSerializableMessageConverter();
+
+ public Object postProcessBeforeInitialization( Object bean, String beanName )
+ throws BeansException
+ {
+ return bean;
+ }
+
+ public Object postProcessAfterInitialization( Object bean, String beanName )
+ throws BeansException
+ {
+
+ if ( !(bean instanceof AnnotationMethodHandlerAdapter) )
+ {
+ return bean;
+ }
+
+ AnnotationMethodHandlerAdapter handlerAdapter = (AnnotationMethodHandlerAdapter) bean;
+
+ HttpMessageConverter<?>[] converterArray = handlerAdapter.getMessageConverters();
+
+ List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>(
+ Arrays.asList( converterArray ) );
+
+ converters.add( 0, messageConverter );
+
+ converterArray = converters.toArray( new HttpMessageConverter<?>[converters.size()] );
+
+ handlerAdapter.setMessageConverters( converterArray );
+
+ log( converterArray );
+
+ return handlerAdapter;
+ }
+
+ private void log( HttpMessageConverter<?>[] array )
+ {
+ StringBuilder sb = new StringBuilder("Converters after adding custom one: ");
+
+ for ( HttpMessageConverter<?> httpMessageConverter : array )
+ {
+ sb.append( httpMessageConverter.getClass().getName() ).append( ", " );
+ }
+
+ String string = sb.toString();
+ logger.info( string.substring( 0, string.length() - 2 ) );
+ }
+
+}
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/resources'
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/resources/META-INF'
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/resources/META-INF/dhis'
=== added file 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-mobile-api/src/main/resources/META-INF/dhis/beans.xml 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mobile-api/src/main/resources/META-INF/dhis/beans.xml 2011-11-29 12:06:35 +0000
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
+
+ <!-- Root Context: defines shared resources visible to all other web components -->
+
+</beans>
=== added file 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/resources/META-INF/dhis/servlet.xml'
--- dhis-2/dhis-web/dhis-web-mobile-api/src/main/resources/META-INF/dhis/servlet.xml 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mobile-api/src/main/resources/META-INF/dhis/servlet.xml 2011-11-29 12:06:35 +0000
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans:beans xmlns="http://www.springframework.org/schema/mvc"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:beans="http://www.springframework.org/schema/beans"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+
+ <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
+
+ <!-- Enables the Spring MVC @Controller programming model -->
+ <annotation-driven />
+
+ <context:component-scan base-package="org.hisp.dhis.api.mobile" />
+
+</beans:beans>
=== added file 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-mobile-api/src/main/resources/struts.xml 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mobile-api/src/main/resources/struts.xml 2011-11-29 12:06:35 +0000
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE struts PUBLIC
+"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
+"http://struts.apache.org/dtds/struts-2.0.dtd">
+<struts>
+ <include file="dhis-web-commons.xml" />
+
+ <package name="dhis-web-api-mobile" extends="dhis-web-commons" namespace="/dhis-web-api-mobile">
+ </package>
+
+</struts>
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/webapp'
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/webapp/WEB-INF'
=== added file 'dhis-2/dhis-web/dhis-web-mobile-api/src/main/webapp/WEB-INF/web.xml'
--- dhis-2/dhis-web/dhis-web-mobile-api/src/main/webapp/WEB-INF/web.xml 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mobile-api/src/main/webapp/WEB-INF/web.xml 2011-11-29 12:06:35 +0000
@@ -0,0 +1,111 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
+<web-app>
+ <display-name>DHIS Mobile API</display-name>
+
+ <context-param>
+ <param-name>contextConfigLocation</param-name>
+ <param-value>classpath*:/META-INF/dhis/beans.xml</param-value>
+ </context-param>
+
+ <context-param>
+ <param-name>automaticAccessType</param-name>
+ <param-value>ghostAdmin</param-value>
+ </context-param>
+
+ <filter>
+ <filter-name>RedirectFilter</filter-name>
+ <filter-class>org.hisp.dhis.servlet.filter.HttpRedirectFilter</filter-class>
+ <init-param>
+ <param-name>redirectPath</param-name>
+ <param-value>/api/mobile/</param-value>
+ </init-param>
+ </filter>
+
+ <filter>
+ <filter-name>OpenSessionInViewFilter</filter-name>
+ <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
+ </filter>
+
+ <filter>
+ <filter-name>springSecurityFilterChain</filter-name>
+ <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
+ </filter>
+
+ <filter>
+ <filter-name>Struts</filter-name>
+ <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
+ </filter>
+
+ <filter>
+ <filter-name>encodingFilter</filter-name>
+ <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
+ <init-param>
+ <param-name>encoding</param-name>
+ <param-value>UTF-8</param-value>
+ </init-param>
+ <init-param>
+ <param-name>forceEncoding</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ </filter>
+
+ <filter-mapping>
+ <filter-name>RedirectFilter</filter-name>
+ <url-pattern>/</url-pattern>
+ </filter-mapping>
+
+ <filter-mapping>
+ <filter-name>OpenSessionInViewFilter</filter-name>
+ <url-pattern>*.action</url-pattern>
+ </filter-mapping>
+
+ <filter-mapping>
+ <filter-name>OpenSessionInViewFilter</filter-name>
+ <url-pattern>/api/*</url-pattern>
+ </filter-mapping>
+
+ <filter-mapping>
+ <filter-name>springSecurityFilterChain</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
+ <filter-mapping>
+ <filter-name>Struts</filter-name>
+ <url-pattern>*.action</url-pattern>
+ </filter-mapping>
+
+ <filter-mapping>
+ <filter-name>encodingFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
+ <listener>
+ <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+ </listener>
+
+ <listener>
+ <listener-class>org.hisp.dhis.system.startup.StartupListener</listener-class>
+ </listener>
+
+ <!-- Processes application requests -->
+ <servlet>
+ <servlet-name>webapiServlet</servlet-name>
+ <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
+ <init-param>
+ <param-name>contextConfigLocation</param-name>
+ <param-value>classpath*:/META-INF/dhis/servlet.xml</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>webapiServlet</servlet-name>
+ <url-pattern>/api</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>webapiServlet</servlet-name>
+ <url-pattern>/api/*</url-pattern>
+ </servlet-mapping>
+</web-app>
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src/test'
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src/test/java'
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src/test/java/org'
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src/test/java/org/hisp'
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src/test/java/org/hisp/dhis'
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src/test/java/org/hisp/dhis/api'
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src/test/java/org/hisp/dhis/api/mobile'
=== added file 'dhis-2/dhis-web/dhis-web-mobile-api/src/test/java/org/hisp/dhis/api/mobile/DataStreamSerializableMessageConverterTest.java'
--- dhis-2/dhis-web/dhis-web-mobile-api/src/test/java/org/hisp/dhis/api/mobile/DataStreamSerializableMessageConverterTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mobile-api/src/test/java/org/hisp/dhis/api/mobile/DataStreamSerializableMessageConverterTest.java 2011-11-29 12:06:35 +0000
@@ -0,0 +1,47 @@
+package org.hisp.dhis.api.mobile;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import static org.junit.Assert.assertTrue;
+
+import org.hisp.dhis.api.mobile.model.OrgUnits;
+import org.hisp.dhis.api.mobile.support.DataStreamSerializableMessageConverter;
+import org.hisp.dhis.api.mobile.support.MediaTypes;
+import org.junit.Test;
+
+public class DataStreamSerializableMessageConverterTest
+{
+
+ @Test
+ public void testAssigning()
+ {
+ boolean writeable = new DataStreamSerializableMessageConverter().canWrite( OrgUnits.class,
+ MediaTypes.MOBILE_SERIALIZED_TYPE );
+ assertTrue( writeable );
+ }
+}
=== added directory 'dhis-2/dhis-web/dhis-web-mobile-api/src/test/java/org/hisp/dhis/api/mobile/controller'
=== added file 'dhis-2/dhis-web/dhis-web-mobile-api/src/test/java/org/hisp/dhis/api/mobile/controller/ActivityPlanTest.java'
--- dhis-2/dhis-web/dhis-web-mobile-api/src/test/java/org/hisp/dhis/api/mobile/controller/ActivityPlanTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mobile-api/src/test/java/org/hisp/dhis/api/mobile/controller/ActivityPlanTest.java 2011-11-29 12:06:35 +0000
@@ -0,0 +1,37 @@
+package org.hisp.dhis.api.mobile.controller;
+
+import static org.junit.Assert.*;
+
+import org.hisp.dhis.api.mobile.model.MobileModel;
+import org.hisp.dhis.dataset.DataSetService;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.transaction.annotation.Transactional;
+
+//@RunWith( SpringJUnit4ClassRunner.class )
+//@ContextConfiguration( locations = { "classpath*:/META-INF/dhis/beans.xml", "classpath*:/META-INF/dhis/servlet.xml" } )
+//@Transactional
+public class ActivityPlanTest
+{
+
+// @Autowired
+// private MobileOrganisationUnitController controller;
+//
+// @Autowired
+// private DataSetService dataSetService;
+//
+// @Test
+// public void testActivityPlan() {
+//
+// dataSetService.getDataSetsForMobile( source )
+//
+// MobileModel model = controller.getAllDataForOrgUnit( 525, "en_UK" );
+//
+// assertNotNull(model);
+//
+// System.out.println(model.getDatasets());
+// }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-portal/pom.xml'
--- dhis-2/dhis-web/dhis-web-portal/pom.xml 2011-11-14 12:19:36 +0000
+++ dhis-2/dhis-web/dhis-web-portal/pom.xml 2011-11-29 12:06:35 +0000
@@ -151,6 +151,12 @@
</dependency>
<dependency>
<groupId>org.hisp.dhis</groupId>
+ <artifactId>dhis-web-api-mobile</artifactId>
+ <version>${project.version}</version>
+ <type>war</type>
+ </dependency>
+ <dependency>
+ <groupId>org.hisp.dhis</groupId>
<artifactId>dhis-web-api2</artifactId>
<version>${project.version}</version>
<type>war</type>
=== modified file 'dhis-2/dhis-web/dhis-web-portal/src/main/webapp/WEB-INF/web.xml'
--- dhis-2/dhis-web/dhis-web-portal/src/main/webapp/WEB-INF/web.xml 2011-11-02 11:14:35 +0000
+++ dhis-2/dhis-web/dhis-web-portal/src/main/webapp/WEB-INF/web.xml 2011-11-29 12:06:35 +0000
@@ -46,6 +46,11 @@
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
+ <url-pattern>/api/*</url-pattern>
+ </filter-mapping>
+
+ <filter-mapping>
+ <filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/api2/*</url-pattern>
</filter-mapping>
=== modified file 'dhis-2/dhis-web/pom.xml'
--- dhis-2/dhis-web/pom.xml 2011-11-02 11:14:35 +0000
+++ dhis-2/dhis-web/pom.xml 2011-11-29 12:06:35 +0000
@@ -25,6 +25,7 @@
<module>dhis-web-dashboard-integration</module>
<module>dhis-web-caseentry</module>
<module>dhis-web-api</module>
+ <module>dhis-web-mobile-api</module>
<module>dhis-web-api2</module>
<module>dhis-web-light</module>
<module>dhis-web-portal</module>