← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13995: Impl resource table for category option group set structure

 

------------------------------------------------------------
revno: 13995
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-02-12 13:08:30 +0100
message:
  Impl resource table for category option group set structure
added:
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateCategoryOptionGroupSetTableStatement.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/CategoryOptionGroupSet.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.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/jdbc/JdbcResourceTableStore.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/scheduling/ResourceTableTask.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/resourceTableForm.vm


--
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 10:52:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/CategoryOptionGroupSet.java	2014-02-12 12:08:30 +0000
@@ -63,6 +63,23 @@
     }
 
     // -------------------------------------------------------------------------
+    // Logic
+    // -------------------------------------------------------------------------
+
+    public CategoryOptionGroup getGroup( DataElementCategoryOption categoryOption )
+    {
+        for ( CategoryOptionGroup group : members )
+        {
+            if ( group.getMembers().contains( categoryOption ) )
+            {
+                return group;
+            }
+        }
+
+        return null;
+    }
+
+    // -------------------------------------------------------------------------
     // Getters and setters
     // -------------------------------------------------------------------------
 

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java	2014-02-12 10:52:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java	2014-02-12 12:08:30 +0000
@@ -558,6 +558,8 @@
     
     Collection<CategoryOptionGroup> getCategoryOptionGroupsBetweenByName( int first, int max, String name );
     
+    Collection<CategoryOptionGroup> getAllCategoryOptionGroups();
+    
     // -------------------------------------------------------------------------
     // CategoryOptionGroup
     // -------------------------------------------------------------------------
@@ -575,4 +577,6 @@
     Collection<CategoryOptionGroupSet> getCategoryOptionGroupSetsBetween( int first, int max );
     
     Collection<CategoryOptionGroupSet> getCategoryOptionGroupSetsBetweenByName( int first, int max, String name );
+
+    Collection<CategoryOptionGroupSet> getAllCategoryOptionGroupSets();
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableService.java	2014-01-30 16:10:35 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableService.java	2014-02-12 12:08:30 +0000
@@ -48,6 +48,11 @@
     void generateCategoryOptionComboNames();
     
     /**
+     * Generates a resource table for all category options.
+     */
+    void generateCategoryOptionGroupSetTable();
+    
+    /**
      * Generates a resource table for all data elements.
      */
     void generateDataElementGroupSetTable();

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.java	2013-09-24 07:05:03 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.java	2014-02-12 12:08:30 +0000
@@ -30,6 +30,7 @@
 
 import java.util.List;
 
+import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
 import org.hisp.dhis.dataelement.DataElementCategory;
 import org.hisp.dhis.dataelement.DataElementGroupSet;
 import org.hisp.dhis.indicator.IndicatorGroupSet;
@@ -69,6 +70,13 @@
     void createDataElementCategoryOptionComboName();
     
     /**
+     * Creates a table.
+     * 
+     * @param groupSets the group sets.
+     */
+    void createCategoryOptionGroupSetStructure( List<CategoryOptionGroupSet> groupSets );
+    
+    /**
      * Creates table.
      * 
      * @param groupSets the group sets.

=== 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-01-30 16:10:35 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java	2014-02-12 12:08:30 +0000
@@ -45,6 +45,8 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
+import org.hisp.dhis.dataelement.CategoryOptionGroup;
+import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategory;
 import org.hisp.dhis.dataelement.DataElementCategoryCombo;
@@ -68,6 +70,7 @@
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.resourcetable.statement.CreateCategoryOptionGroupSetTableStatement;
 import org.hisp.dhis.resourcetable.statement.CreateCategoryTableStatement;
 import org.hisp.dhis.resourcetable.statement.CreateDataElementGroupSetTableStatement;
 import org.hisp.dhis.resourcetable.statement.CreateIndicatorGroupSetTableStatement;
@@ -228,6 +231,52 @@
         log.info( "Category option combo name table generated" );
     }
 
+    @Transactional
+    public void generateCategoryOptionGroupSetTable()
+    {
+        // ---------------------------------------------------------------------
+        // 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 );
+        
+        resourceTableStore.createCategoryOptionGroupSetStructure( groupSets );
+
+        // ---------------------------------------------------------------------
+        // Populate table
+        // ---------------------------------------------------------------------
+
+        List<Object[]> batchArgs = new ArrayList<Object[]>();
+        
+        for ( DataElementCategoryOption categoryOption : categoryOptions )
+        {
+            List<Object> values = new ArrayList<Object>();
+
+            values.add( categoryOption.getId() );
+            values.add( categoryOption.getName() );
+            
+            for ( CategoryOptionGroupSet groupSet : groupSets )
+            {
+                CategoryOptionGroup group = groupSet.getGroup( categoryOption );
+                
+                values.add( group != null ? group.getName() : null );
+                values.add( group != null ? group.getUid() : null );
+            }
+            
+            batchArgs.add( values.toArray() );
+        }
+        
+        resourceTableStore.batchUpdate( ( groupSets.size() * 2 ) + 2, CreateCategoryOptionGroupSetTableStatement.TABLE_NAME, batchArgs );
+        
+        log.info( "Category option group set table generated" );
+    }
+    
     // -------------------------------------------------------------------------
     // DataElementGroupSetTable
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java	2014-02-09 15:36:46 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java	2014-02-12 12:08:30 +0000
@@ -33,6 +33,7 @@
 import org.amplecode.quick.Statement;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
 import org.hisp.dhis.dataelement.DataElementCategory;
 import org.hisp.dhis.dataelement.DataElementGroupSet;
 import org.hisp.dhis.indicator.IndicatorGroupSet;
@@ -40,6 +41,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.resourcetable.ResourceTableStore;
+import org.hisp.dhis.resourcetable.statement.CreateCategoryOptionGroupSetTableStatement;
 import org.hisp.dhis.resourcetable.statement.CreateCategoryTableStatement;
 import org.hisp.dhis.resourcetable.statement.CreateDataElementGroupSetTableStatement;
 import org.hisp.dhis.resourcetable.statement.CreateIndicatorGroupSetTableStatement;
@@ -153,6 +155,26 @@
         
         jdbcTemplate.execute( sql );
     }
+
+    // -------------------------------------------------------------------------
+    // CategoryOptionGroupSetTable
+    // -------------------------------------------------------------------------
+
+    public void createCategoryOptionGroupSetStructure( List<CategoryOptionGroupSet> groupSets )
+    {
+        try
+        {
+            jdbcTemplate.execute( "DROP TABLE IF EXISTS " + CreateCategoryOptionGroupSetTableStatement.TABLE_NAME );
+        }
+        catch ( BadSqlGrammarException ex )
+        {
+            // Do nothing, table does not exist
+        }
+        
+        Statement statement = new CreateCategoryOptionGroupSetTableStatement( groupSets, statementBuilder.getColumnQuote() );
+        
+        jdbcTemplate.execute( statement.getStatement() );
+    }
     
     // -------------------------------------------------------------------------
     // DataElementGroupSetTable

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/scheduling/ResourceTableTask.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/scheduling/ResourceTableTask.java	2014-01-30 16:10:35 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/scheduling/ResourceTableTask.java	2014-02-12 12:08:30 +0000
@@ -89,8 +89,9 @@
     private void generateAll()
     {
         resourceTableService.dropAllSqlViews();
-        resourceTableService.generateOrganisationUnitStructures();        
+        resourceTableService.generateOrganisationUnitStructures();   
         resourceTableService.generateCategoryOptionComboNames();
+        resourceTableService.generateCategoryOptionGroupSetTable();
         resourceTableService.generateDataElementGroupSetTable();
         resourceTableService.generateIndicatorGroupSetTable();
         resourceTableService.generateOrganisationUnitGroupSetTable();

=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateCategoryOptionGroupSetTableStatement.java	2014-02-12 12:08:30 +0000
@@ -0,0 +1,78 @@
+package org.hisp.dhis.resourcetable.statement;
+
+/*
+ * Copyright (c) 2004-2013, 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.List;
+
+import org.amplecode.quick.Statement;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class CreateCategoryOptionGroupSetTableStatement
+    implements Statement
+{
+    private static final Log log = LogFactory.getLog( CreateCategoryOptionGroupSetTableStatement.class );
+
+    private static final String LONG_TEXT_COLUMN_TYPE = "VARCHAR (250)";
+    
+    public static final String TABLE_NAME = "_categoryoptiongroupsetstructure";
+    
+    private List<CategoryOptionGroupSet> groupSets;
+    
+    private String quote;
+    
+    public CreateCategoryOptionGroupSetTableStatement( List<CategoryOptionGroupSet> groupSets, String quote )
+    {
+        this.groupSets = groupSets;
+        this.quote = quote;
+    }
+    
+    public String getStatement()
+    {
+        String statement = "CREATE TABLE " + TABLE_NAME + " ( " +
+            "categoryoptionid " + NUMERIC_COLUMN_TYPE + SEPARATOR +
+            "categoryoptionname " + LONG_TEXT_COLUMN_TYPE + SEPARATOR;
+        
+        for ( CategoryOptionGroupSet groupSet : groupSets )
+        {
+            statement += quote + groupSet.getName() + quote + SPACE + LONG_TEXT_COLUMN_TYPE + SEPARATOR;
+            statement += quote + groupSet.getUid() + quote + SPACE + "CHARACTER(11)" + SEPARATOR;
+        }
+        
+        statement += "PRIMARY KEY ( categoryoptionid ) )";
+                
+        log.info( "Create category option group set table SQL: " + statement );
+        
+        return statement;
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java	2014-02-12 10:52:22 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java	2014-02-12 12:08:30 +0000
@@ -797,6 +797,11 @@
         return categoryOptionGroupStore.getAllLikeNameOrderedName( name, first, max );
     }
     
+    public Collection<CategoryOptionGroup> getAllCategoryOptionGroups()
+    {
+        return categoryOptionGroupStore.getAll();
+    }
+    
     // -------------------------------------------------------------------------
     // CategoryOptionGroupSet
     // -------------------------------------------------------------------------
@@ -835,4 +840,9 @@
     {
         return categoryOptionGroupSetStore.getAllLikeNameOrderedName( name, first, max );
     }
+
+    public Collection<CategoryOptionGroupSet> getAllCategoryOptionGroupSets()
+    {
+        return categoryOptionGroupSetStore.getAll();
+    }    
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties	2014-02-05 10:56:38 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties	2014-02-12 12:08:30 +0000
@@ -70,6 +70,7 @@
 organisation_unit_groups_without_group_sets=Organisation unit groups without group sets
 data_integrity_checks_performed=Data integrity checks performed
 data_elements_assigned_to_period_types_with_different_period_types=Data elements assigned to data sets with different period types
+category_option_group_set_structure=Category option group set structure
 data_element_group_set_structure=Data element group set structure
 indicator_group_set_structure=Indicator group set structure
 organisation_unit_group_set_structure=Organisation unit group set structure

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/resourceTableForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/resourceTableForm.vm	2013-09-24 07:05:03 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/resourceTableForm.vm	2014-02-12 12:08:30 +0000
@@ -22,6 +22,7 @@
 
 <ul class="resourceTables">
 <li>$i18n.getString( "organisation_unit_structure" ) <span style="color:#606060">(_orgunitstructure)</span></li>
+<li>$i18n.getString( "category_option_group_set_structure" ) <span style="color:#606060">(_categoryoptiongroupsetstructure)</span></li>
 <li>$i18n.getString( "data_element_group_set_structure" ) <span style="color:#606060">(_dataelementgroupsetstructure)</span></li>
 <li>$i18n.getString( "indicator_group_set_structure" ) <span style="color:#606060">(_indicatorgroupsetstructure)</span></li>
 <li>$i18n.getString( "organisation_unit_group_set_structure" ) <span style="color:#606060">(_organisationunitgroupsetstructure)</span></li>