=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java 2012-04-06 21:31:51 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java 2012-04-07 08:07:14 +0000 @@ -85,7 +85,7 @@ if ( importer != null ) { - List conflicts = importer.importCollection( objects, importOptions ); + List conflicts = importer.importObjects( objects, importOptions ); ImportCount count = importer.getCurrentImportCount(); importSummary.getConflicts().addAll( conflicts ); === modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/IdScheme.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/IdScheme.java 2012-04-06 14:20:16 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/IdScheme.java 2012-04-07 08:07:14 +0000 @@ -67,8 +67,8 @@ if ( scheme != null ) { uidScheme = scheme.equals( IdScheme.UID_SCHEME ); + nameScheme = scheme.equals( IdScheme.NAME_SCHEME ); codeScheme = scheme.equals( IdScheme.CODE_SCHEME ); - nameScheme = scheme.equals( IdScheme.NAME_SCHEME ); } } @@ -77,13 +77,13 @@ return uidScheme; } + public boolean isNameScheme() + { + return nameScheme; + } + public boolean isCodeScheme() { return codeScheme; } - - public boolean isNameScheme() - { - return nameScheme; - } } === modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Importer.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Importer.java 2012-04-06 14:20:16 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Importer.java 2012-04-07 08:07:14 +0000 @@ -38,7 +38,10 @@ public interface Importer { /** - * Import a single object, return null or a ImportConflict is there is a conflict + * Import a single object, return null or a ImportConflict is there is a conflict. + * + * This is meant to be a one-off import of a single object, if you want to import multiple + * objects, then use importObjects.. * * @param object Object to import * @param options Import options @@ -53,7 +56,7 @@ * @param options Import options * @return List of all the ImportConflicts encountered */ - List importCollection( List objects, ImportOptions options ); + List importObjects( List objects, ImportOptions options ); /** * Get an ImportCount instance for the current import numbers. === modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/AbstractImporter.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/AbstractImporter.java 2012-04-06 21:31:51 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/AbstractImporter.java 2012-04-07 08:07:14 +0000 @@ -141,7 +141,7 @@ //------------------------------------------------------------------------------------------------------- @Override - public List importCollection( List objects, ImportOptions options ) + public List importObjects( List objects, ImportOptions options ) { List conflicts = new ArrayList(); @@ -383,7 +383,7 @@ } else if ( uidObject != null && uidObject != nameObject ) { - conflict = reportNameConflict( object, options ); + conflict = reportUidConflict( object, options ); } else if ( codeObject != null && codeObject != nameObject ) { @@ -398,11 +398,11 @@ } else if ( uidObject != null && uidObject != codeObject ) { - conflict = reportNameConflict( object, options ); + conflict = reportUidConflict( object, options ); } else if ( nameObject != null && nameObject != codeObject ) { - conflict = reportCodeConflict( object, options ); + conflict = reportNameConflict( object, options ); } } @@ -435,32 +435,32 @@ private ImportConflict reportUidLookupConflict( IdentifiableObject object, ImportOptions options ) { - return new ImportConflict( getDisplayName( object, options.getIdScheme() ), "UID LOOKUP CONFLICT" ); + return new ImportConflict( getDisplayName( object, options.getIdScheme() ), "Object does not exist, lookup done using UID." ); } private ImportConflict reportNameLookupConflict( IdentifiableObject object, ImportOptions options ) { - return new ImportConflict( getDisplayName( object, options.getIdScheme() ), "NAME LOOKUP CONFLICT" ); + return new ImportConflict( getDisplayName( object, options.getIdScheme() ), "Object does not exist, lookup done using NAME." ); } private ImportConflict reportCodeLookupConflict( IdentifiableObject object, ImportOptions options ) { - return new ImportConflict( getDisplayName( object, options.getIdScheme() ), "CODE LOOKUP CONFLICT" ); + return new ImportConflict( getDisplayName( object, options.getIdScheme() ), "Object does not exist, lookup done using CODE." ); } private ImportConflict reportUidConflict( IdentifiableObject object, ImportOptions options ) { - return new ImportConflict( getDisplayName( object, options.getIdScheme() ), "UID CONFLICT" ); + return new ImportConflict( getDisplayName( object, options.getIdScheme() ), "Object already exists, lookup done using UID." ); } private ImportConflict reportNameConflict( IdentifiableObject object, ImportOptions options ) { - return new ImportConflict( getDisplayName( object, options.getIdScheme() ), "NAME CONFLICT" ); + return new ImportConflict( getDisplayName( object, options.getIdScheme() ), "Object already exists, lookup done using NAME." ); } private ImportConflict reportCodeConflict( IdentifiableObject object, ImportOptions options ) { - return new ImportConflict( getDisplayName( object, options.getIdScheme() ), "CODE CONFLICT" ); + return new ImportConflict( getDisplayName( object, options.getIdScheme() ), "Object already exists, lookup done using CODE." ); } private T getObject( T object, IdScheme scheme ) === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2012-03-29 16:45:18 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2012-04-07 08:07:14 +0000 @@ -27,16 +27,15 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.PostConstruct; import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Set; -import javax.annotation.PostConstruct; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.transaction.annotation.Transactional; - import static org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty; /** @@ -55,12 +54,12 @@ } private Map, GenericIdentifiableObjectStore> objectStoreMap; - + @PostConstruct public void init() { objectStoreMap = new HashMap, GenericIdentifiableObjectStore>(); - + for ( GenericIdentifiableObjectStore store : objectStores ) { objectStoreMap.put( store.getClazz(), store ); @@ -87,63 +86,83 @@ objectStoreMap.get( object.getClass() ).delete( object ); } - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) public Map getIdMap( Class clazz, IdentifiableProperty property ) { Map map = new HashMap(); - + GenericIdentifiableObjectStore store = (GenericIdentifiableObjectStore) objectStoreMap.get( clazz ); - + Collection objects = store.getAll(); - + for ( T object : objects ) { if ( IdentifiableProperty.ID.equals( property ) ) { - map.put( String.valueOf( object.getId() ), object ); + // since we are using primitives for ID, check that the ID is larger than 0, so that it is a valid + // hibernate identifier. + if ( object.getId() > 0 ) + { + map.put( String.valueOf( object.getId() ), object ); + } } else if ( IdentifiableProperty.UID.equals( property ) ) { - map.put( object.getUid(), object ); + if ( object.getUid() != null ) + { + map.put( object.getUid(), object ); + } + } + else if ( IdentifiableProperty.NAME.equals( property ) ) + { + if ( object.getName() != null ) + { + map.put( object.getName(), object ); + } } else if ( IdentifiableProperty.CODE.equals( property ) ) { - map.put( object.getCode(), object ); - } - else if ( IdentifiableProperty.NAME.equals( property ) ) - { - map.put( object.getName(), object ); + if ( object.getCode() != null ) + { + map.put( object.getCode(), object ); + } } } - + return map; } - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) public T getObject( Class clazz, IdentifiableProperty property, String id ) { GenericIdentifiableObjectStore store = (GenericIdentifiableObjectStore) objectStoreMap.get( clazz ); - - if ( IdentifiableProperty.ID.equals( property ) ) - { - return store.get( Integer.valueOf( id ) ); - } - else if ( IdentifiableProperty.UID.equals( property ) ) - { - return store.getByUid( id ); - } - else if ( IdentifiableProperty.CODE.equals( property ) ) - { - return store.getByCode( id ); - } - else if ( IdentifiableProperty.NAME.equals( property ) ) - { - return store.getByName( id ); - } - + + if ( id != null ) + { + if ( IdentifiableProperty.ID.equals( property ) ) + { + if ( Integer.valueOf( id ) > 0 ) + { + return store.get( Integer.valueOf( id ) ); + } + } + else if ( IdentifiableProperty.UID.equals( property ) ) + { + return store.getByUid( id ); + } + else if ( IdentifiableProperty.CODE.equals( property ) ) + { + return store.getByCode( id ); + } + else if ( IdentifiableProperty.NAME.equals( property ) ) + { + return store.getByName( id ); + } + } + throw new IllegalArgumentException( String.valueOf( property ) ); } - + public IdentifiableObject getObject( String uid, String simpleClassName ) { for ( GenericIdentifiableObjectStore objectStore : objectStores ) @@ -153,10 +172,10 @@ return objectStore.getByUid( uid ); } } - + return null; } - + public IdentifiableObject getObject( int id, String simpleClassName ) { for ( GenericIdentifiableObjectStore objectStore : objectStores ) @@ -166,7 +185,7 @@ return objectStore.get( id ); } } - + return null; } }