← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7647: [mobile] modify the OrgUnits link

 

------------------------------------------------------------
revno: 7647
committer: Long <thanhlongngo1988@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-07-20 15:07:59 +0700
message:
  [mobile] modify the OrgUnits link
modified:
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/DataSet.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/MobileOrgUnitLinks.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/OrgUnits.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ModelMapping.java
  dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java
  dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java
  dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/DataStreamSerializer.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
=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/DataSet.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/DataSet.java	2012-06-26 07:43:35 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/DataSet.java	2012-07-20 08:07:59 +0000
@@ -188,7 +188,6 @@
             section.deSerialize( dataInputStream );
             sections.add( section );
         }
-
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/MobileOrgUnitLinks.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/MobileOrgUnitLinks.java	2012-07-10 09:24:04 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/MobileOrgUnitLinks.java	2012-07-20 08:07:59 +0000
@@ -28,7 +28,6 @@
  */
 
 import java.io.DataInputStream;
-import java.io.DataOutput;
 import java.io.DataOutputStream;
 import java.io.IOException;
 
@@ -189,7 +188,6 @@
         dataOutputStream.writeUTF( this.changeUpdateDataSetLangUrl );
         dataOutputStream.writeUTF( this.searchUrl );
         dataOutputStream.writeUTF( this.updateNewVersionUrl );
-
     }
 
     public void deSerialize( DataInputStream dataInputStream )
@@ -235,6 +233,7 @@
         dataOutputStream.writeUTF( this.updateDataSetUrl );
         dataOutputStream.writeUTF( this.changeUpdateDataSetLangUrl );
         dataOutputStream.writeUTF( this.searchUrl );
+        dataOutputStream.writeUTF( this.updateNewVersionUrl );
     }
 
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/OrgUnits.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/OrgUnits.java	2012-07-10 11:10:30 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/OrgUnits.java	2012-07-20 08:07:59 +0000
@@ -32,11 +32,9 @@
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
-
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
-
 @XmlRootElement
 public class OrgUnits
     implements DataStreamSerializable
@@ -79,13 +77,20 @@
     public void serialize( DataOutputStream dataOutputStream )
         throws IOException
     {
-        //send the current version to client for updating or not
-        dataOutputStream.writeDouble( MobileOrgUnitLinks.currentVersion );
-        
-        dataOutputStream.writeInt( orgUnits.size() );
-        for ( MobileOrgUnitLinks unit : orgUnits )
-        {
-            unit.serialize( dataOutputStream );
+        // send the current version to client for updating or not
+        // dataOutputStream.writeDouble( MobileOrgUnitLinks.currentVersion );
+        // dataOutputStream.writeInt( orgUnits.size() );
+        // for ( MobileOrgUnitLinks unit : orgUnits )
+        // {
+        // unit.serialize( dataOutputStream );
+        // }
+        if ( this.getClientVersion().equals( DataStreamSerializable.TWO_POINT_EIGHT ) )
+        {
+            this.serializeVerssion2_8( dataOutputStream );
+        }
+        else
+        {
+            this.serializeVerssion2_9( dataOutputStream );
         }
     }
 
@@ -112,7 +117,7 @@
         dataOutputStream.writeInt( orgUnits.size() );
         for ( MobileOrgUnitLinks unit : orgUnits )
         {
-            unit.serialize( dataOutputStream );
+            unit.serializeVerssion2_8( dataOutputStream );
         }
     }
 
@@ -120,6 +125,8 @@
     public void serializeVerssion2_9( DataOutputStream dataOutputStream )
         throws IOException
     {
+        // send the current version to client for updating or not
+        dataOutputStream.writeDouble( MobileOrgUnitLinks.currentVersion );
         dataOutputStream.writeInt( orgUnits.size() );
         for ( MobileOrgUnitLinks unit : orgUnits )
         {

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ModelMapping.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ModelMapping.java	2012-06-28 08:44:43 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ModelMapping.java	2012-07-20 08:07:59 +0000
@@ -74,14 +74,6 @@
     {
         DataElementCategoryCombo categoryCombo = dataElement.getCategoryCombo();
 
-        // Set<DataElementCategoryOptionCombo> deCatOptCombs =
-        // dataElement.getCategoryCombo().getOptionCombos();
-
-        // if ( deCatOptCombs.size() < 2 )
-        // {
-        // return null;
-        // }
-
         // Client DataElement
         ModelList deCateOptCombo = new ModelList();
         List<Model> listCateOptCombo = new ArrayList<Model>();

=== modified file 'dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java'
--- dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java	2012-07-02 06:43:56 +0000
+++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java	2012-07-20 08:07:59 +0000
@@ -3,10 +3,9 @@
 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.DataStreamSerializable;
 import org.hisp.dhis.api.mobile.model.MobileOrgUnitLinks;
 import org.hisp.dhis.api.mobile.model.OrgUnits;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -15,38 +14,65 @@
 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.PathVariable;
 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
+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 );
+    public OrgUnits getOrgUnitsForUser2_8( 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 ) );
+        }
+        OrgUnits orgUnits = new OrgUnits( unitList );
+        orgUnits.setClientVersion( DataStreamSerializable.TWO_POINT_EIGHT );
+        return orgUnits;
+    }
+    
+    @RequestMapping( method = RequestMethod.GET, value = "/{version}" )
+    @ResponseBody
+    public OrgUnits getOrgUnitsForUser( HttpServletRequest request, @PathVariable String version )
+        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 ) );
+        }
+        OrgUnits orgUnits = new OrgUnits( unitList );
+        orgUnits.setClientVersion( DataStreamSerializable.TWO_POINT_NINE );
+        return orgUnits;
     }
 
     private MobileOrgUnitLinks getOrgUnit( OrganisationUnit unit, HttpServletRequest request )
@@ -63,10 +89,10 @@
         orgUnit.setUpdateDataSetUrl( getUrl( request, unit.getId(), "updateDataSets" ) );
         orgUnit.setChangeUpdateDataSetLangUrl( getUrl( request, unit.getId(), "changeLanguageDataSet" ) );
         orgUnit.setSearchUrl( getUrl( request, unit.getId(), "search" ) );
-        
-        //generate URL for download new version
+
+        // generate URL for download new version
         String full = UrlUtils.buildFullRequestUrl( request );
-        String root = full.substring( 0, full.length() - UrlUtils.buildRequestUrl( request ).length());
+        String root = full.substring( 0, full.length() - UrlUtils.buildRequestUrl( request ).length() );
         String updateNewVersionUrl = root + "/dhis-web-api-mobile/updateClient.action";
         orgUnit.setUpdateNewVersionUrl( updateNewVersionUrl );
         return orgUnit;

=== modified file 'dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java'
--- dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java	2012-07-03 02:22:08 +0000
+++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java	2012-07-20 08:07:59 +0000
@@ -28,7 +28,7 @@
 import org.springframework.web.bind.annotation.ResponseBody;
 
 @Controller
-@RequestMapping( value = "/mobile/orgUnits" )
+@RequestMapping( value = "/mobile" )
 public class MobileOrganisationUnitController
     extends AbstractMobileController
 {
@@ -51,7 +51,8 @@
     @Autowired
     private I18nService i18nService;
 
-    @RequestMapping( method = RequestMethod.GET, value = "{id}/all" )
+    // Initialize download for client version 2.8 and lower
+    @RequestMapping( method = RequestMethod.GET, value = "orgUnits/{id}/all" )
     @ResponseBody
     public MobileModel getAllDataForOrgUnit( @PathVariable int id, @RequestHeader( "accept-language" ) String locale )
     {
@@ -65,10 +66,12 @@
         mobileModel.setLocales( getLocalStrings( i18nService.getAvailableLocales() ) );
         return mobileModel;
     }
-    
-    @RequestMapping( method = RequestMethod.GET, value = "{id}/all/2.9" )
+
+    // Initialize download for client version 2.9 and higher
+    @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/all" )
     @ResponseBody
-    public MobileModel getAllDataForOrgUnit2_9( @PathVariable int id, @RequestHeader( "accept-language" ) String locale )
+    public MobileModel getAllDataForOrgUnit2_9( @PathVariable String clientVersion, @PathVariable int id,
+        @RequestHeader( "accept-language" ) String locale )
     {
         MobileModel mobileModel = new MobileModel();
         mobileModel.setClientVersion( DataStreamSerializable.TWO_POINT_NINE );
@@ -82,7 +85,7 @@
         return mobileModel;
     }
 
-    @RequestMapping( method = RequestMethod.POST, value = "{id}/updateDataSets" )
+    @RequestMapping( method = RequestMethod.POST, value = "orgUnits/{id}/updateDataSets" )
     @ResponseBody
     public DataSetList checkUpdatedDataSet( @PathVariable int id, @RequestBody DataSetList dataSetList,
         @RequestHeader( "accept-language" ) String locale )
@@ -90,7 +93,15 @@
         return facilityReportingService.getUpdatedDataSet( dataSetList, getUnit( id ), locale );
     }
 
-    @RequestMapping( method = RequestMethod.GET, value = "{id}/changeLanguageDataSet" )
+    @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/updateDataSets" )
+    @ResponseBody
+    public DataSetList checkUpdatedDataSet2_9( @PathVariable String clientVersion, @PathVariable int id,
+        @RequestBody DataSetList dataSetList, @RequestHeader( "accept-language" ) String locale )
+    {
+        return facilityReportingService.getUpdatedDataSet( dataSetList, getUnit( id ), locale );
+    }
+
+    @RequestMapping( method = RequestMethod.GET, value = "orgUnits/{id}/changeLanguageDataSet" )
     @ResponseBody
     public DataSetList changeLanguageDataSet( @PathVariable int id, @RequestHeader( "accept-language" ) String locale )
     {
@@ -103,7 +114,7 @@
      * @param dataSetValue - the report to save
      * @throws NotAllowedException if the {@link DataSetValue} is invalid
      */
-    @RequestMapping( method = RequestMethod.POST, value = "     {id}/dataSets" )
+    @RequestMapping( method = RequestMethod.POST, value = "orgUnits/{id}/dataSets" )
     @ResponseBody
     public String saveDataSetValues( @PathVariable int id, @RequestBody DataSetValue dataSetValue )
         throws NotAllowedException
@@ -119,7 +130,7 @@
      * @throws NotAllowedException if the {@link ActivityValue activity value}
      *         is invalid
      */
-    @RequestMapping( method = RequestMethod.POST, value = "{id}/activities" )
+    @RequestMapping( method = RequestMethod.POST, value = "orgUnits/{id}/activities" )
     @ResponseBody
     public String saveActivityReport( @PathVariable int id, @RequestBody ActivityValue activityValue )
         throws NotAllowedException
@@ -128,7 +139,7 @@
         return ACTIVITY_REPORT_UPLOADED;
     }
 
-    @RequestMapping( method = RequestMethod.POST, value = "{id}/activitiyplan" )
+    @RequestMapping( method = RequestMethod.POST, value = "orgUnits/{id}/activitiyplan" )
     @ResponseBody
     public MobileModel updatePrograms( @PathVariable int id, @RequestHeader( "accept-language" ) String locale,
         @RequestBody ModelList programsFromClient )
@@ -140,7 +151,7 @@
         return model;
     }
 
-    @RequestMapping( method = RequestMethod.GET, value = "{id}/search" )
+    @RequestMapping( method = RequestMethod.GET, value = "orgUnits/{id}/search" )
     @ResponseBody
     public ActivityPlan search( @PathVariable int id, @RequestHeader( "identifier" ) String identifier )
         throws NotAllowedException

=== modified file 'dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/DataStreamSerializer.java'
--- dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/DataStreamSerializer.java	2012-04-20 02:32:43 +0000
+++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/DataStreamSerializer.java	2012-07-20 08:07:59 +0000
@@ -27,10 +27,12 @@
         }
         catch ( InstantiationException e )
         {
+            e.printStackTrace();
             throw new IOException( "Can't instantiate class " + clazz.getName(), e );
         }
         catch ( IllegalAccessException e )
         {
+            e.printStackTrace();
             throw new IOException( "Not allowed to instantiate class " + clazz.getName(), e );
         }
     }