← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14636: Approval UI, WIP

 

------------------------------------------------------------
revno: 14636
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-04-03 15:57:45 +0200
message:
  Approval UI, WIP
added:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonIdentifiableObjects.vm
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataapproval/action/GetCategoryOptionGroupsAction.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevel.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml


--
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/dataapproval/DataApprovalLevel.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevel.java	2014-03-30 22:00:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevel.java	2014-04-03 13:57:45 +0000
@@ -40,7 +40,7 @@
  * @author Jim Grace
  */
 public class DataApprovalLevel
-        implements Serializable
+    implements Serializable
 {
     private static final long serialVersionUID = -8424400562969386167L;
 
@@ -117,7 +117,7 @@
     public String getName()
     {
         String name = orgUnitLevel
-                + ( categoryOptionGroupSet == null ? "" : ( " - " + categoryOptionGroupSet.getName() ) );
+            + ( categoryOptionGroupSet == null ? "" : ( " - " + categoryOptionGroupSet.getName() ) );
 
         return name;
     }
@@ -130,9 +130,15 @@
      */
     public String getCategoryOptionGroupSetName()
     {
-        String categoryOptionGroupSetName = ( categoryOptionGroupSet == null ? "" : categoryOptionGroupSet.getName() );
-
-        return categoryOptionGroupSetName;
+        return ( categoryOptionGroupSet == null ? "" : categoryOptionGroupSet.getName() );
+    }
+    
+    /**
+     * Indicates whether this approval level specified a category option group set.
+     */
+    public boolean hasCategoryOptionGroupSet()
+    {
+        return categoryOptionGroupSet != null;
     }
 
     // -------------------------------------------------------------------------
@@ -208,5 +214,4 @@
     {
         this.orgUnitLevelName = orgUnitLevelName;
     }
-
 }

=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonIdentifiableObjects.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonIdentifiableObjects.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonIdentifiableObjects.vm	2014-04-03 13:57:45 +0000
@@ -0,0 +1,17 @@
+#set( $size = $objects.size() )
+{ "objects": [
+#foreach( $object in $objects )
+  {
+    "id": $!{object.id},
+    "uid": "$!{object.uid}",
+    "name": "$!encoder.jsonEncode( ${object.displayName} )",
+    "code": "$!encoder.jsonEncode( ${object.code} )",
+    "created": "$!encoder.jsonEncode( ${object.created} )",
+    "lastUpdated": "$!encoder.jsonEncode( ${object.lastUpdated} )"
+  }#if( $velocityCount < $size ),#end
+#end
+]
+#if( $usePaging ),
+    "paging":#parse( "/dhis-web-commons/ajax/jsonPaging.vm" )
+#end
+}
\ No newline at end of file

=== added file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataapproval/action/GetCategoryOptionGroupsAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataapproval/action/GetCategoryOptionGroupsAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataapproval/action/GetCategoryOptionGroupsAction.java	2014-04-03 13:57:45 +0000
@@ -0,0 +1,154 @@
+package org.hisp.dhis.reporting.dataapproval.action;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.hisp.dhis.dataapproval.DataApprovalLevel;
+import org.hisp.dhis.dataapproval.DataApprovalLevelService;
+import org.hisp.dhis.dataelement.CategoryOptionGroup;
+import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.system.util.Filter;
+import org.hisp.dhis.system.util.FilterUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.opensymphony.xwork2.Action;
+
+public class GetCategoryOptionGroupsAction
+    implements Action
+{
+    @Autowired
+    private DataApprovalLevelService approvalLevelService;
+
+    @Autowired
+    private OrganisationUnitService organisationUnitService;
+    
+    @Autowired
+    private DataElementCategoryService categoryService;
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private String ou;
+    
+    public void setOu( String ou )
+    {
+        this.ou = ou;
+    }
+
+    // -------------------------------------------------------------------------
+    // Output
+    // -------------------------------------------------------------------------
+
+    private List<CategoryOptionGroup> objects;
+
+    public List<CategoryOptionGroup> getObjects()
+    {
+        return objects;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    /**
+     * Category option groups will be filtered by i) group sets which are available
+     * to the current user through approval levels and ii) the organisation unit
+     * level selected.
+     */
+    @Override
+    public String execute()
+        throws Exception
+    {
+        if ( ou != null )
+        {
+            int ouLevel = organisationUnitService.getLevelOfOrganisationUnit( ou );
+            
+            List<DataApprovalLevel> approvalLevels = approvalLevelService.getUserDataApprovalLevels(); // TODO filter by org unit level
+    
+            Set<CategoryOptionGroupSet> groupSets = getCategoryOptionGroupSets( approvalLevels );
+            
+            objects = new ArrayList<CategoryOptionGroup>( categoryService.getAllCategoryOptionGroups() );
+            
+            FilterUtils.filter( objects, new CategoryOptionGroupGroupSetFilter( groupSets ) );        
+        }
+        
+        return SUCCESS;    
+    }
+
+    // -------------------------------------------------------------------------
+    // Supportive methods
+    // -------------------------------------------------------------------------
+
+    /**
+     * Returns the category option group sets associated with the given list of
+     * data approval levels.
+     * 
+     * @param approvalLevels the collection of data approval levels.
+     * @return a set of category option group sets.
+     */
+    private Set<CategoryOptionGroupSet> getCategoryOptionGroupSets( Collection<DataApprovalLevel> approvalLevels )
+    {
+        Set<CategoryOptionGroupSet> groupSets = new HashSet<CategoryOptionGroupSet>();
+        
+        for ( DataApprovalLevel level : approvalLevels )
+        {
+            if ( level != null && level.hasCategoryOptionGroupSet() )
+            {
+                groupSets.add( level.getCategoryOptionGroupSet() );
+            }
+        }
+        
+        return groupSets;
+    }
+    
+    class CategoryOptionGroupGroupSetFilter
+        implements Filter<CategoryOptionGroup>
+    {
+        private Set<CategoryOptionGroupSet> groupSets;
+        
+        public CategoryOptionGroupGroupSetFilter( Set<CategoryOptionGroupSet> groupSets )
+        {
+            this.groupSets = groupSets;
+        }
+        
+        @Override
+        public boolean retain( CategoryOptionGroup group )
+        {
+            return groupSets != null && groupSets.contains( group.getGroupSet() );
+        }
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml	2014-04-02 12:33:53 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml	2014-04-03 13:57:45 +0000
@@ -115,6 +115,10 @@
   <bean id="org.hisp.dhis.reporting.dataapproval.action.GetDataApprovalOptionsAction" class="org.hisp.dhis.reporting.dataapproval.action.GetDataApprovalOptionsAction"
     scope="prototype">
   </bean>
+  
+  <bean id="org.hisp.dhis.reporting.dataapproval.action.GetCategoryOptionGroupsAction" class="org.hisp.dhis.reporting.dataapproval.action.GetCategoryOptionGroupsAction"
+    scope="prototype">
+  </bean>
 
   <!-- Data completeness -->
 

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml	2014-04-02 15:49:34 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml	2014-04-03 13:57:45 +0000
@@ -197,6 +197,11 @@
       <param name="javascripts">../dhis-web-commons/oust/oust.js,javascript/dataSetReport.js,javascript/dataApproval.js</param>
       <param name="stylesheets">style/dhis-web-reporting.css</param>
     </action>
+    
+    <action name="getCategoryOptionGroups" class="org.hisp.dhis.reporting.dataapproval.action.GetCategoryOptionGroupsAction">    
+      <result name="success" type="velocity-json">/dhis-web-commons/ajax/jsonIdentifiableObjects.vm</result>
+      <param name="onExceptionReturn">plainTextError</param>
+    </action>
 
     <!-- Organisation Unit Distribution -->