← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6696: Split OrganitionUnitLevelStore out from OranisationUnitStore. Importing of OrganisationUnitLevels...

 

------------------------------------------------------------
revno: 6696
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-04-23 12:49:08 +0300
message:
  Split OrganitionUnitLevelStore out from OranisationUnitStore. Importing of OrganisationUnitLevels now works correctly for import.
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitLevelStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitLevelStore.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java
  dhis-2/dhis-dxf2/src/main/resources/META-INF/dhis/beans.xml
  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/HibernateOrganisationUnitStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitStoreTest.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
=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitLevelStore.java	2012-04-23 09:49:08 +0000
@@ -0,0 +1,70 @@
+package org.hisp.dhis.organisationunit;
+
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+
+import java.util.Collection;
+
+/**
+ * Defines methods for persisting OrganisationUnitLevels.
+ *
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public interface OrganisationUnitLevelStore
+    extends GenericIdentifiableObjectStore<OrganisationUnitLevel>
+{
+    String ID = OrganisationUnitLevelStore.class.getName();
+
+    /**
+     * Deletes all OrganisationUnitLevels.
+     */
+    void deleteAll();
+
+    /**
+     * Gets all OrganisationUnitLevels.
+     *
+     * @return a Collection of all OrganisationUnitLevels.
+     */
+    Collection<OrganisationUnitLevel> getOrganisationUnitLevels();
+
+    /**
+     * Gets the OrganisationUnitLevel at the given level.
+     *
+     * @param level the level.
+     * @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/OrganisationUnitStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java	2012-04-23 09:49:08 +0000
@@ -27,15 +27,15 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.common.GenericNameableObjectStore;
+
 import java.util.Collection;
 import java.util.Map;
 import java.util.Set;
 
-import org.hisp.dhis.common.GenericNameableObjectStore;
-
 /**
  * Defines methods for persisting OrganisationUnits.
- * 
+ *
  * @author Kristian Nordal
  * @version $Id: OrganisationUnitStore.java 5645 2008-09-04 10:01:02Z larshelg $
  */
@@ -50,7 +50,7 @@
 
     /**
      * Returns an OrganisationUnit with a given name. Case is ignored.
-     * 
+     *
      * @param name the name of the OrganisationUnit to return.
      * @return the OrganisationUnit with the given name, or null if not match.
      */
@@ -59,7 +59,7 @@
     /**
      * Returns all root OrganisationUnits. A root OrganisationUnit is an
      * OrganisationUnit with no parent/has the parent set to null.
-     * 
+     *
      * @return a collection containing all root OrganisationUnits, or an empty
      *         collection if there are no OrganisationUnits.
      */
@@ -67,114 +67,37 @@
 
     /**
      * Returns all OrganisationUnits which are not a member of any OrganisationUnitGroups.
-     * 
+     *
      * @return all OrganisationUnits which are not a member of any OrganisationUnitGroups.
      */
     Collection<OrganisationUnit> getOrganisationUnitsWithoutGroups();
-    
+
     Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups, boolean limit );
 
     Map<Integer, Set<Integer>> getOrganisationUnitDataSetAssocationMap();
-    
+
     Set<Integer> getOrganisationUnitIdsWithoutData();
-    
+
     // -------------------------------------------------------------------------
     // OrganisationUnitHierarchy
     // -------------------------------------------------------------------------
 
     /**
-     * Get the OrganisationUnit hierarchy. 
-     * 
+     * Get the OrganisationUnit hierarchy.
+     *
      * @return a Collection with OrganisationUnitRelationship entries.
      */
     OrganisationUnitHierarchy getOrganisationUnitHierarchy();
 
     /**
      * Updates the parent id of the organisation unit with the given id.
-     * 
+     *
      * @param organisationUnitId the child organisation unit identifier.
-     * @param parentId the parent organisation unit identifier.
+     * @param parentId           the parent organisation unit identifier.
      */
     void updateOrganisationUnitParent( int organisationUnitId, int parentId );
-    
-    // -------------------------------------------------------------------------
-    // OrganisationUnitLevel
-    // -------------------------------------------------------------------------
-
-    /**
-     * Adds an OrganisationUnitLevel.
-     * 
-     * @param level the OrganisationUnitLevel to add.
-     * @return the generated identifier.
-     */
-    int addOrganisationUnitLevel( OrganisationUnitLevel level );
-    
-    /**
-     * Updates an OrganisationUnitLevel.
-     * 
-     * @param level the OrganisationUnitLevel to update.
-     */
-    void updateOrganisationUnitLevel( OrganisationUnitLevel level );
-    
-    /**
-     * Gets an OrganisationUnitLevel.
-     * 
-     * @param id the identifier of the OrganisationUnitLevel.
-     * @return the OrganisationUnitLevel with the given identifier.
-     */
-    OrganisationUnitLevel getOrganisationUnitLevel( int id );
-    
-    /**
-     * Gets an OrganisationUnitLevel.
-     *
-     * @param uid the identifier of the OrganisationUnitLevel.
-     * @return the OrganisationUnitLevel with the given identifier.
-     */
-    OrganisationUnitLevel getOrganisationUnitLevel( String uid );
-
-    /**
-     * Deletes an OrganisationUnitLevel.
-     * 
-     * @param level the OrganisationUnitLevel to delete.
-     */
-    void deleteOrganisationUnitLevel( OrganisationUnitLevel level );
-    
-    /**
-     * Deletes all OrganisationUnitLevels.
-     */
-    void deleteOrganisationUnitLevels();
-    
-    /**
-     * Gets all OrganisationUnitLevels.
-     * 
-     * @return a Collection of all OrganisationUnitLevels.
-     */
-    Collection<OrganisationUnitLevel> getOrganisationUnitLevels();
-    
-    /**
-     * Gets the OrganisationUnitLevel at the given level.
-     * 
-     * @param level the level.
-     * @return the OrganisationUnitLevel at the given level.
-     */
-    OrganisationUnitLevel getOrganisationUnitLevelByLevel( int level );
-    
-    /**
-     * Gets the OrganisationUnitLevel with the given name.
-     * 
-     * @param name the name of the OrganisationUnitLevel to get.
-     * @return the OrganisationUnitLevel with the given name.
-     */
-    OrganisationUnitLevel getOrganisationUnitLevelByName( String name );
-    
-    /**
-     * Gets the maximum level from the hierarchy.
-     * 
-     * @return the maximum number of level.
-     */
-    int getMaxOfOrganisationUnitLevels();
-    
+
     void update( Collection<OrganisationUnit> units );
-    
+
     Collection<OrganisationUnit> get( Boolean hasPatients );
 }

=== modified file 'dhis-2/dhis-dxf2/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-dxf2/src/main/resources/META-INF/dhis/beans.xml	2012-04-22 16:16:24 +0000
+++ dhis-2/dhis-dxf2/src/main/resources/META-INF/dhis/beans.xml	2012-04-23 09:49:08 +0000
@@ -118,6 +118,11 @@
         value="org.hisp.dhis.organisationunit.OrganisationUnit" />
   </bean>
 
+  <bean id="organisationUnitLevelImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultIdentifiableObjectImporter">
+    <constructor-arg name="importerClass" type="java.lang.Class"
+        value="org.hisp.dhis.organisationunit.OrganisationUnitLevel" />
+  </bean>
+
   <bean id="organisationUnitGroupImporter"
       class="org.hisp.dhis.dxf2.metadata.importers.DefaultIdentifiableObjectImporter">
     <constructor-arg name="importerClass" type="java.lang.Class"

=== 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	2012-04-03 10:52:58 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2012-04-23 09:49:08 +0000
@@ -27,17 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -53,6 +42,8 @@
 import org.hisp.dhis.version.VersionService;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.*;
+
 /**
  * @author Torgeir Lorange Ostby
  * @version $Id: DefaultOrganisationUnitService.java 5951 2008-10-16 17:41:34Z
@@ -77,6 +68,13 @@
         this.organisationUnitStore = organisationUnitStore;
     }
 
+    private OrganisationUnitLevelStore organisationUnitLevelStore;
+
+    public void setOrganisationUnitLevelStore( OrganisationUnitLevelStore organisationUnitLevelStore )
+    {
+        this.organisationUnitLevelStore = organisationUnitLevelStore;
+    }
+
     private CurrentUserService currentUserService;
 
     public void setCurrentUserService( CurrentUserService currentUserService )
@@ -142,7 +140,7 @@
 
         log.info( AuditLogUtil.logMessage( currentUserService.getCurrentUsername(), AuditLogUtil.ACTION_DELETE,
             OrganisationUnit.class.getSimpleName(), organisationUnit.getName() ) );
-        
+
         updateVersion();
     }
 
@@ -159,7 +157,7 @@
     public void searchOrganisationUnitByName( List<OrganisationUnit> orgUnits, String key )
     {
         Iterator<OrganisationUnit> iterator = orgUnits.iterator();
-        
+
         while ( iterator.hasNext() )
         {
             if ( !iterator.next().getName().toLowerCase().contains( key.toLowerCase() ) )
@@ -168,7 +166,7 @@
             }
         }
     }
-    
+
     public Collection<OrganisationUnit> getOrganisationUnits( final Collection<Integer> identifiers )
     {
         Collection<OrganisationUnit> objects = getAllOrganisationUnits();
@@ -181,16 +179,16 @@
             }
         } );
     }
-    
+
     public Set<OrganisationUnit> getOrganisationUnitsByUid( Collection<String> uids )
     {
         Set<OrganisationUnit> organisationUnits = new HashSet<OrganisationUnit>();
-        
+
         for ( String uid : uids )
         {
             organisationUnits.add( organisationUnitStore.getByUid( uid ) );
         }
-        
+
         return organisationUnits;
     }
 
@@ -218,7 +216,7 @@
     {
         return organisationUnitStore.getRootOrganisationUnits();
     }
-    
+
     public int getLevelOfOrganisationUnit( int id )
     {
         return getOrganisationUnit( id ).getOrganisationUnitLevel();
@@ -227,16 +225,16 @@
     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 );
@@ -439,7 +437,7 @@
         Collection<OrganisationUnitGroup> groups, OrganisationUnit parent, boolean limit )
     {
         // Can only limit in query if parent is not set and we get all units
-        
+
         boolean _limit = limit && parent == null;
 
         final Collection<OrganisationUnit> result = organisationUnitStore.getOrganisationUnitsByNameAndGroups( name,
@@ -519,16 +517,16 @@
     public void filterOrganisationUnitsWithoutData( Collection<OrganisationUnit> organisationUnits )
     {
         final Set<Integer> unitsWithoutData = organisationUnitStore.getOrganisationUnitIdsWithoutData();
-        
+
         FilterUtils.filter( organisationUnits, new Filter<OrganisationUnit>()
         {
             public boolean retain( OrganisationUnit unit )
             {
-                return unit != null && ( !unitsWithoutData.contains( unit.getId() ) || unit.hasChild() );
+                return unit != null && (!unitsWithoutData.contains( unit.getId() ) || unit.hasChild());
             }
         } );
     }
-    
+
     public Collection<OrganisationUnit> getOrganisationUnitsBetween( int first, int max )
     {
         return organisationUnitStore.getBetween( first, max );
@@ -538,7 +536,7 @@
     {
         return organisationUnitStore.getBetweenByName( name, first, max );
     }
-    
+
     // -------------------------------------------------------------------------
     // OrganisationUnitHierarchy
     // -------------------------------------------------------------------------
@@ -557,14 +555,14 @@
     // OrganisationUnitLevel
     // -------------------------------------------------------------------------
 
-    public int addOrganisationUnitLevel( OrganisationUnitLevel level )
+    public int addOrganisationUnitLevel( OrganisationUnitLevel organisationUnitLevel )
     {
-        return organisationUnitStore.addOrganisationUnitLevel( level );
+        return organisationUnitLevelStore.save( organisationUnitLevel );
     }
 
-    public void updateOrganisationUnitLevel( OrganisationUnitLevel level )
+    public void updateOrganisationUnitLevel( OrganisationUnitLevel organisationUnitLevel )
     {
-        organisationUnitStore.updateOrganisationUnitLevel( level );
+        organisationUnitLevelStore.update( organisationUnitLevel );
     }
 
     public void addOrUpdateOrganisationUnitLevel( OrganisationUnitLevel level )
@@ -596,12 +594,12 @@
 
     public OrganisationUnitLevel getOrganisationUnitLevel( int id )
     {
-        return organisationUnitStore.getOrganisationUnitLevel( id );
+        return organisationUnitLevelStore.get( id );
     }
 
     public OrganisationUnitLevel getOrganisationUnitLevel( String uid )
     {
-        return organisationUnitStore.getOrganisationUnitLevel( uid );
+        return organisationUnitLevelStore.getByUid( uid );
     }
 
     public Collection<OrganisationUnitLevel> getOrganisationUnitLevels( final Collection<Integer> identifiers )
@@ -617,34 +615,34 @@
         } );
     }
 
-    public void deleteOrganisationUnitLevel( OrganisationUnitLevel level )
+    public void deleteOrganisationUnitLevel( OrganisationUnitLevel organisationUnitLevel )
     {
-        organisationUnitStore.deleteOrganisationUnitLevel( level );
+        organisationUnitLevelStore.delete( organisationUnitLevel );
     }
 
     public void deleteOrganisationUnitLevels()
     {
-        organisationUnitStore.deleteOrganisationUnitLevels();
+        organisationUnitLevelStore.deleteAll();
     }
 
     public List<OrganisationUnitLevel> getOrganisationUnitLevels()
     {
-        List<OrganisationUnitLevel> levels = new ArrayList<OrganisationUnitLevel>(
-            organisationUnitStore.getOrganisationUnitLevels() );
-
-        Collections.sort( levels, new OrganisationUnitLevelComparator() );
-
-        return levels;
+        List<OrganisationUnitLevel> organisationUnitLevels = new ArrayList<OrganisationUnitLevel>(
+            organisationUnitLevelStore.getAll() );
+
+        Collections.sort( organisationUnitLevels, new OrganisationUnitLevelComparator() );
+
+        return organisationUnitLevels;
     }
 
     public OrganisationUnitLevel getOrganisationUnitLevelByLevel( int level )
     {
-        return organisationUnitStore.getOrganisationUnitLevelByLevel( level );
+        return organisationUnitLevelStore.getByLevel( level );
     }
 
     public OrganisationUnitLevel getOrganisationUnitLevelByName( String name )
     {
-        return organisationUnitStore.getOrganisationUnitLevelByName( name );
+        return organisationUnitLevelStore.getByName( name );
     }
 
     public List<OrganisationUnitLevel> getFilledOrganisationUnitLevels()
@@ -687,7 +685,7 @@
     @Override
     public int getMaxOfOrganisationUnitLevels()
     {
-        return organisationUnitStore.getMaxOfOrganisationUnitLevels();
+        return organisationUnitLevelStore.getMaxLevels();
     }
 
     @Override

=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitLevelStore.java	2012-04-23 09:49:08 +0000
@@ -0,0 +1,72 @@
+package org.hisp.dhis.organisationunit.hibernate;
+
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hibernate.Criteria;
+import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
+import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
+import org.hisp.dhis.organisationunit.OrganisationUnitLevelStore;
+
+import java.util.Collection;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class HibernateOrganisationUnitLevelStore
+    extends HibernateIdentifiableObjectStore<OrganisationUnitLevel>
+    implements OrganisationUnitLevelStore
+{
+    public void deleteAll()
+    {
+        String hql = "delete from OrganisationUnitLevel";
+
+        sessionFactory.getCurrentSession().createQuery( hql ).executeUpdate();
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public Collection<OrganisationUnitLevel> getOrganisationUnitLevels()
+    {
+        return sessionFactory.getCurrentSession().createCriteria( OrganisationUnitLevel.class ).list();
+    }
+
+    public OrganisationUnitLevel getByLevel( int level )
+    {
+        Criteria criteria = sessionFactory.getCurrentSession().createCriteria( OrganisationUnitLevel.class );
+
+        return (OrganisationUnitLevel) criteria.add( Restrictions.eq( "level", level ) ).uniqueResult();
+    }
+
+    @Override
+    public int getMaxLevels()
+    {
+        final String sql = "SELECT MAX(level) FROM orgunitlevel";
+
+        return jdbcTemplate.queryForInt( sql );
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java	2012-04-23 09:49:08 +0000
@@ -27,31 +27,21 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Timestamp;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.StringUtils;
 import org.hibernate.Criteria;
 import org.hibernate.Query;
 import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
-import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
-import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
-import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.organisationunit.OrganisationUnitStore;
+import org.hisp.dhis.organisationunit.*;
 import org.hisp.dhis.system.objectmapper.OrganisationUnitRelationshipRowMapper;
 import org.springframework.jdbc.core.RowCallbackHandler;
 
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.util.*;
+
 /**
  * @author Kristian Nordal
  */
@@ -60,19 +50,6 @@
     implements OrganisationUnitStore
 {
     // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-
-    //TODO this should be a separate class!
-    
-    private HibernateIdentifiableObjectStore<OrganisationUnitLevel> orgLevelStore;
-
-    public void setOrgLevelStore( HibernateIdentifiableObjectStore<OrganisationUnitLevel> orgLevelStore )
-    {
-        this.orgLevelStore = orgLevelStore;
-    }    
-    
-    // -------------------------------------------------------------------------
     // OrganisationUnit
     // -------------------------------------------------------------------------
 
@@ -148,32 +125,32 @@
 
         return query.list();
     }
-        
+
     public Map<Integer, Set<Integer>> getOrganisationUnitDataSetAssocationMap()
     {
         final String sql = "select datasetid, sourceid from datasetsource";
-        
+
         final Map<Integer, Set<Integer>> map = new HashMap<Integer, Set<Integer>>();
-        
+
         jdbcTemplate.query( sql, new RowCallbackHandler()
         {
             public void processRow( ResultSet rs ) throws SQLException
             {
                 int dataSetId = rs.getInt( 1 );
                 int organisationUnitId = rs.getInt( 2 );
-                
+
                 Set<Integer> dataSets = map.get( organisationUnitId );
-                
+
                 if ( dataSets == null )
                 {
                     dataSets = new HashSet<Integer>();
                     map.put( organisationUnitId, dataSets );
                 }
-                
+
                 dataSets.add( dataSetId );
             }
         } );
-        
+
         return map;
     }
 
@@ -181,9 +158,9 @@
     {
         final String sql = "select organisationunitid from organisationunit ou where not exists (" +
             "select sourceid from datavalue where sourceid=ou.organisationunitid)";
-        
+
         final Set<Integer> units = new HashSet<Integer>();
-        
+
         jdbcTemplate.query( sql, new RowCallbackHandler()
         {
             public void processRow( ResultSet rs ) throws SQLException
@@ -191,7 +168,7 @@
                 units.add( rs.getInt( 1 ) );
             }
         } );
-        
+
         return units;
     }
 
@@ -209,82 +186,18 @@
     public void updateOrganisationUnitParent( int organisationUnitId, int parentId )
     {
         Timestamp now = new Timestamp( new Date().getTime() );
-        
+
         final String sql = "update organisationunit " + "set parentid=" + parentId + ", lastupdated='"
             + now + "' " + "where organisationunitid=" + organisationUnitId;
 
         jdbcTemplate.execute( sql );
     }
 
-    // -------------------------------------------------------------------------
-    // OrganisationUnitLevel
-    // -------------------------------------------------------------------------
-
-    public int addOrganisationUnitLevel( OrganisationUnitLevel level )
-    {
-        return orgLevelStore.save( level );
-    }
-
-    public void updateOrganisationUnitLevel( OrganisationUnitLevel level )
-    {
-        orgLevelStore.update( level );
-    }
-
-    public OrganisationUnitLevel getOrganisationUnitLevel( int id )
-    {
-        return orgLevelStore.get(  id );
-    }
-
-    public OrganisationUnitLevel getOrganisationUnitLevel( String uid )
-    {
-        return orgLevelStore.getByUid( uid );
-    }
-
-    public void deleteOrganisationUnitLevel( OrganisationUnitLevel level )
-    {
-        orgLevelStore.delete( level );
-    }
-
-    public void deleteOrganisationUnitLevels()
-    {
-        String hql = "delete from OrganisationUnitLevel";
-
-        sessionFactory.getCurrentSession().createQuery( hql ).executeUpdate();
-    }
-
-    @SuppressWarnings( "unchecked" )
-    public Collection<OrganisationUnitLevel> getOrganisationUnitLevels()
-    {
-        return sessionFactory.getCurrentSession().createCriteria( OrganisationUnitLevel.class ).list();
-    }
-
-    public OrganisationUnitLevel getOrganisationUnitLevelByLevel( int level )
-    {
-        Criteria criteria = sessionFactory.getCurrentSession().createCriteria( OrganisationUnitLevel.class );
-
-        return (OrganisationUnitLevel) criteria.add( Restrictions.eq( "level", level ) ).uniqueResult();
-    }
-
-    public OrganisationUnitLevel getOrganisationUnitLevelByName( String name )
-    {
-        Criteria criteria = sessionFactory.getCurrentSession().createCriteria( OrganisationUnitLevel.class );
-
-        return (OrganisationUnitLevel) criteria.add( Restrictions.eq( "name", name ) ).uniqueResult();
-    }
-
-    @Override
-    public int getMaxOfOrganisationUnitLevels()
-    {
-        final String sql = "SELECT MAX(level) FROM orgunitlevel";
-
-        return jdbcTemplate.queryForInt( sql );
-    }
-
     @Override
     public void update( Collection<OrganisationUnit> units )
     {
         Timestamp now = new Timestamp( new Date().getTime() );
-        
+
         Collection<Integer> unitIds = new HashSet<Integer>();
 
         for ( OrganisationUnit orgunit : units )
@@ -294,13 +207,13 @@
 
         if ( unitIds.size() > 0 )
         {
-            String sql = "update OrganisationUnit set hasPatients=true,lastUpdated='" + now + 
+            String sql = "update OrganisationUnit set hasPatients=true,lastUpdated='" + now +
                 "' where organisationunitid in (:unitIds)";
             Query query = sessionFactory.getCurrentSession().createQuery( sql );
             query.setParameterList( "unitIds", unitIds );
             query.executeUpdate();
 
-            sql = "UPDATE OrganisationUnit SET hasPatients=false,lastUpdated='" + now + 
+            sql = "UPDATE OrganisationUnit SET hasPatients=false,lastUpdated='" + now +
                 "' WHERE organisationunitid not in ( :unitIds )";
             query = sessionFactory.getCurrentSession().createQuery( sql );
             query.setParameterList( "unitIds", unitIds );
@@ -308,7 +221,7 @@
         }
         else
         {
-            String sql = "update OrganisationUnit set hasPatients=false,,lastUpdated='" + now +"'";
+            String sql = "update OrganisationUnit set hasPatients=false,,lastUpdated='" + now + "'";
             Query query = sessionFactory.getCurrentSession().createQuery( sql );
             query.executeUpdate();
         }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2012-04-18 17:01:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2012-04-23 09:49:08 +0000
@@ -153,7 +153,7 @@
     <property name="cacheable" value="true" />
   </bean>
 
-  <bean id="org.hisp.dhis.organisationunit.OrganisationUnitLevelStore" class="org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore">
+  <bean id="org.hisp.dhis.organisationunit.OrganisationUnitLevelStore" class="org.hisp.dhis.organisationunit.hibernate.HibernateOrganisationUnitLevelStore">
     <property name="clazz" value="org.hisp.dhis.organisationunit.OrganisationUnitLevel" />
     <property name="sessionFactory" ref="sessionFactory" />
     <property name="cacheable" value="true" />
@@ -164,7 +164,6 @@
     <property name="sessionFactory" ref="sessionFactory" />
     <property name="jdbcTemplate" ref="jdbcTemplate" />
     <property name="cacheable" value="true" />
-    <property name="orgLevelStore" ref="org.hisp.dhis.organisationunit.OrganisationUnitLevelStore" />
   </bean>
 
   <bean id="org.hisp.dhis.organisationunit.OrganisationUnitGroupStore" class="org.hisp.dhis.organisationunit.hibernate.HibernateOrganisationUnitGroupStore">
@@ -368,6 +367,7 @@
 
   <bean id="org.hisp.dhis.organisationunit.OrganisationUnitService" class="org.hisp.dhis.organisationunit.DefaultOrganisationUnitService">
     <property name="organisationUnitStore" ref="org.hisp.dhis.organisationunit.OrganisationUnitStore" />
+    <property name="organisationUnitLevelStore" ref="org.hisp.dhis.organisationunit.OrganisationUnitLevelStore" />
     <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
     <property name="versionService" ref="org.hisp.dhis.version.VersionService" />
   </bean>

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitStoreTest.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitStoreTest.java	2012-04-23 09:49:08 +0000
@@ -27,16 +27,13 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.assertNull;
-import static junit.framework.Assert.assertTrue;
-
-import java.util.Collection;
-
 import org.hisp.dhis.DhisSpringTest;
 import org.junit.Test;
 
+import java.util.Collection;
+
+import static junit.framework.Assert.*;
+
 /**
  * @author Lars Helge Overland
  * @version $Id$
@@ -45,13 +42,16 @@
     extends DhisSpringTest
 {
     private OrganisationUnitStore organisationUnitStore;
-    
+
+    private OrganisationUnitLevelStore organisationUnitLevelStore;
+
     @Override
     public void setUpTest()
     {
         organisationUnitStore = (OrganisationUnitStore) getBean( OrganisationUnitStore.ID );
+        organisationUnitLevelStore = (OrganisationUnitLevelStore) getBean( OrganisationUnitLevelStore.ID );
     }
-    
+
     // -------------------------------------------------------------------------
     // OrganisationUnitLevel
     // -------------------------------------------------------------------------
@@ -61,12 +61,12 @@
     {
         OrganisationUnitLevel levelA = new OrganisationUnitLevel( 1, "National" );
         OrganisationUnitLevel levelB = new OrganisationUnitLevel( 2, "District" );
-        
-        int idA = organisationUnitStore.addOrganisationUnitLevel( levelA );
-        int idB = organisationUnitStore.addOrganisationUnitLevel( levelB );
-        
-        assertEquals( levelA, organisationUnitStore.getOrganisationUnitLevel( idA ) );
-        assertEquals( levelB, organisationUnitStore.getOrganisationUnitLevel( idB ) );        
+
+        int idA = organisationUnitLevelStore.save( levelA );
+        int idB = organisationUnitLevelStore.save( levelB );
+
+        assertEquals( levelA, organisationUnitLevelStore.get( idA ) );
+        assertEquals( levelB, organisationUnitLevelStore.get( idB ) );
     }
 
     @Test
@@ -74,12 +74,12 @@
     {
         OrganisationUnitLevel levelA = new OrganisationUnitLevel( 1, "National" );
         OrganisationUnitLevel levelB = new OrganisationUnitLevel( 2, "District" );
-        
-        organisationUnitStore.addOrganisationUnitLevel( levelA );
-        organisationUnitStore.addOrganisationUnitLevel( levelB );
-        
-        Collection<OrganisationUnitLevel> actual = organisationUnitStore.getOrganisationUnitLevels();
-        
+
+        organisationUnitLevelStore.save( levelA );
+        organisationUnitLevelStore.save( levelB );
+
+        Collection<OrganisationUnitLevel> actual = organisationUnitLevelStore.getAll();
+
         assertNotNull( actual );
         assertEquals( 2, actual.size() );
         assertTrue( actual.contains( levelA ) );
@@ -91,21 +91,21 @@
     {
         OrganisationUnitLevel levelA = new OrganisationUnitLevel( 1, "National" );
         OrganisationUnitLevel levelB = new OrganisationUnitLevel( 2, "District" );
-        
-        int idA = organisationUnitStore.addOrganisationUnitLevel( levelA );
-        int idB = organisationUnitStore.addOrganisationUnitLevel( levelB );
-        
-        assertNotNull( organisationUnitStore.getOrganisationUnitLevel( idA ) );
-        assertNotNull( organisationUnitStore.getOrganisationUnitLevel( idB ) );
-        
-        organisationUnitStore.deleteOrganisationUnitLevel( levelA );
-
-        assertNull( organisationUnitStore.getOrganisationUnitLevel( idA ) );
-        assertNotNull( organisationUnitStore.getOrganisationUnitLevel( idB ) );
-
-        organisationUnitStore.deleteOrganisationUnitLevel( levelB );
-
-        assertNull( organisationUnitStore.getOrganisationUnitLevel( idA ) );
-        assertNull( organisationUnitStore.getOrganisationUnitLevel( idB ) );        
+
+        int idA = organisationUnitLevelStore.save( levelA );
+        int idB = organisationUnitLevelStore.save( levelB );
+
+        assertNotNull( organisationUnitLevelStore.get( idA ) );
+        assertNotNull( organisationUnitLevelStore.get( idB ) );
+
+        organisationUnitLevelStore.delete( levelA );
+
+        assertNull( organisationUnitLevelStore.get( idA ) );
+        assertNotNull( organisationUnitLevelStore.get( idB ) );
+
+        organisationUnitLevelStore.delete( levelB );
+
+        assertNull( organisationUnitLevelStore.get( idA ) );
+        assertNull( organisationUnitLevelStore.get( idB ) );
     }
 }
\ No newline at end of file