=== 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-03 10:24:37 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java 2012-04-03 12:59:54 +0000 @@ -145,7 +145,7 @@ if ( importer != null ) { List conflicts = importer.importCollection( objects, importOptions ); - ImportCount count = importer.getImportCount(); + ImportCount count = importer.getCurrentImportCount(); importSummary.getConflicts().addAll( conflicts ); importSummary.getCounts().add( count ); === 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-03 10:24:37 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Importer.java 2012-04-03 12:59:54 +0000 @@ -38,11 +38,28 @@ */ public interface Importer { + /** + * @param object Object to import + * @param options Import options + * @return ImportConflict instance if a conflict occurred, if not null + */ ImportConflict importObject( T object, ImportOptions options ); + /** + * Import a collection of objects. + * + * @param objects The collection to import + * @param options Import options + * @return List of all the ImportConflicts encountered + */ List importCollection( Collection objects, ImportOptions options ); - ImportCount getImportCount(); + /** + * Get an ImportCount instance for the current import numbers. + * + * @return ImportCount instance filled with current values + */ + ImportCount getCurrentImportCount(); boolean canHandle( Class clazz ); } === 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-03 10:24:37 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/AbstractImporter.java 2012-04-03 12:59:54 +0000 @@ -47,21 +47,53 @@ public abstract class AbstractImporter implements Importer { + //------------------------------------------------------------------------------------------------------- + // Dependencies + //------------------------------------------------------------------------------------------------------- + @Autowired private IdentifiableObjectManager manager; + //------------------------------------------------------------------------------------------------------- + // Current import counts + //------------------------------------------------------------------------------------------------------- + protected int imports; protected int updates; protected int ignores; + //------------------------------------------------------------------------------------------------------- + // Abstract methods that sub-classes needs to implement + //------------------------------------------------------------------------------------------------------- + + /** + * Called every time a new object is to be imported. + * + * @param object Object to import + */ protected abstract void newObject( T object ); + /** + * Update object from old => new. + * + * @param object Object to import + * @param oldObject The current version of the object + */ protected abstract void updatedObject( T object, T oldObject ); + /** + * Current object name, used to fill name part of a ImportConflict + * + * @return Name of object + */ protected abstract String getObjectName(); + //------------------------------------------------------------------------------------------------------- + // Importer Implementation + //------------------------------------------------------------------------------------------------------- + @Override public List importCollection( Collection objects, ImportOptions options ) { @@ -131,7 +163,7 @@ } @Override - public ImportCount getImportCount() + public ImportCount getCurrentImportCount() { ImportCount importCount = new ImportCount( getObjectName() ); @@ -142,6 +174,10 @@ return importCount; } + //------------------------------------------------------------------------------------------------------- + // Helpers + //------------------------------------------------------------------------------------------------------- + protected Map getIdMap( Class clazz, IdScheme scheme ) { if ( scheme.isUidScheme() )