← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15927: support including optionSets (capped at 50 by default, change with maxOptions=) in /api/me/assign...

 

------------------------------------------------------------
revno: 15927
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-07-01 18:10:50 +0800
message:
  support including optionSets (capped at 50 by default, change with maxOptions=) in /api/me/assignedDataSets
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/CurrentUserController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/Forms.java
  dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/dhis-web-mobile-resources/js/dhis2.storage.js


--
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/webapi/controller/user/CurrentUserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/CurrentUserController.java	2014-06-26 15:29:06 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/CurrentUserController.java	2014-07-01 10:10:50 +0000
@@ -29,6 +29,7 @@
  */
 
 import org.apache.commons.collections.CollectionUtils;
+import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.webapi.controller.exception.FilterTooShortException;
 import org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException;
 import org.hisp.dhis.webapi.utils.ContextUtils;
@@ -477,7 +478,8 @@
 
     @SuppressWarnings( "unchecked" )
     @RequestMapping( value = { "/assignedDataSets", "/dataSets" }, produces = { "application/json", "text/*" } )
-    public void getDataSets( HttpServletResponse response, @RequestParam Map<String, String> parameters ) throws IOException, NotAuthenticatedException
+    public void getDataSets( @RequestParam( defaultValue = "false" ) boolean optionSets, @RequestParam( defaultValue = "50" ) int maxOptions,
+        HttpServletResponse response, @RequestParam Map<String, String> parameters ) throws IOException, NotAuthenticatedException
     {
         User currentUser = currentUserService.getCurrentUser();
 
@@ -569,6 +571,24 @@
 
                 forms.getForms().put( uid, FormUtils.fromDataSet( dataSet ) );
                 formOrganisationUnit.getDataSets().add( formDataSet );
+
+                if ( optionSets )
+                {
+                    for ( DataElement dataElement : dataSet.getDataElements() )
+                    {
+                        if ( dataElement.hasOptionSet() )
+                        {
+                            int size = maxOptions;
+
+                            if ( size >= dataElement.getOptionSet().getOptions().size() )
+                            {
+                                size = dataElement.getOptionSet().getOptions().size();
+                            }
+
+                            forms.getOptionSets().put( dataElement.getOptionSet().getUid(), dataElement.getOptionSet().getOptions().subList( 0, size - 1 ) );
+                        }
+                    }
+                }
             }
 
             forms.getOrganisationUnits().put( formOrganisationUnit.getId(), formOrganisationUnit );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/Forms.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/Forms.java	2014-05-22 12:40:24 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/Forms.java	2014-07-01 10:10:50 +0000
@@ -29,9 +29,12 @@
  */
 
 import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.collect.Maps;
+import org.hisp.dhis.option.OptionSet;
 import org.hisp.dhis.webapi.webdomain.form.Form;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -45,6 +48,8 @@
     // maps dataSet.uid => form instance
     private Map<String, Form> forms = new HashMap<String, Form>();
 
+    private Map<String, List<String>> optionSets = Maps.newHashMap();
+
     public Forms()
     {
     }
@@ -70,4 +75,15 @@
     {
         this.forms = forms;
     }
+
+    @JsonProperty
+    public Map<String, List<String>> getOptionSets()
+    {
+        return optionSets;
+    }
+
+    public void setOptionSets( Map<String, List<String>> optionSets )
+    {
+        this.optionSets = optionSets;
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/dhis-web-mobile-resources/js/dhis2.storage.js'
--- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/dhis-web-mobile-resources/js/dhis2.storage.js	2013-08-23 16:11:13 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/dhis-web-mobile-resources/js/dhis2.storage.js	2014-07-01 10:10:50 +0000
@@ -26,7 +26,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-
 var dhis2 = dhis2 || {};
 dhis2['storage'] = dhis2['storage'] || {};