← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11570: exposed easy access to version of optionSets/dataSets, /api/dataSets/{uid}/version and /api/optio...

 

------------------------------------------------------------
revno: 11570
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-08-05 15:52:20 +0700
message:
  exposed easy access to version of optionSets/dataSets, /api/dataSets/{uid}/version and /api/optionSets/{uid}/version
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataSetController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/OptionSetController.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/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java	2013-07-22 05:14:19 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java	2013-08-05 08:52:20 +0000
@@ -345,7 +345,7 @@
             }
         }
     }
-    
+
     //--------------------------------------------------------------------------
     // Reflection helpers
     //--------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataSetController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataSetController.java	2013-02-04 07:29:22 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataSetController.java	2013-08-05 08:52:20 +0000
@@ -58,6 +58,7 @@
 import org.hisp.dhis.dxf2.metadata.MetaData;
 import org.hisp.dhis.dxf2.utils.JacksonUtils;
 import org.hisp.dhis.i18n.I18nService;
+import org.hisp.dhis.option.OptionSet;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
@@ -88,10 +89,10 @@
 
     @Autowired
     private DataSetService dataSetService;
-    
+
     @Autowired
     private DataEntryFormService dataEntryFormService;
-    
+
     @Autowired
     private ExportService exportService;
 
@@ -123,6 +124,18 @@
         transformer.transform( new StreamSource( input ), new StreamResult( response.getOutputStream() ) );
     }
 
+    @RequestMapping( value = "/{uid}/version", method = RequestMethod.GET )
+    public void getVersion( @PathVariable( "uid" ) String uid, @RequestParam Map<String, String> parameters,
+        HttpServletResponse response ) throws IOException
+    {
+        DataSet dataSet = manager.get( DataSet.class, uid );
+
+        Map<String, Integer> versionMap = new HashMap<String, Integer>();
+        versionMap.put( "version", dataSet.getVersion() );
+
+        JacksonUtils.toJson( response.getOutputStream(), versionMap );
+    }
+
     @RequestMapping( value = "/{uid}/form", method = RequestMethod.GET, produces = "application/json" )
     public void getFormJson( @PathVariable( "uid" ) String uid, @RequestParam( value = "ou", required = false ) String orgUnit,
         @RequestParam( value = "pe", required = false ) String period, HttpServletResponse response ) throws IOException
@@ -199,7 +212,7 @@
 
     @RequestMapping( value = "/{uid}/customDataEntryForm", method = { RequestMethod.PUT, RequestMethod.POST }, consumes = "text/html" )
     @PreAuthorize( "hasRole('ALL')" )
-    public void updateCustomDataEntryForm( @PathVariable( "uid" ) String uid, 
+    public void updateCustomDataEntryForm( @PathVariable( "uid" ) String uid,
         @RequestBody String formContent,
         HttpServletResponse response ) throws Exception
     {
@@ -210,14 +223,14 @@
             ContextUtils.notFoundResponse( response, "Data set not found for identifier: " + uid );
             return;
         }
-        
+
         DataEntryForm form = dataSet.getDataEntryForm();
-        
+
         if ( form == null )
         {
             form = new DataEntryForm( dataSet.getName(), DataEntryForm.STYLE_REGULAR, formContent );
             dataEntryFormService.addDataEntryForm( form );
-            
+
             dataSet.setDataEntryForm( form );
             dataSetService.updateDataSet( dataSet );
         }
@@ -227,7 +240,7 @@
             dataEntryFormService.updateDataEntryForm( form );
         }
     }
-    
+
     /**
      * Select only the meta-data required to describe form definitions.
      *

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/OptionSetController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/OptionSetController.java	2012-05-30 09:38:06 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/OptionSetController.java	2013-08-05 08:52:20 +0000
@@ -27,17 +27,38 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.dxf2.utils.JacksonUtils;
 import org.hisp.dhis.option.OptionSet;
 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.RequestParam;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
 @Controller
-@RequestMapping( value = OptionSetController.RESOURCE_PATH )
+@RequestMapping(value = OptionSetController.RESOURCE_PATH)
 public class OptionSetController
     extends AbstractCrudController<OptionSet>
 {
     public static final String RESOURCE_PATH = "/optionSets";
+
+    @RequestMapping( value = "/{uid}/version", method = RequestMethod.GET )
+    public void getVersion( @PathVariable( "uid" ) String uid, @RequestParam Map<String, String> parameters,
+        HttpServletResponse response ) throws IOException
+    {
+        OptionSet optionSet = manager.get( OptionSet.class, uid );
+
+        Map<String, Integer> versionMap = new HashMap<String, Integer>();
+        versionMap.put( "version", optionSet.getVersion() );
+
+        JacksonUtils.toJson( response.getOutputStream(), versionMap );
+    }
 }