=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2012-05-17 11:28:33 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2012-05-17 12:05:39 +0000 @@ -114,7 +114,7 @@ * @param object Object to import * @return An ImportConflict instance if there was a conflict, otherwise null */ - protected List newObject( T object ) + protected List newObject( T object, ImportOptions options ) { List importConflicts = new ArrayList(); @@ -129,11 +129,11 @@ Map> identifiableObjectCollections = scanIdentifiableObjectCollections( object ); - importConflicts.addAll( updateIdentifiableObjects( object, scanIdentifiableObjects( object ) ) ); + importConflicts.addAll( updateIdentifiableObjects( object, scanIdentifiableObjects( object ), options ) ); objectBridge.saveObject( object ); - importConflicts.addAll( updateIdentifiableObjectCollections( object, identifiableObjectCollections ) ); + importConflicts.addAll( updateIdentifiableObjectCollections( object, identifiableObjectCollections, options ) ); updatePeriodTypes( object ); objectBridge.updateObject( object ); @@ -150,15 +150,15 @@ * @param oldObject The current version of the object * @return An ImportConflict instance if there was a conflict, otherwise null */ - protected List updatedObject( T object, T oldObject ) + protected List updatedObject( T object, T oldObject, ImportOptions options ) { List importConflicts = new ArrayList(); log.debug( "Starting update of object " + getDisplayName( oldObject ) + " (" + oldObject.getClass() .getSimpleName() + ")" ); - importConflicts.addAll( updateIdentifiableObjects( object, scanIdentifiableObjects( object ) ) ); - importConflicts.addAll( updateIdentifiableObjectCollections( object, scanIdentifiableObjectCollections( object ) ) ); + importConflicts.addAll( updateIdentifiableObjects( object, scanIdentifiableObjects( object ), options ) ); + importConflicts.addAll( updateIdentifiableObjectCollections( object, scanIdentifiableObjectCollections( object ), options ) ); oldObject.mergeWith( object ); updatePeriodTypes( oldObject ); @@ -318,7 +318,7 @@ if ( ImportStrategy.NEW.equals( options.getImportStrategy() ) ) { - importConflicts.addAll( newObject( object ) ); + importConflicts.addAll( newObject( object, options ) ); if ( importConflicts.isEmpty() ) { @@ -327,7 +327,7 @@ } else if ( ImportStrategy.UPDATES.equals( options.getImportStrategy() ) ) { - importConflicts.addAll( updatedObject( object, oldObject ) ); + importConflicts.addAll( updatedObject( object, oldObject, options ) ); if ( importConflicts.isEmpty() ) { @@ -338,7 +338,7 @@ { if ( oldObject != null ) { - importConflicts.addAll( updatedObject( object, oldObject ) ); + importConflicts.addAll( updatedObject( object, oldObject, options ) ); if ( importConflicts.isEmpty() ) { @@ -347,7 +347,7 @@ } else { - importConflicts.addAll( newObject( object ) ); + importConflicts.addAll( newObject( object, options ) ); if ( importConflicts.isEmpty() ) { @@ -449,7 +449,7 @@ return new ImportConflict( getDisplayName( object ), "Object already exists." ); } - private IdentifiableObject findObjectByReference( IdentifiableObject identifiableObject ) + private IdentifiableObject findObjectByReference( IdentifiableObject identifiableObject, ImportOptions options ) { if ( identifiableObject == null ) { @@ -461,7 +461,10 @@ Period period = (Period) identifiableObject; period = periodStore.reloadForceAddPeriod( period ); - sessionFactory.getCurrentSession().flush(); + if(!options.isDryRun()) + { + sessionFactory.getCurrentSession().flush(); + } return period; } @@ -483,22 +486,24 @@ if ( ref != null ) { identifiableObjects.put( field, ref ); + ReflectionUtils.invokeSetterMethod( field.getName(), identifiableObject, new Object[]{ null } ); } } + } return identifiableObjects; } - private List updateIdentifiableObjects( IdentifiableObject identifiableObject, Map identifiableObjects ) + private List updateIdentifiableObjects( IdentifiableObject identifiableObject, + Map identifiableObjects, ImportOptions options ) { List importConflicts = new ArrayList(); for ( Field field : identifiableObjects.keySet() ) { IdentifiableObject idObject = identifiableObjects.get( field ); - IdentifiableObject ref = findObjectByReference( idObject ); + IdentifiableObject ref = findObjectByReference( idObject, options ); if ( ref == null ) { @@ -514,14 +519,17 @@ importConflicts.add( importConflict ); } - ReflectionUtils.invokeSetterMethod( field.getName(), identifiableObject, ref ); + if ( !options.isDryRun() ) + { + ReflectionUtils.invokeSetterMethod( field.getName(), identifiableObject, ref ); + } } return importConflicts; } - private Map> scanIdentifiableObjectCollections( IdentifiableObject - identifiableObject ) + private Map> scanIdentifiableObjectCollections( + IdentifiableObject identifiableObject ) { Map> collected = new HashMap>(); Field[] fields = identifiableObject.getClass().getDeclaredFields(); @@ -549,7 +557,7 @@ } private List updateIdentifiableObjectCollections( IdentifiableObject identifiableObject, - Map> identifiableObjectCollections ) + Map> identifiableObjectCollections, ImportOptions options ) { List importConflicts = new ArrayList(); @@ -574,7 +582,7 @@ for ( IdentifiableObject idObject : identifiableObjects ) { - IdentifiableObject ref = findObjectByReference( idObject ); + IdentifiableObject ref = findObjectByReference( idObject, options ); if ( ref != null ) { @@ -595,7 +603,10 @@ } } - ReflectionUtils.invokeSetterMethod( field.getName(), identifiableObject, objects ); + if ( !options.isDryRun() ) + { + ReflectionUtils.invokeSetterMethod( field.getName(), identifiableObject, objects ); + } } return importConflicts;