← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1254: Fixed validation weakness in report table.

 

------------------------------------------------------------
revno: 1254
committer: Lars Helge Oeverland <larshelge@xxxxxxxxx>
branch nick: trunk
timestamp: Sun 2009-12-20 19:25:43 +0100
message:
  Fixed validation weakness in report table.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementCategoryOptionComboConverter.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/table.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-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java	2009-12-11 17:54:58 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java	2009-12-20 18:25:43 +0000
@@ -32,7 +32,6 @@
 import java.util.Map;
 import java.util.Set;
 
-import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.hierarchy.HierarchyViolationException;
 
 /**

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java	2009-12-11 02:18:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java	2009-12-20 18:25:43 +0000
@@ -29,10 +29,8 @@
 
 import java.util.Collection;
 import java.util.List;
-import java.util.Map;
 
 import org.hisp.dhis.dataelement.DataElement;
-import org.hisp.dhis.dataelement.DataElementCategoryCombo;
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.source.Source;
 

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java	2009-12-10 13:30:07 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java	2009-12-20 18:25:43 +0000
@@ -419,6 +419,11 @@
             throw new IllegalArgumentException( "ReportTable cannot contain more than one out of dataelements, indicators, and datasets" );
         }
                 
+        if ( trueVars( doIndicators, doPeriods, doUnits ) == 3 || trueVars( doIndicators, doPeriods, doUnits ) == 0 )
+        {
+            throw new IllegalArgumentException( "ReportTable must crosstab on one or two dimensions" );
+        }
+        
         // ---------------------------------------------------------------------
         // Init tableName, allPeriods and allUnits
         // ---------------------------------------------------------------------
@@ -851,6 +856,24 @@
     }
     
     /**
+     * Returns the number of booleans among the arguments which are true.
+     */
+    private int trueVars( Boolean... vars )
+    {
+        int trueVars = 0;
+        
+        for ( Boolean var : vars )
+        {
+            if ( var )
+            {
+                ++trueVars;
+            }
+        }
+        
+        return trueVars;
+    }
+    
+    /**
      * Generates a pretty-print column name based on short-names of the argument
      * objects. Null arguments are ignored in the name.
      */

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementCategoryOptionComboConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementCategoryOptionComboConverter.java	2009-12-16 10:41:19 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementCategoryOptionComboConverter.java	2009-12-20 18:25:43 +0000
@@ -29,9 +29,6 @@
 
 import java.util.Collection;
 import java.util.Map;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
 
 import org.amplecode.staxwax.reader.XMLReader;
 import org.amplecode.staxwax.writer.XMLWriter;
@@ -54,9 +51,6 @@
 public class DataElementCategoryOptionComboConverter
     extends AbstractDataElementCategoryOptionComboConverter implements XMLConverter
 {
-
-    private static final Log log = LogFactory.getLog(DataElementCategoryOptionComboConverter.class);
-
     public static final String COLLECTION_NAME = "categoryOptionCombos";
     public static final String ELEMENT_NAME = "categoryOptionCombo";
     

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/table.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/table.js	2009-11-24 11:01:39 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/table.js	2009-12-20 18:25:43 +0000
@@ -162,7 +162,7 @@
         return false;
     }
     
-    if ( !hasValue( "dimension" ) && !isChecked( "doIndicators" ) && !isChecked( "doPeriods" ) && !isChecked( "doOrganisationUnits" ) )
+    if ( !isTrue( "dimension" ) && !isChecked( "doIndicators" ) && !isChecked( "doPeriods" ) && !isChecked( "doOrganisationUnits" ) )
     {
         setMessage( i18n_cannot_crosstab_no_dimensions );
         
@@ -200,9 +200,11 @@
     return true;
 }
 
-function hasValue( elementId )
+function isTrue( elementId )
 {
-	return document.getElementById( elementId ).value != "" ? true : false;
+    var value = document.getElementById( elementId ).value;
+    
+    return value && value == "true" ? true : false;
 }
 
 function relativePeriodsChecked()