← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13997: Minor

 

------------------------------------------------------------
revno: 13997
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-02-12 16:22:28 +0100
message:
  Minor
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/CategoryOptionGroupSet.java
  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/statement/CreateCategoryOptionGroupSetTableStatement.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/CategoryOptionGroupSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/CategoryOptionGroupSet.java	2014-02-12 12:08:30 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/CategoryOptionGroupSet.java	2014-02-12 15:22:28 +0000
@@ -30,7 +30,9 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Set;
 
+import org.apache.commons.collections.CollectionUtils;
 import org.hisp.dhis.common.BaseDimensionalObject;
 import org.hisp.dhis.common.DxfNamespaces;
 import org.hisp.dhis.common.annotation.Scanned;
@@ -66,11 +68,15 @@
     // Logic
     // -------------------------------------------------------------------------
 
-    public CategoryOptionGroup getGroup( DataElementCategoryOption categoryOption )
+    //TODO link group set to category to avoid conflicting grouping of category option combos
+    
+    public CategoryOptionGroup getGroup( DataElementCategoryOptionCombo optionCombo )
     {
+        Set<DataElementCategoryOption> categoryOptions = optionCombo.getCategoryOptions();
+        
         for ( CategoryOptionGroup group : members )
         {
-            if ( group.getMembers().contains( categoryOption ) )
+            if ( !CollectionUtils.intersection( group.getMembers(), categoryOptions ).isEmpty() )
             {
                 return group;
             }

=== 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	2014-02-12 12:08:30 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java	2014-02-12 15:22:28 +0000
@@ -238,13 +238,12 @@
         // Create table
         // ---------------------------------------------------------------------
 
-        List<DataElementCategoryOption> categoryOptions = new ArrayList<DataElementCategoryOption>( categoryService.getAllDataElementCategoryOptions() );
-        
-        Collections.sort( categoryOptions, IdentifiableObjectNameComparator.INSTANCE );
-        
         List<CategoryOptionGroupSet> groupSets = new ArrayList<CategoryOptionGroupSet>();
         
         Collections.sort( groupSets, IdentifiableObjectNameComparator.INSTANCE );
+
+        List<DataElementCategoryOptionCombo> categoryOptionCombos = 
+            new ArrayList<DataElementCategoryOptionCombo>( categoryService.getAllDataElementCategoryOptionCombos() );
         
         resourceTableStore.createCategoryOptionGroupSetStructure( groupSets );
 
@@ -254,16 +253,15 @@
 
         List<Object[]> batchArgs = new ArrayList<Object[]>();
         
-        for ( DataElementCategoryOption categoryOption : categoryOptions )
+        for ( DataElementCategoryOptionCombo categoryOptionCombo : categoryOptionCombos )
         {
             List<Object> values = new ArrayList<Object>();
 
-            values.add( categoryOption.getId() );
-            values.add( categoryOption.getName() );
+            values.add( categoryOptionCombo.getId() );
             
             for ( CategoryOptionGroupSet groupSet : groupSets )
             {
-                CategoryOptionGroup group = groupSet.getGroup( categoryOption );
+                CategoryOptionGroup group = groupSet.getGroup( categoryOptionCombo );
                 
                 values.add( group != null ? group.getName() : null );
                 values.add( group != null ? group.getUid() : null );
@@ -272,7 +270,7 @@
             batchArgs.add( values.toArray() );
         }
         
-        resourceTableStore.batchUpdate( ( groupSets.size() * 2 ) + 2, CreateCategoryOptionGroupSetTableStatement.TABLE_NAME, batchArgs );
+        resourceTableStore.batchUpdate( ( groupSets.size() * 2 ) + 1, CreateCategoryOptionGroupSetTableStatement.TABLE_NAME, batchArgs );
         
         log.info( "Category option group set table generated" );
     }

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateCategoryOptionGroupSetTableStatement.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateCategoryOptionGroupSetTableStatement.java	2014-02-12 12:08:30 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateCategoryOptionGroupSetTableStatement.java	2014-02-12 15:22:28 +0000
@@ -60,8 +60,7 @@
     public String getStatement()
     {
         String statement = "CREATE TABLE " + TABLE_NAME + " ( " +
-            "categoryoptionid " + NUMERIC_COLUMN_TYPE + SEPARATOR +
-            "categoryoptionname " + LONG_TEXT_COLUMN_TYPE + SEPARATOR;
+            "categoryoptioncomboid " + NUMERIC_COLUMN_TYPE + SEPARATOR;
         
         for ( CategoryOptionGroupSet groupSet : groupSets )
         {
@@ -69,7 +68,7 @@
             statement += quote + groupSet.getUid() + quote + SPACE + "CHARACTER(11)" + SEPARATOR;
         }
         
-        statement += "PRIMARY KEY ( categoryoptionid ) )";
+        statement += "PRIMARY KEY ( categoryoptioncomboid ) )";
                 
         log.info( "Create category option group set table SQL: " + statement );