← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21043: Resource tables and analytics. Getting the no of org unit levels from organisationunit.hierarchyl...

 

------------------------------------------------------------
revno: 21043
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-11-12 19:37:11 +0100
message:
  Resource tables and analytics. Getting the no of org unit levels from organisationunit.hierarchylevel column query.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitLevelStore.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/databrowser/jdbc/JDBCDataBrowserStore.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-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitLevelStore.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.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/organisationunit/OrganisationUnitLevelStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitLevelStore.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitLevelStore.java	2015-11-12 18:37:11 +0000
@@ -52,11 +52,4 @@
      * @return the OrganisationUnitLevel at the given level.
      */
     OrganisationUnitLevel getByLevel( int level );
-
-    /**
-     * Gets the maximum level from the hierarchy.
-     *
-     * @return the maximum number of level.
-     */
-    int getMaxLevels();
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java	2015-10-12 10:12:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java	2015-11-12 18:37:11 +0000
@@ -431,8 +431,6 @@
 
     int getNumberOfOrganisationUnits();
 
-    int getMaxOfOrganisationUnitLevels();
-
     /**
      * Return the number of organisation unit levels to cache offline, e.g. for
      * organisation unit tree. Looks for level to return in the following order:

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/databrowser/jdbc/JDBCDataBrowserStore.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/databrowser/jdbc/JDBCDataBrowserStore.java	2015-09-16 18:31:45 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/databrowser/jdbc/JDBCDataBrowserStore.java	2015-11-12 18:37:11 +0000
@@ -480,7 +480,7 @@
     {
         if ( maxLevel == null )
         {
-            maxLevel = organisationUnitService.getMaxOfOrganisationUnitLevels();
+            maxLevel = organisationUnitService.getNumberOfOrganisationalLevels();
         }
 
         int curLevel = organisationUnitService.getOrganisationUnit( orgUnitSelected ).getLevel();

=== 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	2015-11-02 03:45:34 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java	2015-11-12 18:37:11 +0000
@@ -134,7 +134,7 @@
     {
         resourceTableStore.generateResourceTable( new OrganisationUnitStructureResourceTable( 
             null, statementBuilder.getColumnQuote(), 
-            organisationUnitService, organisationUnitService.getMaxOfOrganisationUnitLevels() ) );
+            organisationUnitService, organisationUnitService.getNumberOfOrganisationalLevels() ) );
     }
     
     @Override

=== 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	2015-10-02 17:20:28 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java	2015-11-12 18:37:11 +0000
@@ -84,7 +84,7 @@
         jdbcTemplate.execute( createTableSql );
 
         // ---------------------------------------------------------------------
-        // Populate table
+        // Populate table through SQL or object batch update
         // ---------------------------------------------------------------------
 
         if ( populateTableSql.isPresent() )

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java	2015-10-06 17:53:30 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java	2015-11-12 18:37:11 +0000
@@ -96,7 +96,7 @@
     public void update( Integer lastYears, TaskId taskId )
     {
         int processNo = getProcessNo();
-        int orgUnitLevelNo = organisationUnitService.getMaxOfOrganisationUnitLevels();
+        int orgUnitLevelNo = organisationUnitService.getNumberOfOrganisationalLevels();
         
         Clock clock = new Clock( log ).startClock().logTime( "Starting update, processes: " + processNo + ", org unit levels: " + orgUnitLevelNo );
         
@@ -214,7 +214,7 @@
     
     private void applyAggregationLevels( List<AnalyticsTable> tables )
     {
-        int maxLevels = organisationUnitService.getMaxOfOrganisationUnitLevels();
+        int maxLevels = organisationUnitService.getNumberOfOrganisationalLevels();
         
         boolean hasAggLevels = false;
         

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java	2015-10-20 07:16:41 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java	2015-11-12 18:37:11 +0000
@@ -92,7 +92,7 @@
             return "No data values exist, not updating aggregate analytics tables";
         }
 
-        int orgUnitLevels = organisationUnitService.getMaxOfOrganisationUnitLevels();
+        int orgUnitLevels = organisationUnitService.getNumberOfOrganisationalLevels();
 
         if ( orgUnitLevels == 0 )
         {

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2015-10-15 21:33:41 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2015-11-12 18:37:11 +0000
@@ -685,12 +685,6 @@
     }
 
     @Override
-    public int getMaxOfOrganisationUnitLevels()
-    {
-        return organisationUnitLevelStore.getMaxLevels();
-    }
-
-    @Override
     public int getOfflineOrganisationUnitLevels()
     {
         // ---------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitLevelStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitLevelStore.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitLevelStore.java	2015-11-12 18:37:11 +0000
@@ -53,14 +53,4 @@
     {
         return (OrganisationUnitLevel) getCriteria( Restrictions.eq( "level", level ) ).uniqueResult();
     }
-
-    @Override
-    public int getMaxLevels()
-    {
-        final String sql = "SELECT MAX(level) FROM orgunitlevel";
-
-        Integer level = jdbcTemplate.queryForObject( sql, Integer.class );
-        
-        return level != null ? level : 0;
-    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java	2015-10-08 14:29:41 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java	2015-11-12 18:37:11 +0000
@@ -339,12 +339,37 @@
         OrganisationUnit unit7 = createOrganisationUnit( '7' );
         organisationUnitService.addOrganisationUnit( unit7 );
 
-        assertTrue( organisationUnitService.getOrganisationUnitsAtLevel( 1 ).size() == 2 );
-        assertTrue( organisationUnitService.getOrganisationUnitsAtLevel( 3 ).size() == 3 );
-        assertTrue( organisationUnitService.getNumberOfOrganisationalLevels() == 4 );
+        assertEquals( 2, organisationUnitService.getOrganisationUnitsAtLevel( 1 ).size() );
+        assertEquals( 3, organisationUnitService.getOrganisationUnitsAtLevel( 3 ).size() );
+        assertEquals( 4, organisationUnitService.getNumberOfOrganisationalLevels() );
         assertTrue( unit4.getLevel() == 3 );
         assertTrue( unit1.getLevel() == 1 );
         assertTrue( unit6.getLevel() == 4 );
+    }    
+
+    @Test
+    public void testGetNumberOfOrganisationalLevels()
+    {
+        assertEquals( 0, organisationUnitService.getNumberOfOrganisationalLevels() );
+        
+        OrganisationUnit unit1 = createOrganisationUnit( '1' );
+        organisationUnitService.addOrganisationUnit( unit1 );
+
+        OrganisationUnit unit2 = createOrganisationUnit( '2', unit1 );
+        unit1.getChildren().add( unit2 );
+        organisationUnitService.addOrganisationUnit( unit2 );
+
+        assertEquals( 2, organisationUnitService.getNumberOfOrganisationalLevels() );
+
+        OrganisationUnit unit3 = createOrganisationUnit( '3', unit2 );
+        unit2.getChildren().add( unit3 );
+        organisationUnitService.addOrganisationUnit( unit3 );
+
+        OrganisationUnit unit4 = createOrganisationUnit( '4', unit2 );
+        unit2.getChildren().add( unit4 );
+        organisationUnitService.addOrganisationUnit( unit4 );
+
+        assertEquals( 3, organisationUnitService.getNumberOfOrganisationalLevels() );
     }
     
     @Test
@@ -858,20 +883,6 @@
     }
 
     @Test
-    public void testGetMaxLevels()
-    {
-        assertEquals( 0, organisationUnitService.getMaxOfOrganisationUnitLevels() );
-
-        OrganisationUnitLevel levelA = new OrganisationUnitLevel( 1, "National" );
-        OrganisationUnitLevel levelB = new OrganisationUnitLevel( 2, "District" );
-
-        organisationUnitService.addOrganisationUnitLevel( levelA );
-        organisationUnitService.addOrganisationUnitLevel( levelB );
-
-        assertEquals( 2, organisationUnitService.getMaxOfOrganisationUnitLevels() );
-    }
-    
-    @Test
     public void testIsInUserHierarchy()
     {
         OrganisationUnit ouA = createOrganisationUnit( 'A' );