← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15856: Data set report, made sure that dynamic dimensions follow access control rules. Simplified implem...

 

------------------------------------------------------------
revno: 15856
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-06-25 17:56:22 +0200
message:
  Data set report, made sure that dynamic dimensions follow access control rules. Simplified implementation.
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/dataSetReportForm.vm
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataSetReport.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-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java	2014-06-25 15:03:58 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java	2014-06-25 15:56:22 +0000
@@ -323,17 +323,17 @@
     {
         DimensionalObject dimension = getDimension( uid );
         
-        BaseDimensionalObject object = new BaseDimensionalObject();
-        object.mergeWith( dimension );
+        BaseDimensionalObject copy = new BaseDimensionalObject();
+        copy.mergeWith( dimension );
         
         if ( filterCanRead )
         {
             User user = currentUserService.getCurrentUser();
-            List<NameableObject> items = getCanReadObjects( user, object.getItems() );
-            object.setItems( items );
+            List<NameableObject> items = getCanReadObjects( user, dimension.getItems() );
+            copy.setItems( items );
         }
         
-        return dimension;
+        return copy;
     }
 
     //--------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java	2014-06-25 15:03:58 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java	2014-06-25 15:56:22 +0000
@@ -28,6 +28,14 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 import org.hisp.dhis.common.DimensionService;
 import org.hisp.dhis.common.DimensionalObject;
 import org.hisp.dhis.common.IdentifiableObjectManager;
@@ -35,7 +43,6 @@
 import org.hisp.dhis.common.Pager;
 import org.hisp.dhis.common.PagerUtils;
 import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
-import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.webapi.service.LinkService;
 import org.hisp.dhis.webapi.utils.ContextUtils;
@@ -49,14 +56,6 @@
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
 @Controller
 @RequestMapping( value = DimensionController.RESOURCE_PATH )
 public class DimensionController
@@ -182,7 +181,7 @@
         
         List<DimensionalObject> dimensions = new ArrayList<>();
         dimensions.addAll( dataSet.getCategoryCombo().getCategories() );
-        dimensions.addAll( identifiableObjectManager.getAll( CategoryOptionGroupSet.class ) );
+        dimensions.addAll( dataSet.getCategoryOptionGroupSets() );
         
         dimensions = dimensionService.getCanReadObjects( dimensions );
         

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/dataSetReportForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/dataSetReportForm.vm	2014-06-24 16:36:24 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/dataSetReportForm.vm	2014-06-25 15:56:22 +0000
@@ -16,45 +16,6 @@
   #end
 });
 
-dhis2.dsr.metaData = {
-
-"defaultCategoryCombo":"${defaultCategoryCombo.uid}",
-"categoryCombos": {
-#set( $size1 = $categoryCombos.size() )
-#foreach( $categoryCombo in $categoryCombos )
-"${categoryCombo.uid}":{"id":"${categoryCombo.uid}","name":"$encoder.jsonEncode( ${categoryCombo.displayName} )","categories":[
-#set( $size2 = $categoryCombo.categories.size() )
-#foreach( $category in $categoryCombo.categories )
-"${category.uid}"#if( $velocityCount < $size2 ),#end
-#end
-] }#if( $velocityCount < $size1 ),#end
-#end
-},
-"categoryOptionGroupSets": {
-#set( $size1 = $categoryOptionGroupSets.size() )
-#foreach( $groupSet in $categoryOptionGroupSets )
-"${groupSet.uid}":{"id":"${groupSet.uid}","name":"$encoder.jsonEncode( ${groupSet.displayName} )","members":[
-#set( $size2 = $groupSet.members.size() )
-#foreach( $group in $groupSet.members )
-"${group.uid}"#if( $velocityCount < $size2 ),#end
-#end
-] }#if( $velocityCount < $size1 ),#end
-#end
-},
-"dataSets": {
-#set( $size1 = $dataSets.size() )
-#foreach( $dataSet in $dataSets )
-"${dataSet.uid}":{"id":"{dataSet.uid}","name":"$encoder.jsonEncode( ${dataSet.displayName} )",
-"categoryCombo":"$!{dataSet.categoryCombo.uid}","categoryOptionGroupSets":[
-#set( $size2 = $dataSet.categoryOptionGroupSets.size() )
-#foreach( $cogs in $dataSet.categoryOptionGroupSets )
-"${cogs.uid}"#if( $velocityCount < $size2 ),#end
-#end
-] }#if( $velocityCount < $size1 ),#end
-#end
-}
-}
-
 var i18n_select_data_set = '$encoder.jsEscape( $i18n.getString( "select_data_set" ), "'")';
 var i18n_select_period = '$encoder.jsEscape( $i18n.getString( "select_period" ), "'")';
 var i18n_select_organisation_unit = '$encoder.jsEscape( $i18n.getString( "select_organisation_unit" ), "'")';
@@ -100,8 +61,7 @@
 </select>
 </div>
 
-<div id="categoryOptionGroupSetDiv" style="display:none"></div>
-<div id="attributeComboDiv" style="display:none"></div>
+<div id="dimensionsDiv" style="display:none"></div>
 
 <!-- Period -->
 

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataSetReport.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataSetReport.js	2014-06-24 16:36:24 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataSetReport.js	2014-06-25 15:56:22 +0000
@@ -76,101 +76,49 @@
 dhis2.dsr.dataSetSelected = function()
 {
 	var ds = $( "#dataSetId" ).val();
-	var cc = dhis2.dsr.metaData.dataSets[ds].categoryCombo;
-	var cogs = dhis2.dsr.metaData.dataSets[ds].categoryOptionGroupSets;
-	
-	if ( cc && cc != dhis2.dsr.metaData.defaultCategoryCombo ) {
-		var categoryCombo = dhis2.dsr.metaData.categoryCombos[cc];
-		var categoryIds = categoryCombo.categories;
-		
-		dhis2.dsr.setAttributesMarkup( categoryIds );		
-	}
-	else {
-		$( "#attributeComboDiv" ).empty().hide();
-	}
-	
-	if ( cogs && cogs.length ) {
-		dhis2.dsr.setCategoryOptionGroupSetsMarkup( cogs );
-	}
-	else {
-		$( "#categoryOptionGroupSetDiv" ).empty().hide();
-	}
-}
-
-/**
- * Sets markup for drop down boxes for the given category option group sets in the
- * selection div.
- */
-dhis2.dsr.setCategoryOptionGroupSetsMarkup = function( groupSetIds )
-{
-	if ( !groupSetIds || groupSetIds.length == 0 ) {
-		return;
-	}
-	
-	var cogsRx = [];
-	$.each( groupSetIds, function( idx, id ) {
-		cogsRx.push( $.get( "../api/categoryOptionGroupSets/" + id + ".json" ) );
-	} );
-	
-	$.when.apply( $, cogsRx ).done( function() {
-		var html = '';
-		var args = dhis2.util.normalizeArguments( arguments );
-		
-		$.each( args, function( idx, cogs ) {
-			var groupSet = cogs[0];			
-
-			html += '<div class="inputSection">';
-			html += '<div><label>' + groupSet.name + '</label></div>';
-			html += '<select class="dimension" data-uid="' + groupSet.id + '" style="width:330px">';
-			html += '<option value="-1">[ ' + i18n_select_option_view_all + ' ]</option>';
-			
-			$.each( groupSet.items, function( idx, option ) {
-				html += '<option value="' + option.id + '">' + option.name + '</option>';
-			} );
-			
-			html += '</select>';
-			html += '</div>';
-		} );
-
-		$( "#categoryOptionGroupSetDiv" ).show().html( html );
-	} );
-}
-
-/**
-* Sets markup for drop down boxes for the given categories in the selection div.
-*/
-dhis2.dsr.setAttributesMarkup = function( categoryIds )
-{
-	if ( !categoryIds || categoryIds.length == 0 ) {
-		return;
-	}
-	
-	var categoryRx = [];	
-	$.each( categoryIds, function( idx, id ) {
-		categoryRx.push( $.get( "../api/categories/" + id + ".json" ) );
-	} );
-
-	$.when.apply( $, categoryRx ).done( function() {
-		var html = '';
-		var args = dhis2.util.normalizeArguments( arguments );
-		
-		$.each( args, function( idx, cat ) {
-			var category = cat[0];
-			
-			html += '<div class="inputSection">';
-			html += '<div><label>' + category.name + '</label></div>';
-			html += '<select class="dimension" data-uid="' + category.id + '" style="width:330px">';
-			html += '<option value="-1">[ ' + i18n_select_option_view_all + ' ]</option>';
-			
-			$.each( category.items, function( idx, option ) {
-				html += '<option value="' + option.id + '">' + option.name + '</option>';
-			} );
-			
-			html += '</select>';
-			html += '</div>';
-		} );
-
-		$( "#attributeComboDiv" ).show().html( html );
+	
+	var html = '';
+	
+	$.getJSON( "../api/dimensions/dataSet/" + ds, function( json ) {
+		
+		if ( !json.dimensions ) {
+			$( "#dimensionsDiv" ).hide();
+		}
+		else
+		{
+			var rx = [];
+			
+			$.each( json.dimensions, function( idx, dim ) {
+				rx.push( $.get( "../api/dimensions/" + dim.id + ".json" ) );
+			} );
+			
+			$.when.apply( $, rx ).done( function() {
+				var html = '';
+				var response = dhis2.util.normalizeArguments( arguments );
+	
+				$.each( response, function( idx, dimension ) {
+					var dim = dimension[0];
+	
+					if ( dim.hasOwnProperty( 'items' ) ) {
+						html += '<div class="inputSection">';
+						html += '<div><label>' + dim.name + '</label></div>';
+						html += '<select class="dimension" data-uid="' + dim.id + '" style="width:330px">';
+						html += '<option value="-1">[ ' + i18n_select_option_view_all + ' ]</option>';
+											
+						$.each( dim.items, function( idx, option ) {
+							html += '<option value="' + option.id + '">' + option.name + '</option>';
+						} );
+						
+						html += '</select>';
+						html += '</div>';
+					}
+				} );
+	
+				$( "#dimensionsDiv" ).show().html( html );
+			} );
+		}
+	} ).fail( function() {
+		$( "#dimensionsDiv" ).hide();
 	} );
 }