← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2561: Included parent orgunit itself in report table for parent orgunit parameter. Added column indicat...

 

------------------------------------------------------------
revno: 2561
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-01-13 18:32:48 +0100
message:
  Included parent orgunit itself in report table for parent orgunit parameter. Added column indicating whether orgunit is parent
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.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/java/org/hisp/dhis/reporttable/statement/CreateReportTableStatement.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/OrganisationUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2010-12-14 03:56:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2011-01-13 17:32:48 +0000
@@ -79,8 +79,6 @@
 
     private Set<OrganisationUnitGroup> groups = new HashSet<OrganisationUnitGroup>();
     
-    private transient int level;
-    
     private String contactPerson;
     
     private String address;
@@ -88,6 +86,10 @@
     private String email;
     
     private String phoneNumber;
+
+    private transient int level;
+    
+    private transient boolean currentParent;
     
     // -------------------------------------------------------------------------
     // Constructors
@@ -488,16 +490,6 @@
         this.groups = groups;
     }
 
-    public int getLevel()
-    {
-        return level;
-    }
-
-    public void setLevel( int level )
-    {
-        this.level = level;
-    }
-
     public String getContactPerson()
     {
         return contactPerson;
@@ -537,5 +529,24 @@
     {
         this.phoneNumber = phoneNumber;
     }
-    
+
+    public int getLevel()
+    {
+        return level;
+    }
+
+    public void setLevel( int level )
+    {
+        this.level = level;
+    }
+
+    public boolean isCurrentParent()
+    {
+        return currentParent;
+    }
+
+    public void setCurrentParent( boolean currentParent )
+    {
+        this.currentParent = currentParent;
+    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java	2011-01-13 04:50:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java	2011-01-13 17:32:48 +0000
@@ -29,8 +29,8 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.regex.Matcher;
@@ -77,6 +77,7 @@
 
     public static final String REPORTING_MONTH_COLUMN_NAME = "reporting_month_name";
     public static final String PARAM_ORGANISATIONUNIT_COLUMN_NAME = "param_organisationunit_name";
+    public static final String ORGANISATION_UNIT_IS_PARENT_COLUMN_NAME = "organisation_unit_is_parent";
     
     public static final String SEPARATOR = "_";
     public static final String SPACE = " ";
@@ -91,8 +92,11 @@
     
     public static final String REGRESSION_COLUMN_PREFIX = "regression_";
 
-    public static final List<String> DB_COLUMNS = Arrays.asList( DATAELEMENT_ID, CATEGORYCOMBO_ID, 
-        INDICATOR_ID, DATASET_ID, PERIOD_ID, ORGANISATIONUNIT_ID, REPORTING_MONTH_COLUMN_NAME, PARAM_ORGANISATIONUNIT_COLUMN_NAME );
+    public static final String TRUE = "true";
+    public static final String FALSE = "false";
+    
+    public static final List<String> DB_COLUMNS = Arrays.asList( DATAELEMENT_ID, CATEGORYCOMBO_ID, INDICATOR_ID, DATASET_ID, 
+        PERIOD_ID, ORGANISATIONUNIT_ID, REPORTING_MONTH_COLUMN_NAME, PARAM_ORGANISATIONUNIT_COLUMN_NAME, ORGANISATION_UNIT_IS_PARENT_COLUMN_NAME );
     
     public static final Map<String, String> PRETTY_COLUMNS = new HashMap<String, String>() { {
         put( DATAELEMENT_NAME, "Data element" );
@@ -546,7 +550,7 @@
         else
         {
             crossTabPeriods.add( null );
-            reportPeriods = new ArrayList<Period>( new HashSet<Period>( allPeriods ) ); // Remove potential duplicates from relative periods / params
+            reportPeriods = new ArrayList<Period>( removeDuplicates( allPeriods ) ); // Remove potential duplicates from relative periods / params
             indexColumns.add( PERIOD_ID );
             indexNameColumns.add( PERIOD_NAME );
         }
@@ -560,7 +564,7 @@
         else
         {
             crossTabUnits.add( null );
-            reportUnits = new ArrayList<OrganisationUnit>( new HashSet<OrganisationUnit>( allUnits ) ); // Remove potential duplicates from params
+            reportUnits = new ArrayList<OrganisationUnit>( removeDuplicates( allUnits ) ); // Remove potential duplicates from params
             indexColumns.add( ORGANISATIONUNIT_ID );
             indexNameColumns.add( ORGANISATIONUNIT_NAME );
         }
@@ -993,6 +997,26 @@
         
         return string;
     }
+
+    /**
+     * Removes duplicates from the given list while maintaining the order.
+     */
+    private <T> List<T> removeDuplicates( List<T> list )
+    {
+        final List<T> temp = new ArrayList<T>( list );
+        Collections.reverse( temp );        
+        list.clear();
+        
+        for ( T object : temp )
+        {
+            if ( !list.contains( object ) )
+            {
+                list.add( object );
+            }
+        }
+        
+        return list;
+    }
     
     /**
      * Supportive method.

=== 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	2010-12-26 15:38:45 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java	2011-01-13 17:32:48 +0000
@@ -181,6 +181,8 @@
             if ( reportTable.getReportParams() != null && reportTable.getReportParams().isParamParentOrganisationUnit() )
             {
                 OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId );
+                organisationUnit.setCurrentParent( true );
+                reportTable.getRelativeUnits().add( organisationUnit );
                 reportTable.getRelativeUnits().addAll( new ArrayList<OrganisationUnit>( organisationUnit.getChildren() ) );
                 reportTable.setOrganisationUnitName( organisationUnit.getName() );
                 
@@ -507,6 +509,12 @@
                         // -----------------------------------------------------
 
                         grid.addValue( reportTable.getOrganisationUnitName() );
+
+                        // ---------------------------------------------------------------------
+                        // Organisation unit is parent
+                        // ---------------------------------------------------------------------
+
+                        grid.addValue( unit != null && unit.isCurrentParent() ? ReportTable.TRUE : ReportTable.FALSE );
                         
                         // -----------------------------------------------------
                         // Values

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/statement/CreateReportTableStatement.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/statement/CreateReportTableStatement.java	2010-12-10 19:33:05 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/statement/CreateReportTableStatement.java	2011-01-13 17:32:48 +0000
@@ -92,6 +92,12 @@
         // ---------------------------------------------------------------------
 
         buffer.append( ReportTable.PARAM_ORGANISATIONUNIT_COLUMN_NAME + SPACE + LONG_TEXT_COLUMN_TYPE + SEPARATOR );
+
+        // ---------------------------------------------------------------------
+        // Organisation unit is parent
+        // ---------------------------------------------------------------------
+
+        buffer.append( ReportTable.ORGANISATION_UNIT_IS_PARENT_COLUMN_NAME + SPACE + SHORT_TEXT_COLUMN_TYPE + SEPARATOR );
         
         // ---------------------------------------------------------------------
         // Crosstab