← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18177: support merge strategy in dxf2 importer, defaults to MERGE_IF_NOT_NULL

 

------------------------------------------------------------
revno: 18177
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-02-05 14:52:28 +0700
message:
  support merge strategy in dxf2 importer, defaults to MERGE_IF_NOT_NULL
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportOptions.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.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-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportOptions.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportOptions.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportOptions.java	2015-02-05 07:52:28 +0000
@@ -29,22 +29,23 @@
  */
 
 import org.hisp.dhis.common.IdentifiableProperty;
+import org.hisp.dhis.common.MergeStrategy;
 import org.hisp.dhis.importexport.ImportStrategy;
 
 /**
  * The idScheme is a general setting which will apply to all objects. The idSchemes
  * can also be defined for specific objects such as dataElementIdScheme. The
  * general setting will override specific settings.
- * 
+ *
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
 public class ImportOptions
 {
-    private static final ImportOptions DEFAULT_OPTIONS = new ImportOptions( 
+    private static final ImportOptions DEFAULT_OPTIONS = new ImportOptions(
         IdentifiableProperty.UID, IdentifiableProperty.UID, false, true, ImportStrategy.NEW_AND_UPDATES, false );
 
     private IdentifiableProperty idScheme;
-    
+
     private IdentifiableProperty dataElementIdScheme;
 
     private IdentifiableProperty orgUnitIdScheme;
@@ -57,6 +58,8 @@
 
     private ImportStrategy importStrategy;
 
+    private MergeStrategy mergeStrategy = MergeStrategy.MERGE_IF_NOT_NULL;
+
     private boolean skipExistingCheck;
 
     private boolean sharing;
@@ -74,7 +77,7 @@
         this.importStrategy = importStrategy;
     }
 
-    public ImportOptions( IdentifiableProperty dataElementIdScheme, IdentifiableProperty orgUnitIdScheme, 
+    public ImportOptions( IdentifiableProperty dataElementIdScheme, IdentifiableProperty orgUnitIdScheme,
         boolean dryRun, boolean preheatCache, ImportStrategy importStrategy, boolean skipExistingCheck )
     {
         this.dataElementIdScheme = dataElementIdScheme;
@@ -85,7 +88,7 @@
         this.skipExistingCheck = skipExistingCheck;
     }
 
-    public ImportOptions( IdentifiableProperty idScheme, IdentifiableProperty dataElementIdScheme, IdentifiableProperty orgUnitIdScheme, 
+    public ImportOptions( IdentifiableProperty idScheme, IdentifiableProperty dataElementIdScheme, IdentifiableProperty orgUnitIdScheme,
         boolean dryRun, boolean preheatCache, ImportStrategy importStrategy, boolean skipExistingCheck )
     {
         this.idScheme = idScheme;
@@ -117,14 +120,14 @@
 
     public IdentifiableProperty getDataElementIdScheme()
     {
-        return dataElementIdScheme != null ? dataElementIdScheme : ( idScheme != null ? idScheme : IdentifiableProperty.UID );
+        return dataElementIdScheme != null ? dataElementIdScheme : (idScheme != null ? idScheme : IdentifiableProperty.UID);
     }
 
     public IdentifiableProperty getOrgUnitIdScheme()
     {
-        return orgUnitIdScheme != null ? orgUnitIdScheme : ( idScheme != null ? idScheme : IdentifiableProperty.UID );
+        return orgUnitIdScheme != null ? orgUnitIdScheme : (idScheme != null ? idScheme : IdentifiableProperty.UID);
     }
-    
+
     public boolean isDryRun()
     {
         return dryRun;
@@ -140,6 +143,11 @@
         return importStrategy != null ? importStrategy : ImportStrategy.NEW_AND_UPDATES;
     }
 
+    public MergeStrategy getMergeStrategy()
+    {
+        return mergeStrategy;
+    }
+
     public boolean isSkipExistingCheck()
     {
         return skipExistingCheck;

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2015-02-05 06:53:38 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2015-02-05 07:52:28 +0000
@@ -449,12 +449,12 @@
         if ( !options.isSharing() )
         {
             User persistedObjectUser = persistedObject.getUser();
-            persistedObject.mergeWith( object, MergeStrategy.MERGE_IF_NOT_NULL );
+            persistedObject.mergeWith( object, options.getMergeStrategy() );
             persistedObject.setUser( persistedObjectUser );
         }
         else
         {
-            persistedObject.mergeWith( object, MergeStrategy.MERGE_IF_NOT_NULL );
+            persistedObject.mergeWith( object, options.getMergeStrategy() );
             persistedObject.mergeSharingWith( object );
         }
 
@@ -478,7 +478,7 @@
                     userService.encodeAndSetPassword( userCredentials, userCredentials.getPassword() );
                 }
 
-                ((User) persistedObject).getUserCredentials().mergeWith( userCredentials, MergeStrategy.MERGE_IF_NOT_NULL );
+                ((User) persistedObject).getUserCredentials().mergeWith( userCredentials, options.getMergeStrategy() );
                 reattachCollectionFields( ((User) persistedObject).getUserCredentials(), collectionFieldsUserCredentials, user );
 
                 sessionFactory.getCurrentSession().saveOrUpdate( ((User) persistedObject).getUserCredentials() );