← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17019: change default format of JdbcEventStore to use long format (iso 8601 compatible), speeds up csv e...

 

------------------------------------------------------------
revno: 17019
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-10-09 19:18:20 +0700
message:
  change default format of JdbcEventStore to use long format (iso 8601 compatible), speeds up csv export by 96%.
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/csv/DefaultCsvEventService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.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/events/event/AbstractEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java	2014-10-09 07:43:10 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java	2014-10-09 12:18:20 +0000
@@ -377,11 +377,16 @@
         List<OrganisationUnit> organisationUnits, TrackedEntityInstance trackedEntityInstance, Date startDate,
         Date endDate, EventStatus status )
     {
+        Timer<Long> timer = new SystemNanoTimer().start();
+
         List<Event> eventList = eventStore.getAll( program, programStage, programStatus, followUp, organisationUnits,
             trackedEntityInstance, startDate, endDate, status );
         Events events = new Events();
         events.setEvents( eventList );
 
+        timer.stop();
+        log.info( "Export done, completed in " + timer.toString() );
+
         return events;
     }
 

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java	2014-09-17 14:51:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java	2014-10-09 12:18:20 +0000
@@ -39,6 +39,7 @@
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramStage;
 import org.hisp.dhis.program.ProgramStatus;
+import org.hisp.dhis.system.util.DateUtils;
 import org.hisp.dhis.system.util.SqlHelper;
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -132,10 +133,14 @@
 
                 event.setStoredBy( rowSet.getString( "psi_completeduser" ) );
                 event.setOrgUnit( rowSet.getString( "ou_uid" ) );
+
                 event.setDueDate( StringUtils.defaultIfEmpty(
-                    rowSet.getString( "psi_duedate" ), rowSet.getString( "psi_duedate" ) ) );
+                    DateUtils.getLongDateString( rowSet.getDate( "psi_duedate" ) ), DateUtils.getLongDateString( rowSet.getDate(
+                        "psi_duedate" ) ) ) );
+
                 event.setEventDate( StringUtils.defaultIfEmpty(
-                    rowSet.getString( "psi_executiondate" ), rowSet.getString( "psi_executiondate" ) ) );
+                    DateUtils.getLongDateString( rowSet.getDate( "psi_executiondate" ) ), DateUtils.getLongDateString( rowSet.getDate(
+                        "psi_executiondate" ) ) ) );
 
                 if ( rowSet.getBoolean( "ps_capturecoordinates" ) )
                 {
@@ -204,9 +209,13 @@
         SqlHelper hlp = new SqlHelper();
 
         String sql =
-            "select pa.uid as tei_uid, pi.uid as pi_uid, pi.status as pi_status, pi.followup as pi_followup, p.uid as p_uid, p.type as p_type, ps.uid as ps_uid, ps.capturecoordinates as ps_capturecoordinates, pa.uid as pa_uid, psi.uid as psi_uid, psi.status as psi_status, ou.uid as ou_uid, " +
-                "psi.executiondate as psi_executiondate, psi.duedate as psi_duedate, psi.completeduser as psi_completeduser, psi.longitude as psi_longitude, psi.latitude as psi_latitude, " +
-                "psinote.trackedentitycommentid as psinote_id, psinote.commenttext as psinote_value, psinote.createddate as psinote_soreddate, psinote.creator as psinote_storedby, " +
+            "select pa.uid as tei_uid, pi.uid as pi_uid, pi.status as pi_status, pi.followup as pi_followup, p.uid as p_uid, " +
+                "p.type as p_type, ps.uid as ps_uid, ps.capturecoordinates as ps_capturecoordinates, pa.uid as pa_uid, " +
+                "psi.uid as psi_uid, psi.status as psi_status, ou.uid as ou_uid, " +
+                "psi.executiondate as psi_executiondate, psi.duedate as psi_duedate, psi.completeduser as psi_completeduser, " +
+                "psi.longitude as psi_longitude, psi.latitude as psi_latitude, " +
+                "psinote.trackedentitycommentid as psinote_id, psinote.commenttext as psinote_value, " +
+                "psinote.createddate as psinote_soreddate, psinote.creator as psinote_storedby, " +
                 "pdv.value as pdv_value, pdv.storedby as pdv_storedby, pdv.providedelsewhere as pdv_providedelsewhere, de.uid as de_uid " +
                 "from program p " +
                 "left join programstage ps on ps.programid=p.programid " +
@@ -300,11 +309,13 @@
             }
             else if ( status == EventStatus.SCHEDULE )
             {
-                sql += "and psi.executiondate is null and date(now()) <= date(psi.duedate) and psi.status = '" + EventStatus.SCHEDULE.name() + "' ";
+                sql += "and psi.executiondate is null and date(now()) <= date(psi.duedate) and psi.status = '" + EventStatus.SCHEDULE
+                    .name() + "' ";
             }
             else if ( status == EventStatus.OVERDUE )
             {
-                sql += "and psi.executiondate is null and date(now()) > date(psi.duedate) and psi.status = '" + EventStatus.SCHEDULE.name() + "' ";
+                sql += "and psi.executiondate is null and date(now()) > date(psi.duedate) and psi.status = '" + EventStatus.SCHEDULE.name
+                    () + "' ";
             }
             else
             {

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/csv/DefaultCsvEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/csv/DefaultCsvEventService.java	2014-10-08 07:48:52 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/csv/DefaultCsvEventService.java	2014-10-09 12:18:20 +0000
@@ -34,15 +34,11 @@
 import com.fasterxml.jackson.dataformat.csv.CsvMapper;
 import com.fasterxml.jackson.dataformat.csv.CsvParser;
 import com.fasterxml.jackson.dataformat.csv.CsvSchema;
-import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.hisp.dhis.dxf2.events.event.Coordinate;
 import org.hisp.dhis.dxf2.events.event.DataValue;
 import org.hisp.dhis.dxf2.events.event.Event;
 import org.hisp.dhis.dxf2.events.event.Events;
 import org.hisp.dhis.event.EventStatus;
-import org.hisp.dhis.program.ProgramStageInstance;
-import org.hisp.dhis.system.util.DateUtils;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.StringUtils;
 
 import java.io.IOException;
@@ -65,9 +61,6 @@
         csvMapper.enable( CsvParser.Feature.WRAP_AS_ARRAY );
     }
 
-    @Autowired
-    private IdentifiableObjectManager manager;
-
     @Override
     public void writeEvents( OutputStream outputStream, Events events, boolean withHeader ) throws IOException
     {
@@ -77,8 +70,6 @@
 
         for ( Event event : events.getEvents() )
         {
-            ProgramStageInstance psi = manager.get( ProgramStageInstance.class, event.getEvent() );
-
             CsvEventDataValue templateDataValue = new CsvEventDataValue();
             templateDataValue.setEvent( event.getEvent() );
             templateDataValue.setStatus( event.getStatus() != null ? event.getStatus().name() : null );
@@ -86,8 +77,8 @@
             templateDataValue.setProgramStage( event.getProgramStage() );
             templateDataValue.setEnrollment( event.getEnrollment() );
             templateDataValue.setOrgUnit( event.getOrgUnit() );
-            templateDataValue.setEventDate( DateUtils.getLongDateString( psi.getExecutionDate() ) );
-            templateDataValue.setDueDate( DateUtils.getLongDateString( psi.getDueDate() ) );
+            templateDataValue.setEventDate( event.getEventDate() );
+            templateDataValue.setDueDate( event.getDueDate() );
             templateDataValue.setStoredBy( event.getStoredBy() );
 
             if ( event.getCoordinate() != null )

=== 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	2014-10-09 06:32:38 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java	2014-10-09 12:18:20 +0000
@@ -203,6 +203,8 @@
         }
 
         csvEventService.writeEvents( response.getOutputStream(), events, !skipHeader );
+        response.getOutputStream().flush();
+        response.getOutputStream().close();
     }
 
     @RequestMapping( value = "", method = RequestMethod.GET )