← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1307: - Made the OrganisationUnitGroupSet-OrganisationUnitGroup association one-to-many. - Made Orgunit...

 

------------------------------------------------------------
revno: 1307
committer: Lars Helge Oeverland <larshelge@xxxxxxxxx>
branch nick: trunk
timestamp: Fri 2010-01-15 12:32:18 +0100
message:
  - Made the OrganisationUnitGroupSet-OrganisationUnitGroup association one-to-many. - Made OrgunitGroupSet implement Dimension. Made OrgunitGroup implement DimensionOption. Made Orgunit implement DimensionOptionElement. - Implemented category option combo resource table. This table contains columns categoryoptioncomboid, categoryoptioncomboname, then columns for each category with the relevant categoryoption as value. GUI function is located under resource table in data administration module.
added:
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateCategoryTableStatement.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dimension/DimensionType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroup.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupSet.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/hibernate/HibernateResourceTableStore.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateOrganisationUnitGroupSetTableStatement.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnitGroup.hbm.xml
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/CodecUtils.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/resourcetable/GenerateResourceTableAction.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/javascript/resourceTable.js
  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/dimension/DimensionType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dimension/DimensionType.java	2009-11-24 11:01:39 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dimension/DimensionType.java	2010-01-15 11:32:18 +0000
@@ -34,5 +34,6 @@
 {
     CATEGORY,
     DATAELEMENTGROUPSET,
-    INDICATORGROUPSET
+    INDICATORGROUPSET,
+    ORGANISATIONUNITGROUPSET
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2010-01-14 07:10:41 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2010-01-15 11:32:18 +0000
@@ -27,10 +27,14 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
+import org.hisp.dhis.dimension.DimensionOption;
+import org.hisp.dhis.dimension.DimensionOptionElement;
 import org.hisp.dhis.source.Source;
 
 /**
@@ -38,7 +42,7 @@
  * @version $Id: OrganisationUnit.java 6251 2008-11-10 14:37:05Z larshelg $
  */
 public class OrganisationUnit
-    extends Source
+    extends Source implements DimensionOptionElement
 {
     private Set<OrganisationUnit> children = new HashSet<OrganisationUnit>();
 
@@ -128,6 +132,15 @@
     }
 
     // -------------------------------------------------------------------------
+    // Dimension
+    // -------------------------------------------------------------------------
+
+    public List<? extends DimensionOption> getDimensionOptions()
+    {
+        return new ArrayList<DimensionOption>( groups );
+    }
+    
+    // -------------------------------------------------------------------------
     // Logic
     // -------------------------------------------------------------------------
 

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroup.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroup.java	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroup.java	2010-01-15 11:32:18 +0000
@@ -27,17 +27,21 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.io.Serializable;
 import java.util.HashSet;
 import java.util.Set;
 
+import org.hisp.dhis.dimension.Dimension;
+import org.hisp.dhis.dimension.DimensionOption;
+import org.hisp.dhis.dimension.DimensionOptionElement;
+import org.hisp.dhis.dimension.DimensionType;
+
 /**
  * @author Kristian Nordal
  * @version $Id: OrganisationUnitGroup.java 5296 2008-05-29 16:06:14Z larshelg $
  */
 
 public class OrganisationUnitGroup
-    implements Serializable
+    implements DimensionOption
 {
     private int id;
     
@@ -49,6 +53,8 @@
     private String name;
 
     private Set<OrganisationUnit> members = new HashSet<OrganisationUnit>();
+    
+    private OrganisationUnitGroupSet groupSet;
 
     // -------------------------------------------------------------------------
     // Constructors
@@ -67,6 +73,25 @@
     // hashCode and equals
     // -------------------------------------------------------------------------
 
+    public Dimension getDimension()
+    {
+        return groupSet;
+    }
+
+    public Set<? extends DimensionOptionElement> getDimensionOptionElements()
+    {
+        return members;
+    }
+
+    public DimensionType getDimensionType()
+    {
+        return DimensionType.ORGANISATIONUNITGROUPSET;
+    }
+    
+    // -------------------------------------------------------------------------
+    // hashCode and equals
+    // -------------------------------------------------------------------------
+
     @Override
     public int hashCode()
     {
@@ -126,6 +151,16 @@
         this.uuid = uuid;
     }
 
+    public String getName()
+    {
+        return name;
+    }
+
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+
     public Set<OrganisationUnit> getMembers()
     {
         return members;
@@ -136,13 +171,13 @@
         this.members = members;
     }
 
-    public String getName()
+    public OrganisationUnitGroupSet getGroupSet()
     {
-        return name;
+        return groupSet;
     }
 
-    public void setName( String name )
+    public void setGroupSet( OrganisationUnitGroupSet groupSet )
     {
-        this.name = name;
+        this.groupSet = groupSet;
     }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupSet.java	2009-09-26 07:35:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupSet.java	2010-01-15 11:32:18 +0000
@@ -27,18 +27,20 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.io.Serializable;
+import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
-import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
+import org.hisp.dhis.dimension.Dimension;
+import org.hisp.dhis.dimension.DimensionOption;
 
 /**
  * @author Kristian Nordal
  * @version $Id: OrganisationUnitGroupSet.java 1905 2006-09-23 14:34:55Z torgeilo $
  */
 public class OrganisationUnitGroupSet
-    implements Serializable
+    extends Dimension
 {
     private int id;
 
@@ -69,14 +71,18 @@
     }
 
     // -------------------------------------------------------------------------
+    // Dimension
+    // -------------------------------------------------------------------------
+
+    public List<? extends DimensionOption> getDimensionOptions()
+    {
+        return new ArrayList<DimensionOption>( organisationUnitGroups );
+    }
+    
+    // -------------------------------------------------------------------------
     // Logic
     // -------------------------------------------------------------------------
 
-    public boolean hasOrganisationUnitGroups()
-    {
-        return organisationUnitGroups != null && organisationUnitGroups.size() > 0;
-    }
-    
     public boolean isMemberOfOrganisationUnitGroups( OrganisationUnit organisationUnit )
     {
         for ( OrganisationUnitGroup group : organisationUnitGroups )
@@ -86,10 +92,15 @@
                 return true;
             }
         }
+    
+        return false;
+    }
+
+    public boolean hasOrganisationUnitGroups()
+    {
+        return organisationUnitGroups != null && organisationUnitGroups.size() > 0;
+    }
         
-        return false;
-    }
-    
     // -------------------------------------------------------------------------
     // hashCode and equals
     // -------------------------------------------------------------------------

=== 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	2010-01-12 08:12:04 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableService.java	2010-01-15 11:32:18 +0000
@@ -67,4 +67,9 @@
      * Generates a resource table for all organisation units 
      */
     void generateOrganisationUnitGroupSetTable();
+    
+    /**
+     * Generates a resource table for all category option combos.
+     */
+    void generateCategoryTable();
 }

=== 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	2010-01-12 08:12:04 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.java	2010-01-15 11:32:18 +0000
@@ -3,6 +3,7 @@
 import java.util.Collection;
 import java.util.List;
 
+import org.hisp.dhis.dataelement.DataElementCategory;
 import org.hisp.dhis.dataelement.DataElementGroupSet;
 import org.hisp.dhis.indicator.IndicatorGroupSet;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
@@ -114,4 +115,11 @@
      */
     void createOrganisationUnitGroupSetStructure( List<OrganisationUnitGroupSet> groupSets );
     
+    /**
+     * Creates table.
+     * 
+     * @param categories the categories.
+     */
+    void createCategoryStructure( List<DataElementCategory> categories );
+    
 }

=== 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	2010-01-12 08:12:04 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java	2010-01-15 11:32:18 +0000
@@ -40,10 +40,12 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategory;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataelement.DataElementGroupSet;
 import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataelement.comparator.DataElementCategoryNameComparator;
 import org.hisp.dhis.dataelement.comparator.DataElementGroupSetNameComparator;
 import org.hisp.dhis.dataelement.comparator.DataElementNameComparator;
 import org.hisp.dhis.dimension.Dimension;
@@ -63,6 +65,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.organisationunit.comparator.OrganisationUnitGroupSetNameComparator;
 import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator;
+import org.hisp.dhis.resourcetable.statement.CreateCategoryTableStatement;
 import org.hisp.dhis.resourcetable.statement.CreateDataElementGroupSetTableStatement;
 import org.hisp.dhis.resourcetable.statement.CreateIndicatorGroupSetTableStatement;
 import org.hisp.dhis.resourcetable.statement.CreateOrganisationUnitGroupSetTableStatement;
@@ -396,17 +399,67 @@
             final List<String> values = new ArrayList<String>();
 
             values.add( String.valueOf( unit.getId() ) );
-
-            for ( OrganisationUnitGroupSet groupSet : groupSets )
-            {
-                OrganisationUnitGroup group = organisationUnitGroupService.getOrganisationUnitGroup( groupSet, unit );
-
-                values.add( group != null ? group.getName() : Statement.EMPTY );
-            }
-
-            batchHandler.addObject( values );
-        }
-
+            values.add( unit.getName() );
+
+            for ( Dimension groupSet : groupSets )
+            {
+                DimensionOption dimensionOption = groupSet.getDimensionOption( unit );
+                
+                values.add( dimensionOption != null ? dimensionOption.getName() : null );
+            }
+
+            batchHandler.addObject( values );
+        }
+
+        batchHandler.flush();
+    }
+    
+    // -------------------------------------------------------------------------
+    // CategoryTable
+    // -------------------------------------------------------------------------
+
+    public void generateCategoryTable()
+    {
+        // ---------------------------------------------------------------------
+        // Create table
+        // ---------------------------------------------------------------------
+
+        List<DataElementCategory> categories = new ArrayList<DataElementCategory>( categoryService.getAllDataElementCategories() );
+        
+        Collections.sort( categories, new DataElementCategoryNameComparator() );
+        
+        List<DataElementCategoryOptionCombo> categoryOptionCombos = 
+            new ArrayList<DataElementCategoryOptionCombo>( categoryService.getAllDataElementCategoryOptionCombos() );
+        
+        resourceTableStore.createCategoryStructure( categories );
+
+        // ---------------------------------------------------------------------
+        // Populate table
+        // ---------------------------------------------------------------------
+
+        BatchHandler<Object> batchHandler = batchHandlerFactory.createBatchHandler( GenericBatchHandler.class );
+
+        batchHandler.setTableName( CreateCategoryTableStatement.TABLE_NAME );
+
+        batchHandler.init();
+        
+        for ( DataElementCategoryOptionCombo categoryOptionCombo : categoryOptionCombos )
+        {
+            final List<String> values = new ArrayList<String>();
+            
+            values.add( String.valueOf( categoryOptionCombo.getId() ) );
+            values.add( categoryOptionCombo.getName() );
+            
+            for ( Dimension category : categories )
+            {
+                DimensionOption dimensionOption = category.getDimensionOption( categoryOptionCombo );
+                
+                values.add( dimensionOption != null ? dimensionOption.getName() : null );    
+            }
+            
+            batchHandler.addObject( values );
+        }
+        
         batchHandler.flush();
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/hibernate/HibernateResourceTableStore.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/hibernate/HibernateResourceTableStore.java	2010-01-12 08:12:04 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/hibernate/HibernateResourceTableStore.java	2010-01-15 11:32:18 +0000
@@ -35,6 +35,7 @@
 import org.hibernate.Query;
 import org.hibernate.Session;
 import org.hibernate.SessionFactory;
+import org.hisp.dhis.dataelement.DataElementCategory;
 import org.hisp.dhis.dataelement.DataElementGroupSet;
 import org.hisp.dhis.indicator.IndicatorGroupSet;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
@@ -42,6 +43,7 @@
 import org.hisp.dhis.resourcetable.GroupSetStructure;
 import org.hisp.dhis.resourcetable.OrganisationUnitStructure;
 import org.hisp.dhis.resourcetable.ResourceTableStore;
+import org.hisp.dhis.resourcetable.statement.CreateCategoryTableStatement;
 import org.hisp.dhis.resourcetable.statement.CreateDataElementGroupSetTableStatement;
 import org.hisp.dhis.resourcetable.statement.CreateIndicatorGroupSetTableStatement;
 import org.hisp.dhis.resourcetable.statement.CreateOrganisationUnitGroupSetTableStatement;
@@ -222,4 +224,24 @@
         
         jdbcTemplate.update( statement.getStatement() );
     }
+    
+    // -------------------------------------------------------------------------
+    // CategoryTable
+    // -------------------------------------------------------------------------
+
+    public void createCategoryStructure( List<DataElementCategory> categories )
+    {
+        try
+        {
+            jdbcTemplate.update( "DROP TABLE " + CreateCategoryTableStatement.TABLE_NAME );
+        }
+        catch ( BadSqlGrammarException ex )
+        {
+            // Do nothing, table does not exist
+        }
+        
+        Statement statement = new CreateCategoryTableStatement( categories );
+        
+        jdbcTemplate.update( statement.getStatement() );
+    }
 }

=== added file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateCategoryTableStatement.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateCategoryTableStatement.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateCategoryTableStatement.java	2010-01-15 11:32:18 +0000
@@ -0,0 +1,74 @@
+package org.hisp.dhis.resourcetable.statement;
+
+/*
+ * Copyright (c) 2004-2007, 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.DataElementCategory;
+import org.hisp.dhis.system.util.CodecUtils;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class CreateCategoryTableStatement
+    implements Statement
+{
+    private static final Log log = LogFactory.getLog( CreateCategoryTableStatement.class );
+    
+    private static final String LONG_TEXT_COLUMN_TYPE = "VARCHAR (160)";
+    
+    public static final String TABLE_NAME = "_categorystructure";
+    
+    private List<DataElementCategory> categories;
+    
+    public CreateCategoryTableStatement( List<DataElementCategory> categories )
+    {
+        this.categories = categories;
+    }    
+
+    public String getStatement()
+    {
+        String statement = "CREATE TABLE " + TABLE_NAME + " ( " +
+            "categoryoptioncomboid " + NUMERIC_COLUMN_TYPE + SEPARATOR +
+            "categoryoptioncomboname " + LONG_TEXT_COLUMN_TYPE + SEPARATOR;
+        
+        for ( DataElementCategory category : categories )
+        {
+            statement += CodecUtils.databaseEncode( category.getName() ) + SPACE + LONG_TEXT_COLUMN_TYPE + SEPARATOR;
+        }
+
+        statement += "PRIMARY KEY ( categoryoptioncomboid ) )";
+                
+        log.info( "Create category table SQL: " + statement );
+        
+        return statement;
+    }        
+}

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateOrganisationUnitGroupSetTableStatement.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateOrganisationUnitGroupSetTableStatement.java	2010-01-12 08:12:04 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateOrganisationUnitGroupSetTableStatement.java	2010-01-15 11:32:18 +0000
@@ -30,6 +30,8 @@
 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.organisationunit.OrganisationUnitGroupSet;
 import org.hisp.dhis.system.util.CodecUtils;
 
@@ -39,6 +41,8 @@
 public class CreateOrganisationUnitGroupSetTableStatement
     implements Statement
 {
+    private static final Log log = LogFactory.getLog( CreateOrganisationUnitGroupSetTableStatement.class );
+    
     public static final String TABLE_NAME = "_organisationunitgroupsetstructure";
 
     private static final String LONG_TEXT_COLUMN_TYPE = "VARCHAR (160)";
@@ -52,17 +56,19 @@
     
     public String getStatement()
     {
-        StringBuffer buffer = new StringBuffer( "CREATE TABLE " + TABLE_NAME + " ( organisationunitid " );
-        
-        buffer.append( NUMERIC_COLUMN_TYPE + SEPARATOR );
-        
+        String statement = "CREATE TABLE " + TABLE_NAME + " ( " +
+            "organisationunitid " + NUMERIC_COLUMN_TYPE + SEPARATOR +
+            "organisationunitname " + LONG_TEXT_COLUMN_TYPE + SEPARATOR;
+                
         for ( OrganisationUnitGroupSet groupSet : groupSets )
         {
-            buffer.append( CodecUtils.databaseEncode( groupSet.getName() ) + SPACE + LONG_TEXT_COLUMN_TYPE + SEPARATOR );
+            statement += CodecUtils.databaseEncode( groupSet.getName() ) + SPACE + LONG_TEXT_COLUMN_TYPE + SEPARATOR;
         }
         
-        buffer.append( "PRIMARY KEY ( organisationunitid ) )" );
-        
-        return buffer.toString();
+        statement += "PRIMARY KEY ( organisationunitid ) )";
+        
+        log.info( "Create organisation unit group set table SQL: " + statement );
+        
+        return statement;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnitGroup.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnitGroup.hbm.xml	2009-11-07 13:03:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnitGroup.hbm.xml	2010-01-15 11:32:18 +0000
@@ -23,5 +23,10 @@
           column="organisationunitid" foreign-key="fk_orgunitgroup_organisationunitid"/>
     </set>
     
+    <join table="orgunitgroupsetmembers" inverse="true">
+      <key column="orgunitgroupid"/>
+      <many-to-one column="orgunitgroupsetid" name="groupSet"/> 
+    </join>
+	
   </class>
 </hibernate-mapping>

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/CodecUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/CodecUtils.java	2009-11-30 15:32:55 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/CodecUtils.java	2010-01-15 11:32:18 +0000
@@ -172,6 +172,7 @@
             string = string.replaceAll( " ", EMPTY_REPLACEMENT );
             string = string.replaceAll( "<", EMPTY_REPLACEMENT + "lt" + EMPTY_REPLACEMENT );
             string = string.replaceAll( ">", EMPTY_REPLACEMENT + "gt" + EMPTY_REPLACEMENT );
+            string = string.replaceAll( "default", "_default" );
             
             StringBuffer buffer = new StringBuffer();
             

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/resourcetable/GenerateResourceTableAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/resourcetable/GenerateResourceTableAction.java	2010-01-12 08:12:04 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/resourcetable/GenerateResourceTableAction.java	2010-01-15 11:32:18 +0000
@@ -87,6 +87,13 @@
     {
         this.organisationUnitGroupSetStructure = organisationUnitGroupSetStructure;
     }
+    
+    private boolean categoryStructure;
+
+    public void setCategoryStructure( boolean categoryStructure )
+    {
+        this.categoryStructure = categoryStructure;
+    }
 
     private boolean categoryOptionComboName; 
 
@@ -127,6 +134,11 @@
             resourceTableService.generateOrganisationUnitGroupSetTable();
         }
         
+        if ( categoryStructure )
+        {
+            resourceTableService.generateCategoryTable();
+        }
+        
         if ( categoryOptionComboName )
         {
             resourceTableService.generateCategoryOptionComboNames();

=== 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	2010-01-12 08:12:04 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties	2010-01-15 11:32:18 +0000
@@ -136,3 +136,4 @@
 invalid_indicator_numerators										= Invalid indicator numerators
 invalid_validation_rule_left_side_expressions						= Invalid validation rule left side expressions
 invalid_validation_rule_right_side_expressions						= Invalid validation rule right side expressions
+category_structure													= Category structure

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/resourceTable.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/resourceTable.js	2010-01-12 08:12:04 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/resourceTable.js	2010-01-15 11:32:18 +0000
@@ -6,10 +6,11 @@
     var dataElementGroupSetStructure = document.getElementById( "dataElementGroupSetStructure" ).checked;
     var indicatorGroupSetStructure = document.getElementById( "indicatorGroupSetStructure" ).checked;
     var organisationUnitGroupSetStructure = document.getElementById( "organisationUnitGroupSetStructure" ).checked;
+    var categoryStructure = document.getElementById( "categoryStructure" ).checked;
     var categoryOptionComboName = document.getElementById( "categoryOptionComboName" ).checked;
     
-    if ( organisationUnit || groupSet || dataElementGroupSetStructure || 
-        indicatorGroupSetStructure || organisationUnitGroupSetStructure || categoryOptionComboName )
+    if ( organisationUnit || groupSet || dataElementGroupSetStructure || indicatorGroupSetStructure || 
+        organisationUnitGroupSetStructure || categoryStructure || categoryOptionComboName )
     {
         setMessage( i18n_generating_resource_tables );
             
@@ -18,6 +19,7 @@
             "&dataElementGroupSetStructure=" + dataElementGroupSetStructure +
             "&indicatorGroupSetStructure=" + indicatorGroupSetStructure +
             "&organisationUnitGroupSetStructure=" + organisationUnitGroupSetStructure +
+            "&categoryStructure=" + categoryStructure +
             "&categoryOptionComboName=" + categoryOptionComboName;
             
         var url = "generateResourceTable.action";

=== 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	2010-01-12 08:12:04 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/resourceTableForm.vm	2010-01-15 11:32:18 +0000
@@ -27,6 +27,11 @@
 </p>
 
 <p>
+	<input type="checkbox" id="categoryStructure">
+	<label for="categoryStructure">$i18n.getString( "category_structure" ) <span style="color:#606060">(_categorystructure)</span></label>
+</p>
+
+<p>
     <input type="checkbox" id="categoryOptionComboName">
     <label for="categoryOptionComboName">$i18n.getString( "data_element_category_option_combo_name" ) <span style="color:#606060">(categoryoptioncomboname)</span></label>
 </p>