← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13243: added new strategies to ImportStrategy, CREATE, UPDATE, CREATE_AND_UPDATE, DELETE. ImportStrategy...

 

------------------------------------------------------------
revno: 13243
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-12-16 09:58:27 +0100
message:
  added new strategies to ImportStrategy, CREATE, UPDATE, CREATE_AND_UPDATE, DELETE. ImportStrategy.isCreate, .isUpdate, .isCreateAndUpdate, isDelete should be used (since two strategies can be equal)
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/importexport/ImportStrategy.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/AbstractImporter.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/importexport/ImportStrategy.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/importexport/ImportStrategy.java	2013-12-12 13:27:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/importexport/ImportStrategy.java	2013-12-16 08:58:27 +0000
@@ -31,10 +31,35 @@
 /**
  * @author Lars Helge Overland
  */
-public enum ImportStrategy 
+public enum ImportStrategy
 {
+    CREATE,
+    UPDATE,
+    CREATE_AND_UPDATE,
+    DELETE,
+
     NEW_AND_UPDATES,
     NEW,
     UPDATES,
-    DELETES
+    DELETES;
+
+    public boolean isCreate()
+    {
+        return this.equals( NEW ) || this.equals( CREATE );
+    }
+
+    public boolean isUpdate()
+    {
+        return this.equals( UPDATES ) || this.equals( UPDATE );
+    }
+
+    public boolean isCreateAndUpdate()
+    {
+        return this.equals( NEW_AND_UPDATES ) || this.equals( CREATE_AND_UPDATE );
+    }
+
+    public boolean isDelete()
+    {
+        return this.equals( DELETE ) || this.equals( DELETES );
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java	2013-12-12 13:27:33 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java	2013-12-16 08:58:27 +0000
@@ -412,7 +412,7 @@
 
             if ( !skipExistingCheck && batchHandler.objectExists( internalValue ) )
             {
-                if ( NEW_AND_UPDATES.equals( strategy ) || UPDATES.equals( strategy ) )
+                if ( strategy.isCreateAndUpdate() || strategy.isUpdate() )
                 {
                     if ( !dryRun )
                     {
@@ -424,7 +424,7 @@
             }
             else
             {
-                if ( NEW_AND_UPDATES.equals( strategy ) || NEW.equals( strategy ) )
+                if ( strategy.isCreateAndUpdate() || strategy.isCreate() )
                 {
                     if ( !dryRun )
                     {

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java	2013-12-13 16:03:24 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java	2013-12-16 08:58:27 +0000
@@ -35,7 +35,6 @@
 import org.hisp.dhis.cache.HibernateCacheManager;
 import org.hisp.dhis.dxf2.timer.SystemNanoTimer;
 import org.hisp.dhis.dxf2.timer.Timer;
-import org.hisp.dhis.importexport.ImportStrategy;
 import org.hisp.dhis.scheduling.TaskId;
 import org.hisp.dhis.system.notification.NotificationLevel;
 import org.hisp.dhis.system.notification.Notifier;
@@ -68,7 +67,7 @@
     // Dependencies
     //-------------------------------------------------------------------------------------------------------
 
-    @Autowired( required = false )
+    @Autowired(required = false)
     private Set<Importer> importerClasses = new HashSet<Importer>();
 
     @Autowired
@@ -128,7 +127,7 @@
 
         List<String> types;
 
-        if ( ImportStrategy.DELETES.equals( importOptions.getImportStrategy() ) )
+        if ( importOptions.getImportStrategy().isDelete() )
         {
             types = Lists.reverse( Lists.newArrayList( ExchangeClasses.getImportMap().values() ) );
         }

=== 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	2013-12-13 10:01:25 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2013-12-16 08:58:27 +0000
@@ -57,7 +57,6 @@
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.PeriodType;
-import org.hisp.dhis.sqlview.SqlView;
 import org.hisp.dhis.system.util.CollectionUtils;
 import org.hisp.dhis.system.util.ReflectionUtils;
 import org.hisp.dhis.system.util.functional.Function1;
@@ -111,7 +110,7 @@
     @Autowired
     private SessionFactory sessionFactory;
 
-    @Autowired( required = false )
+    @Autowired(required = false)
     private List<ObjectHandler<T>> objectHandlers;
 
     //-------------------------------------------------------------------------------------------------------
@@ -165,7 +164,7 @@
                 deleteExpression( object, "rightSide" );
                 deleteDataEntryForm( object, "dataEntryForm" );
 
-                if ( ImportStrategy.DELETES.equals( options.getImportStrategy() ) )
+                if ( options.getImportStrategy().isDelete() )
                 {
                     deleteDataElementOperands( object, "compulsoryDataElementOperands" );
                 }
@@ -677,14 +676,14 @@
     {
         T persistedObject = objectBridge.getObject( object );
 
-        if ( ImportStrategy.NEW.equals( options.getImportStrategy() ) )
+        if ( options.getImportStrategy().isCreate() )
         {
             if ( newObject( user, object ) )
             {
                 summaryType.incrementImported();
             }
         }
-        else if ( ImportStrategy.UPDATES.equals( options.getImportStrategy() ) )
+        else if ( options.getImportStrategy().isUpdate() )
         {
             if ( updateObject( user, object, persistedObject ) )
             {
@@ -695,7 +694,7 @@
                 summaryType.incrementIgnored();
             }
         }
-        else if ( ImportStrategy.NEW_AND_UPDATES.equals( options.getImportStrategy() ) )
+        else if ( options.getImportStrategy().isCreateAndUpdate() )
         {
             if ( persistedObject != null )
             {
@@ -720,7 +719,7 @@
                 }
             }
         }
-        else if ( ImportStrategy.DELETES.equals( options.getImportStrategy() ) )
+        else if ( options.getImportStrategy().isDelete() )
         {
             if ( deleteObject( user, persistedObject ) )
             {
@@ -738,7 +737,7 @@
         ImportConflict conflict = null;
         boolean success = true;
 
-        if ( ImportStrategy.DELETES.equals( options.getImportStrategy() ) )
+        if ( options.getImportStrategy().isDelete() )
         {
             success = validateForDeleteStrategy( object );
             return success;
@@ -764,15 +763,15 @@
             summaryType.getImportConflicts().add( conflict );
         }
 
-        if ( ImportStrategy.NEW.equals( options.getImportStrategy() ) )
+        if ( options.getImportStrategy().isCreate() )
         {
             success = validateForNewStrategy( object );
         }
-        else if ( ImportStrategy.UPDATES.equals( options.getImportStrategy() ) )
+        else if ( options.getImportStrategy().isUpdate() )
         {
             success = validateForUpdatesStrategy( object );
         }
-        else if ( ImportStrategy.NEW_AND_UPDATES.equals( options.getImportStrategy() ) )
+        else if ( options.getImportStrategy().isCreateAndUpdate() )
         {
             // if we have a match on at least one of the objects, then assume update
             if ( objectBridge.getObjects( object ).size() > 0 )

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/AbstractImporter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/AbstractImporter.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/AbstractImporter.java	2013-12-16 08:58:27 +0000
@@ -106,7 +106,7 @@
                     }
                 }
             }
-            else if ( params.getImportStrategy() == NEW_AND_UPDATES ) // Similar object exists
+            else if ( params.getImportStrategy().isCreateAndUpdate() ) // Similar object exists
             {
                 if ( !params.isPreview() ) // Import object
                 {