← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4586: Report table: Implemented new report parameter for leaf organisation units within the subtree of ...

 

Merge authors:
  Lars Helge Øverland (larshelge)
------------------------------------------------------------
revno: 4586 [merge]
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-09-14 17:17:47 +0200
message:
  Report table: Implemented new report parameter for leaf organisation units within the subtree of a parent organisation unit.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportParams.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/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/reporttable/hibernate/ReportTable.hbm.xml
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/SaveTableAction.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addTableForm.vm
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/inputReportParamsForm.vm
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/table.js


--
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/OrganisationUnitService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java	2011-09-14 03:44:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java	2011-09-14 14:35:02 +0000
@@ -159,6 +159,15 @@
     Collection<OrganisationUnit> getRootOrganisationUnits();
 
     /**
+     * Returns all OrganisationUnits which are part of the subtree of the
+     * OrganisationUnit with the given identifer and have no children.
+     * 
+     * @param id the identifier of the parent OrganisationUnit.
+     * @return a collection of OrganisationUnits.
+     */
+    Collection<OrganisationUnit> getLeafOrganisationUnits( int id );
+    
+    /**
      * Returns an OrganisationUnit and all its children.
      * 
      * @param id the id of the parent OrganisationUnit in the subtree.

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java	2011-09-05 21:35:18 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java	2011-09-14 15:17:22 +0000
@@ -37,7 +37,6 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.regex.Pattern;
 
 /**
  * The superclass of all PeriodTypes.

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportParams.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportParams.java	2011-05-05 21:14:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportParams.java	2011-09-14 15:17:22 +0000
@@ -47,6 +47,8 @@
 
     private Boolean paramReportingMonth;
 
+    private Boolean paramLeafParentOrganisationUnit;
+    
     private Boolean paramGrandParentOrganisationUnit;
     
     private Boolean paramParentOrganisationUnit;
@@ -61,9 +63,11 @@
     {
     }
     
-    public ReportParams( boolean paramReportingMonth, boolean paramGrandParentOrganisationUnit, boolean paramParentOrganisationUnit, boolean paramOrganisationUnit )
+    public ReportParams( boolean paramReportingMonth, boolean paramLeafParentOrganisationUnit,
+        boolean paramGrandParentOrganisationUnit, boolean paramParentOrganisationUnit, boolean paramOrganisationUnit )
     {
         this.paramReportingMonth = paramReportingMonth;
+        this.paramLeafParentOrganisationUnit = paramLeafParentOrganisationUnit;
         this.paramGrandParentOrganisationUnit = paramGrandParentOrganisationUnit;
         this.paramParentOrganisationUnit = paramParentOrganisationUnit;
         this.paramOrganisationUnit = paramOrganisationUnit;
@@ -78,6 +82,11 @@
         return paramReportingMonth != null && paramReportingMonth;
     }
     
+    public boolean isParamLeafParentOrganisationUnit()
+    {
+        return paramLeafParentOrganisationUnit != null && paramLeafParentOrganisationUnit;
+    }
+    
     public boolean isParamGrandParentOrganisationUnit()
     {
         return paramGrandParentOrganisationUnit != null && paramGrandParentOrganisationUnit;
@@ -95,9 +104,15 @@
     
     public boolean isSet()
     {
-        return isParamReportingMonth() || isParamGrandParentOrganisationUnit() || isParamParentOrganisationUnit() || isParamOrganisationUnit();
+        return isParamReportingMonth() || isOrganisationUnitSet();
     }
 
+    public boolean isOrganisationUnitSet()
+    {
+        return isParamLeafParentOrganisationUnit() || isParamGrandParentOrganisationUnit() || 
+            isParamParentOrganisationUnit() || isParamOrganisationUnit();
+    }
+    
     // -------------------------------------------------------------------------
     // Getters and setters
     // -------------------------------------------------------------------------
@@ -112,6 +127,16 @@
         this.paramReportingMonth = paramReportingMonth;
     }
 
+    public Boolean getParamLeafParentOrganisationUnit()
+    {
+        return paramLeafParentOrganisationUnit;
+    }
+
+    public void setParamLeafParentOrganisationUnit( Boolean paramLeafParentOrganisationUnit )
+    {
+        this.paramLeafParentOrganisationUnit = paramLeafParentOrganisationUnit;
+    }
+
     public Boolean getParamGrandParentOrganisationUnit()
     {
         return paramGrandParentOrganisationUnit;

=== 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	2011-09-14 12:46:13 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2011-09-14 14:35:02 +0000
@@ -217,6 +217,19 @@
         return organisationUnitStore.getRootOrganisationUnits();
     }
 
+    public Collection<OrganisationUnit> getLeafOrganisationUnits( int id )
+    {
+        Collection<OrganisationUnit> units = getOrganisationUnitWithChildren( id );
+        
+        return FilterUtils.filter( units, new Filter<OrganisationUnit>()
+        {
+            public boolean retain( OrganisationUnit object )
+            {
+                return object != null && object.getChildren().isEmpty();
+            }            
+        } );
+    }
+    
     public Collection<OrganisationUnit> getOrganisationUnitWithChildren( int id )
     {
         OrganisationUnit organisationUnit = getOrganisationUnit( id );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java	2011-09-06 09:21:23 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java	2011-09-14 14:35:02 +0000
@@ -32,6 +32,7 @@
 import static junit.framework.Assert.assertNotNull;
 import static junit.framework.Assert.assertNull;
 import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.fail;
 
 import java.util.Collection;
 import java.util.HashSet;
@@ -189,8 +190,8 @@
 
         int idA = dataElementService.addDataElement( dataElementA );
         int idB = dataElementService.addDataElement( dataElementB );
-        int idC1 = dataElementService.addDataElement( dataElementC1 );
-        int idC2 = dataElementService.addDataElement( dataElementC2 );
+        dataElementService.addDataElement( dataElementC1 );
+        dataElementService.addDataElement( dataElementC2 );
 
         dataElementA = dataElementService.getDataElementByCode( "codeA" );
         assertNotNull( dataElementA );
@@ -202,13 +203,17 @@
         assertEquals( idB, dataElementB.getId() );
         assertEquals( "DataElementB", dataElementB.getName() );
 
-        try {
+        try 
+        {
             dataElementService.getDataElementByCode( "codeC" );
-            assertEquals("Should have thrown exception","not thrown");
-        } catch (org.hibernate.NonUniqueResultException e ) {}
+            fail( "Should have thrown exception" );
+        } 
+        catch ( Exception ex )
+        {
+        }
         
         DataElement dataElementE = dataElementService.getDataElementByCode( "codeE" );
-        assertNull(dataElementE);
+        assertNull( dataElementE );
     }
 
     @Test

=== 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	2011-09-02 12:06:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java	2011-09-14 14:35:02 +0000
@@ -145,7 +145,10 @@
         organisationUnitService.addOrganisationUnit( unit3 );
         organisationUnitService.addOrganisationUnit( unit4 );
 
-        assertTrue( organisationUnitService.getOrganisationUnitWithChildren( id1 ).size() == 3 );
+        Collection<OrganisationUnit> actual = organisationUnitService.getOrganisationUnitWithChildren( id1 );        
+        assertEquals( 3, actual.size() );
+        assertTrue( actual.contains( unit1 ) );
+        assertTrue( actual.contains( unit2 ) );
     }
 
     @Test
@@ -184,8 +187,6 @@
 
         unit4 = organisationUnitService.getOrganisationUnitByCode( "foo" );
         assertNull( unit4 );
-
-
     }
 
     @Test

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java	2011-09-14 14:00:14 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java	2011-09-14 15:17:22 +0000
@@ -391,11 +391,26 @@
         }
 
         // ---------------------------------------------------------------------
+        // Leaf parent organisation unit report parameter
+        // ---------------------------------------------------------------------
+
+        if ( reportTable.getReportParams() != null &&
+            reportTable.getReportParams().isParamLeafParentOrganisationUnit() )
+        {
+            OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId );
+            reportTable.getRelativeUnits().addAll(
+                new ArrayList<OrganisationUnit>( organisationUnitService.getLeafOrganisationUnits( organisationUnitId ) ) );
+            reportTable.setOrganisationUnitName( organisationUnit.getName() );
+            
+            log.info( "Leaf parent organisation unit: " + organisationUnit.getName() );
+        }
+        
+        // ---------------------------------------------------------------------
         // Grand parent organisation unit report parameter
         // ---------------------------------------------------------------------
 
-        if ( reportTable.getReportParams() != null
-            && reportTable.getReportParams().isParamGrandParentOrganisationUnit() )
+        if ( reportTable.getReportParams() != null && 
+            reportTable.getReportParams().isParamGrandParentOrganisationUnit() )
         {
             OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId );
             organisationUnit.setCurrentParent( true );

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/reporttable/hibernate/ReportTable.hbm.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/reporttable/hibernate/ReportTable.hbm.xml	2011-07-28 03:25:28 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/reporttable/hibernate/ReportTable.hbm.xml	2011-09-14 15:17:22 +0000
@@ -80,6 +80,7 @@
 
     <component name="reportParams">
       <property name="paramReportingMonth" />
+	  <property name="paramLeafParentOrganisationUnit" />
       <property name="paramGrandParentOrganisationUnit" />
       <property name="paramParentOrganisationUnit" />
       <property name="paramOrganisationUnit" />

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/SaveTableAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/SaveTableAction.java	2011-03-29 20:06:47 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/SaveTableAction.java	2011-09-14 15:17:22 +0000
@@ -270,6 +270,13 @@
         this.paramReportingMonth = paramReportingMonth;
     }
 
+    private boolean paramLeafParentOrganisationUnit;
+    
+    public void setParamLeafParentOrganisationUnit( boolean paramLeafParentOrganisationUnit )
+    {
+        this.paramLeafParentOrganisationUnit = paramLeafParentOrganisationUnit;
+    }
+
     private boolean paramGrandParentOrganisationUnit;
     
     public void setParamGrandParentOrganisationUnit( boolean paramGrandParentOrganisationUnit )
@@ -346,6 +353,7 @@
         ReportParams reportParams = new ReportParams();
         
         reportParams.setParamReportingMonth( paramReportingMonth );
+        reportParams.setParamLeafParentOrganisationUnit( paramLeafParentOrganisationUnit );
         reportParams.setParamGrandParentOrganisationUnit( paramGrandParentOrganisationUnit );
         reportParams.setParamParentOrganisationUnit( paramParentOrganisationUnit );
         reportParams.setParamOrganisationUnit( paramOrganisationUnit );

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties	2011-09-07 13:14:46 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties	2011-09-14 15:17:22 +0000
@@ -383,4 +383,5 @@
 stacked_bar_chart = Stacked bar chart
 stacked_bar3d_chart = Stacked 3D bar chart
 domain_axis_label_x = Domain axis label (x)
-range_axis_label_y = Range axis label (y)
\ No newline at end of file
+range_axis_label_y = Range axis label (y)
+leaf_parent_organisation_unit = Leaf organisation units
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addTableForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addTableForm.vm	2011-07-01 08:11:03 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addTableForm.vm	2011-09-14 15:17:22 +0000
@@ -441,8 +441,12 @@
     	<td>
     		<label for="paramReportingMonth">$i18n.getString( "reporting_month" )</label>
     	    <input type="checkbox" id="paramReportingMonth" name="paramReportingMonth" value="true"#if( $reportTable.reportParams.isParamReportingMonth() ) checked#end>&nbsp;
+    	    <label for="paramLeafParentOrganisationUnit">$i18n.getString( "leaf_parent_organisation_unit" )</label>
+            <input type="checkbox" id="paramLeafParentOrganisationUnit" name="paramLeafParentOrganisationUnit" value="true"#if( $reportTable.reportParams.isParamLeafParentOrganisationUnit() ) checked#end>&nbsp;
     	    <label for="paramGrandParentOrganisationUnit">$i18n.getString( "grand_parent_organisation_unit" )</label>
-            <input type="checkbox" id="paramGrandParentOrganisationUnit" name="paramGrandParentOrganisationUnit" value="true"#if( $reportTable.reportParams.isParamGrandParentOrganisationUnit() ) checked#end>&nbsp;
+            <input type="checkbox" id="paramGrandParentOrganisationUnit" name="paramGrandParentOrganisationUnit" value="true"#if( $reportTable.reportParams.isParamGrandParentOrganisationUnit() ) checked#end>
+        </td>
+        <td>
     	    <label for="paramParentOrganisationUnit">$i18n.getString( "parent_organisation_unit" )</label>
             <input type="checkbox" id="paramParentOrganisationUnit" name="paramParentOrganisationUnit" value="true"#if( $reportTable.reportParams.isParamParentOrganisationUnit() ) checked#end>&nbsp;
             <label for="paramOrganisationUnit">$i18n.getString( "organisation_unit" )</label>

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/inputReportParamsForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/inputReportParamsForm.vm	2011-04-03 11:02:16 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/inputReportParamsForm.vm	2011-09-14 15:17:22 +0000
@@ -58,7 +58,7 @@
     
     <!-- OrganisationUnit -->
     
-    #if ( $!reportParams.isParamGrandParentOrganisationUnit() || $!reportParams.isParamParentOrganisationUnit() || $!reportParams.isParamOrganisationUnit() )
+    #if ( $!reportParams.isOrganisationUnitSet() )
         
 	<tr>
         <th>$i18n.getString( "organisation_unit" )</th>

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/table.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/table.js	2011-08-19 07:40:22 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/table.js	2011-09-14 15:17:22 +0000
@@ -114,13 +114,18 @@
 
 function organisationUnitReportParamsChecked()
 {
-    return ( isChecked( "paramGrandParentOrganisationUnit" ) || isChecked( "paramParentOrganisationUnit" ) || isChecked( "paramOrganisationUnit" ) );
+    return ( isChecked( "paramLeafParentOrganisationUnit" ) || isChecked( "paramGrandParentOrganisationUnit" ) 
+    	|| isChecked( "paramParentOrganisationUnit" ) || isChecked( "paramOrganisationUnit" ) );
 }
 
 function bothOrganisationUnitReportParamsChecked()
 {
     var count = 0;
 
+    if ( isChecked( "paramLeafParentOrganisationUnit" ) )
+    {
+        count++;
+    }
     if ( isChecked( "paramGrandParentOrganisationUnit" ) )
     {
         count++;