← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20912: minor fix, use NONE as default feature type in CSV import

 

------------------------------------------------------------
revno: 20912
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-11-02 10:24:16 +0700
message:
  minor fix, use NONE as default feature type in CSV import
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/csv/DefaultCsvImportService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/ImportEventTask.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JacksonEventService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java
  dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/event/ImportEventAction.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/csv/DefaultCsvImportService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/csv/DefaultCsvImportService.java	2015-10-15 10:08:08 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/csv/DefaultCsvImportService.java	2015-11-02 03:24:16 +0000
@@ -321,7 +321,7 @@
                 object.setOpeningDate( getMediumDate( getSafe( values, 7, "1970-01-01", null ) ) );
                 object.setClosedDate( getMediumDate( getSafe( values, 8, null, null ) ) );
                 object.setComment( getSafe( values, 9, null, null ) );
-                object.setFeatureType( FeatureType.valueOf( getSafe( values, 10, null, 50 ) ) );
+                object.setFeatureType( FeatureType.valueOf( getSafe( values, 10, "NONE", 50 ) ) );
                 object.setCoordinates( getSafe( values, 11, null, null ) );
                 object.setUrl( getSafe( values, 12, null, 255 ) );
                 object.setContactPerson( getSafe( values, 13, null, 255 ) );

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java	2015-10-22 03:37:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java	2015-11-02 03:24:16 +0000
@@ -66,6 +66,10 @@
 
     Event getEvent( ProgramStageInstance programStageInstance );
 
+    List<Event> getEventsXml( InputStream inputStream ) throws IOException;
+
+    List<Event> getEventsJson( InputStream inputStream ) throws IOException;
+
     // -------------------------------------------------------------------------
     // CREATE
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/ImportEventTask.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/ImportEventTask.java	2015-09-10 10:22:46 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/ImportEventTask.java	2015-11-02 03:24:16 +0000
@@ -28,12 +28,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import org.hisp.dhis.security.SecurityContextRunnable;
 import org.hisp.dhis.dxf2.common.ImportOptions;
 import org.hisp.dhis.scheduling.TaskId;
+import org.hisp.dhis.security.SecurityContextRunnable;
 
-import java.io.IOException;
-import java.io.InputStream;
+import java.util.List;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -41,7 +40,7 @@
 public class ImportEventTask
     extends SecurityContextRunnable
 {
-    private final InputStream inputStream;
+    private final List<Event> events;
 
     private final EventService eventService;
 
@@ -49,39 +48,17 @@
 
     private final TaskId taskId;
 
-    private final boolean jsonInput;
-
-    public ImportEventTask( InputStream inputStream, EventService eventService, ImportOptions importOptions, TaskId taskId, boolean jsonInput )
+    public ImportEventTask( List<Event> events, EventService eventService, ImportOptions importOptions, TaskId taskId )
     {
-        this.inputStream = inputStream;
+        this.events = events;
         this.eventService = eventService;
         this.importOptions = importOptions;
         this.taskId = taskId;
-        this.jsonInput = jsonInput;
     }
 
     @Override
     public void call()
     {
-        if ( jsonInput )
-        {
-            try
-            {
-                eventService.addEventsJson( inputStream, taskId, importOptions );
-            }
-            catch ( IOException ignored )
-            {
-            }
-        }
-        else
-        {
-            try
-            {
-                eventService.addEventsXml( inputStream, taskId, importOptions );
-            }
-            catch ( IOException ignored )
-            {
-            }
-        }
+        eventService.addEvents( events, importOptions, taskId );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JacksonEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JacksonEventService.java	2015-10-23 07:11:19 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JacksonEventService.java	2015-11-02 03:24:16 +0000
@@ -91,6 +91,46 @@
     }
 
     @Override
+    public List<Event> getEventsXml( InputStream inputStream ) throws IOException
+    {
+        String input = StreamUtils.copyToString( inputStream, Charset.forName( "UTF-8" ) );
+        List<Event> events = new ArrayList<>();
+
+        try
+        {
+            Events fromXml = fromXml( input, Events.class );
+            events.addAll( fromXml.getEvents() );
+        }
+        catch ( Exception ex )
+        {
+            Event fromXml = fromXml( input, Event.class );
+            events.add( fromXml );
+        }
+
+        return events;
+    }
+
+    @Override
+    public List<Event> getEventsJson( InputStream inputStream ) throws IOException
+    {
+        String input = StreamUtils.copyToString( inputStream, Charset.forName( "UTF-8" ) );
+        List<Event> events = new ArrayList<>();
+
+        try
+        {
+            Events fromXml = fromJson( input, Events.class );
+            events.addAll( fromXml.getEvents() );
+        }
+        catch ( Exception ex )
+        {
+            Event fromXml = fromJson( input, Event.class );
+            events.add( fromXml );
+        }
+
+        return events;
+    }
+
+    @Override
     public ImportSummaries addEventsXml( InputStream inputStream, ImportOptions importOptions ) throws IOException
     {
         return addEventsXml( inputStream, null, importOptions );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java	2015-10-23 04:36:05 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java	2015-11-02 03:24:16 +0000
@@ -80,6 +80,7 @@
 import java.io.OutputStream;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.zip.GZIPInputStream;
 import java.util.zip.GZIPOutputStream;
@@ -368,7 +369,8 @@
         else
         {
             TaskId taskId = new TaskId( TaskCategory.EVENT_IMPORT, currentUserService.getCurrentUser() );
-            scheduler.executeTask( new ImportEventTask( inputStream, eventService, importOptions, taskId, false ) );
+            List<Event> events = eventService.getEventsXml( inputStream );
+            scheduler.executeTask( new ImportEventTask( events, eventService, importOptions, taskId ) );
             response.setHeader( "Location", ContextUtils.getRootPath( request ) + "/system/tasks/" + TaskCategory.EVENT_IMPORT );
             response.setStatus( HttpServletResponse.SC_NO_CONTENT );
         }
@@ -407,7 +409,8 @@
         else
         {
             TaskId taskId = new TaskId( TaskCategory.EVENT_IMPORT, currentUserService.getCurrentUser() );
-            scheduler.executeTask( new ImportEventTask( inputStream, eventService, importOptions, taskId, true ) );
+            List<Event> events = eventService.getEventsJson( inputStream );
+            scheduler.executeTask( new ImportEventTask( events, eventService, importOptions, taskId ) );
             response.setHeader( "Location", ContextUtils.getRootPath( request ) + "/system/tasks/" + TaskCategory.EVENT_IMPORT );
             response.setStatus( HttpServletResponse.SC_NO_CONTENT );
         }

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/event/ImportEventAction.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/event/ImportEventAction.java	2015-08-30 17:07:42 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/event/ImportEventAction.java	2015-11-02 03:24:16 +0000
@@ -28,13 +28,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-
+import com.opensymphony.xwork2.Action;
 import org.hisp.dhis.common.IdentifiableProperty;
 import org.hisp.dhis.commons.util.StreamUtils;
 import org.hisp.dhis.dxf2.common.ImportOptions;
+import org.hisp.dhis.dxf2.events.event.Event;
 import org.hisp.dhis.dxf2.events.event.EventService;
 import org.hisp.dhis.dxf2.events.event.Events;
 import org.hisp.dhis.dxf2.events.event.ImportEventTask;
@@ -47,12 +45,15 @@
 import org.hisp.dhis.user.CurrentUserService;
 import org.springframework.beans.factory.annotation.Autowired;
 
-import com.opensymphony.xwork2.Action;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.List;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
-public class ImportEventAction 
+public class ImportEventAction
     implements Action
 {
     public static final String FORMAT_CSV = "csv";
@@ -144,8 +145,18 @@
         }
         else
         {
-            boolean jsonInput = FORMAT_JSON.equals( payloadFormat );
-            scheduler.executeTask( new ImportEventTask( in, eventService, importOptions, taskId, jsonInput ) );
+            List<Event> events;
+
+            if ( FORMAT_JSON.equals( payloadFormat ) )
+            {
+                events = eventService.getEventsJson( in );
+            }
+            else
+            {
+                events = eventService.getEventsXml( in );
+            }
+
+            scheduler.executeTask( new ImportEventTask( events, eventService, importOptions, taskId ) );
         }
 
         return SUCCESS;