← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9708: Removed name-uniqueness from OrgUnit, OrgUnitGroup, OrgUnitGroupSet. Updated services, etc. Old i...

 

------------------------------------------------------------
revno: 9708
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-02-04 21:57:16 +0700
message:
  Removed name-uniqueness from OrgUnit, OrgUnitGroup, OrgUnitGroupSet. Updated services, etc. Old importers will still work, but with name-matching, only the first match will be used. Validators updated. WIP
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericIdentifiableObjectStore.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericNameableObjectStore.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitGroupService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupSetPopulator.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.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/importer/GroupSetImporter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OrganisationUnitGroupImporter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OrganisationUnitImporter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OrganisationUnitLevelImporter.java
  dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf/DXFOrganisationUnitsTest.java
  dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf/GML2DXFTest.java
  dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/importobject/ImportObjectServiceImportAllTest.java
  dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityServiceController.java
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/ValidateOrganisationUnitAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroup/ValidateOrganisationUnitGroupAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroupset/ValidateGroupSetAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/addOrganisationUnitForm.vm
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetOrganisationUnitInfoFacilityAction.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/common/GenericIdentifiableObjectStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericIdentifiableObjectStore.java	2013-02-04 03:14:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericIdentifiableObjectStore.java	2013-02-04 14:57:16 +0000
@@ -85,11 +85,19 @@
      * @param name the name.
      * @return a Collection of objects.
      */
-    Collection<T> getAllEqName( String name );
+    List<T> getAllEqName( String name );
+
+    /**
+     * Retrieves a Collection of objects where the name is equal the given name (ignore case).
+     *
+     * @param name the name.
+     * @return a Collection of objects.
+     */
+    List<T> getAllEqNameIgnoreCase( String name );
 
     /**
      * Return the number of objects where the name is equal the given name.
-     *
+     * <p/>
      * This count is _unfiltered_ (no ACL!), so this is not the same as
      * getAllEqName().size().
      *

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericNameableObjectStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericNameableObjectStore.java	2013-02-04 03:14:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericNameableObjectStore.java	2013-02-04 14:57:16 +0000
@@ -28,6 +28,7 @@
  */
 
 import java.util.Collection;
+import java.util.List;
 
 /**
  * @author Lars Helge Overland
@@ -61,5 +62,13 @@
      * @param shortName the name.
      * @return a Collection of objects.
      */
-    Collection<T> getAllEqShortName( String shortName );
+    List<T> getAllEqShortName( String shortName );
+
+    /**
+     * Retrieves a Collection of objects where the name is like the given name (ignore case).
+     *
+     * @param shortName the name.
+     * @return a Collection of objects.
+     */
+    List<T> getAllEqShortNameIgnoreCase( String shortName );
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupService.java	2013-01-11 13:12:31 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupService.java	2013-02-04 14:57:16 +0000
@@ -102,11 +102,12 @@
     /**
      * Returns an OrganisationUnitGroup with a given name.
      * 
+     *
      * @param name the name of the OrganisationUnitGroup.
      * @return the OrganisationUnitGroup with the given name, or null if no
      *         match.
      */
-    OrganisationUnitGroup getOrganisationUnitGroupByName( String name );
+    List<OrganisationUnitGroup> getOrganisationUnitGroupByName( String name );
 
     /**
      * Returns all OrganisationUnitGroups.
@@ -196,11 +197,12 @@
     /**
      * Returns an OrganisationUnitGroupSet with a given name.
      * 
+     *
      * @param name the name of the OrganisationUnitGroupSet to return.
      * @return the OrganisationUnitGroupSet with the given name, or null if no
      *         match.
      */
-    OrganisationUnitGroupSet getOrganisationUnitGroupSetByName( String name );
+    List<OrganisationUnitGroupSet> getOrganisationUnitGroupSetByName( String name );
 
     /**
      * Returns all OrganisationUnitGroupSets.

=== 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	2012-12-13 10:47:58 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java	2013-02-04 14:57:16 +0000
@@ -176,7 +176,7 @@
      * @param name the name of the OrganisationUnit to return.
      * @return the OrganisationUnit with the given name, or null if not match.
      */
-    OrganisationUnit getOrganisationUnitByName( String name );
+    List<OrganisationUnit> getOrganisationUnitByName( String name );
 
     /**
      * Returns an OrganisationUnit with a given name. Case is ignored.
@@ -184,7 +184,7 @@
      * @param name the name of the OrganisationUnit to return.
      * @return the OrganisationUnit with the given name, or null if not match.
      */
-    OrganisationUnit getOrganisationUnitByNameIgnoreCase( String name );
+    Collection<OrganisationUnit> getOrganisationUnitByNameIgnoreCase( String name );
 
     /**
      * Returns all root OrganisationUnits. A root OrganisationUnit is an
@@ -358,7 +358,7 @@
 
     OrganisationUnitLevel getOrganisationUnitLevelByLevel( int level );
 
-    OrganisationUnitLevel getOrganisationUnitLevelByName( String name );
+    List<OrganisationUnitLevel> getOrganisationUnitLevelByName( String name );
 
     List<OrganisationUnitLevel> getFilledOrganisationUnitLevels();
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitGroupService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitGroupService.java	2013-01-11 13:12:31 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitGroupService.java	2013-02-04 14:57:16 +0000
@@ -27,18 +27,18 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.i18n.I18nUtils.*;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.hisp.dhis.i18n.I18nService;
 import org.hisp.dhis.system.util.Filter;
 import org.hisp.dhis.system.util.FilterUtils;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import static org.hisp.dhis.i18n.I18nUtils.*;
+
 /**
  * @author Torgeir Lorange Ostby
  * @version $Id: DefaultOrganisationUnitGroupService.java 5017 2008-04-25 09:19:19Z larshelg $
@@ -57,7 +57,7 @@
     {
         this.organisationUnitGroupStore = organisationUnitGroupStore;
     }
-    
+
     private GenericIdentifiableObjectStore<OrganisationUnitGroupSet> organisationUnitGroupSetStore;
 
     public void setOrganisationUnitGroupSetStore( GenericIdentifiableObjectStore<OrganisationUnitGroupSet> organisationUnitGroupSetStore )
@@ -95,18 +95,18 @@
     {
         return i18n( i18nService, organisationUnitGroupStore.get( id ) );
     }
-    
+
     public Collection<OrganisationUnitGroup> getOrganisationUnitGroups( final Collection<Integer> identifiers )
     {
         Collection<OrganisationUnitGroup> objects = getAllOrganisationUnitGroups();
-        
+
         return identifiers == null ? objects : FilterUtils.filter( objects, new Filter<OrganisationUnitGroup>()
+        {
+            public boolean retain( OrganisationUnitGroup object )
             {
-                public boolean retain( OrganisationUnitGroup object )
-                {
-                    return identifiers.contains( object.getId() );
-                }
-            } );
+                return identifiers.contains( object.getId() );
+            }
+        } );
     }
 
     public List<OrganisationUnitGroup> getOrganisationUnitGroupsByUid( Collection<String> uids )
@@ -119,16 +119,16 @@
         return i18n( i18nService, organisationUnitGroupStore.getByUid( uid ) );
     }
 
-    public OrganisationUnitGroup getOrganisationUnitGroupByName( String name )
+    public List<OrganisationUnitGroup> getOrganisationUnitGroupByName( String name )
     {
-        return i18n( i18nService, organisationUnitGroupStore.getByName( name ) );
+        return new ArrayList<OrganisationUnitGroup>( i18n( i18nService, organisationUnitGroupStore.getAllEqName( name ) ) );
     }
 
     public Collection<OrganisationUnitGroup> getAllOrganisationUnitGroups()
     {
         return i18n( i18nService, organisationUnitGroupStore.getAll() );
     }
-    
+
     public Collection<OrganisationUnitGroup> getOrganisationUnitGroupsWithGroupSets()
     {
         return i18n( i18nService, organisationUnitGroupStore.getOrganisationUnitGroupsWithGroupSets() );
@@ -143,7 +143,7 @@
     {
         return getCountByName( i18nService, organisationUnitGroupStore, name );
     }
-    
+
     public Collection<OrganisationUnitGroup> getOrganisationUnitGroupsBetween( int first, int max )
     {
         return getObjectsBetween( i18nService, organisationUnitGroupStore, first, max );
@@ -181,12 +181,12 @@
     public OrganisationUnitGroupSet getOrganisationUnitGroupSet( int id, boolean i18nGroups )
     {
         OrganisationUnitGroupSet groupSet = getOrganisationUnitGroupSet( id );
-        
+
         if ( i18nGroups )
         {
             i18n( i18nService, groupSet.getOrganisationUnitGroups() );
         }
-        
+
         return groupSet;
     }
 
@@ -194,18 +194,18 @@
     {
         return i18n( i18nService, organisationUnitGroupSetStore.getByUid( uid ) );
     }
-    
+
     public Collection<OrganisationUnitGroupSet> getOrganisationUnitGroupSets( final Collection<Integer> identifiers )
     {
         Collection<OrganisationUnitGroupSet> objects = getAllOrganisationUnitGroupSets();
-        
+
         return identifiers == null ? objects : FilterUtils.filter( objects, new Filter<OrganisationUnitGroupSet>()
+        {
+            public boolean retain( OrganisationUnitGroupSet object )
             {
-                public boolean retain( OrganisationUnitGroupSet object )
-                {
-                    return identifiers.contains( object.getId() );
-                }
-            } );
+                return identifiers.contains( object.getId() );
+            }
+        } );
     }
 
     public List<OrganisationUnitGroupSet> getOrganisationUnitGroupSetsByUid( Collection<String> uids )
@@ -213,9 +213,9 @@
         return organisationUnitGroupSetStore.getByUid( uids );
     }
 
-    public OrganisationUnitGroupSet getOrganisationUnitGroupSetByName( String name )
+    public List<OrganisationUnitGroupSet> getOrganisationUnitGroupSetByName( String name )
     {
-        return i18n( i18nService, organisationUnitGroupSetStore.getByName( name ) );
+        return new ArrayList<OrganisationUnitGroupSet>( i18n( i18nService, organisationUnitGroupSetStore.getAllEqName( name ) ) );
     }
 
     public Collection<OrganisationUnitGroupSet> getAllOrganisationUnitGroupSets()
@@ -226,7 +226,7 @@
     public Collection<OrganisationUnitGroupSet> getCompulsoryOrganisationUnitGroupSets()
     {
         Collection<OrganisationUnitGroupSet> groupSets = new ArrayList<OrganisationUnitGroupSet>();
-        
+
         for ( OrganisationUnitGroupSet groupSet : getAllOrganisationUnitGroupSets() )
         {
             if ( groupSet.isCompulsory() )
@@ -234,21 +234,21 @@
                 groupSets.add( groupSet );
             }
         }
-        
+
         return groupSets;
     }
 
     public Collection<OrganisationUnitGroupSet> getCompulsoryOrganisationUnitGroupSetsWithMembers()
     {
         return FilterUtils.filter( getAllOrganisationUnitGroupSets(), new Filter<OrganisationUnitGroupSet>()
+        {
+            public boolean retain( OrganisationUnitGroupSet object )
             {
-                public boolean retain( OrganisationUnitGroupSet object )
-                {
-                    return object.isCompulsory() && object.hasOrganisationUnitGroups();
-                }
-            } );
+                return object.isCompulsory() && object.hasOrganisationUnitGroups();
+            }
+        } );
     }
-    
+
     public OrganisationUnitGroup getOrganisationUnitGroup( OrganisationUnitGroupSet groupSet, OrganisationUnit unit )
     {
         for ( OrganisationUnitGroup group : groupSet.getOrganisationUnitGroups() )
@@ -258,14 +258,14 @@
                 return group;
             }
         }
-        
+
         return null;
     }
-    
+
     public Collection<OrganisationUnitGroupSet> getCompulsoryOrganisationUnitGroupSetsNotAssignedTo( OrganisationUnit organisationUnit )
     {
         Collection<OrganisationUnitGroupSet> groupSets = new ArrayList<OrganisationUnitGroupSet>();
-        
+
         for ( OrganisationUnitGroupSet groupSet : getCompulsoryOrganisationUnitGroupSets() )
         {
             if ( !groupSet.isMemberOfOrganisationUnitGroups( organisationUnit ) && groupSet.hasOrganisationUnitGroups() )
@@ -273,25 +273,25 @@
                 groupSets.add( groupSet );
             }
         }
-        
+
         return groupSets;
     }
-    
+
     public int getOrganisationUnitGroupSetCount()
     {
         return organisationUnitGroupSetStore.getCount();
     }
-    
+
     public int getOrganisationUnitGroupSetCountByName( String name )
     {
         return getCountByName( i18nService, organisationUnitGroupSetStore, name );
     }
-    
+
     public Collection<OrganisationUnitGroupSet> getOrganisationUnitGroupSetsBetween( int first, int max )
     {
         return getObjectsBetween( i18nService, organisationUnitGroupSetStore, first, max );
     }
-    
+
     public Collection<OrganisationUnitGroupSet> getOrganisationUnitGroupSetsBetweenByName( String name, int first, int max )
     {
         return getObjectsBetweenByName( i18nService, organisationUnitGroupSetStore, name, first, max );

=== 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	2013-01-28 06:30:22 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2013-02-04 14:57:16 +0000
@@ -27,8 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.i18n.I18nUtils.i18n;
-
 import org.apache.commons.collections.CollectionUtils;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.hierarchy.HierarchyViolationException;
@@ -54,6 +52,8 @@
 import java.util.Set;
 import java.util.UUID;
 
+import static org.hisp.dhis.i18n.I18nUtils.i18n;
+
 /**
  * @author Torgeir Lorange Ostby
  * @version $Id: DefaultOrganisationUnitService.java 5951 2008-10-16 17:41:34Z
@@ -225,9 +225,9 @@
         return organisationUnitStore.getByUid( uid );
     }
 
-    public OrganisationUnit getOrganisationUnitByName( String name )
+    public List<OrganisationUnit> getOrganisationUnitByName( String name )
     {
-        return organisationUnitStore.getByName( name );
+        return organisationUnitStore.getAllEqName( name );
     }
 
     public OrganisationUnit getOrganisationUnitByCode( String code )
@@ -235,9 +235,9 @@
         return organisationUnitStore.getByCode( code );
     }
 
-    public OrganisationUnit getOrganisationUnitByNameIgnoreCase( String name )
+    public Collection<OrganisationUnit> getOrganisationUnitByNameIgnoreCase( String name )
     {
-        return organisationUnitStore.getOrganisationUnitByNameIgnoreCase( name );
+        return organisationUnitStore.getAllEqNameIgnoreCase( name );
     }
 
     public Collection<OrganisationUnit> getRootOrganisationUnits()
@@ -465,7 +465,7 @@
         return organisationUnitStore.getOrganisationUnitsByNameAndGroups( query, groups, limit );
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name,
         Collection<OrganisationUnitGroup> groups, OrganisationUnit parent, boolean limit )
     {
@@ -692,9 +692,9 @@
         return i18n( i18nService, organisationUnitLevelStore.getByLevel( level ) );
     }
 
-    public OrganisationUnitLevel getOrganisationUnitLevelByName( String name )
+    public List<OrganisationUnitLevel> getOrganisationUnitLevelByName( String name )
     {
-        return i18n( i18nService, organisationUnitLevelStore.getByName( name ) );
+        return new ArrayList<OrganisationUnitLevel>( i18n( i18nService, organisationUnitLevelStore.getAllEqName( name ) ) );
     }
 
     public List<OrganisationUnitLevel> getFilledOrganisationUnitLevels()

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupSetPopulator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupSetPopulator.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupSetPopulator.java	2013-02-04 14:57:16 +0000
@@ -29,6 +29,9 @@
 
 import org.hisp.dhis.system.startup.AbstractStartupRoutine;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * @author Lars Helge Overland
  * @version $Id$
@@ -44,7 +47,7 @@
     // -------------------------------------------------------------------------
 
     private OrganisationUnitGroupService organisationUnitGroupService;
-    
+
     public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService )
     {
         this.organisationUnitGroupService = organisationUnitGroupService;
@@ -57,27 +60,29 @@
     public void execute()
         throws Exception
     {
-        OrganisationUnitGroupSet type = organisationUnitGroupService.getOrganisationUnitGroupSetByName( NAME_TYPE );
-        
+        List<OrganisationUnitGroupSet> types = new ArrayList<OrganisationUnitGroupSet>( organisationUnitGroupService.getOrganisationUnitGroupSetByName( NAME_TYPE ) );
+        OrganisationUnitGroupSet type = types.isEmpty() ? null : types.get( 0 );
+
         if ( type == null )
         {
             type = new OrganisationUnitGroupSet();
             type.setName( "Type" );
             type.setDescription( "Type of organisation unit, examples are PHU, chiefdom and district" );
             type.setCompulsory( false );
-            
+
             organisationUnitGroupService.addOrganisationUnitGroupSet( type );
         }
-        
-        OrganisationUnitGroupSet ownership = organisationUnitGroupService.getOrganisationUnitGroupSetByName( NAME_OWNERSHIP );
-        
+
+        List<OrganisationUnitGroupSet> ownerships = new ArrayList<OrganisationUnitGroupSet>( organisationUnitGroupService.getOrganisationUnitGroupSetByName( NAME_OWNERSHIP ) );
+        OrganisationUnitGroupSet ownership = ownerships.isEmpty() ? null : ownerships.get( 0 );
+
         if ( ownership == null )
         {
             ownership = new OrganisationUnitGroupSet();
             ownership.setName( "Ownership" );
             ownership.setDescription( "Ownership of organisation unit, examples are private and public" );
             ownership.setCompulsory( false );
-            
+
             organisationUnitGroupService.addOrganisationUnitGroupSet( ownership );
         }
     }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2013-01-30 07:31:03 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2013-02-04 14:57:16 +0000
@@ -480,7 +480,7 @@
 
         executeSql( "update report set type='jasperReportTable' where type is null and reporttableid is not null" );
         executeSql( "update report set type='jasperJdbc' where type is null and reporttableid is null" );
-        
+
         // upgrade authorities
 
         executeSql( "UPDATE userroleauthorities SET authority='F_DOCUMENT_PUBLIC_ADD' WHERE authority='F_DOCUMENT_ADD'" );
@@ -503,9 +503,14 @@
         executeSql( "UPDATE userroleauthorities SET authority='F_USERGROUP_LIST' WHERE authority='F_USER_GRUP_LIST'" );
 
         // update denominator of indicator which has indicatortype as 'number'
-        
-        executeSql( "UPDATE indicator SET denominator = 1, denominatordescription = '' WHERE indicatortypeid IN (SELECT DISTINCT indicatortypeid FROM indicatortype WHERE indicatornumber = true) AND denominator IS NULL");
-        
+
+        executeSql( "UPDATE indicator SET denominator = 1, denominatordescription = '' WHERE indicatortypeid IN (SELECT DISTINCT indicatortypeid FROM indicatortype WHERE indicatornumber = true) AND denominator IS NULL" );
+
+        // remove name/shortName uniqueness
+        executeSql( "ALTER TABLE organisationunit DROP CONSTRAINT organisationunit_name_key" );
+        executeSql( "ALTER TABLE orgunitgroup DROP CONSTRAINT orgunitgroup_name_key" );
+        executeSql( "ALTER TABLE orgunitgroupset DROP CONSTRAINT orgunitgroupset_name_key" );
+
         log.info( "Tables updated" );
     }
 

=== 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	2013-01-14 21:35:56 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java	2013-02-04 14:57:16 +0000
@@ -27,11 +27,9 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
+import org.hisp.dhis.DhisSpringTest;
+import org.junit.Ignore;
+import org.junit.Test;
 
 import java.util.Arrays;
 import java.util.Collection;
@@ -39,9 +37,7 @@
 import java.util.Iterator;
 import java.util.List;
 
-import org.hisp.dhis.DhisSpringTest;
-import org.junit.Ignore;
-import org.junit.Test;
+import static org.junit.Assert.*;
 
 /**
  * @author Kristian Nordal
@@ -53,7 +49,7 @@
     private OrganisationUnitService organisationUnitService;
 
     private OrganisationUnitGroupService organisationUnitGroupService;
-    
+
     @Override
     public void setUpTest()
         throws Exception
@@ -87,15 +83,15 @@
         String organisationUnitName2 = "organisationUnitName2";
         OrganisationUnit organisationUnit2 = new OrganisationUnit( organisationUnitName2, organisationUnit1,
             "shortName2", "organisationUnitCode2", new Date(), new Date(), true, "comment" );
-        
+
         int id2 = organisationUnitService.addOrganisationUnit( organisationUnit2 );
 
         assertTrue( organisationUnitService.getOrganisationUnit( id2 ).getParent().getId() == id1 );
-        
+
         organisationUnitService.deleteOrganisationUnit( organisationUnitService.getOrganisationUnit( id2 ) );
-        
+
         organisationUnitService.deleteOrganisationUnit( organisationUnitService.getOrganisationUnit( id1 ) );
-        
+
         // assert delOrganisationUnit
         assertNull( organisationUnitService.getOrganisationUnit( id1 ) );
         assertNull( organisationUnitService.getOrganisationUnit( id2 ) );
@@ -146,7 +142,7 @@
         organisationUnitService.addOrganisationUnit( unit3 );
         organisationUnitService.addOrganisationUnit( unit4 );
 
-        Collection<OrganisationUnit> actual = organisationUnitService.getOrganisationUnitWithChildren( id1 );        
+        Collection<OrganisationUnit> actual = organisationUnitService.getOrganisationUnitWithChildren( id1 );
         assertEquals( 3, actual.size() );
         assertTrue( actual.contains( unit1 ) );
         assertTrue( actual.contains( unit2 ) );
@@ -177,16 +173,16 @@
         organisationUnitService.addOrganisationUnit( organisationUnit2 );
         organisationUnitService.addOrganisationUnit( organisationUnit3 );
 
-        OrganisationUnit unit1 = organisationUnitService.getOrganisationUnitByName( oU1Name );
+        OrganisationUnit unit1 = organisationUnitService.getOrganisationUnitByName( oU1Name ).get( 0 );
         assertEquals( unit1.getName(), oU1Name );
 
-        OrganisationUnit unit4 = organisationUnitService.getOrganisationUnitByName( "foo" );
-        assertNull( unit4 );
+        List<OrganisationUnit> foo = organisationUnitService.getOrganisationUnitByName( "foo" );
+        assertTrue( foo.isEmpty() );
 
         unit1 = organisationUnitService.getOrganisationUnitByCode( oU1Code );
         assertEquals( unit1.getName(), oU1Name );
 
-        unit4 = organisationUnitService.getOrganisationUnitByCode( "foo" );
+        OrganisationUnit unit4 = organisationUnitService.getOrganisationUnitByCode( "foo" );
         assertNull( unit4 );
     }
 
@@ -235,7 +231,7 @@
         organisationUnitService.addOrganisationUnit( unit5 );
 
         Collection<OrganisationUnit> units = organisationUnitService.getAllOrganisationUnits();
-        
+
         assertNotNull( units );
         assertEquals( 5, units.size() );
         assertTrue( units.contains( unit1 ) );
@@ -316,7 +312,7 @@
         OrganisationUnit unitM = createOrganisationUnit( 'M', unitF );
         OrganisationUnit unitN = createOrganisationUnit( 'N', unitG );
         OrganisationUnit unitO = createOrganisationUnit( 'O', unitG );
-        
+
         unitA.getChildren().add( unitB );
         unitA.getChildren().add( unitC );
         unitB.getChildren().add( unitD );
@@ -331,7 +327,7 @@
         unitF.getChildren().add( unitM );
         unitG.getChildren().add( unitN );
         unitG.getChildren().add( unitO );
-        
+
         organisationUnitService.addOrganisationUnit( unitA );
         organisationUnitService.addOrganisationUnit( unitB );
         organisationUnitService.addOrganisationUnit( unitC );
@@ -347,12 +343,12 @@
         organisationUnitService.addOrganisationUnit( unitM );
         organisationUnitService.addOrganisationUnit( unitN );
         organisationUnitService.addOrganisationUnit( unitO );
-        
+
         assertTrue( equals( organisationUnitService.getOrganisationUnitsAtLevel( 2, unitB ), unitB ) );
         assertTrue( equals( organisationUnitService.getOrganisationUnitsAtLevel( 3, unitB ), unitD, unitE ) );
         assertTrue( equals( organisationUnitService.getOrganisationUnitsAtLevel( 4, unitB ), unitH, unitI, unitJ, unitK ) );
     }
-    
+
     @Test
     public void testGetOrganisationUnitsByNameAndGroups()
     {
@@ -363,23 +359,23 @@
         organisationUnitService.addOrganisationUnit( unitA );
         organisationUnitService.addOrganisationUnit( unitB );
         organisationUnitService.addOrganisationUnit( unitC );
-        
+
         OrganisationUnitGroup groupA = createOrganisationUnitGroup( 'A' );
         OrganisationUnitGroup groupB = createOrganisationUnitGroup( 'B' );
         OrganisationUnitGroup groupC = createOrganisationUnitGroup( 'C' );
-        
+
         groupA.getMembers().add( unitA );
         groupA.getMembers().add( unitB );
         groupA.getMembers().add( unitC );
         groupB.getMembers().add( unitA );
         groupB.getMembers().add( unitB );
         groupC.getMembers().add( unitA );
-        
+
         organisationUnitGroupService.addOrganisationUnitGroup( groupA );
         organisationUnitGroupService.addOrganisationUnitGroup( groupB );
         organisationUnitGroupService.addOrganisationUnitGroup( groupC );
-        
-        List<OrganisationUnitGroup> groups = Arrays.asList( groupA );        
+
+        List<OrganisationUnitGroup> groups = Arrays.asList( groupA );
         Collection<OrganisationUnit> units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups, false );
         assertEquals( 3, units.size() );
         units = organisationUnitService.getOrganisationUnitsByNameAndGroups( unitA.getName().toLowerCase(), groups, false );
@@ -404,11 +400,11 @@
         units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups, unitA, false );
         assertEquals( 2, units.size() );
 
-        groups = Arrays.asList( groupA, groupB, groupC );        
-        units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups, false );        
+        groups = Arrays.asList( groupA, groupB, groupC );
+        units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups, false );
         assertEquals( 1, units.size() );
     }
-    
+
     // -------------------------------------------------------------------------
     // OrganisationUnitGroup
     // -------------------------------------------------------------------------
@@ -454,7 +450,7 @@
         int ougid = organisationUnitGroupService.addOrganisationUnitGroup( organisationUnitGroup );
 
         assertTrue( organisationUnitGroupService.getOrganisationUnitGroup( ougid ).getMembers().size() == 2 );
-        
+
         organisationUnitGroup.getMembers().remove( organisationUnit1 );
 
         organisationUnitGroupService.updateOrganisationUnitGroup( organisationUnitGroup );
@@ -506,10 +502,10 @@
         organisationUnitGroupService.addOrganisationUnitGroup( organisationUnitGroup1 );
         organisationUnitGroupService.addOrganisationUnitGroup( organisationUnitGroup2 );
 
-        OrganisationUnitGroup group1 = organisationUnitGroupService.getOrganisationUnitGroupByName( oUG1Name );
+        OrganisationUnitGroup group1 = organisationUnitGroupService.getOrganisationUnitGroupByName( oUG1Name ).get( 0 );
         assertEquals( group1.getName(), oUG1Name );
 
-        OrganisationUnitGroup group2 = organisationUnitGroupService.getOrganisationUnitGroupByName( oUG2Name );
+        OrganisationUnitGroup group2 = organisationUnitGroupService.getOrganisationUnitGroupByName( oUG2Name ).get( 0 );
         assertEquals( group2.getName(), oUG2Name );
     }
 
@@ -546,14 +542,14 @@
 
         // retrieves children from hierarchyVersion ver_id and parentId id2
         Collection<Integer> children1 = hierarchy.getChildren( unit2.getId() );
-        
+
         // assert 4, 5, 6 are children of 2
         assertEquals( 4, children1.size() );
         assertTrue( children1.contains( id2 ) );
         assertTrue( children1.contains( id4 ) );
         assertTrue( children1.contains( id5 ) );
         assertTrue( children1.contains( id6 ) );
-                
+
         // retrieves children from hierarchyVersion ver_id and parentId id1
         Collection<Integer> children2 = hierarchy.getChildren( unit1.getId() );
 
@@ -562,11 +558,11 @@
 
         // retrieves children from hierarchyVersion ver_id and parentId id5
         Collection<Integer> children3 = hierarchy.getChildren( unit5.getId() );
-        
+
         // assert 6 is children of 5
         assertEquals( 2, children3.size() );
         assertTrue( children3.contains( id5 ) );
-        assertTrue( children3.contains( id6 ) );        
+        assertTrue( children3.contains( id6 ) );
     }
 
     // -------------------------------------------------------------------------
@@ -606,14 +602,14 @@
         assertEquals( organisationUnitGroupService.getOrganisationUnitGroupSet( id1 ).getName(), "ougs1" );
 
         assertTrue( organisationUnitGroupService.getOrganisationUnitGroupSet( id1 ).getOrganisationUnitGroups().size() == 3 );
-        
+
         organisationUnitGroupSet1.getOrganisationUnitGroups().remove( organisationUnitGroup3 );
 
         organisationUnitGroupService.updateOrganisationUnitGroupSet( organisationUnitGroupSet1 );
 
         // assert update
         assertTrue( organisationUnitGroupService.getOrganisationUnitGroupSet( id1 ).getOrganisationUnitGroups().size() == 2 );
-        
+
         OrganisationUnitGroupSet organisationUnitGroupSet2 = new OrganisationUnitGroupSet();
         organisationUnitGroupSet2.setName( "ougs2" );
         organisationUnitGroupSet2.setCompulsory( true );
@@ -623,10 +619,10 @@
 
         // assert getAllOrderedName
         assertTrue( organisationUnitGroupService.getAllOrganisationUnitGroupSets().size() == 2 );
-        
+
         organisationUnitGroupService.deleteOrganisationUnitGroupSet( organisationUnitGroupSet1 );
         organisationUnitGroupService.deleteOrganisationUnitGroupSet( organisationUnitGroupSet2 );
-        
+
         assertNull( organisationUnitGroupService.getOrganisationUnitGroupSet( id1 ) );
         assertNull( organisationUnitGroupService.getOrganisationUnitGroupSet( id2 ) );
     }
@@ -667,8 +663,8 @@
         organisationUnitGroupService.addOrganisationUnitGroupSet( organisationUnitGroupSet1 );
         organisationUnitGroupService.addOrganisationUnitGroupSet( organisationUnitGroupSet2 );
 
-        OrganisationUnitGroupSet set1 = organisationUnitGroupService.getOrganisationUnitGroupSetByName( ougs1 );
-        OrganisationUnitGroupSet set2 = organisationUnitGroupService.getOrganisationUnitGroupSetByName( ougs2 );
+        OrganisationUnitGroupSet set1 = organisationUnitGroupService.getOrganisationUnitGroupSetByName( ougs1 ).get( 0 );
+        OrganisationUnitGroupSet set2 = organisationUnitGroupService.getOrganisationUnitGroupSetByName( ougs2 ).get( 0 );
 
         assertEquals( set1.getName(), ougs1 );
         assertEquals( set2.getName(), ougs2 );
@@ -687,12 +683,12 @@
     {
         OrganisationUnitLevel levelA = new OrganisationUnitLevel( 1, "National" );
         OrganisationUnitLevel levelB = new OrganisationUnitLevel( 2, "District" );
-        
+
         int idA = organisationUnitService.addOrganisationUnitLevel( levelA );
         int idB = organisationUnitService.addOrganisationUnitLevel( levelB );
-        
+
         assertEquals( levelA, organisationUnitService.getOrganisationUnitLevel( idA ) );
-        assertEquals( levelB, organisationUnitService.getOrganisationUnitLevel( idB ) );        
+        assertEquals( levelB, organisationUnitService.getOrganisationUnitLevel( idB ) );
     }
 
     @Test
@@ -701,33 +697,33 @@
         OrganisationUnitLevel level1 = new OrganisationUnitLevel( 1, "National" );
         OrganisationUnitLevel level2 = new OrganisationUnitLevel( 2, "District" );
         OrganisationUnitLevel level4 = new OrganisationUnitLevel( 4, "PHU" );
-        
+
         organisationUnitService.addOrganisationUnitLevel( level1 );
         organisationUnitService.addOrganisationUnitLevel( level2 );
         organisationUnitService.addOrganisationUnitLevel( level4 );
-        
+
         OrganisationUnit unitA = createOrganisationUnit( 'A' );
         OrganisationUnit unitB = createOrganisationUnit( 'B', unitA );
         OrganisationUnit unitC = createOrganisationUnit( 'C', unitB );
         OrganisationUnit unitD = createOrganisationUnit( 'D', unitC );
-        
+
         unitA.getChildren().add( unitB );
         unitB.getChildren().add( unitC );
         unitC.getChildren().add( unitD );
-        
+
         organisationUnitService.addOrganisationUnit( unitA );
         organisationUnitService.addOrganisationUnit( unitB );
         organisationUnitService.addOrganisationUnit( unitC );
         organisationUnitService.addOrganisationUnit( unitD );
-                
+
         Iterator<OrganisationUnitLevel> actual = organisationUnitService.getOrganisationUnitLevels().iterator();
-        
+
         assertNotNull( actual );
         assertEquals( level1, actual.next() );
         assertEquals( level2, actual.next() );
-        
+
         level4 = actual.next();
-        
+
         assertEquals( 4, level4.getLevel() );
         assertEquals( "PHU", level4.getName() );
     }
@@ -737,13 +733,13 @@
     {
         OrganisationUnitLevel levelA = new OrganisationUnitLevel( 1, "National" );
         OrganisationUnitLevel levelB = new OrganisationUnitLevel( 2, "District" );
-        
+
         int idA = organisationUnitService.addOrganisationUnitLevel( levelA );
         int idB = organisationUnitService.addOrganisationUnitLevel( levelB );
-        
+
         assertNotNull( organisationUnitService.getOrganisationUnitLevel( idA ) );
         assertNotNull( organisationUnitService.getOrganisationUnitLevel( idB ) );
-        
+
         organisationUnitService.deleteOrganisationUnitLevel( levelA );
 
         assertNull( organisationUnitService.getOrganisationUnitLevel( idA ) );
@@ -752,6 +748,6 @@
         organisationUnitService.deleteOrganisationUnitLevel( levelB );
 
         assertNull( organisationUnitService.getOrganisationUnitLevel( idA ) );
-        assertNull( organisationUnitService.getOrganisationUnitLevel( idB ) );        
+        assertNull( organisationUnitService.getOrganisationUnitLevel( idB ) );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/GroupSetImporter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/GroupSetImporter.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/GroupSetImporter.java	2013-02-04 14:57:16 +0000
@@ -35,6 +35,8 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
 
+import java.util.List;
+
 /**
  * @author Lars Helge Overland
  * @version $Id: AbstractGroupSetConverter.java 4646 2008-02-26 14:54:29Z larshelg $
@@ -47,18 +49,18 @@
     public GroupSetImporter()
     {
     }
-    
+
     public GroupSetImporter( BatchHandler<OrganisationUnitGroupSet> batchHandler, OrganisationUnitGroupService organisationUnitGroupService )
     {
         this.batchHandler = batchHandler;
         this.organisationUnitGroupService = organisationUnitGroupService;
     }
-    
+
     @Override
     public void importObject( OrganisationUnitGroupSet object, ImportParams params )
     {
         NameMappingUtil.addGroupSetMapping( object.getId(), object.getName() );
-        
+
         read( object, GroupMemberType.NONE, params );
     }
 
@@ -74,14 +76,16 @@
         match.setName( object.getName() );
         match.setDescription( object.getDescription() );
         match.setCompulsory( object.isCompulsory() );
-        
+
         organisationUnitGroupService.updateOrganisationUnitGroupSet( match );
     }
 
     @Override
     protected OrganisationUnitGroupSet getMatching( OrganisationUnitGroupSet object )
     {
-        return organisationUnitGroupService.getOrganisationUnitGroupSetByName( object.getName() );
+        List<OrganisationUnitGroupSet> organisationUnitGroupSetByName = organisationUnitGroupService.getOrganisationUnitGroupSetByName( object.getName() );
+
+        return organisationUnitGroupSetByName.isEmpty() ? null : organisationUnitGroupSetByName.get( 0 );
     }
 
     @Override
@@ -99,7 +103,7 @@
         {
             return false;
         }
-        
+
         return true;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OrganisationUnitGroupImporter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OrganisationUnitGroupImporter.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OrganisationUnitGroupImporter.java	2013-02-04 14:57:16 +0000
@@ -8,6 +8,8 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
 
+import java.util.List;
+
 /*
  * Copyright (c) 2004-2012, University of Oslo
  * All rights reserved.
@@ -43,18 +45,18 @@
     public OrganisationUnitGroupImporter()
     {
     }
-    
+
     public OrganisationUnitGroupImporter( BatchHandler<OrganisationUnitGroup> batchHandler, OrganisationUnitGroupService organisationUnitGroupService )
     {
         this.batchHandler = batchHandler;
         this.organisationUnitGroupService = organisationUnitGroupService;
     }
-    
+
     @Override
     public void importObject( OrganisationUnitGroup object, ImportParams params )
     {
         NameMappingUtil.addOrganisationUnitGroupMapping( object.getId(), object.getName() );
-        
+
         read( object, GroupMemberType.NONE, params );
     }
 
@@ -68,14 +70,16 @@
     protected void importMatching( OrganisationUnitGroup object, OrganisationUnitGroup match )
     {
         match.setName( object.getName() );
-        
+
         organisationUnitGroupService.updateOrganisationUnitGroup( match );
     }
 
     @Override
     protected OrganisationUnitGroup getMatching( OrganisationUnitGroup object )
     {
-        return organisationUnitGroupService.getOrganisationUnitGroupByName( object.getName() );
+        List<OrganisationUnitGroup> organisationUnitGroupByName = organisationUnitGroupService.getOrganisationUnitGroupByName( object.getName() );
+
+        return organisationUnitGroupByName.isEmpty() ? null : organisationUnitGroupByName.get( 0 );
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OrganisationUnitImporter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OrganisationUnitImporter.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OrganisationUnitImporter.java	2013-02-04 14:57:16 +0000
@@ -27,8 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.apache.commons.lang.StringUtils.defaultIfEmpty;
-
 import org.amplecode.quick.BatchHandler;
 import org.hisp.dhis.importexport.GroupMemberType;
 import org.hisp.dhis.importexport.ImportParams;
@@ -37,6 +35,10 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 
+import java.util.List;
+
+import static org.apache.commons.lang.StringUtils.defaultIfEmpty;
+
 /**
  * @author Lars Helge Overland
  * @version $Id: AbstractOrganisationUnitConverter.java 6251 2008-11-10 14:37:05Z larshelg $
@@ -49,21 +51,21 @@
     public OrganisationUnitImporter()
     {
     }
-    
+
     public OrganisationUnitImporter( BatchHandler<OrganisationUnit> batchHandler, OrganisationUnitService organisationUnitService )
     {
         this.batchHandler = batchHandler;
         this.organisationUnitService = organisationUnitService;
     }
-    
+
     @Override
     public void importObject( OrganisationUnit object, ImportParams params )
     {
         NameMappingUtil.addOrganisationUnitMapping( object.getId(), object.getName() );
-        
+
         read( object, GroupMemberType.NONE, params );
     }
-    
+
     @Override
     protected void importUnique( OrganisationUnit object )
     {
@@ -84,20 +86,21 @@
         match.setFeatureType( defaultIfEmpty( object.getFeatureType(), match.getFeatureType() ) );
         match.setCoordinates( defaultIfEmpty( object.getCoordinates(), match.getCoordinates() ) );
         match.setLastUpdated( object.getLastUpdated() );
-        
+
         organisationUnitService.updateOrganisationUnit( match );
     }
 
     @Override
     protected OrganisationUnit getMatching( OrganisationUnit object )
     {
-        OrganisationUnit match = organisationUnitService.getOrganisationUnitByName( object.getName() );
-        
+        List<OrganisationUnit> organisationUnitByName = organisationUnitService.getOrganisationUnitByName( object.getName() );
+        OrganisationUnit match = organisationUnitByName.isEmpty() ? null : organisationUnitByName.get( 0 );
+
         if ( match == null )
         {
             match = organisationUnitService.getOrganisationUnitByCode( object.getCode() );
         }
-        
+
         return match;
     }
 
@@ -112,15 +115,15 @@
         {
             return false;
         }
-        if ( !isSimiliar( object.getCode(), existing.getCode() ) || ( isNotNull( object.getCode(), existing.getCode() ) && !object.getCode().equals( existing.getCode() ) ) )
-        {
-            return false;
-        }
-        if ( !isSimiliar( object.getOpeningDate(), existing.getOpeningDate() ) || ( isNotNull( object.getOpeningDate(), existing.getOpeningDate() ) && !object.getOpeningDate().equals( existing.getOpeningDate() ) ) )
-        {
-            return false;
-        }
-        if ( !isSimiliar( object.getClosedDate(), existing.getClosedDate() ) || ( isNotNull( object.getClosedDate(), existing.getClosedDate() ) && !object.getClosedDate().equals( existing.getClosedDate() ) ) )
+        if ( !isSimiliar( object.getCode(), existing.getCode() ) || (isNotNull( object.getCode(), existing.getCode() ) && !object.getCode().equals( existing.getCode() )) )
+        {
+            return false;
+        }
+        if ( !isSimiliar( object.getOpeningDate(), existing.getOpeningDate() ) || (isNotNull( object.getOpeningDate(), existing.getOpeningDate() ) && !object.getOpeningDate().equals( existing.getOpeningDate() )) )
+        {
+            return false;
+        }
+        if ( !isSimiliar( object.getClosedDate(), existing.getClosedDate() ) || (isNotNull( object.getClosedDate(), existing.getClosedDate() ) && !object.getClosedDate().equals( existing.getClosedDate() )) )
         {
             return false;
         }
@@ -128,23 +131,23 @@
         {
             return false;
         }
-        if ( !isSimiliar( object.getComment(), existing.getComment() ) || ( isNotNull( object.getComment(), existing.getComment() ) && !object.getComment().equals( existing.getComment() ) ) )
-        {
-            return false;
-        }
-        if ( !isSimiliar( object.getGeoCode(), existing.getGeoCode() ) || ( isNotNull( object.getGeoCode(), existing.getGeoCode() ) && !object.getGeoCode().equals( existing.getGeoCode() ) ) )
-        {
-            return false;
-        }
-        if ( !isSimiliar( object.getFeatureType(), existing.getFeatureType() ) || ( isNotNull( object.getFeatureType(), existing.getFeatureType() ) && !object.getFeatureType().equals( existing.getFeatureType() ) ) )
-        {
-            return false;
-        }
-        if ( !isSimiliar( object.getCoordinates(), existing.getCoordinates() ) || ( isNotNull( object.getCoordinates(), existing.getCoordinates() ) && !object.getCoordinates().equals( existing.getCoordinates() ) ) )
-        {
-            return false;
-        }
-        
+        if ( !isSimiliar( object.getComment(), existing.getComment() ) || (isNotNull( object.getComment(), existing.getComment() ) && !object.getComment().equals( existing.getComment() )) )
+        {
+            return false;
+        }
+        if ( !isSimiliar( object.getGeoCode(), existing.getGeoCode() ) || (isNotNull( object.getGeoCode(), existing.getGeoCode() ) && !object.getGeoCode().equals( existing.getGeoCode() )) )
+        {
+            return false;
+        }
+        if ( !isSimiliar( object.getFeatureType(), existing.getFeatureType() ) || (isNotNull( object.getFeatureType(), existing.getFeatureType() ) && !object.getFeatureType().equals( existing.getFeatureType() )) )
+        {
+            return false;
+        }
+        if ( !isSimiliar( object.getCoordinates(), existing.getCoordinates() ) || (isNotNull( object.getCoordinates(), existing.getCoordinates() ) && !object.getCoordinates().equals( existing.getCoordinates() )) )
+        {
+            return false;
+        }
+
         return true;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OrganisationUnitLevelImporter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OrganisationUnitLevelImporter.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OrganisationUnitLevelImporter.java	2013-02-04 14:57:16 +0000
@@ -79,7 +79,7 @@
         
         if ( match == null )
         {
-            match = organisationUnitService.getOrganisationUnitLevelByName( object.getName() );
+            match = organisationUnitService.getOrganisationUnitLevelByName( object.getName() ).get( 0 );
         }
         
         return match;

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf/DXFOrganisationUnitsTest.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf/DXFOrganisationUnitsTest.java	2012-11-20 17:04:08 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf/DXFOrganisationUnitsTest.java	2013-02-04 14:57:16 +0000
@@ -27,10 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collection;
-
 import org.hisp.dhis.DhisTest;
 import org.hisp.dhis.external.location.LocationManagerException;
 import org.hisp.dhis.importexport.ImportParams;
@@ -41,7 +37,12 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.junit.Test;
 
-import static org.junit.Assert.*;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 /**
  * @author Lars Helge Overland
@@ -50,19 +51,19 @@
     extends DhisTest
 {
     private InputStream inputStream;
-    
+
     private ImportService importService;
-        
+
     @Override
     public void setUpTest() throws LocationManagerException, IOException
     {
         ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
 
         inputStream = classLoader.getResourceAsStream( "dxfOrganisationUnits.xml" );
-        
+
         organisationUnitService = (OrganisationUnitService) getBean( OrganisationUnitService.ID );
     }
-    
+
     @Override
     public void tearDownTest()
         throws Exception
@@ -79,15 +80,15 @@
     @Test
     public void testImportOrganisationUnits() throws Exception
     {
-        importService = (ImportService) getBean( "org.hisp.dhis.importexport.ImportService" );        
+        importService = (ImportService) getBean( "org.hisp.dhis.importexport.ImportService" );
 
         ImportParams params = ImportExportUtils.getImportParams( ImportStrategy.NEW_AND_UPDATES, false, false, false );
-        
+
         importService.importData( params, inputStream );
-        
+
         Collection<OrganisationUnit> units = organisationUnitService.getAllOrganisationUnits();
         OrganisationUnit unit = units.iterator().next();
-        
+
         assertNotNull( units );
         assertEquals( 3, units.size() );
         assertEquals( "GeoCode", unit.getGeoCode() );

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf/GML2DXFTest.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf/GML2DXFTest.java	2012-11-20 17:04:08 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf/GML2DXFTest.java	2013-02-04 14:57:16 +0000
@@ -80,24 +80,24 @@
         assertNotNull( organisationUnitService.getAllOrganisationUnits() );
         assertEquals( 13, organisationUnitService.getAllOrganisationUnits().size() );
         
-        assertEquals( 1, organisationUnitService.getOrganisationUnitByName( "Bo" ).getCoordinatesAsList().size() );
-        assertEquals( 18, organisationUnitService.getOrganisationUnitByName( "Bonthe" ).getCoordinatesAsList().size() );
-        assertEquals( 1, organisationUnitService.getOrganisationUnitByName( "Moyamba" ).getCoordinatesAsList().size() );
-        assertEquals( 3, organisationUnitService.getOrganisationUnitByName( "Pujehun" ).getCoordinatesAsList().size() );
-        assertEquals( 1, organisationUnitService.getOrganisationUnitByName( "Kailahun" ).getCoordinatesAsList().size() );
-        assertEquals( 1, organisationUnitService.getOrganisationUnitByName( "Kenema" ).getCoordinatesAsList().size() );
-        assertEquals( 1, organisationUnitService.getOrganisationUnitByName( "Kono" ).getCoordinatesAsList().size() );
-        assertEquals( 1, organisationUnitService.getOrganisationUnitByName( "Bombali" ).getCoordinatesAsList().size() );
-        assertEquals( 3, organisationUnitService.getOrganisationUnitByName( "Kambia" ).getCoordinatesAsList().size() );
-        assertEquals( 1, organisationUnitService.getOrganisationUnitByName( "Koinadugu" ).getCoordinatesAsList().size() );
-        assertEquals( 9, organisationUnitService.getOrganisationUnitByName( "Port Loko" ).getCoordinatesAsList().size() );
-        assertEquals( 1, organisationUnitService.getOrganisationUnitByName( "Tonkolili" ).getCoordinatesAsList().size() );
-        assertEquals( 2, organisationUnitService.getOrganisationUnitByName( "Western Area" ).getCoordinatesAsList().size() );
+        assertEquals( 1, organisationUnitService.getOrganisationUnitByName( "Bo" ).get( 0 ).getCoordinatesAsList().size() );
+        assertEquals( 18, organisationUnitService.getOrganisationUnitByName( "Bonthe" ).get( 0 ).getCoordinatesAsList().size() );
+        assertEquals( 1, organisationUnitService.getOrganisationUnitByName( "Moyamba" ).get( 0 ).getCoordinatesAsList().size() );
+        assertEquals( 3, organisationUnitService.getOrganisationUnitByName( "Pujehun" ).get( 0 ).getCoordinatesAsList().size() );
+        assertEquals( 1, organisationUnitService.getOrganisationUnitByName( "Kailahun" ).get( 0 ).getCoordinatesAsList().size() );
+        assertEquals( 1, organisationUnitService.getOrganisationUnitByName( "Kenema" ).get( 0 ).getCoordinatesAsList().size() );
+        assertEquals( 1, organisationUnitService.getOrganisationUnitByName( "Kono" ).get( 0 ).getCoordinatesAsList().size() );
+        assertEquals( 1, organisationUnitService.getOrganisationUnitByName( "Bombali" ).get( 0 ).getCoordinatesAsList().size() );
+        assertEquals( 3, organisationUnitService.getOrganisationUnitByName( "Kambia" ).get( 0 ).getCoordinatesAsList().size() );
+        assertEquals( 1, organisationUnitService.getOrganisationUnitByName( "Koinadugu" ).get( 0 ).getCoordinatesAsList().size() );
+        assertEquals( 9, organisationUnitService.getOrganisationUnitByName( "Port Loko" ).get( 0 ).getCoordinatesAsList().size() );
+        assertEquals( 1, organisationUnitService.getOrganisationUnitByName( "Tonkolili" ).get( 0 ).getCoordinatesAsList().size() );
+        assertEquals( 2, organisationUnitService.getOrganisationUnitByName( "Western Area" ).get( 0 ).getCoordinatesAsList().size() );
 
-        assertEquals( 76, organisationUnitService.getOrganisationUnitByName( "Bo" ).getCoordinatesAsList().get( 0 ).getNumberOfCoordinates() );
-        assertEquals( 7, organisationUnitService.getOrganisationUnitByName( "Pujehun" ).getCoordinatesAsList().get( 0 ).getNumberOfCoordinates() );
-        assertEquals( 7, organisationUnitService.getOrganisationUnitByName( "Pujehun" ).getCoordinatesAsList().get( 1 ).getNumberOfCoordinates() );
-        assertEquals( 159, organisationUnitService.getOrganisationUnitByName( "Pujehun" ).getCoordinatesAsList().get( 2 ).getNumberOfCoordinates() );
-        assertEquals( 189, organisationUnitService.getOrganisationUnitByName( "Bonthe" ).getCoordinatesAsList().get( 1 ).getNumberOfCoordinates() );
+        assertEquals( 76, organisationUnitService.getOrganisationUnitByName( "Bo" ).get( 0 ).getCoordinatesAsList().get( 0 ).getNumberOfCoordinates() );
+        assertEquals( 7, organisationUnitService.getOrganisationUnitByName( "Pujehun" ).get( 0 ).getCoordinatesAsList().get( 0 ).getNumberOfCoordinates() );
+        assertEquals( 7, organisationUnitService.getOrganisationUnitByName( "Pujehun" ).get( 0 ).getCoordinatesAsList().get( 1 ).getNumberOfCoordinates() );
+        assertEquals( 159, organisationUnitService.getOrganisationUnitByName( "Pujehun" ).get( 0 ).getCoordinatesAsList().get( 2 ).getNumberOfCoordinates() );
+        assertEquals( 189, organisationUnitService.getOrganisationUnitByName( "Bonthe" ).get( 0 ).getCoordinatesAsList().get( 1 ).getNumberOfCoordinates() );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/importobject/ImportObjectServiceImportAllTest.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/importobject/ImportObjectServiceImportAllTest.java	2012-11-20 17:04:08 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/importobject/ImportObjectServiceImportAllTest.java	2013-02-04 14:57:16 +0000
@@ -27,13 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Collection;
-
 import org.amplecode.quick.BatchHandler;
 import org.amplecode.quick.BatchHandlerFactory;
 import org.hisp.dhis.DhisTest;
@@ -62,18 +55,22 @@
 import org.junit.Ignore;
 import org.junit.Test;
 
+import java.util.Collection;
+
+import static org.junit.Assert.*;
+
 /**
  * @author Lars Helge Overland
  * @version $Id$
  */
-@SuppressWarnings( "unused" )
+@SuppressWarnings("unused")
 public class ImportObjectServiceImportAllTest
     extends DhisTest
 {
     private ImportObjectService importObjectService;
-    
+
     private BatchHandlerFactory batchHandlerFactory;
-    
+
     // -------------------------------------------------------------------------
     // CategoryOption
     // -------------------------------------------------------------------------
@@ -104,7 +101,7 @@
 
     private DataElementCategoryCombo categoryComboA;
     private DataElementCategoryCombo categoryComboB;
-    
+
     private DataElementCategoryCombo categoryComboADuplicate;
     private DataElementCategoryCombo categoryComboBDuplicate;
 
@@ -143,12 +140,12 @@
     // DataElement
     // -------------------------------------------------------------------------
 
-    private DataElement dataElementA;    
+    private DataElement dataElementA;
     private DataElement dataElementB;
     private DataElement dataElementC;
     private DataElement dataElementD;
-    
-    private DataElement dataElementAModified;    
+
+    private DataElement dataElementAModified;
     private DataElement dataElementBModified;
     private DataElement dataElementCModified;
     private DataElement dataElementDModified;
@@ -157,11 +154,11 @@
     // DataElementGroup
     // -------------------------------------------------------------------------
 
-    private DataElementGroup dataElementGroupA;    
+    private DataElementGroup dataElementGroupA;
     private DataElementGroup dataElementGroupB;
     private DataElementGroup dataElementGroupC;
-    
-    private DataElementGroup dataElementGroupADuplicate;    
+
+    private DataElementGroup dataElementGroupADuplicate;
     private DataElementGroup dataElementGroupBDuplicate;
     private DataElementGroup dataElementGroupCDuplicate;
 
@@ -185,7 +182,7 @@
     private PeriodType periodTypeA;
 
     private Period periodA;
-    
+
     private Period periodADuplicate;
 
     // -------------------------------------------------------------------------
@@ -195,7 +192,7 @@
     private OrganisationUnit organisationUnitA;
     private OrganisationUnit organisationUnitB;
     private OrganisationUnit organisationUnitC;
-    
+
     private OrganisationUnit organisationUnitAModified;
     private OrganisationUnit organisationUnitBModified;
     private OrganisationUnit organisationUnitCModified;
@@ -220,7 +217,7 @@
     private DataValue dataValueG;
     private DataValue dataValueH;
     private DataValue dataValueI;
-    
+
     private DataValue dataValueADuplicate;
     private DataValue dataValueBDuplicate;
     private DataValue dataValueCDuplicate;
@@ -230,7 +227,7 @@
     private DataValue dataValueGDuplicate;
     private DataValue dataValueHDuplicate;
     private DataValue dataValueIDuplicate;
-        
+
     // -------------------------------------------------------------------------
     // Fixture
     // -------------------------------------------------------------------------
@@ -243,17 +240,17 @@
         // ---------------------------------------------------------------------
 
         importObjectService = (ImportObjectService) getBean( ImportObjectService.ID );
-        
+
         batchHandlerFactory = (BatchHandlerFactory) getBean( "batchHandlerFactory" );
-        
+
         dataElementService = (DataElementService) getBean( DataElementService.ID );
-        
+
         categoryService = (DataElementCategoryService) getBean( DataElementCategoryService.ID );
-        
+
         periodService = (PeriodService) getBean( PeriodService.ID );
-        
+
         organisationUnitService = (OrganisationUnitService) getBean( OrganisationUnitService.ID );
-        
+
         dataValueService = (DataValueService) getBean( DataValueService.ID );
 
         // ---------------------------------------------------------------------
@@ -264,12 +261,12 @@
         categoryOptionB = new DataElementCategoryOption( "CategoryOptionB" );
         categoryOptionC = new DataElementCategoryOption( "CategoryOptionC" );
         categoryOptionD = new DataElementCategoryOption( "CategoryOptionD" );
-        
+
         categoryService.addDataElementCategoryOption( categoryOptionA );
         categoryService.addDataElementCategoryOption( categoryOptionB );
         categoryService.addDataElementCategoryOption( categoryOptionC );
         categoryService.addDataElementCategoryOption( categoryOptionD );
-        
+
         categoryOptionADuplicate = new DataElementCategoryOption( "CategoryOptionA" );
         categoryOptionBDuplicate = new DataElementCategoryOption( "CategoryOptionB" );
         categoryOptionCDuplicate = new DataElementCategoryOption( "CategoryOptionC" );
@@ -279,7 +276,7 @@
         categoryOptionBDuplicate.setId( 'B' );
         categoryOptionCDuplicate.setId( 'C' );
         categoryOptionDDuplicate.setId( 'D' );
-        
+
         importObjectService.addImportObject( ImportObjectStatus.MATCH, categoryOptionADuplicate, null );
         importObjectService.addImportObject( ImportObjectStatus.MATCH, categoryOptionBDuplicate, null );
         importObjectService.addImportObject( ImportObjectStatus.MATCH, categoryOptionCDuplicate, null );
@@ -291,15 +288,15 @@
 
         categoryA = new DataElementCategory( "CategoryA" );
         categoryB = new DataElementCategory( "CategoryB" );
-        
+
         categoryA.getCategoryOptions().add( categoryOptionA );
         categoryA.getCategoryOptions().add( categoryOptionB );
         categoryB.getCategoryOptions().add( categoryOptionC );
         categoryB.getCategoryOptions().add( categoryOptionD );
-        
+
         categoryService.addDataElementCategory( categoryA );
         categoryService.addDataElementCategory( categoryB );
-        
+
         categoryADuplicate = new DataElementCategory( "CategoryA" );
         categoryBDuplicate = new DataElementCategory( "CategoryB" );
 
@@ -317,7 +314,7 @@
         categoryCategoryOptionAssociationB = new GroupMemberAssociation( 'A', 'B', 2 );
         categoryCategoryOptionAssociationC = new GroupMemberAssociation( 'B', 'C', 1 );
         categoryCategoryOptionAssociationD = new GroupMemberAssociation( 'B', 'D', 2 );
-        
+
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.CATEGORY_CATEGORYOPTION, categoryCategoryOptionAssociationA );
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.CATEGORY_CATEGORYOPTION, categoryCategoryOptionAssociationB );
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.CATEGORY_CATEGORYOPTION, categoryCategoryOptionAssociationC );
@@ -329,20 +326,20 @@
 
         categoryComboA = new DataElementCategoryCombo( "CategoryComboA" );
         categoryComboB = new DataElementCategoryCombo( "CategoryComboB" );
-        
+
         categoryComboA.getCategories().add( categoryA );
         categoryComboA.getCategories().add( categoryB );
         categoryComboB.getCategories().add( categoryA );
-        
+
         categoryService.addDataElementCategoryCombo( categoryComboA );
         categoryService.addDataElementCategoryCombo( categoryComboB );
-        
+
         categoryComboADuplicate = new DataElementCategoryCombo( "CategoryComboA" );
         categoryComboBDuplicate = new DataElementCategoryCombo( "CategoryComboB" );
-        
+
         categoryComboADuplicate.setId( 'A' );
         categoryComboBDuplicate.setId( 'B' );
-        
+
         importObjectService.addImportObject( ImportObjectStatus.MATCH, categoryComboADuplicate, null );
         importObjectService.addImportObject( ImportObjectStatus.MATCH, categoryComboBDuplicate, null );
 
@@ -353,7 +350,7 @@
         categoryComboCategoryAssociationA = new GroupMemberAssociation( 'A', 'A', 1 );
         categoryComboCategoryAssociationB = new GroupMemberAssociation( 'A', 'B', 2 );
         categoryComboCategoryAssociationC = new GroupMemberAssociation( 'B', 'A', 1 );
-        
+
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.CATEGORYCOMBO_CATEGORY, categoryComboCategoryAssociationA );
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.CATEGORYCOMBO_CATEGORY, categoryComboCategoryAssociationB );
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.CATEGORYCOMBO_CATEGORY, categoryComboCategoryAssociationC );
@@ -371,41 +368,41 @@
         categoryOptionComboB.setCategoryCombo( categoryComboA );
         categoryOptionComboC.setCategoryCombo( categoryComboB );
         categoryOptionComboD.setCategoryCombo( categoryComboB );
-        
+
         categoryOptionComboA.getCategoryOptions().add( categoryOptionA );
         categoryOptionComboA.getCategoryOptions().add( categoryOptionC );
         categoryOptionComboB.getCategoryOptions().add( categoryOptionB );
         categoryOptionComboB.getCategoryOptions().add( categoryOptionD );
         categoryOptionComboC.getCategoryOptions().add( categoryOptionA );
         categoryOptionComboD.getCategoryOptions().add( categoryOptionB );
-        
+
         categoryService.addDataElementCategoryOptionCombo( categoryOptionComboA );
         categoryService.addDataElementCategoryOptionCombo( categoryOptionComboB );
         categoryService.addDataElementCategoryOptionCombo( categoryOptionComboC );
         categoryService.addDataElementCategoryOptionCombo( categoryOptionComboD );
-        
+
         categoryOptionComboADuplicate = new DataElementCategoryOptionCombo();
         categoryOptionComboBDuplicate = new DataElementCategoryOptionCombo();
         categoryOptionComboCDuplicate = new DataElementCategoryOptionCombo();
         categoryOptionComboDDuplicate = new DataElementCategoryOptionCombo();
-        
+
         categoryOptionComboADuplicate.setId( 'A' );
         categoryOptionComboBDuplicate.setId( 'B' );
         categoryOptionComboCDuplicate.setId( 'C' );
         categoryOptionComboDDuplicate.setId( 'D' );
-        
+
         categoryOptionComboADuplicate.setCategoryCombo( categoryComboADuplicate );
         categoryOptionComboBDuplicate.setCategoryCombo( categoryComboADuplicate );
         categoryOptionComboCDuplicate.setCategoryCombo( categoryComboBDuplicate );
         categoryOptionComboDDuplicate.setCategoryCombo( categoryComboBDuplicate );
-        
+
         categoryOptionComboADuplicate.getCategoryOptions().add( categoryOptionADuplicate );
         categoryOptionComboADuplicate.getCategoryOptions().add( categoryOptionCDuplicate );
         categoryOptionComboBDuplicate.getCategoryOptions().add( categoryOptionBDuplicate );
         categoryOptionComboBDuplicate.getCategoryOptions().add( categoryOptionDDuplicate );
         categoryOptionComboCDuplicate.getCategoryOptions().add( categoryOptionADuplicate );
         categoryOptionComboDDuplicate.getCategoryOptions().add( categoryOptionBDuplicate );
-        
+
         importObjectService.addImportObject( ImportObjectStatus.MATCH, categoryOptionComboADuplicate, null );
         importObjectService.addImportObject( ImportObjectStatus.MATCH, categoryOptionComboBDuplicate, null );
         importObjectService.addImportObject( ImportObjectStatus.MATCH, categoryOptionComboCDuplicate, null );
@@ -415,8 +412,8 @@
         // DataElement
         // ---------------------------------------------------------------------
 
-        dataElementA = createDataElement( 'A', categoryComboA );        
-        dataElementB = createDataElement( 'B', categoryComboA );        
+        dataElementA = createDataElement( 'A', categoryComboA );
+        dataElementB = createDataElement( 'B', categoryComboA );
         dataElementC = createDataElement( 'C', categoryComboA );
         dataElementD = createDataElement( 'D', categoryComboA );
 
@@ -424,12 +421,12 @@
         dataElementBModified = createDataElement( 'B', categoryComboADuplicate );
         dataElementCModified = createDataElement( 'C', categoryComboADuplicate );
         dataElementDModified = createDataElement( 'D', categoryComboADuplicate );
-        
+
         dataElementAModified.setId( 'A' );
         dataElementBModified.setId( 'B' );
         dataElementCModified.setId( 'C' );
         dataElementDModified.setId( 'D' );
-                
+
         dataElementAModified.setShortName( "ShortNameModifiedA" );
         dataElementBModified.setShortName( "ShortNameModifiedB" );
         dataElementCModified.setShortName( "ShortNameModifiedC" );
@@ -446,18 +443,18 @@
         dataElementGroupADuplicate = createDataElementGroup( 'A' );
         dataElementGroupBDuplicate = createDataElementGroup( 'B' );
         dataElementGroupCDuplicate = createDataElementGroup( 'C' );
-        
+
         dataElementGroupADuplicate.setId( 'A' );
         dataElementGroupBDuplicate.setId( 'B' );
         dataElementGroupCDuplicate.setId( 'C' );
-                        
+
         dataElementGroupAssociationA = new GroupMemberAssociation( 'A', 'A' );
         dataElementGroupAssociationB = new GroupMemberAssociation( 'A', 'B' );
         dataElementGroupAssociationC = new GroupMemberAssociation( 'A', 'C' );
         dataElementGroupAssociationD = new GroupMemberAssociation( 'A', 'D' );
         dataElementGroupAssociationE = new GroupMemberAssociation( 'B', 'A' );
         dataElementGroupAssociationF = new GroupMemberAssociation( 'B', 'B' );
-        dataElementGroupAssociationG = new GroupMemberAssociation( 'B', 'C' ); 
+        dataElementGroupAssociationG = new GroupMemberAssociation( 'B', 'C' );
         dataElementGroupAssociationH = new GroupMemberAssociation( 'B', 'D' );
         dataElementGroupAssociationI = new GroupMemberAssociation( 'C', 'A' );
         dataElementGroupAssociationJ = new GroupMemberAssociation( 'C', 'B' );
@@ -471,9 +468,9 @@
         periodTypeA = periodService.getPeriodTypeByName( MonthlyPeriodType.NAME );
 
         periodA = createPeriod( periodTypeA, getDate( 1, 0, 2000 ), getDate( 31, 0, 2000 ) );
-        
+
         periodADuplicate = createPeriod( periodTypeA, getDate( 1, 0, 2000 ), getDate( 31, 0, 2000 ) );
-        
+
         periodADuplicate.setId( 'A' );
 
         // ---------------------------------------------------------------------
@@ -483,15 +480,15 @@
         organisationUnitA = createOrganisationUnit( 'A' );
         organisationUnitB = createOrganisationUnit( 'B' );
         organisationUnitC = createOrganisationUnit( 'C' );
-        
+
         organisationUnitAModified = createOrganisationUnit( 'A' );
         organisationUnitBModified = createOrganisationUnit( 'B' );
         organisationUnitCModified = createOrganisationUnit( 'C' );
-        
+
         organisationUnitAModified.setId( 'A' );
         organisationUnitBModified.setId( 'B' );
         organisationUnitCModified.setId( 'C' );
-                
+
         organisationUnitAModified.setShortName( "ShortNameModifiedA" );
         organisationUnitBModified.setShortName( "ShortNameModifiedB" );
         organisationUnitCModified.setShortName( "ShortNameModifiedC" );
@@ -516,7 +513,7 @@
         dataValueG = createDataValue( dataElementC, periodA, organisationUnitA, "10", categoryOptionComboA );
         dataValueH = createDataValue( dataElementC, periodA, organisationUnitB, "10", categoryOptionComboA );
         dataValueI = createDataValue( dataElementC, periodA, organisationUnitC, "10", categoryOptionComboA );
-        
+
         dataValueADuplicate = createDataValue( dataElementAModified, periodADuplicate, organisationUnitAModified, "10", categoryOptionComboADuplicate );
         dataValueBDuplicate = createDataValue( dataElementAModified, periodADuplicate, organisationUnitBModified, "10", categoryOptionComboADuplicate );
         dataValueCDuplicate = createDataValue( dataElementAModified, periodADuplicate, organisationUnitCModified, "10", categoryOptionComboADuplicate );
@@ -525,9 +522,9 @@
         dataValueFDuplicate = createDataValue( dataElementBModified, periodADuplicate, organisationUnitCModified, "10", categoryOptionComboADuplicate );
         dataValueGDuplicate = createDataValue( dataElementCModified, periodADuplicate, organisationUnitAModified, "10", categoryOptionComboADuplicate );
         dataValueHDuplicate = createDataValue( dataElementCModified, periodADuplicate, organisationUnitBModified, "10", categoryOptionComboADuplicate );
-        dataValueIDuplicate = createDataValue( dataElementCModified, periodADuplicate, organisationUnitCModified, "10", categoryOptionComboADuplicate );        
+        dataValueIDuplicate = createDataValue( dataElementCModified, periodADuplicate, organisationUnitCModified, "10", categoryOptionComboADuplicate );
     }
-    
+
     @Override
     public boolean emptyDatabaseAfterTest()
     {
@@ -545,11 +542,11 @@
         importObjectService.addImportObject( ImportObjectStatus.NEW, dataElementAModified, null );
         importObjectService.addImportObject( ImportObjectStatus.NEW, dataElementBModified, null );
         importObjectService.addImportObject( ImportObjectStatus.NEW, dataElementCModified, null );
-        
+
         importObjectService.addImportObject( ImportObjectStatus.NEW, dataElementGroupADuplicate, null );
         importObjectService.addImportObject( ImportObjectStatus.NEW, dataElementGroupBDuplicate, null );
         importObjectService.addImportObject( ImportObjectStatus.NEW, dataElementGroupCDuplicate, null );
-        
+
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationA );
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationB );
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationC );
@@ -563,30 +560,30 @@
         dbmsManager.clearSession();
 
         importObjectService.importAll();
-        
+
         Collection<DataElement> dataElements = dataElementService.getAllDataElements();
-        
+
         assertEquals( dataElements.size(), 3 );
-        
+
         assertTrue( dataElements.contains( dataElementA ) );
         assertTrue( dataElements.contains( dataElementB ) );
         assertTrue( dataElements.contains( dataElementC ) );
-        
+
         Collection<DataElementGroup> dataElementGroups = dataElementService.getAllDataElementGroups();
-        
+
         assertEquals( dataElementGroups.size(), 3 );
-        
+
         assertTrue( dataElementGroups.contains( dataElementGroupA ) );
         assertTrue( dataElementGroups.contains( dataElementGroupB ) );
         assertTrue( dataElementGroups.contains( dataElementGroupC ) );
-        
+
         for ( DataElementGroup dataElementGroup : dataElementGroups )
         {
             assertEquals( dataElementGroup.getMembers().size(), 3 );
-            
+
             assertTrue( dataElementGroup.getMembers().containsAll( dataElements ) );
         }
-        
+
         assertEquals( importObjectService.getImportObjects( DataElement.class ).size(), 0 );
         assertEquals( importObjectService.getImportObjects( DataElementGroup.class ).size(), 0 );
         assertEquals( importObjectService.getImportObjects( GroupMemberAssociation.class ).size(), 0 );
@@ -599,57 +596,57 @@
         dataElementService.addDataElement( dataElementA );
         dataElementService.addDataElement( dataElementB );
         dataElementService.addDataElement( dataElementC );
-        
+
         dataElementGroupA.getMembers().add( dataElementA );
         dataElementGroupB.getMembers().add( dataElementA );
-        dataElementGroupC.getMembers().add( dataElementA );  
-        
+        dataElementGroupC.getMembers().add( dataElementA );
+
         dataElementService.addDataElementGroup( dataElementGroupA );
         dataElementService.addDataElementGroup( dataElementGroupB );
         dataElementService.addDataElementGroup( dataElementGroupC );
-        
+
         importObjectService.addImportObject( ImportObjectStatus.UPDATE, dataElementAModified, dataElementA );
         importObjectService.addImportObject( ImportObjectStatus.UPDATE, dataElementBModified, dataElementB );
         importObjectService.addImportObject( ImportObjectStatus.UPDATE, dataElementCModified, dataElementC );
-        
+
         importObjectService.addImportObject( ImportObjectStatus.MATCH, GroupMemberType.NONE, dataElementGroupADuplicate );
         importObjectService.addImportObject( ImportObjectStatus.MATCH, GroupMemberType.NONE, dataElementGroupBDuplicate );
         importObjectService.addImportObject( ImportObjectStatus.MATCH, GroupMemberType.NONE, dataElementGroupCDuplicate );
-        
+
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationB );
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationC );
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationF );
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationG );
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationJ );
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationK );
-        
+
         dbmsManager.clearSession();
-        
+
         importObjectService.importAll();
 
         Collection<DataElement> dataElements = dataElementService.getAllDataElements();
-        
+
         assertEquals( dataElements.size(), 3 );
-        
+
         assertTrue( dataElements.contains( dataElementAModified ) );
         assertTrue( dataElements.contains( dataElementBModified ) );
         assertTrue( dataElements.contains( dataElementCModified ) );
-        
+
         Collection<DataElementGroup> dataElementGroups = dataElementService.getAllDataElementGroups();
-        
+
         assertEquals( dataElementGroups.size(), 3 );
-        
+
         assertTrue( dataElementGroups.contains( dataElementGroupA ) );
         assertTrue( dataElementGroups.contains( dataElementGroupB ) );
         assertTrue( dataElementGroups.contains( dataElementGroupC ) );
-        
+
         for ( DataElementGroup dataElementGroup : dataElementGroups )
         {
             assertEquals( dataElementGroup.getMembers().size(), 3 );
-            
+
             assertTrue( dataElementGroup.getMembers().containsAll( dataElements ) );
         }
-        
+
         assertEquals( importObjectService.getImportObjects( DataElement.class ).size(), 0 );
         assertEquals( importObjectService.getImportObjects( DataElementGroup.class ).size(), 0 );
         assertEquals( importObjectService.getImportObjects( GroupMemberAssociation.class ).size(), 0 );
@@ -662,23 +659,23 @@
         dataElementService.addDataElement( dataElementA );
         dataElementService.addDataElement( dataElementB );
         dataElementService.addDataElement( dataElementC );
-        
+
         dataElementGroupA.getMembers().add( dataElementA );
         dataElementGroupB.getMembers().add( dataElementA );
-        dataElementGroupC.getMembers().add( dataElementA );  
-        
+        dataElementGroupC.getMembers().add( dataElementA );
+
         dataElementService.addDataElementGroup( dataElementGroupA );
         dataElementService.addDataElementGroup( dataElementGroupB );
         dataElementService.addDataElementGroup( dataElementGroupC );
-        
+
         importObjectService.addImportObject( ImportObjectStatus.MATCH, dataElementAModified, null );
         importObjectService.addImportObject( ImportObjectStatus.MATCH, dataElementBModified, null );
         importObjectService.addImportObject( ImportObjectStatus.MATCH, dataElementCModified, null );
-        
+
         importObjectService.addImportObject( ImportObjectStatus.MATCH, GroupMemberType.NONE, dataElementGroupADuplicate );
         importObjectService.addImportObject( ImportObjectStatus.MATCH, GroupMemberType.NONE, dataElementGroupBDuplicate );
         importObjectService.addImportObject( ImportObjectStatus.MATCH, GroupMemberType.NONE, dataElementGroupCDuplicate );
-        
+
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationB );
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationC );
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationF );
@@ -687,32 +684,32 @@
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationK );
 
         dbmsManager.clearSession();
-        
+
         importObjectService.importAll();
 
         Collection<DataElement> dataElements = dataElementService.getAllDataElements();
-        
+
         assertEquals( dataElements.size(), 3 );
-        
+
         assertTrue( dataElements.contains( dataElementA ) );
         assertTrue( dataElements.contains( dataElementB ) );
         assertTrue( dataElements.contains( dataElementC ) );
-        
+
         Collection<DataElementGroup> dataElementGroups = dataElementService.getAllDataElementGroups();
-        
+
         assertEquals( dataElementGroups.size(), 3 );
-        
+
         assertTrue( dataElementGroups.contains( dataElementGroupA ) );
         assertTrue( dataElementGroups.contains( dataElementGroupB ) );
         assertTrue( dataElementGroups.contains( dataElementGroupC ) );
-        
+
         for ( DataElementGroup dataElementGroup : dataElementGroups )
         {
             assertEquals( dataElementGroup.getMembers().size(), 3 );
-            
+
             assertTrue( dataElementGroup.getMembers().containsAll( dataElements ) );
         }
-        
+
         assertEquals( importObjectService.getImportObjects( DataElement.class ).size(), 0 );
         assertEquals( importObjectService.getImportObjects( DataElementGroup.class ).size(), 0 );
         assertEquals( importObjectService.getImportObjects( GroupMemberAssociation.class ).size(), 0 );
@@ -723,15 +720,15 @@
     public void testMatchAndImportAll()
     {
         int existingObjectIdA = dataElementService.addDataElement( dataElementA );
-        
+
         dataElementGroupA.getMembers().add( dataElementA );
-        
+
         int existingObjectIdB = dataElementService.addDataElementGroup( dataElementGroupA );
-        
+
         int importObjectIdA = importObjectService.addImportObject( ImportObjectStatus.NEW, dataElementBModified, null );
         int importObjectIdB = importObjectService.addImportObject( ImportObjectStatus.NEW, dataElementCModified, null );
         importObjectService.addImportObject( ImportObjectStatus.NEW, dataElementDModified, null );
-        
+
         int importObjectIdC = importObjectService.addImportObject( ImportObjectStatus.NEW, dataElementGroupBDuplicate, null );
         importObjectService.addImportObject( ImportObjectStatus.NEW, dataElementGroupCDuplicate, null );
 
@@ -743,31 +740,31 @@
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationL );
 
         dbmsManager.clearSession();
-        
+
         importObjectService.matchObject( importObjectIdA, existingObjectIdA );
         importObjectService.matchObject( importObjectIdB, existingObjectIdA );
         importObjectService.matchObject( importObjectIdC, existingObjectIdB );
-        
+
         importObjectService.importAll();
-        
+
         Collection<DataElement> dataElements = dataElementService.getAllDataElements();
-        
+
         assertEquals( dataElements.size(), 2 );
-        
+
         assertTrue( dataElements.contains( dataElementA ) );
         assertTrue( dataElements.contains( dataElementDModified ) );
-        
+
         Collection<DataElementGroup> dataElementGroups = dataElementService.getAllDataElementGroups();
-        
+
         assertEquals( dataElementGroups.size(), 2 );
-        
+
         assertTrue( dataElementGroups.contains( dataElementGroupA ) );
         assertTrue( dataElementGroups.contains( dataElementGroupCDuplicate ) );
-        
+
         for ( DataElementGroup dataElementGroup : dataElementGroups )
         {
             assertEquals( dataElementGroup.getMembers().size(), 2 );
-            
+
             assertTrue( dataElementGroup.getMembers().containsAll( dataElements ) );
         }
 
@@ -781,15 +778,15 @@
     public void testDeleteAndImportAll()
     {
         dataElementService.addDataElement( dataElementA );
-        
+
         dataElementGroupA.getMembers().add( dataElementA );
-        
+
         dataElementService.addDataElementGroup( dataElementGroupA );
-        
+
         int importObjectIdA = importObjectService.addImportObject( ImportObjectStatus.NEW, dataElementBModified, null );
         int importObjectIdB = importObjectService.addImportObject( ImportObjectStatus.NEW, dataElementCModified, null );
         importObjectService.addImportObject( ImportObjectStatus.NEW, dataElementDModified, null );
-        
+
         int importObjectIdC = importObjectService.addImportObject( ImportObjectStatus.NEW, dataElementGroupBDuplicate, null );
         importObjectService.addImportObject( ImportObjectStatus.NEW, dataElementGroupCDuplicate, null );
 
@@ -801,31 +798,31 @@
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationL );
 
         dbmsManager.clearSession();
-        
+
         importObjectService.cascadeDeleteImportObject( importObjectIdA );
         importObjectService.cascadeDeleteImportObject( importObjectIdB );
         importObjectService.cascadeDeleteImportObject( importObjectIdC );
-                
+
         importObjectService.importAll();
-        
+
         Collection<DataElement> dataElements = dataElementService.getAllDataElements();
-        
+
         assertEquals( dataElements.size(), 2 );
-        
+
         assertTrue( dataElements.contains( dataElementA ) );
         assertTrue( dataElements.contains( dataElementDModified ) );
-        
+
         Collection<DataElementGroup> dataElementGroups = dataElementService.getAllDataElementGroups();
-        
+
         assertEquals( dataElementGroups.size(), 2 );
-        
+
         assertTrue( dataElementGroups.contains( dataElementGroupA ) );
         assertTrue( dataElementGroups.contains( dataElementGroupCDuplicate ) );
-        
+
         for ( DataElementGroup dataElementGroup : dataElementGroups )
         {
             assertEquals( dataElementGroup.getMembers().size(), 1 );
-        }        
+        }
 
         assertEquals( importObjectService.getImportObjects( DataElement.class ).size(), 0 );
         assertEquals( importObjectService.getImportObjects( DataElementGroup.class ).size(), 0 );
@@ -839,29 +836,29 @@
         importObjectService.addImportObject( ImportObjectStatus.NEW, organisationUnitAModified, null );
         importObjectService.addImportObject( ImportObjectStatus.NEW, organisationUnitBModified, null );
         importObjectService.addImportObject( ImportObjectStatus.NEW, organisationUnitCModified, null );
-        
+
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.ORGANISATIONUNITRELATIONSHIP, relationshipAssociationA );
         importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.ORGANISATIONUNITRELATIONSHIP, relationshipAssociationB );
 
-        dbmsManager.clearSession();       
-        
+        dbmsManager.clearSession();
+
         importObjectService.importAll();
-        
-        organisationUnitAModified = organisationUnitService.getOrganisationUnitByName( organisationUnitAModified.getName() );
-        organisationUnitBModified = organisationUnitService.getOrganisationUnitByName( organisationUnitBModified.getName() );
-        organisationUnitCModified = organisationUnitService.getOrganisationUnitByName( organisationUnitCModified.getName() );
-        
+
+        organisationUnitAModified = organisationUnitService.getOrganisationUnitByName( organisationUnitAModified.getName() ).get( 0 );
+        organisationUnitBModified = organisationUnitService.getOrganisationUnitByName( organisationUnitBModified.getName() ).get( 0 );
+        organisationUnitCModified = organisationUnitService.getOrganisationUnitByName( organisationUnitCModified.getName() ).get( 0 );
+
         assertNotNull( organisationUnitAModified );
         assertNotNull( organisationUnitBModified );
         assertNotNull( organisationUnitCModified );
-        
+
         assertNull( organisationUnitAModified.getParent() );
         assertNotNull( organisationUnitBModified.getParent() );
         assertNotNull( organisationUnitCModified.getParent() );
-                        
+
         assertTrue( organisationUnitBModified.getParent().equals( organisationUnitAModified ) );
         assertTrue( organisationUnitCModified.getParent().equals( organisationUnitBModified ) );
-        
+
         assertEquals( importObjectService.getImportObjects( OrganisationUnit.class ).size(), 0 );
         assertEquals( importObjectService.getImportObjects( GroupMemberAssociation.class ).size(), 0 );
     }
@@ -873,17 +870,17 @@
         importObjectService.addImportObject( ImportObjectStatus.NEW, dataElementAModified, null );
         importObjectService.addImportObject( ImportObjectStatus.NEW, dataElementBModified, null );
         importObjectService.addImportObject( ImportObjectStatus.NEW, dataElementCModified, null );
-        
+
         importObjectService.addImportObject( ImportObjectStatus.NEW, periodADuplicate, null );
-        
+
         importObjectService.addImportObject( ImportObjectStatus.NEW, organisationUnitAModified, null );
         importObjectService.addImportObject( ImportObjectStatus.NEW, organisationUnitBModified, null );
         importObjectService.addImportObject( ImportObjectStatus.NEW, organisationUnitCModified, null );
-        
+
         BatchHandler<ImportDataValue> batchHandler = batchHandlerFactory.createBatchHandler( ImportDataValueBatchHandler.class );
-        
+
         batchHandler.init();
-        
+
         batchHandler.addObject( new ImportDataValue( dataValueADuplicate, ImportObjectStatus.NEW ) );
         batchHandler.addObject( new ImportDataValue( dataValueBDuplicate, ImportObjectStatus.NEW ) );
         batchHandler.addObject( new ImportDataValue( dataValueCDuplicate, ImportObjectStatus.NEW ) );
@@ -893,21 +890,21 @@
         batchHandler.addObject( new ImportDataValue( dataValueGDuplicate, ImportObjectStatus.NEW ) );
         batchHandler.addObject( new ImportDataValue( dataValueHDuplicate, ImportObjectStatus.NEW ) );
         batchHandler.addObject( new ImportDataValue( dataValueIDuplicate, ImportObjectStatus.NEW ) );
-        
+
         batchHandler.flush();
 
         dbmsManager.clearSession();
-        
+
         importObjectService.importAll();
-        
+
         assertEquals( dataElementService.getAllDataElements().size(), 3 );
-        
+
         assertEquals( periodService.getPeriodsByPeriodType( periodTypeA ).size(), 1 );
-        
+
         assertEquals( organisationUnitService.getAllOrganisationUnits().size(), 3 );
-        
+
         assertEquals( dataValueService.getAllDataValues().size(), 9 );
-        
+
         assertEquals( importObjectService.getImportObjects( DataElement.class ).size(), 0 );
         assertEquals( importObjectService.getImportObjects( Period.class ).size(), 0 );
         assertEquals( importObjectService.getImportObjects( OrganisationUnit.class ).size(), 0 );
@@ -920,29 +917,29 @@
         dataElementService.addDataElement( dataElementA );
         dataElementService.addDataElement( dataElementB );
         dataElementService.addDataElement( dataElementC );
-        
+
         organisationUnitService.addOrganisationUnit( organisationUnitA );
         organisationUnitService.addOrganisationUnit( organisationUnitB );
         organisationUnitService.addOrganisationUnit( organisationUnitC );
 
         dataValueService.addDataValue( dataValueA );
         dataValueService.addDataValue( dataValueE );
-        dataValueService.addDataValue( dataValueI );        
-        
+        dataValueService.addDataValue( dataValueI );
+
         importObjectService.addImportObject( ImportObjectStatus.UPDATE, dataElementAModified, dataElementA );
         importObjectService.addImportObject( ImportObjectStatus.UPDATE, dataElementBModified, dataElementB );
         importObjectService.addImportObject( ImportObjectStatus.UPDATE, dataElementCModified, dataElementC );
-        
+
         importObjectService.addImportObject( ImportObjectStatus.MATCH, periodADuplicate, null );
-        
+
         importObjectService.addImportObject( ImportObjectStatus.UPDATE, organisationUnitAModified, organisationUnitA );
         importObjectService.addImportObject( ImportObjectStatus.UPDATE, organisationUnitBModified, organisationUnitB );
         importObjectService.addImportObject( ImportObjectStatus.UPDATE, organisationUnitCModified, organisationUnitC );
 
         BatchHandler<ImportDataValue> batchHandler = batchHandlerFactory.createBatchHandler( ImportDataValueBatchHandler.class );
-        
+
         batchHandler.init();
-        
+
         batchHandler.addObject( new ImportDataValue( dataValueADuplicate, ImportObjectStatus.UPDATE ) );
         batchHandler.addObject( new ImportDataValue( dataValueBDuplicate, ImportObjectStatus.NEW ) );
         batchHandler.addObject( new ImportDataValue( dataValueCDuplicate, ImportObjectStatus.NEW ) );
@@ -952,21 +949,21 @@
         batchHandler.addObject( new ImportDataValue( dataValueGDuplicate, ImportObjectStatus.NEW ) );
         batchHandler.addObject( new ImportDataValue( dataValueHDuplicate, ImportObjectStatus.NEW ) );
         batchHandler.addObject( new ImportDataValue( dataValueIDuplicate, ImportObjectStatus.UPDATE ) );
-        
+
         batchHandler.flush();
 
         dbmsManager.clearSession();
-        
+
         importObjectService.importAll();
 
         assertEquals( dataElementService.getAllDataElements().size(), 3 );
-        
+
         assertEquals( periodService.getPeriodsByPeriodType( periodTypeA ).size(), 1 );
-        
+
         assertEquals( organisationUnitService.getAllOrganisationUnits().size(), 3 );
-        
+
         assertEquals( dataValueService.getAllDataValues().size(), 9 );
-        
+
         assertEquals( importObjectService.getImportObjects( DataElement.class ).size(), 0 );
         assertEquals( importObjectService.getImportObjects( Period.class ).size(), 0 );
         assertEquals( importObjectService.getImportObjects( OrganisationUnit.class ).size(), 0 );

=== modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java'
--- dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java	2013-02-04 03:14:27 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java	2013-02-04 14:57:16 +0000
@@ -392,7 +392,7 @@
     }
 
     @Override
-    public Collection<T> getAllEqName( String name )
+    public List<T> getAllEqName( String name )
     {
         Query query = sharingEnabled() ? getQueryAllEqNameACL( name ) : getQueryAllEqName( name );
 
@@ -423,7 +423,38 @@
     }
 
     @Override
-    public Collection<T> getAllEqShortName( String shortName )
+    public List<T> getAllEqNameIgnoreCase( String name )
+    {
+        Query query = sharingEnabled() ? getQueryAllEqNameACLIgnoreCase( name ) : getQueryAllEqNameIgnoreCase( name );
+
+        return query.list();
+    }
+
+    private Query getQueryAllEqNameACLIgnoreCase( String name )
+    {
+        String hql = "select distinct c from " + clazz.getName() + " c"
+            + " where lower(name) = :name and ( c.publicAccess like 'r%' or c.user IS NULL or c.user=:user"
+            + " or exists "
+            + "     (from c.userGroupAccesses uga join uga.userGroup ug join ug.members ugm where ugm = :user and uga.access like 'r%')"
+            + " ) order by c.name";
+
+        Query query = getQuery( hql );
+        query.setEntity( "user", currentUserService.getCurrentUser() );
+        query.setString( "name", name.toLowerCase() );
+
+        return query;
+    }
+
+    private Query getQueryAllEqNameIgnoreCase( String name )
+    {
+        Query query = getQuery( "from " + clazz.getName() + " c where lower(name) = :name order by c.name" );
+        query.setString( "name", name.toLowerCase() );
+
+        return query;
+    }
+
+    @Override
+    public List<T> getAllEqShortName( String shortName )
     {
         Query query = sharingEnabled() ? getQueryAllEqShortNameACL( shortName ) : getQueryAllEqShortName( shortName );
 
@@ -454,6 +485,37 @@
     }
 
     @Override
+    public List<T> getAllEqShortNameIgnoreCase( String shortName )
+    {
+        Query query = sharingEnabled() ? getQueryAllEqShortNameACLIgnoreCase( shortName ) : getQueryAllEqShortNameIgnoreCase( shortName );
+
+        return query.list();
+    }
+
+    private Query getQueryAllEqShortNameACLIgnoreCase( String shortName )
+    {
+        String hql = "select distinct c from " + clazz.getName() + " c"
+            + " where lower(shortName) = :shortName and ( c.publicAccess like 'r%' or c.user IS NULL or c.user=:user"
+            + " or exists "
+            + "     (from c.userGroupAccesses uga join uga.userGroup ug join ug.members ugm where ugm = :user and uga.access like 'r%')"
+            + " ) order by c.shortName";
+
+        Query query = getQuery( hql );
+        query.setEntity( "user", currentUserService.getCurrentUser() );
+        query.setString( "shortName", shortName.toLowerCase() );
+
+        return query;
+    }
+
+    private Query getQueryAllEqShortNameIgnoreCase( String shortName )
+    {
+        Query query = getQuery( "from " + clazz.getName() + " c where lower(shortName) = :shortName order by c.shortName" );
+        query.setString( "shortName", shortName.toLowerCase() );
+
+        return query;
+    }
+
+    @Override
     @SuppressWarnings( "unchecked" )
     public Collection<T> getAllLikeName( String name )
     {

=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java	2013-02-03 05:46:01 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java	2013-02-04 14:57:16 +0000
@@ -491,16 +491,6 @@
                 return new ResponseEntity<String>( MessageResponseUtils.jsonMessage( "No object with that identifier exists." ),
                     headers, HttpStatus.NOT_FOUND );
             }
-            else if ( !organisationUnit.getName().equals( organisationUnitUpdate.getName() ) )
-            {
-                OrganisationUnit ouByName = organisationUnitService.getOrganisationUnitByName( organisationUnitUpdate.getName() );
-
-                if ( ouByName != null && !organisationUnit.getUid().equals( ouByName.getUid() ) )
-                {
-                    return new ResponseEntity<String>( MessageResponseUtils.jsonMessage( "Another object with the same name already exists." ),
-                        headers, HttpStatus.CONFLICT );
-                }
-            }
             else if ( organisationUnitUpdate.getCode() != null )
             {
                 OrganisationUnit ouByCode = organisationUnitService.getOrganisationUnitByCode( organisationUnitUpdate.getCode() );

=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityServiceController.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityServiceController.java	2012-12-13 17:04:35 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityServiceController.java	2013-02-04 14:57:16 +0000
@@ -179,16 +179,6 @@
                 return new ResponseEntity<String>( MessageResponseUtils.jsonMessage( "No object with that identifier exists." ),
                     headers, HttpStatus.NOT_FOUND );
             }
-            else if ( !ou.getName().equals( organisationUnit.getName() ) )
-            {
-                OrganisationUnit ouByName = organisationUnitService.getOrganisationUnitByName( organisationUnit.getName() );
-
-                if ( ouByName != null && !ou.getUid().equals( ouByName.getUid() ) )
-                {
-                    return new ResponseEntity<String>( MessageResponseUtils.jsonMessage( "Another object with the same name already exists." ),
-                        headers, HttpStatus.CONFLICT );
-                }
-            }
             else if ( organisationUnit.getCode() != null )
             {
                 OrganisationUnit ouByCode = organisationUnitService.getOrganisationUnitByCode( organisationUnit.getCode() );

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties	2013-02-03 08:35:03 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties	2013-02-04 14:57:16 +0000
@@ -271,6 +271,8 @@
 
 #-- About ----------------------------------------------------------------------#
 
+name_exists=Warning, name already exists
+name_is_required=Error, name is required
 version=Version
 build_revision=Build revision
 build_date=Build date

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/ValidateOrganisationUnitAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/ValidateOrganisationUnitAction.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/ValidateOrganisationUnitAction.java	2013-02-04 14:57:16 +0000
@@ -27,11 +27,12 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.opensymphony.xwork2.Action;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 
-import com.opensymphony.xwork2.Action;
+import java.util.List;
 
 /**
  * @author Torgeir Lorange Ostby
@@ -69,7 +70,7 @@
     {
         this.name = name;
     }
-    
+
     private String code;
 
     public void setCode( String code )
@@ -105,18 +106,37 @@
         // Validate values
         // ---------------------------------------------------------------------
 
-        if ( name != null )
+        if ( name != null && !name.trim().isEmpty() )
         {
-            OrganisationUnit match = organisationUnitService.getOrganisationUnitByName( name );
+            List<OrganisationUnit> organisationUnits = organisationUnitService.getOrganisationUnitByName( name );
 
-            if ( match != null && (id == null || match.getId() != id) )
+            if ( !organisationUnits.isEmpty() && id == null )
             {
-                message = i18n.getString( "name_in_use" );
+                message = i18n.getString( "name_exists" );
 
                 return ERROR;
             }
+            else if ( !organisationUnits.isEmpty() )
+            {
+                boolean found = false;
+
+                for ( OrganisationUnit organisationUnit : organisationUnits )
+                {
+                    if ( organisationUnit.getId() == id )
+                    {
+                        found = true;
+                    }
+                }
+
+                if ( !found )
+                {
+                    message = i18n.getString( "name_exists" );
+
+                    return ERROR;
+                }
+            }
         }
-        
+
         if ( code != null && !code.trim().isEmpty() )
         {
             OrganisationUnit match = organisationUnitService.getOrganisationUnitByCode( code );
@@ -126,9 +146,9 @@
                 message = i18n.getString( "code_in_use" );
 
                 return ERROR;
-            }            
+            }
         }
-        
+
         message = "OK";
 
         return SUCCESS;

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroup/ValidateOrganisationUnitGroupAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroup/ValidateOrganisationUnitGroupAction.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroup/ValidateOrganisationUnitGroupAction.java	2013-02-04 14:57:16 +0000
@@ -27,11 +27,12 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.opensymphony.xwork2.Action;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
 
-import com.opensymphony.xwork2.Action;
+import java.util.List;
 
 /**
  * @author Torgeir Lorange Ostby
@@ -97,16 +98,36 @@
         // ---------------------------------------------------------------------
         // Validate values
         // ---------------------------------------------------------------------
-        if ( name != null )
+
+        if ( name != null && !name.trim().isEmpty() )
         {
-            OrganisationUnitGroup match = organisationUnitGroupService.getOrganisationUnitGroupByName( name );
+            List<OrganisationUnitGroup> organisationUnitGroups = organisationUnitGroupService.getOrganisationUnitGroupByName( name );
 
-            if ( match != null && (id == null || match.getId() != id) )
+            if ( !organisationUnitGroups.isEmpty() && id == null )
             {
-                message = i18n.getString( "name_is_already_in_use" );
+                message = i18n.getString( "name_exists" );
 
                 return ERROR;
             }
+            else if ( !organisationUnitGroups.isEmpty() )
+            {
+                boolean found = false;
+
+                for ( OrganisationUnitGroup organisationUnitGroup : organisationUnitGroups )
+                {
+                    if ( organisationUnitGroup.getId() == id )
+                    {
+                        found = true;
+                    }
+                }
+
+                if ( !found )
+                {
+                    message = i18n.getString( "name_exists" );
+
+                    return ERROR;
+                }
+            }
         }
 
         message = "OK";

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroupset/ValidateGroupSetAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroupset/ValidateGroupSetAction.java	2012-01-25 17:11:43 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroupset/ValidateGroupSetAction.java	2013-02-04 14:57:16 +0000
@@ -27,20 +27,20 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.opensymphony.xwork2.Action;
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupSetPopulator;
+import org.hisp.dhis.system.util.ListUtils;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.HashSet;
 import java.util.List;
 
-import org.hisp.dhis.i18n.I18n;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
-import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
-import org.hisp.dhis.system.util.ListUtils;
-
-import com.opensymphony.xwork2.Action;
-
 /**
  * @author Lars Helge Overland
  * @version $Id$
@@ -75,7 +75,7 @@
     public void setName( String name )
     {
         this.name = name;
-    }    
+    }
 
     private Collection<Integer> selectedGroups = new HashSet<Integer>();
 
@@ -112,17 +112,36 @@
         // Validate values
         // ---------------------------------------------------------------------
 
-        if ( name != null )
+        if ( name != null && !name.trim().isEmpty() )
         {
-            OrganisationUnitGroupSet match = organisationUnitGroupService.getOrganisationUnitGroupSetByName( name );
+            List<OrganisationUnitGroupSet> organisationUnitGroupSets = organisationUnitGroupService.getOrganisationUnitGroupSetByName( name );
 
-            if ( match != null && (id == null || match.getId() != id) )
+            if ( !organisationUnitGroupSets.isEmpty() && id == null )
             {
-                message = i18n.getString( "name_in_use" );
+                message = i18n.getString( "name_exists" );
 
                 return ERROR;
             }
-        }      
+            else if ( !organisationUnitGroupSets.isEmpty() )
+            {
+                boolean found = false;
+
+                for ( OrganisationUnitGroupSet organisationUnitGroupSet : organisationUnitGroupSets )
+                {
+                    if ( organisationUnitGroupSet.getId() == id )
+                    {
+                        found = true;
+                    }
+                }
+
+                if ( !found )
+                {
+                    message = i18n.getString( "name_exists" );
+
+                    return ERROR;
+                }
+            }
+        }
 
         // ---------------------------------------------------------------------
         // When adding or updating an exclusive group set any unit in the

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/addOrganisationUnitForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/addOrganisationUnitForm.vm	2013-02-03 10:13:17 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/addOrganisationUnitForm.vm	2013-02-04 14:57:16 +0000
@@ -10,7 +10,7 @@
 	        },
 			'rules' : getValidationRules("organisationUnit")
 		});
-	
+
         checkValueIsExist("name", "validateOrganisationUnit.action");
         checkValueIsExist("code", "validateOrganisationUnit.action");
         datePickerValid('openingDate', false);

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetOrganisationUnitInfoFacilityAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetOrganisationUnitInfoFacilityAction.java	2012-10-01 16:08:41 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetOrganisationUnitInfoFacilityAction.java	2013-02-04 14:57:16 +0000
@@ -92,7 +92,7 @@
         object = organisationUnitService.getOrganisationUnit( id );
 
         OrganisationUnitGroupSet typeGroupSet = organisationUnitGroupService
-            .getOrganisationUnitGroupSetByName( OrganisationUnitGroupSetPopulator.NAME_TYPE );
+            .getOrganisationUnitGroupSetByName( OrganisationUnitGroupSetPopulator.NAME_TYPE ).get( 0 );
 
         object.setType( object.getGroupNameInGroupSet( typeGroupSet ) );