← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13272: Web API, query of options in option set

 

------------------------------------------------------------
revno: 13272
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-12-17 10:19:20 +0100
message:
  Web API, query of options in option set
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.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-api/src/main/java/org/hisp/dhis/option/OptionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionService.java	2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionService.java	2013-12-17 09:19:20 +0000
@@ -52,6 +52,8 @@
 
     Collection<OptionSet> getAllOptionSets();
 
+    List<String> getOptions( String optionSetUid, String key, Integer max );
+    
     List<String> getOptions( int optionSetId, String name, Integer max );
 
     Integer getOptionSetsCountByName( String name );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java	2013-12-17 09:19:20 +0000
@@ -102,6 +102,13 @@
         return i18n( i18nService, optionStore.getAll() );
     }
 
+    public List<String> getOptions( String optionSetUid, String key, Integer max )
+    {
+        OptionSet optionSet = getOptionSet( optionSetUid );
+        
+        return getOptions( optionSet.getId(), key, max );
+    }
+    
     public List<String> getOptions( int optionSetId, String key, Integer max )
     {
         List<String> options = null;

=== 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	2013-08-23 16:00:30 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/OptionSetController.java	2013-12-17 09:19:20 +0000
@@ -28,19 +28,23 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletResponse;
+
 import org.hisp.dhis.dxf2.utils.JacksonUtils;
+import org.hisp.dhis.option.OptionService;
 import org.hisp.dhis.option.OptionSet;
+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.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>
  */
@@ -50,6 +54,9 @@
     extends AbstractCrudController<OptionSet>
 {
     public static final String RESOURCE_PATH = "/optionSets";
+    
+    @Autowired
+    private OptionService optionService;
 
     @RequestMapping( value = "/{uid}/version", method = RequestMethod.GET )
     public void getVersion( @PathVariable( "uid" ) String uid, @RequestParam Map<String, String> parameters,
@@ -62,4 +69,15 @@
 
         JacksonUtils.toJson( response.getOutputStream(), versionMap );
     }
+    
+    @RequestMapping( value = "/{uid}/options", method = RequestMethod.GET )
+    public void getOptions( @PathVariable( "uid" ) String uid, 
+        @RequestParam(required = false) String key, 
+        @RequestParam(required = false) Integer max,
+        HttpServletResponse response ) throws IOException
+    {
+        List<String> options = optionService.getOptions( uid, key, max );
+        
+        JacksonUtils.toJson( response.getOutputStream(), options );
+    }
 }