← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18806: Resource tables, added check for invalid category combos

 

------------------------------------------------------------
revno: 18806
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-04-03 17:22:51 +0200
message:
  Resource tables, added check for invalid category combos
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.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/dataelement/DataElementCategoryCombo.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java	2015-02-05 06:53:38 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java	2015-04-03 15:22:51 +0000
@@ -111,6 +111,29 @@
     {
         return name.equals( DEFAULT_CATEGORY_COMBO_NAME );
     }
+    
+    /**
+     * Indicates whether this category combo has at least one category, has at
+     * least one category option combo and that all categories have at least one
+     * category option.
+     */
+    public boolean isValid()
+    {
+        if ( categories == null || categories.isEmpty() || optionCombos == null || optionCombos.isEmpty() )
+        {
+            return false;
+        }
+        
+        for ( DataElementCategory category : categories )
+        {
+            if ( category == null || category.getCategoryOptions() == null || category.getCategoryOptions().isEmpty() )
+            {
+                return false;
+            }
+        }
+        
+        return true;
+    }
 
     public List<DataElementCategoryOption> getCategoryOptions()
     {

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java	2015-03-13 15:48:26 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java	2015-04-03 15:22:51 +0000
@@ -214,6 +214,12 @@
 
         for ( DataElementCategoryCombo combo : combos )
         {
+            if ( !combo.isValid() )
+            {
+                log.warn( "Ignoring category combo, not valid: " + combo );
+                continue;
+            }
+            
             for ( DataElementCategoryOptionCombo coc : combo.getSortedOptionCombos() )
             {
                 List<Object> values = new ArrayList<>();