dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #14804
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5127: Applied patch from Jason, makes the number of columns in orgunitstructure resource table matching...
------------------------------------------------------------
revno: 5127
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-11-08 20:51:29 +0100
message:
Applied patch from Jason, makes the number of columns in orgunitstructure resource table matching the actual number of levels
modified:
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
--
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/resourcetable/ResourceTableStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.java 2011-03-17 19:31:16 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.java 2011-11-08 19:51:29 +0000
@@ -52,7 +52,7 @@
/**
* Creates a table.
*/
- void createOrganisationUnitStructure();
+ void createOrganisationUnitStructure( int maxLevel );
// -------------------------------------------------------------------------
// DataElementCategoryOptionComboName
=== 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 2011-11-08 08:56:01 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java 2011-11-08 19:51:29 +0000
@@ -134,12 +134,14 @@
public void generateOrganisationUnitStructures()
{
- resourceTableStore.createOrganisationUnitStructure();
+ int maxLevel = organisationUnitService.getMaxOfOrganisationUnitLevels();
+
+ resourceTableStore.createOrganisationUnitStructure( maxLevel );
BatchHandler<Object> batchHandler = batchHandlerFactory.createBatchHandler( GenericBatchHandler.class ).
setTableName( ResourceTableStore.TABLE_NAME_ORGANISATION_UNIT_STRUCTURE ).init();
- for ( int i = 0; i < 8; i++ )
+ for ( int i = 0; i < maxLevel; i++ )
{
int level = i + 1;
@@ -147,10 +149,10 @@
for ( OrganisationUnit unit : units )
{
- List<Object> structure = new ArrayList<Object>();
+ List<Integer> structure = new ArrayList<Integer>();
- structure.add( String.valueOf( unit.getId() ) );
- structure.add( String.valueOf( level ) );
+ structure.add( unit.getId() );
+ structure.add( level );
Map<Integer, Integer> identifiers = new HashMap<Integer, Integer>();
@@ -160,16 +162,12 @@
unit = unit.getParent();
}
-
- structure.add( identifiers.get( 1 ) );
- structure.add( identifiers.get( 2 ) );
- structure.add( identifiers.get( 3 ) );
- structure.add( identifiers.get( 4 ) );
- structure.add( identifiers.get( 5 ) );
- structure.add( identifiers.get( 6 ) );
- structure.add( identifiers.get( 7 ) );
- structure.add( identifiers.get( 8 ) );
-
+
+ for (int k = 1 ; k <= maxLevel ; k ++ )
+ {
+ structure.add( identifiers.get( k ) );
+ }
+
batchHandler.addObject( structure );
}
}
=== 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 2011-03-17 19:31:16 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/hibernate/HibernateResourceTableStore.java 2011-11-08 19:51:29 +0000
@@ -46,7 +46,6 @@
/**
* @author Lars Helge Overland
- * @version $Id$
*/
public class HibernateResourceTableStore
implements ResourceTableStore
@@ -68,7 +67,7 @@
// OrganisationUnitStructure
// -------------------------------------------------------------------------
- public void createOrganisationUnitStructure()
+ public void createOrganisationUnitStructure( int maxLevel )
{
try
{
@@ -79,22 +78,23 @@
// Do nothing, table does not exist
}
- String sql = "CREATE TABLE " + TABLE_NAME_ORGANISATION_UNIT_STRUCTURE + " ( " +
- "organisationunitid INTEGER NOT NULL, " +
- "level INTEGER, " +
- "idlevel1 INTEGER, " +
- "idlevel2 INTEGER, " +
- "idlevel3 INTEGER, " +
- "idlevel4 INTEGER, " +
- "idlevel5 INTEGER, " +
- "idlevel6 INTEGER, " +
- "idlevel7 INTEGER, " +
- "idlevel8 INTEGER, " +
- "PRIMARY KEY (organisationunitid) )";
+ StringBuilder sql = new StringBuilder();
+
+ sql.append( "CREATE TABLE " ).append( TABLE_NAME_ORGANISATION_UNIT_STRUCTURE ).
+ append( " ( organisationunitid INTEGER NOT NULL, level INTEGER, " );
+
+ for ( int k = 1 ; k <= maxLevel; k++ )
+ {
+ String levelName = "idlevel" + String.valueOf( k );
+ sql.append ( levelName );
+ sql.append (" INTEGER, ");
+ }
+
+ sql.append( "PRIMARY KEY ( organisationunitid ) );" );
log.info( "Create organisation unit structure table SQL: " + sql );
- jdbcTemplate.update( sql );
+ jdbcTemplate.update( sql.toString() );
}
// -------------------------------------------------------------------------