← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5723: Add return message for mobile, fix url builder

 

------------------------------------------------------------
revno: 5723
committer: Long <thanhlongngo1988>
branch nick: dhis2
timestamp: Fri 2012-01-13 14:41:16 +0700
message:
  Add return message for mobile, fix url builder
modified:
  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


--
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-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	2011-12-09 21:21:03 +0000
+++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java	2012-01-13 07:41:16 +0000
@@ -9,6 +9,7 @@
 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.api.mobile.support.MediaTypes;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.user.CurrentUserService;
 import org.hisp.dhis.user.User;
@@ -45,7 +46,7 @@
         {
             unitList.add( getOrgUnit( unit, request ) );
         }
-
+       
         return new OrgUnits( unitList );
     }
 
@@ -70,9 +71,7 @@
     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;
+        url = url + "orgUnits/" + id + "/" + path;
+        return url;
     }
 }

=== 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	2011-11-29 12:06:35 +0000
+++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java	2012-01-13 07:41:16 +0000
@@ -19,6 +19,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -26,10 +27,12 @@
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.ResponseStatus;
 
 @Controller
 @RequestMapping( value = "/mobile/orgUnits" )
-public class MobileOrganisationUnitController extends AbstractMobileController 
+public class MobileOrganisationUnitController
+    extends AbstractMobileController
 {
 
     @Autowired
@@ -47,7 +50,10 @@
     @Autowired
     private I18nService i18nService;
 
-    
+    private static final String DATASET_REPORT_IMPORT_SUCCESS_MESSAGE = "dataset_report_imported";
+
+    private static final String TRACKING_REPORT_IMPORT_SUCCESS_MESSAGE = "tracking_report_imported";
+
     @RequestMapping( method = RequestMethod.GET, value = "{id}/all" )
     @ResponseBody
     public MobileModel getAllDataForOrgUnit( @PathVariable int id, @RequestHeader( "accept-language" ) String locale )
@@ -66,19 +72,15 @@
 
     @RequestMapping( method = RequestMethod.POST, value = "{id}/updateDataSets" )
     @ResponseBody
-    public DataSetList checkUpdatedDataSet( @PathVariable
-    int id, @RequestBody
-    DataSetList dataSetList, @RequestHeader( "accept-language" )
-    String locale )
+    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 )
+    public DataSetList changeLanguageDataSet( @PathVariable int id, @RequestHeader( "accept-language" ) String locale )
     {
         return facilityReportingService.getDataSetsForLocale( getUnit( id ), locale );
     }
@@ -90,10 +92,12 @@
      * @throws NotAllowedException if the {@link DataSetValue} is invalid
      */
     @RequestMapping( method = RequestMethod.POST, value = "     {id}/dataSets" )
-    public void saveDataSetValues( @PathVariable int id, @RequestBody DataSetValue dataSetValue )
+    @ResponseBody
+    public String saveDataSetValues( @PathVariable int id, @RequestBody DataSetValue dataSetValue )
         throws NotAllowedException
     {
         facilityReportingService.saveDataSetValues( getUnit( id ), dataSetValue );
+        return DATASET_REPORT_IMPORT_SUCCESS_MESSAGE;
     }
 
     /**
@@ -104,20 +108,18 @@
      *         is invalid
      */
     @RequestMapping( method = RequestMethod.POST, value = "{id}/activities" )
-    public void saveActivityReport( @PathVariable
-    int id, @RequestBody
-    ActivityValue activityValue )
+    @ResponseBody
+    public String saveActivityReport( @PathVariable int id, @RequestBody ActivityValue activityValue )
         throws NotAllowedException
     {
         activityReportingService.saveActivityReport( getUnit( id ), activityValue );
+        return TRACKING_REPORT_IMPORT_SUCCESS_MESSAGE;
     }
 
     @RequestMapping( method = RequestMethod.POST, value = "{id}/activitiyplan" )
     @ResponseBody
-    public MobileModel updatePrograms( @PathVariable
-    int id, @RequestHeader( "accept-language" )
-    String locale, @RequestBody
-    ModelList programsFromClient )
+    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 ) ) );
@@ -128,15 +130,12 @@
 
     @RequestMapping( method = RequestMethod.GET, value = "{id}/search" )
     @ResponseBody
-    public ActivityPlan search( @PathVariable
-    int id, @RequestHeader( "identifier" )
-    String identifier )
+    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() )
@@ -152,12 +151,9 @@
         return localeStrings;
     }
 
-    
     private OrganisationUnit getUnit( int id )
     {
         return organisationUnitService.getOrganisationUnit( id );
     }
 
-    
-    
 }