← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 286: Implemented exclusive group set structure resource table, will get the name orgunitgroupsetexclus...

 

------------------------------------------------------------
revno: 286
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Wed 2009-05-13 17:51:02 +0200
message:
  Implemented exclusive group set structure resource table, will get the name orgunitgroupsetexclusivestructure
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/jdbc/StatementManager.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupService.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/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-organisationunit/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitGroupService.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

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/jdbc/StatementManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/jdbc/StatementManager.java	2009-03-13 11:51:35 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/jdbc/StatementManager.java	2009-05-13 15:51:02 +0000
@@ -55,7 +55,7 @@
      * @return a pre-initialized statement object.
      */
     StatementHolder getHolder();
-    
+        
     /**
      * Gets a pre-initialized statement object for an internal, embedded,
      * in-memory database.

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupService.java	2009-03-09 12:11:46 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupService.java	2009-05-13 15:51:02 +0000
@@ -194,4 +194,15 @@
      */
     Collection<OrganisationUnitGroupSet> getExclusiveOrganisationUnitGroupSetsContainingGroup(
         OrganisationUnitGroup organisationUnitGroup );
+    
+    /**
+     * Returns the OrganisationUnitGroup of which the given OrganisationUnit is
+     * a member of within the OrganisationUnitGroupSet. This will return the first
+     * group found so the given group set should be exclusive.
+     * 
+     * @param groupSet the OrganisationUnitGroupSet.
+     * @param unit the OrganisationUNit.
+     * @return an OrganisationUnitGroup.
+     */
+    OrganisationUnitGroup getOrganisationUnitGroup( OrganisationUnitGroupSet groupSet, OrganisationUnit unit );
 }

=== 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	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableService.java	2009-05-13 15:51:02 +0000
@@ -52,4 +52,9 @@
      * all DataElementCategoryOptionCombos.
      */
     void generateCategoryOptionComboNames();
+    
+    /**
+     * Generates a resource table for all organisation units 
+     */
+    void generateExclusiveGroupSetStructures();
 }

=== 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	2009-04-16 18:58:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.java	2009-05-13 15:51:02 +0000
@@ -2,6 +2,8 @@
 
 import java.util.Collection;
 
+import org.hisp.dhis.jdbc.Statement;
+
 public interface ResourceTableStore
 {
     String ID = ResourceTableStore.class.getName();
@@ -83,4 +85,20 @@
      * @return the number of deleted objects.
      */
     int deleteDataElementCategoryOptionComboNames();
+
+    // -------------------------------------------------------------------------
+    // ExclusiveGroupSetStructure
+    // -------------------------------------------------------------------------
+
+    /**
+     * Creates table.
+     * 
+     * @param statement the Statement.
+     */
+    void createExclusiveGroupSetStructureTable( Statement statement );
+    
+    /**
+     * Removes table.
+     */
+    void removeExclusiveGroupSetStructureTable();
 }

=== 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	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java	2009-05-13 15:51:02 +0000
@@ -27,28 +27,31 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.hisp.dhis.resourcetable.DataElementCategoryOptionComboName;
-import org.hisp.dhis.resourcetable.GroupSetStructure;
-import org.hisp.dhis.resourcetable.OrganisationUnitStructure;
-import org.hisp.dhis.resourcetable.ResourceTableService;
-import org.hisp.dhis.resourcetable.ResourceTableStore;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionComboService;
+import org.hisp.dhis.jdbc.BatchHandler;
 import org.hisp.dhis.jdbc.BatchHandlerFactory;
-import org.hisp.dhis.jdbc.BatchHandler;
+import org.hisp.dhis.jdbc.Statement;
+import org.hisp.dhis.jdbc.batchhandler.GenericBatchHandler;
 import org.hisp.dhis.jdbc.batchhandler.GroupSetStructureBatchHandler;
 import org.hisp.dhis.jdbc.batchhandler.OrganisationUnitStructureBatchHandler;
-import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
-import org.hisp.dhis.dataelement.DataElementCategoryOptionComboService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
 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.CreateExclusiveGroupSetTableStatement;
 
 /**
  * @author Lars Helge Overland
@@ -220,4 +223,62 @@
             resourceTableStore.addDataElementCategoryOptionComboName( entry );
         }
     }
+
+    // -------------------------------------------------------------------------
+    // Exclusive GroupSetStructure
+    // -------------------------------------------------------------------------
+    
+    public void generateExclusiveGroupSetStructures()
+    {
+        // ---------------------------------------------------------------------
+        // Drop table
+        // ---------------------------------------------------------------------
+        
+        resourceTableStore.removeExclusiveGroupSetStructureTable();
+
+        // ---------------------------------------------------------------------
+        // Create table
+        // ---------------------------------------------------------------------
+        
+        List<OrganisationUnit> units = new ArrayList<OrganisationUnit>( organisationUnitService.getAllOrganisationUnits() );
+        
+        Collections.sort( units, new OrganisationUnitNameComparator() );
+        
+        List<OrganisationUnitGroupSet> groupSets = new ArrayList<OrganisationUnitGroupSet>( 
+            organisationUnitGroupService.getExclusiveOrganisationUnitGroupSets() );
+        
+        Collections.sort( groupSets, new OrganisationUnitGroupSetNameComparator() );
+        
+        Statement statement = new CreateExclusiveGroupSetTableStatement( groupSets );
+        
+        resourceTableStore.createExclusiveGroupSetStructureTable( statement );
+
+        // ---------------------------------------------------------------------
+        // Populate table
+        // ---------------------------------------------------------------------
+        
+        BatchHandler batchHandler = batchHandlerFactory.createBatchHandler( GenericBatchHandler.class );
+        
+        batchHandler.setTableName( CreateExclusiveGroupSetTableStatement.TABLE_NAME );
+        
+        batchHandler.init();
+        
+        for ( OrganisationUnit unit : units )
+        {
+            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 );
+        }
+        
+        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	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/hibernate/HibernateResourceTableStore.java	2009-05-13 15:51:02 +0000
@@ -29,14 +29,20 @@
 
 import java.util.Collection;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.hibernate.Criteria;
 import org.hibernate.Query;
 import org.hibernate.Session;
 import org.hisp.dhis.hibernate.HibernateSessionManager;
+import org.hisp.dhis.jdbc.Statement;
+import org.hisp.dhis.jdbc.StatementHolder;
+import org.hisp.dhis.jdbc.StatementManager;
 import org.hisp.dhis.resourcetable.DataElementCategoryOptionComboName;
 import org.hisp.dhis.resourcetable.GroupSetStructure;
 import org.hisp.dhis.resourcetable.OrganisationUnitStructure;
 import org.hisp.dhis.resourcetable.ResourceTableStore;
+import org.hisp.dhis.resourcetable.statement.CreateExclusiveGroupSetTableStatement;
 
 /**
  * @author Lars Helge Overland
@@ -45,6 +51,8 @@
 public class HibernateResourceTableStore
     implements ResourceTableStore
 {
+    private static final Log log = LogFactory.getLog( HibernateResourceTableStore.class );
+    
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -55,6 +63,13 @@
     {
         this.sessionManager = sessionManager;
     }
+    
+    private StatementManager statementManager;
+
+    public void setStatementManager( StatementManager statementManager )
+    {
+        this.statementManager = statementManager;
+    }
 
     // -------------------------------------------------------------------------
     // OrganisationUnitStructure
@@ -144,5 +159,45 @@
         Query query = session.createQuery( "DELETE FROM DataElementCategoryOptionComboName" );
 
         return query.executeUpdate();
+    }
+
+    // -------------------------------------------------------------------------
+    // ExclusiveGroupSetStructure
+    // -------------------------------------------------------------------------
+
+    public void createExclusiveGroupSetStructureTable( Statement statement )
+    {
+        StatementHolder holder = statementManager.getHolder();
+        
+        try
+        {
+            holder.getStatement().executeUpdate( statement.getStatement() );
+        }
+        catch ( Exception ex )
+        {
+            throw new RuntimeException( "Failed to create table: " + statement.getStatement() );
+        }
+        finally
+        {
+            holder.close();
+        }        
+    }
+    
+    public void removeExclusiveGroupSetStructureTable()
+    {
+        StatementHolder holder = statementManager.getHolder();
+        
+        try
+        {
+            holder.getStatement().executeUpdate( "DROP TABLE " + CreateExclusiveGroupSetTableStatement.TABLE_NAME );
+        }
+        catch ( Exception ex )
+        {
+            log.info( "Table " + CreateExclusiveGroupSetTableStatement.TABLE_NAME + " does not exist" );
+        }
+        finally
+        {
+            holder.close();
+        }        
     }    
 }

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml	2009-04-24 10:42:55 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml	2009-05-13 15:51:02 +0000
@@ -10,6 +10,8 @@
     class="org.hisp.dhis.resourcetable.hibernate.HibernateResourceTableStore">
     <property name="sessionManager"
       ref="org.hisp.dhis.hibernate.HibernateSessionManager"/>
+    <property name="statementManager"
+      ref="org.hisp.dhis.jdbc.StatementManager"/>
   </bean>
     
   <bean id="org.hisp.dhis.resourcetable.ResourceTableService"

=== modified file 'dhis-2/dhis-services/dhis-service-organisationunit/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitGroupService.java'
--- dhis-2/dhis-services/dhis-service-organisationunit/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitGroupService.java	2009-03-09 22:33:48 +0000
+++ dhis-2/dhis-services/dhis-service-organisationunit/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitGroupService.java	2009-05-13 15:51:02 +0000
@@ -214,4 +214,17 @@
 
         return result;
     }
+    
+    public OrganisationUnitGroup getOrganisationUnitGroup( OrganisationUnitGroupSet groupSet, OrganisationUnit unit )
+    {
+        for ( OrganisationUnitGroup group : groupSet.getOrganisationUnitGroups() )
+        {
+            if ( group.getMembers().contains( unit ) )
+            {
+                return group;
+            }
+        }
+        
+        return null;
+    }
 }

=== 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	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/resourcetable/GenerateResourceTableAction.java	2009-05-13 15:51:02 +0000
@@ -67,6 +67,13 @@
         this.groupSet = groupSet;
     }
 
+    private boolean exclusiveGroupSet;
+
+    public void setExclusiveGroupSet( boolean exclusiveGroupSet )
+    {
+        this.exclusiveGroupSet = exclusiveGroupSet;
+    }
+    
     private boolean categoryOptionComboName; 
 
     public void setCategoryOptionComboName( boolean categoryOptionComboName )
@@ -90,6 +97,11 @@
         {
             resourceTableService.generateGroupSetStructures();
         }
+
+        if ( exclusiveGroupSet )
+        {
+            resourceTableService.generateExclusiveGroupSetStructures();
+        }
         
         if ( categoryOptionComboName )
         {

=== 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	2009-04-17 00:20:52 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties	2009-05-13 15:51:02 +0000
@@ -96,3 +96,4 @@
 data_elements_assigned_to_period_types_with_different_period_types	= Data elements assigned to data sets with different period types
 select_a_period_type												= Please select a period type
 select_a_period														= Please select a period
+exclusive_group_set_structure										= Exclusive group set structure
\ No newline at end of file

=== 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	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/resourceTable.js	2009-05-13 15:51:02 +0000
@@ -3,14 +3,16 @@
 {
     var organisationUnit = document.getElementById( "organisationUnit" ).checked;
     var groupSet = document.getElementById( "groupSet" ).checked;
+    var exclusiveGroupSet = document.getElementById( "exclusiveGroupSet" ).checked;
     var categoryOptionComboName = document.getElementById( "categoryOptionComboName" ).checked;
     
-    if ( organisationUnit || groupSet || categoryOptionComboName )
+    if ( organisationUnit || groupSet || exclusiveGroupSet || categoryOptionComboName )
     {
         setMessage( i18n_generating_resource_tables );
             
         var params = "organisationUnit=" + organisationUnit + 
             "&groupSet=" + groupSet + 
+            "&exclusiveGroupSet=" + exclusiveGroupSet +
             "&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	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/resourceTableForm.vm	2009-05-13 15:51:02 +0000
@@ -12,6 +12,11 @@
 </p>
 
 <p>
+    <input type="checkbox" id="exclusiveGroupSet">
+    <label for="exclusiveGroupSet">$i18n.getString( "exclusive_group_set_structure" )</label>
+</p>
+
+<p>
     <input type="checkbox" id="categoryOptionComboName">
     <label for="groupSet">$i18n.getString( "data_element_category_option_combo_name" )</label>
 </p>



--
Trunk
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.