← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20187: Re-implemented getOrganisationUnitWithChildren using getOrganisationUnits( OrganisationUnitQueryP...

 

------------------------------------------------------------
revno: 20187
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-09-16 20:31:45 +0200
message:
  Re-implemented getOrganisationUnitWithChildren using getOrganisationUnits( OrganisationUnitQueryParams ). Re-implemented OrganisationUnit.getLevel using the path property. Improves performance since we can rely on path property directly in regex and HQL queries instead of fetching org units one by one from database.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/comparator/OrganisationUnitByLevelComparator.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/databrowser/jdbc/JDBCDataBrowserStore.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsUtils.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/security/DefaultAnalyticsSecurityManager.java
  dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventQueryPlannerTest.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/jdbc/JdbcDataAnalysisStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.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/program/DefaultProgramInstanceService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/OrganisationUnitExtended.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceCategoryOptionGroupTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/OrganisationUnitConverter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/OrganisationUnitHierarchyConverter.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/OrganisationUnitAboveOrEqualToLevelFilter.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/MapViewController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/CurrentUserController.java
  dhis-2/dhis-web/dhis-web-ohie/src/main/java/org/hisp/dhis/web/ohie/fred/FredSpringWebTest.java
  dhis-2/dhis-web/dhis-web-ohie/src/main/java/org/hisp/dhis/web/ohie/fred/webapi/v1/controller/FacilityController.java
  dhis-2/dhis-web/dhis-web-ohie/src/main/java/org/hisp/dhis/web/ohie/fred/webapi/v1/utils/OrganisationUnitToFacilityConverter.java
  dhis-2/dhis-web/dhis-web-ohie/src/test/java/org/hisp/dhis/web/ohie/fred/webapi/v1/utils/OrganisationUnitToFacilityConverterTest.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	2015-09-14 10:09:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2015-09-16 18:31:45 +0000
@@ -83,7 +83,8 @@
 {
     private static final long serialVersionUID = 1228298379303894619L;
 
-    private static final Joiner PATH_JOINER = Joiner.on( "/" );
+    private static final String PATH_SEP = "/";
+    private static final Joiner PATH_JOINER = Joiner.on( PATH_SEP );
 
     public static final String FEATURETYPE_NONE = "None";
     public static final String FEATURETYPE_MULTIPOLYGON = "MultiPolygon";
@@ -153,8 +154,6 @@
 
     private transient boolean currentParent;
 
-    private transient int level;
-
     private transient String type;
 
     private transient List<String> groupNames = new ArrayList<>();
@@ -703,22 +702,9 @@
 
     @JsonProperty( "level" )
     @JacksonXmlProperty( localName = "level", isAttribute = true )
-    public int getOrganisationUnitLevel()
+    public int getLevel()
     {
-        int currentLevel = 1;
-
-        OrganisationUnit thisParent = this.parent;
-
-        while ( thisParent != null )
-        {
-            ++currentLevel;
-
-            thisParent = thisParent.getParent();
-        }
-
-        this.level = currentLevel;
-
-        return currentLevel;
+        return StringUtils.countMatches( path, PATH_SEP );
     }
 
     public boolean isPolygon()
@@ -809,11 +795,6 @@
         return map;
     }
     
-    public boolean hasLevel()
-    {
-        return level > 0;
-    }
-
     @Override
     public boolean haveUniqueNames()
     {
@@ -1143,16 +1124,6 @@
     // Getters and setters for transient fields
     // -------------------------------------------------------------------------
 
-    public int getLevel()
-    {
-        return level;
-    }
-
-    public void setLevel( int level )
-    {
-        this.level = level;
-    }
-
     public List<String> getGroupNames()
     {
         return groupNames;

=== 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-09-16 14:49:50 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java	2015-09-16 18:31:45 +0000
@@ -206,20 +206,6 @@
     List<OrganisationUnit> getRootOrganisationUnits();
 
     /**
-     * Returns the level of the organisation unit with the given identifier.
-     *
-     * @return the level of the organisation unit with the given identifier.
-     */
-    int getLevelOfOrganisationUnit( int id );
-
-    /**
-     * Returns the level of the organisation unit (whether loaded or not.)
-     *
-     * @return the level of the organisation unit with the given identifier.
-     */
-    int getLevelOfOrganisationUnit( OrganisationUnit unit );
-
-    /**
      * Returns the intersection of the members of the given OrganisationUnitGroups
      * and the OrganisationUnits which are children of the given collection of
      * parents in the hierarchy. If the given parent collection is null or empty,
@@ -435,14 +421,6 @@
      */
     boolean isInUserHierarchy( String uid, Set<OrganisationUnit> organisationUnits );
     
-    /**
-     * Sets the transient level property of each organisation unit in the given
-     * list. Fetches the organisation unit from the database.
-     * 
-     * @param organisationUnits the collection of organisation units.
-     */
-    void setOrganisationUnitLevel( Collection<OrganisationUnit> organisationUnits );
-
     // -------------------------------------------------------------------------
     // OrganisationUnitHierarchy
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/comparator/OrganisationUnitByLevelComparator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/comparator/OrganisationUnitByLevelComparator.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/comparator/OrganisationUnitByLevelComparator.java	2015-09-16 18:31:45 +0000
@@ -43,6 +43,6 @@
     @Override
     public int compare( OrganisationUnit o1, OrganisationUnit o2 )
     {
-        return ((Integer) o1.getOrganisationUnitLevel()).compareTo( o2.getOrganisationUnitLevel() );
+        return ( (Integer) o1.getLevel() ).compareTo( o2.getLevel() );
     }
 }

=== 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-10 16:35:55 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/databrowser/jdbc/JDBCDataBrowserStore.java	2015-09-16 18:31:45 +0000
@@ -483,7 +483,7 @@
             maxLevel = organisationUnitService.getMaxOfOrganisationUnitLevels();
         }
 
-        int curLevel = organisationUnitService.getLevelOfOrganisationUnit( orgUnitSelected );
+        int curLevel = organisationUnitService.getOrganisationUnit( orgUnitSelected ).getLevel();
         int loopSize = betweenPeriodIds.size();
 
         String descendantQuery = this.setUpQueryGetDescendants( curLevel, maxLevel, orgUnitSelected );

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsUtils.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsUtils.java	2015-08-10 21:57:49 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsUtils.java	2015-09-16 18:31:45 +0000
@@ -96,7 +96,7 @@
         for ( NameableObject orgUnit : orgUnits )
         {
             OrganisationUnit ou = (OrganisationUnit) orgUnit;
-            int level = ou.getOrganisationUnitLevel();
+            int level = ou.getLevel();
             sql += "(dv.sourceid in (select organisationunitid from _orgunitstructure where idlevel" + level + " = " + ou.getId() + ")) or ";            
         }
 

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2015-09-13 17:49:03 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2015-09-16 18:31:45 +0000
@@ -1210,13 +1210,6 @@
                 }
             }
 
-            // -----------------------------------------------------------------
-            // Set level property
-            // -----------------------------------------------------------------
-
-            Collection<OrganisationUnit> typedOus = NameableObjectUtils.asTypedList( ous );
-            organisationUnitService.setOrganisationUnitLevel( typedOus );
-            
             List<NameableObject> orgUnits = new UniqueArrayList<>();
             List<OrganisationUnit> ousList = NameableObjectUtils.asTypedList( ous );
 

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java	2015-09-15 07:17:41 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java	2015-09-16 18:31:45 +0000
@@ -719,9 +719,7 @@
         {
             OrganisationUnit ou = (OrganisationUnit) orgUnit;
 
-            int level = ou.getLevel() != 0 ? ou.getLevel() : organisationUnitService.getLevelOfOrganisationUnit( ou.getId() );
-
-            ou.setLevel( level );
+            int level = ou.getLevel();
 
             map.putValue( level, orgUnit );
         }

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java	2015-09-09 14:56:40 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java	2015-09-16 18:31:45 +0000
@@ -43,12 +43,9 @@
 import org.hisp.dhis.analytics.event.EventQueryPlanner;
 import org.hisp.dhis.analytics.partition.PartitionManager;
 import org.hisp.dhis.analytics.table.PartitionUtils;
-import org.hisp.dhis.common.DimensionalObject;
 import org.hisp.dhis.common.IllegalQueryException;
 import org.hisp.dhis.common.MaintenanceModeException;
-import org.hisp.dhis.common.NameableObject;
 import org.hisp.dhis.common.QueryItem;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.program.ProgramIndicator;
@@ -194,16 +191,7 @@
             queryPeriod.setEndDate( params.getEndDate() );            
             params.setPartitions( PartitionUtils.getPartitions( queryPeriod, EVENT_ANALYTICS_TABLE_NAME, tableSuffix, validPartitions ) );
         }
-        
-        if ( params.hasDimensionOrFilter( DimensionalObject.ORGUNIT_DIM_ID ) )
-        {
-            for ( NameableObject object : params.getDimensionOrFilterItems( DimensionalObject.ORGUNIT_DIM_ID ) )
-            {
-                OrganisationUnit unit = (OrganisationUnit) object; 
-                unit.setLevel( organisationUnitService.getLevelOfOrganisationUnit( unit.getId() ) );
-            }
-        }
-        
+                
         //TODO periods, convert to start/end dates
         
         return params;

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/security/DefaultAnalyticsSecurityManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/security/DefaultAnalyticsSecurityManager.java	2015-08-07 17:59:15 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/security/DefaultAnalyticsSecurityManager.java	2015-09-16 18:31:45 +0000
@@ -144,11 +144,6 @@
             
             if ( approvalLevels != null && !approvalLevels.isEmpty() )
             {
-                for ( OrganisationUnit unit : approvalLevels.keySet() )
-                {
-                    unit.setLevel( organisationUnitService.getLevelOfOrganisationUnit( unit.getId() ) );
-                }
-                
                 params.setDataApprovalLevels( approvalLevels );
                 
                 log.debug( "User: " + user.getUsername() + " constrained by data approval levels: " + approvalLevels.values() );

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventQueryPlannerTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventQueryPlannerTest.java	2015-06-18 21:47:26 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventQueryPlannerTest.java	2015-09-16 18:31:45 +0000
@@ -68,13 +68,10 @@
         prA.setUid( "programuida" );
         
         ouA = createOrganisationUnit( 'A' );
-        ouB = createOrganisationUnit( 'B' );
+        ouB = createOrganisationUnit( 'B', ouA );
         
         organisationUnitService.addOrganisationUnit( ouA );
         organisationUnitService.addOrganisationUnit( ouB );
-        
-        ouA.setLevel( 1 );
-        ouB.setLevel( 2 );        
     }
     
     @Test

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/jdbc/JdbcDataAnalysisStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/jdbc/JdbcDataAnalysisStore.java	2015-07-03 01:33:37 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/jdbc/JdbcDataAnalysisStore.java	2015-09-16 18:31:45 +0000
@@ -258,7 +258,7 @@
     @Override
     public List<DeflatedDataValue> getFollowupDataValues( OrganisationUnit organisationUnit, int limit )
     {
-        final String idLevelColumn = "idlevel" + organisationUnit.getOrganisationUnitLevel();
+        final String idLevelColumn = "idlevel" + organisationUnit.getLevel();
 
         String sql =
             "select dv.dataelementid, dv.periodid, dv.sourceid, dv.categoryoptioncomboid, dv.value, " +

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java	2015-07-15 09:45:45 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java	2015-09-16 18:31:45 +0000
@@ -152,7 +152,7 @@
     @Override
     public DataApprovalLevel getHighestDataApprovalLevel( OrganisationUnit orgUnit )
     {
-        int orgUnitLevel = organisationUnitService.getLevelOfOrganisationUnit( orgUnit );
+        int orgUnitLevel = orgUnit.getLevel();
 
         DataApprovalLevel levelAbove = null;
 
@@ -197,7 +197,7 @@
             }
         }
 
-        int orgUnitLevel = organisationUnitService.getLevelOfOrganisationUnit( orgUnit );
+        int orgUnitLevel = orgUnit.getLevel();
 
         List<DataApprovalLevel> approvalLevels = getDataApprovalLevelsByOrgUnitLevel( orgUnitLevel );
         
@@ -272,8 +272,7 @@
 
             for ( OrganisationUnit orgUnit : user.getOrganisationUnits() )
             {
-                int orgUnitLevel = orgUnit.hasLevel() ?
-                    orgUnit.getLevel() : organisationUnitService.getLevelOfOrganisationUnit( orgUnit.getId() );
+                int orgUnitLevel = orgUnit.getLevel();
 
                 userOrgUnitLevels.add( orgUnitLevel );
 
@@ -721,7 +720,7 @@
      */
     private DataApprovalLevel getUserApprovalLevel( OrganisationUnit orgUnit, User user, List<DataApprovalLevel> approvalLevels )
     {
-        int userOrgUnitLevel = organisationUnitService.getLevelOfOrganisationUnit( orgUnit );
+        int userOrgUnitLevel = orgUnit.getLevel();
 
         DataApprovalLevel userLevel = null;
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java	2015-06-01 23:57:56 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java	2015-09-16 18:31:45 +0000
@@ -157,10 +157,10 @@
                 throw new DataMayNotBeApprovedException();
             }
 
-            if ( organisationUnitService.getLevelOfOrganisationUnit( da.getOrganisationUnit() ) != da.getDataApprovalLevel().getOrgUnitLevel() )
+            if ( da.getOrganisationUnit().getLevel() != da.getDataApprovalLevel().getOrgUnitLevel() )
             {
                 log.warn( "approveData: org unit " + da.getOrganisationUnit().getUid() + " '" + da.getOrganisationUnit().getName() +
-                    "' has wrong org unit level " + organisationUnitService.getLevelOfOrganisationUnit( da.getOrganisationUnit() ) +
+                    "' has wrong org unit level " + da.getOrganisationUnit().getLevel() +
                     " for approval level " + da.getDataApprovalLevel().getLevel());
 
                 throw new DataMayNotBeApprovedException();

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.java	2015-09-13 17:45:53 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.java	2015-09-16 18:31:45 +0000
@@ -293,7 +293,7 @@
 
         if ( orgUnit != null )
         {
-            orgUnitLevel = organisationUnitService.getLevelOfOrganisationUnit( orgUnit );
+            orgUnitLevel = orgUnit.getLevel();
             orgUnitJoinOn = "o.organisationunitid = " + orgUnit.getId();
             highestApprovedOrgUnitCompare = "da.organisationunitid = o.organisationunitid ";
         }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java	2015-06-26 16:44:31 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java	2015-09-16 18:31:45 +0000
@@ -175,11 +175,7 @@
     @Override
     public MapView getMapView( int id )
     {
-        MapView mapView = mapViewStore.get( id );
-
-        setMapViewLevel( mapView );
-
-        return mapView;
+        return mapViewStore.get( id );
     }
 
     @Override
@@ -187,22 +183,9 @@
     {
         MapView mapView = mapViewStore.getByUid( uid );
 
-        setMapViewLevel( mapView );
-
         return mapView;
     }
 
-    private void setMapViewLevel( MapView mapView )
-    {
-        if ( mapView != null )
-        {
-            for ( OrganisationUnit unit : mapView.getOrganisationUnits() )
-            {
-                unit.setLevel( organisationUnitService.getLevelOfOrganisationUnit( unit.getId() ) );
-            }
-        }
-    }
-
     @Override
     public MapView getMapViewByName( String name )
     {
@@ -232,22 +215,7 @@
     @Override
     public List<MapView> getAllMapViews()
     {
-        List<MapView> mapViews = mapViewStore.getAll();
-
-        if ( mapViews.size() > 0 )
-        {
-            for ( MapView mapView : mapViews )
-            {
-                //TODO poor performance, fix
-
-                for ( OrganisationUnit unit : mapView.getOrganisationUnits() )
-                {
-                    unit.setLevel( organisationUnitService.getLevelOfOrganisationUnit( unit.getId() ) );
-                }
-            }
-        }
-
-        return mapViews;
+        return mapViewStore.getAll();
     }
 
     @Override

=== 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-09-13 17:45:53 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2015-09-16 18:31:45 +0000
@@ -60,6 +60,7 @@
 import org.springframework.transaction.annotation.Transactional;
 
 import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
 
 /**
  * @author Torgeir Lorange Ostby
@@ -270,18 +271,6 @@
     }
 
     @Override
-    public int getLevelOfOrganisationUnit( OrganisationUnit unit )
-    {
-        return unit.getLevel() != 0 ? unit.getLevel() : unit.getOrganisationUnitLevel();
-    }
-
-    @Override
-    public int getLevelOfOrganisationUnit( int id )
-    {
-        return getOrganisationUnit( id ).getOrganisationUnitLevel();
-    }
-
-    @Override
     public List<OrganisationUnit> getOrganisationUnits( Collection<OrganisationUnitGroup> groups, Collection<OrganisationUnit> parents )
     {
         List<OrganisationUnit> members = new ArrayList<>();
@@ -395,45 +384,15 @@
             return new ArrayList<>();
         }
 
-        List<OrganisationUnit> result = new ArrayList<>();
-
-        int rootLevel = organisationUnit.getOrganisationUnitLevel();
-
-        organisationUnit.setLevel( rootLevel );
-        result.add( organisationUnit );
-
-        final Integer maxLevel = maxLevels != null ? (rootLevel + maxLevels - 1) : null;
-
-        addOrganisationUnitChildren( organisationUnit, result, rootLevel, maxLevel );
-
-        return result;
-    }
-
-    /**
-     * Support method for getOrganisationUnitWithChildren(). Adds all
-     * OrganisationUnit children to a result collection.
-     */
-    private void addOrganisationUnitChildren( OrganisationUnit parent, List<OrganisationUnit> result, int level, final Integer maxLevel )
-    {
-        if ( parent.getChildren() != null && parent.getChildren().size() > 0 )
-        {
-            level++;
-        }
-
-        if ( maxLevel != null && level > maxLevel )
-        {
-            return;
-        }
-
-        List<OrganisationUnit> childList = parent.getSortedChildren();
-
-        for ( OrganisationUnit child : childList )
-        {
-            child.setLevel( level );
-            result.add( child );
-
-            addOrganisationUnitChildren( child, result, level, maxLevel );
-        }
+        int rootLevel = organisationUnit.getLevel();
+        
+        Integer levels = maxLevels != null ? ( rootLevel + maxLevels - 1 ) : null;
+
+        OrganisationUnitQueryParams params = new OrganisationUnitQueryParams();
+        params.setParents( Sets.newHashSet( organisationUnit ) );
+        params.setMaxLevels( levels );
+        
+        return organisationUnitStore.getOrganisationUnits( params );
     }
 
     @Override
@@ -495,6 +454,7 @@
         return getOrganisationUnitsAtLevels( levels, parents );
     }
 
+    //TODO rewrite using path
     @Override
     public List<OrganisationUnit> getOrganisationUnitsAtLevels( Collection<Integer> levels, Collection<OrganisationUnit> parents )
     {
@@ -514,7 +474,7 @@
 
             for ( OrganisationUnit parent : parents )
             {
-                int parentLevel = parent.getOrganisationUnitLevel();
+                int parentLevel = parent.getLevel();
 
                 if ( level < parentLevel )
                 {
@@ -524,7 +484,6 @@
 
                 if ( level == parentLevel )
                 {
-                    parent.setLevel( level );
                     result.add( parent );
                 }
                 else
@@ -547,11 +506,7 @@
     {
         if ( currentLevel == targetLevel )
         {
-            for ( OrganisationUnit child : parent.getChildren() )
-            {
-                child.setLevel( currentLevel );
-                result.add( child );
-            }
+            result.addAll( parent.getChildren() );
         }
         else
         {
@@ -733,18 +688,6 @@
         return organisationUnit != null ? organisationUnit.isDescendant( organisationUnits ) : false;
     }
 
-    @Override
-    public void setOrganisationUnitLevel( Collection<OrganisationUnit> organisationUnits )
-    {
-        for ( OrganisationUnit unit : organisationUnits )
-        {
-            if ( unit != null && !unit.hasLevel() )
-            {
-                unit.setLevel( getLevelOfOrganisationUnit( unit.getId() ) );
-            }
-        }
-    }
-
     // -------------------------------------------------------------------------
     // OrganisationUnitHierarchy
     // -------------------------------------------------------------------------
@@ -927,7 +870,7 @@
         {
             OrganisationUnit organisationUnit = user.getOrganisationUnit();
 
-            int level = getLevelOfOrganisationUnit( organisationUnit.getId() );
+            int level = organisationUnit.getLevel();
 
             OrganisationUnitLevel orgUnitLevel = getOrganisationUnitLevelByLevel( level );
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java	2015-09-11 11:54:53 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java	2015-09-16 18:31:45 +0000
@@ -241,14 +241,6 @@
             params.setOrganisationUnits( organisationUnits );
         }
 
-        for ( OrganisationUnit organisationUnit : params.getOrganisationUnits() )
-        {
-            if ( !organisationUnit.hasLevel() )
-            {
-                organisationUnit.setLevel( organisationUnitService.getLevelOfOrganisationUnit( organisationUnit.getId() ) );
-            }
-        }
-
         if ( !params.isPaging() && !params.isSkipPaging() )
         {
             params.setDefaultPaging();
@@ -283,14 +275,6 @@
             params.setOrganisationUnits( organisationUnits );
         }
 
-        for ( OrganisationUnit organisationUnit : params.getOrganisationUnits() )
-        {
-            if ( !organisationUnit.hasLevel() )
-            {
-                organisationUnit.setLevel( organisationUnitService.getLevelOfOrganisationUnit( organisationUnit.getId() ) );
-            }
-        }
-
         params.setSkipPaging( true );
 
         return programInstanceStore.countProgramInstances( params );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java	2015-09-10 10:35:39 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java	2015-09-16 18:31:45 +0000
@@ -154,14 +154,6 @@
             params.setOrganisationUnits( organisationUnits );
         }
 
-        for ( OrganisationUnit organisationUnit : params.getOrganisationUnits() )
-        {
-            if ( !organisationUnit.hasLevel() )
-            {
-                organisationUnit.setLevel( organisationUnitService.getLevelOfOrganisationUnit( organisationUnit.getId() ) );
-            }
-        }
-
         if ( !params.isPaging() && !params.isSkipPaging() )
         {
             params.setDefaultPaging();
@@ -189,14 +181,6 @@
             params.setOrganisationUnitMode( OrganisationUnitSelectionMode.DESCENDANTS );
         }
 
-        for ( OrganisationUnit organisationUnit : params.getOrganisationUnits() )
-        {
-            if ( !organisationUnit.hasLevel() )
-            {
-                organisationUnit.setLevel( organisationUnitService.getLevelOfOrganisationUnit( organisationUnit.getId() ) );
-            }
-        }
-
         if ( !params.isPaging() && !params.isSkipPaging() )
         {
             params.setDefaultPaging();

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java	2015-08-25 21:48:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java	2015-09-16 18:31:45 +0000
@@ -466,8 +466,6 @@
             sql = removeLastAnd( sql ) + ") ";
         }
 
-        System.err.println( "sql: " + sql );
-
         return sql;
     }
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/OrganisationUnitExtended.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/OrganisationUnitExtended.java	2015-02-19 09:18:17 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/OrganisationUnitExtended.java	2015-09-16 18:31:45 +0000
@@ -60,7 +60,7 @@
         this.source = source;
         this.toBeValidated = toBeValidated;
         children = new HashSet<>( source.getChildren() );
-        level = source.getOrganisationUnitLevel();
+        level = source.getLevel();
     }
 
     public String toString()

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceCategoryOptionGroupTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceCategoryOptionGroupTest.java	2015-09-13 17:45:53 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceCategoryOptionGroupTest.java	2015-09-16 18:31:45 +0000
@@ -287,13 +287,6 @@
         china = createOrganisationUnit( "China", asia );
         india = createOrganisationUnit( "India", asia );
 
-        global.setLevel( 1 );
-        americas.setLevel( 2 );
-        asia.setLevel( 2 );
-        brazil.setLevel( 3 );
-        china.setLevel( 3 );
-        india.setLevel( 3 );
-
         organisationUnitService.addOrganisationUnit( global );
         organisationUnitService.addOrganisationUnit( americas );
         organisationUnitService.addOrganisationUnit( asia );
@@ -665,8 +658,6 @@
     {
         String[] approvalStrings = getUserApprovalsAndPermissions( mockUserService, dataSet, period, orgUnit );
 
-        System.out.println( "assertArrayEquals( new String[] {" );
-
         int count = 0;
 
         for ( String s : approvalStrings )

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java	2015-09-13 17:45:53 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java	2015-09-16 18:31:45 +0000
@@ -251,13 +251,6 @@
         organisationUnitE = createOrganisationUnit( 'E', organisationUnitB );
         organisationUnitF = createOrganisationUnit( 'F', organisationUnitE );
 
-        organisationUnitA.setLevel( 1 );
-        organisationUnitB.setLevel( 2 );
-        organisationUnitC.setLevel( 3 );
-        organisationUnitD.setLevel( 4 );
-        organisationUnitE.setLevel( 3 );
-        organisationUnitF.setLevel( 4 );
-
         organisationUnitService.addOrganisationUnit( organisationUnitA );
         organisationUnitService.addOrganisationUnit( organisationUnitB );
         organisationUnitService.addOrganisationUnit( organisationUnitC );

=== 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-09-13 17:45:53 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java	2015-09-16 18:31:45 +0000
@@ -133,6 +133,57 @@
     }
 
     @Test
+    public void testGetOrganisationUnitWithChildrenB()
+    {
+        OrganisationUnit unitA = createOrganisationUnit( 'A' );
+        OrganisationUnit unitB = createOrganisationUnit( 'B', unitA );
+        OrganisationUnit unitC = createOrganisationUnit( 'C', unitB );
+        OrganisationUnit unitD = createOrganisationUnit( 'D', unitB );
+        OrganisationUnit unitE = createOrganisationUnit( 'E', unitC );
+
+        int idA = organisationUnitService.addOrganisationUnit( unitA );
+        int idB = organisationUnitService.addOrganisationUnit( unitB );
+        int idC = organisationUnitService.addOrganisationUnit( unitC );
+        int idD = organisationUnitService.addOrganisationUnit( unitD );
+        organisationUnitService.addOrganisationUnit( unitE );
+
+        List<OrganisationUnit> actualA = new ArrayList<>( organisationUnitService.getOrganisationUnitWithChildren( idA ) );
+        List<OrganisationUnit> actualB = new ArrayList<>( organisationUnitService.getOrganisationUnitWithChildren( idB ) );
+        List<OrganisationUnit> actualC = new ArrayList<>( organisationUnitService.getOrganisationUnitWithChildren( idC ) );
+        List<OrganisationUnit> actualD = new ArrayList<>( organisationUnitService.getOrganisationUnitWithChildren( idD ) );
+
+        assertEquals( 5, actualA.size() );
+        assertEquals( 4, actualB.size() );
+        assertEquals( 2, actualC.size() );
+        assertEquals( 1, actualD.size() );
+        
+        assertEquals( Sets.newHashSet( unitB, unitC, unitD, unitE ), Sets.newHashSet( actualB ) );
+        assertEquals( Sets.newHashSet( unitC, unitE ), Sets.newHashSet( actualC ) );
+    }
+    
+    @Test
+    public void testGetOrganisationUnitLevel()
+    {
+        OrganisationUnit unitA = createOrganisationUnit( 'A' );
+        OrganisationUnit unitB = createOrganisationUnit( 'B', unitA );
+        OrganisationUnit unitC = createOrganisationUnit( 'C', unitB );
+        OrganisationUnit unitD = createOrganisationUnit( 'D', unitB );
+        OrganisationUnit unitE = createOrganisationUnit( 'E', unitC );
+
+        organisationUnitService.addOrganisationUnit( unitA );
+        organisationUnitService.addOrganisationUnit( unitB );
+        organisationUnitService.addOrganisationUnit( unitC );
+        organisationUnitService.addOrganisationUnit( unitD );
+        organisationUnitService.addOrganisationUnit( unitE );
+
+        assertEquals( 1, unitA.getLevel() );
+        assertEquals( 2, unitB.getLevel() );
+        assertEquals( 3, unitC.getLevel() );
+        assertEquals( 3, unitD.getLevel() );
+        assertEquals( 4, unitE.getLevel() );
+    }
+
+    @Test
     public void testGetOrganisationUnitWithChildrenMaxLevel()
     {
         OrganisationUnit unit1 = createOrganisationUnit( 'A' );
@@ -191,29 +242,6 @@
     }
 
     @Test
-    public void testGetOrganisationUnitWithChildrenWithCorrectLevel()
-    {
-        OrganisationUnit unit1 = createOrganisationUnit( 'A' );
-        OrganisationUnit unit2 = createOrganisationUnit( 'B', unit1 );
-        OrganisationUnit unit3 = createOrganisationUnit( 'C', unit2 );
-
-        int id1 = organisationUnitService.addOrganisationUnit( unit1 );
-        unit1.getChildren().add( unit2 );
-        int id2 = organisationUnitService.addOrganisationUnit( unit2 );
-        organisationUnitService.addOrganisationUnit( unit3 );
-
-        List<OrganisationUnit> actual1 = new ArrayList<>( organisationUnitService.getOrganisationUnitWithChildren( id1 ) );
-        List<OrganisationUnit> actual2 = new ArrayList<>( organisationUnitService.getOrganisationUnitWithChildren( id2 ) );
-
-        assertEquals( 1, actual1.get( 0 ).getLevel() );
-        assertEquals( 2, actual1.get( 1 ).getLevel() );
-        assertEquals( 3, actual1.get( 2 ).getLevel() );
-
-        assertEquals( 2, actual2.get( 0 ).getLevel() );
-        assertEquals( 3, actual2.get( 1 ).getLevel() );
-    }
-
-    @Test
     public void testGetOrganisationUnitsByFields()
     {
         String oU1Name = "OU1name";
@@ -336,9 +364,9 @@
         assertTrue( organisationUnitService.getOrganisationUnitsAtLevel( 1 ).size() == 2 );
         assertTrue( organisationUnitService.getOrganisationUnitsAtLevel( 3 ).size() == 3 );
         assertTrue( organisationUnitService.getNumberOfOrganisationalLevels() == 4 );
-        assertTrue( organisationUnitService.getOrganisationUnit( unit4.getId() ).getOrganisationUnitLevel() == 3 );
-        assertTrue( organisationUnitService.getOrganisationUnit( unit1.getId() ).getOrganisationUnitLevel() == 1 );
-        assertTrue( organisationUnitService.getOrganisationUnit( unit6.getId() ).getOrganisationUnitLevel() == 4 );
+        assertTrue( unit4.getLevel() == 3 );
+        assertTrue( unit1.getLevel() == 1 );
+        assertTrue( unit6.getLevel() == 4 );
     }
     
     @Test

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/OrganisationUnitConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/OrganisationUnitConverter.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/OrganisationUnitConverter.java	2015-09-16 18:31:45 +0000
@@ -154,7 +154,7 @@
         {
             for ( OrganisationUnit unit : units )
             {
-                int level = unit.getOrganisationUnitLevel();
+                int level = unit.getLevel();
 
                 writer.openElement( ELEMENT_NAME );
 

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/OrganisationUnitHierarchyConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/OrganisationUnitHierarchyConverter.java	2015-06-15 13:44:20 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/OrganisationUnitHierarchyConverter.java	2015-09-16 18:31:45 +0000
@@ -115,7 +115,7 @@
             {
                 if ( unit.getParent() != null )
                 {
-                    int level = unit.getOrganisationUnitLevel();
+                    int level = unit.getLevel();
                     
                     writer.openElement( ELEMENT_NAME );
                     

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java	2015-07-03 01:33:37 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java	2015-09-16 18:31:45 +0000
@@ -160,7 +160,7 @@
 
         if ( orgUnit != null )
         {
-            int level = organisationUnitService.getLevelOfOrganisationUnit( orgUnit.getId() );
+            int level = orgUnit.getLevel();
 
             params.put( PARAM_ORGANISATIONUNIT_COLUMN_NAME, orgUnit.getName() );
             params.put( PARAM_ORGANISATIONUNIT_LEVEL, level );

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/OrganisationUnitAboveOrEqualToLevelFilter.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/OrganisationUnitAboveOrEqualToLevelFilter.java	2015-05-28 18:21:56 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/OrganisationUnitAboveOrEqualToLevelFilter.java	2015-09-16 18:31:45 +0000
@@ -33,8 +33,7 @@
 
 /**
  * Retains organisation units which are above or at the same level as the level
- * given in the constructor. This filter must be invoked inside a transactional
- * context in order to work.
+ * given in the constructor.
  * 
  * @author Lars Helge Overland
  */
@@ -51,6 +50,6 @@
     @Override
     public boolean retain( OrganisationUnit object )
     {
-        return object != null && object.getOrganisationUnitLevel() <= level;
+        return object != null && object.getLevel() <= level;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/MapViewController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/MapViewController.java	2015-07-15 15:49:39 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/MapViewController.java	2015-09-16 18:31:45 +0000
@@ -104,8 +104,7 @@
         if ( level == null )
         {
             OrganisationUnit unit = organisationUnitService.getOrganisationUnit( organisationUnitUid );
-
-            level = organisationUnitService.getLevelOfOrganisationUnit( unit.getId() );
+            level = unit.getLevel();
             level++;
         }
 

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitController.java	2015-09-14 17:57:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitController.java	2015-09-16 18:31:45 +0000
@@ -210,7 +210,7 @@
         {
             options.getOptions().put( "useWrapper", "true" );
             int level = options.getInt( "level" );
-            int ouLevel = organisationUnitService.getLevelOfOrganisationUnit( organisationUnit.getId() );
+            int ouLevel = organisationUnit.getLevel();
             int targetLevel = ouLevel + level;
             organisationUnits.addAll( organisationUnitService.getOrganisationUnitsAtLevel( targetLevel, organisationUnit ) );
         }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/CurrentUserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/CurrentUserController.java	2015-09-14 17:57:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/CurrentUserController.java	2015-09-16 18:31:45 +0000
@@ -591,7 +591,7 @@
             FormOrganisationUnit formOrganisationUnit = new FormOrganisationUnit();
             formOrganisationUnit.setId( organisationUnit.getUid() );
             formOrganisationUnit.setLabel( organisationUnit.getDisplayName() );
-            formOrganisationUnit.setLevel( organisationUnit.getOrganisationUnitLevel() );
+            formOrganisationUnit.setLevel( organisationUnit.getLevel() );
 
             if ( organisationUnit.getParent() != null )
             {
@@ -690,7 +690,7 @@
             FormOrganisationUnit formOrganisationUnit = new FormOrganisationUnit();
             formOrganisationUnit.setId( organisationUnit.getUid() );
             formOrganisationUnit.setLabel( organisationUnit.getDisplayName() );
-            formOrganisationUnit.setLevel( organisationUnit.getOrganisationUnitLevel() );
+            formOrganisationUnit.setLevel( organisationUnit.getLevel() );
 
             if ( organisationUnit.getParent() != null )
             {

=== modified file 'dhis-2/dhis-web/dhis-web-ohie/src/main/java/org/hisp/dhis/web/ohie/fred/FredSpringWebTest.java'
--- dhis-2/dhis-web/dhis-web-ohie/src/main/java/org/hisp/dhis/web/ohie/fred/FredSpringWebTest.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-ohie/src/main/java/org/hisp/dhis/web/ohie/fred/FredSpringWebTest.java	2015-09-16 18:31:45 +0000
@@ -150,7 +150,6 @@
         organisationUnit.setShortName( organisationUnit.getName() );
         organisationUnit.setCreated( new Date() );
         organisationUnit.setLastUpdated( organisationUnit.getCreated() );
-        organisationUnit.setLevel( 1 );
 
         return organisationUnit;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-ohie/src/main/java/org/hisp/dhis/web/ohie/fred/webapi/v1/controller/FacilityController.java'
--- dhis-2/dhis-web/dhis-web-ohie/src/main/java/org/hisp/dhis/web/ohie/fred/webapi/v1/controller/FacilityController.java	2015-09-03 03:11:47 +0000
+++ dhis-2/dhis-web/dhis-web-ohie/src/main/java/org/hisp/dhis/web/ohie/fred/webapi/v1/controller/FacilityController.java	2015-09-16 18:31:45 +0000
@@ -361,7 +361,7 @@
                 {
                     int l = Integer.parseInt( level );
 
-                    if ( organisationUnit.getOrganisationUnitLevel() == l )
+                    if ( organisationUnit.getLevel() == l )
                     {
                         shouldRemove = false;
                         break;

=== modified file 'dhis-2/dhis-web/dhis-web-ohie/src/main/java/org/hisp/dhis/web/ohie/fred/webapi/v1/utils/OrganisationUnitToFacilityConverter.java'
--- dhis-2/dhis-web/dhis-web-ohie/src/main/java/org/hisp/dhis/web/ohie/fred/webapi/v1/utils/OrganisationUnitToFacilityConverter.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-ohie/src/main/java/org/hisp/dhis/web/ohie/fred/webapi/v1/utils/OrganisationUnitToFacilityConverter.java	2015-09-16 18:31:45 +0000
@@ -126,7 +126,7 @@
             facility.getProperties().put( "dataSets", dataSets );
         }
 
-        facility.getProperties().put( "level", organisationUnit.getOrganisationUnitLevel() );
+        facility.getProperties().put( "level", organisationUnit.getLevel() );
 
         for ( OrganisationUnitGroup group : organisationUnit.getGroups() )
         {

=== modified file 'dhis-2/dhis-web/dhis-web-ohie/src/test/java/org/hisp/dhis/web/ohie/fred/webapi/v1/utils/OrganisationUnitToFacilityConverterTest.java'
--- dhis-2/dhis-web/dhis-web-ohie/src/test/java/org/hisp/dhis/web/ohie/fred/webapi/v1/utils/OrganisationUnitToFacilityConverterTest.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-ohie/src/test/java/org/hisp/dhis/web/ohie/fred/webapi/v1/utils/OrganisationUnitToFacilityConverterTest.java	2015-09-16 18:31:45 +0000
@@ -110,18 +110,6 @@
     }
 
     @Test
-    public void testLevel()
-    {
-        OrganisationUnit organisationUnit = new OrganisationUnit( "OrgUnit1" );
-
-        Facility facility = converter.convert( organisationUnit );
-
-        Integer level = (Integer) facility.getProperties().get( "level" );
-
-        Assert.assertTrue( level.equals( organisationUnit.getOrganisationUnitLevel() ) );
-    }
-
-    @Test
     @SuppressWarnings("unchecked")
     public void testDataSets()
     {