← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7667: [mobile] sepearte import methods for client version 2.8 and higher

 

------------------------------------------------------------
revno: 7667
committer: Long <thanhlongngo1988@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-07-23 11:34:56 +0700
message:
  [mobile] sepearte import methods for client version 2.8 and higher
modified:
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/ActivityPlan.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/MobileModel.java
  dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.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/ActivityPlan.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/ActivityPlan.java	2012-06-26 07:43:35 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/ActivityPlan.java	2012-07-23 04:34:56 +0000
@@ -77,28 +77,21 @@
     public void serialize( DataOutputStream dout )
         throws IOException
     {
-
-        if ( activitiesList == null )
+        if ( this.clientVersion.equals( TWO_POINT_NINE ) )
         {
-            dout.writeInt( 0 );
+            serializeVerssion2_9( dout );
         }
         else
         {
-            dout.writeInt( activitiesList.size() );
-            for ( int i = 0; i < activitiesList.size(); i++ )
-            {
-                activitiesList.get( i ).serialize( dout );
-            }
+            serializeVerssion2_8( dout );
         }
-
     }
 
     @Override
     public void deSerialize( DataInputStream dataInputStream )
         throws IOException
     {
-        // FIXME: Get implementation from client
-
+       
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/MobileModel.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/MobileModel.java	2012-06-26 07:43:35 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/MobileModel.java	2012-07-23 04:34:56 +0000
@@ -116,60 +116,6 @@
     public void serialize( DataOutputStream dout )
         throws IOException
     {
-        // if ( programs == null )
-        // {
-        // dout.writeInt( 0 );
-        // }
-        // else
-        // {
-        // dout.writeInt( programs.size() );
-        //
-        // for ( Program prog : programs )
-        // {
-        // prog.serialize( dout );
-        // }
-        // }
-        //
-        // // Write ActivityPlans
-        // if ( this.activityPlan == null )
-        // {
-        // dout.writeInt( 0 );
-        // }
-        // else
-        // {
-        // this.activityPlan.serialize( dout );
-        // }
-        //
-        // // Write current server's date
-        // dout.writeLong( serverCurrentDate.getTime() );
-        //
-        // // Write DataSets
-        // if ( datasets == null )
-        // {
-        // dout.writeInt( 0 );
-        // }
-        // else
-        // {
-        // dout.writeInt( datasets.size() );
-        // for ( DataSet ds : datasets )
-        // {
-        // ds.serialize( dout );
-        // }
-        // }
-        //
-        // // Write Locales
-        // if ( locales == null )
-        // {
-        // dout.writeInt( 0 );
-        // }
-        // else
-        // {
-        // dout.writeInt( locales.size() );
-        // for ( String locale : locales )
-        // {
-        // dout.writeUTF( locale );
-        // }
-        // }
         if ( this.getClientVersion().equals( DataStreamSerializable.TWO_POINT_EIGHT ) )
         {
             this.serializeVerssion2_8( dout );

=== 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-20 08:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java	2012-07-23 04:34:56 +0000
@@ -51,10 +51,10 @@
     @Autowired
     private I18nService i18nService;
 
-    // Initialize download for client version 2.8 and lower
+    // 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 )
+    public MobileModel getAllDataForOrgUnit2_8( @PathVariable int id, @RequestHeader( "accept-language" ) String locale )
     {
         MobileModel mobileModel = new MobileModel();
         mobileModel.setClientVersion( DataStreamSerializable.TWO_POINT_EIGHT );
@@ -67,10 +67,77 @@
         return mobileModel;
     }
 
-    // Initialize download for client version 2.9 and higher
+    @RequestMapping( method = RequestMethod.POST, value = "orgUnits/{id}/updateDataSets" )
+    @ResponseBody
+    public DataSetList checkUpdatedDataSet2_8( @PathVariable int id, @RequestBody DataSetList dataSetList,
+        @RequestHeader( "accept-language" ) String locale )
+    {
+        return facilityReportingService.getUpdatedDataSet( dataSetList, 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 = "orgUnits/{id}/dataSets" )
+    @ResponseBody
+    public String saveDataSetValues2_8( @PathVariable int id, @RequestBody DataSetValue dataSetValue )
+        throws NotAllowedException
+    {
+        facilityReportingService.saveDataSetValues( getUnit( id ), dataSetValue );
+        return DATASET_REPORT_UPLOADED;
+    }
+    
+    /**
+     * 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 = "orgUnits/{id}/activities" )
+    @ResponseBody
+    public String saveActivityReport2_8( @PathVariable int id, @RequestBody ActivityValue activityValue )
+        throws NotAllowedException
+    {
+        activityReportingService.saveActivityReport( getUnit( id ), activityValue );
+        return ACTIVITY_REPORT_UPLOADED;
+    }
+
+    @RequestMapping( method = RequestMethod.POST, value = "orgUnits/{id}/activitiyplan" )
+    @ResponseBody
+    public MobileModel updatePrograms2_8( @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 = "orgUnits/{id}/search" )
+    @ResponseBody
+    public ActivityPlan search2_8( @PathVariable int id, @RequestHeader( "identifier" ) String identifier )
+        throws NotAllowedException
+    {
+        return activityReportingService.getActivitiesByIdentifier( identifier );
+    }
+    
+    @RequestMapping( method = RequestMethod.GET, value = "orgUnits/{id}/changeLanguageDataSet" )
+    @ResponseBody
+    public DataSetList changeLanguageDataSet2_8( @PathVariable int id, @RequestHeader( "accept-language" ) String locale )
+    {
+        return facilityReportingService.getDataSetsForLocale( getUnit( id ), locale );
+    }
+
+    // For client version 2.9 and higher
+    
     @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/all" )
     @ResponseBody
-    public MobileModel getAllDataForOrgUnit2_9( @PathVariable String clientVersion, @PathVariable int id,
+    public MobileModel getAllDataForOrgUnit( @PathVariable String clientVersion, @PathVariable int id,
         @RequestHeader( "accept-language" ) String locale )
     {
         MobileModel mobileModel = new MobileModel();
@@ -85,36 +152,22 @@
         return mobileModel;
     }
 
-    @RequestMapping( method = RequestMethod.POST, value = "orgUnits/{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.POST, value = "{clientVersion}/orgUnits/{id}/updateDataSets" )
     @ResponseBody
-    public DataSetList checkUpdatedDataSet2_9( @PathVariable String clientVersion, @PathVariable int id,
+    public DataSetList checkUpdatedDataSet( @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 )
-    {
-        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 = "orgUnits/{id}/dataSets" )
+    
+    @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/dataSets" )
     @ResponseBody
     public String saveDataSetValues( @PathVariable int id, @RequestBody DataSetValue dataSetValue )
         throws NotAllowedException
@@ -122,7 +175,20 @@
         facilityReportingService.saveDataSetValues( getUnit( id ), dataSetValue );
         return DATASET_REPORT_UPLOADED;
     }
-
+    
+    @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/activitiyplan" )
+    @ResponseBody
+    public MobileModel updatePrograms(@PathVariable String clientVersion, @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() );
+        model.setClientVersion( DataStreamSerializable.TWO_POINT_NINE );
+        return model;
+    }
+    
     /**
      * Save activity report for unit
      * 
@@ -130,7 +196,7 @@
      * @throws NotAllowedException if the {@link ActivityValue activity value}
      *         is invalid
      */
-    @RequestMapping( method = RequestMethod.POST, value = "orgUnits/{id}/activities" )
+    @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/activities" )
     @ResponseBody
     public String saveActivityReport( @PathVariable int id, @RequestBody ActivityValue activityValue )
         throws NotAllowedException
@@ -138,26 +204,25 @@
         activityReportingService.saveActivityReport( getUnit( id ), activityValue );
         return ACTIVITY_REPORT_UPLOADED;
     }
-
-    @RequestMapping( method = RequestMethod.POST, value = "orgUnits/{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 = "orgUnits/{id}/search" )
+    
+    @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/search" )
     @ResponseBody
     public ActivityPlan search( @PathVariable int id, @RequestHeader( "identifier" ) String identifier )
         throws NotAllowedException
     {
-        return activityReportingService.getActivitiesByIdentifier( identifier );
-    }
+        ActivityPlan activityPlan = activityReportingService.getActivitiesByIdentifier( identifier );;
+        activityPlan.setClientVersion( DataStreamSerializable.TWO_POINT_NINE );
+        return activityPlan;
+    }
+    
+    @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/changeLanguageDataSet" )
+    @ResponseBody
+    public DataSetList changeLanguageDataSet( @PathVariable int id, @RequestHeader( "accept-language" ) String locale )
+    {
+        return facilityReportingService.getDataSetsForLocale( getUnit( id ), locale );
+    }
+    
+    //Supportive methods
 
     private Collection<String> getLocalStrings( Collection<Locale> locales )
     {