← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20400: proper value validation for updating of events

 

------------------------------------------------------------
revno: 20400
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-09-30 10:35:45 +0700
message:
  proper value validation for updating of events
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/EventService.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	2015-09-24 08:32:10 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java	2015-09-30 03:35:45 +0000
@@ -562,28 +562,34 @@
     // -------------------------------------------------------------------------
 
     @Override
-    public void updateEvents( List<Event> events, boolean singleValue )
+    public ImportSummaries updateEvents( List<Event> events, boolean singleValue )
     {
+        ImportSummaries importSummaries = new ImportSummaries();
+
         for ( Event event : events )
         {
-            updateEvent( event, singleValue );
+            importSummaries.addImportSummary( updateEvent( event, singleValue ) );
         }
-    }
-
-    @Override
-    public void updateEvent( Event event, boolean singleValue )
-    {
-        updateEvent( event, singleValue, null );
-    }
-
-    @Override
-    public void updateEvent( Event event, boolean singleValue, ImportOptions importOptions )
-    {
+
+        return importSummaries;
+    }
+
+    @Override
+    public ImportSummary updateEvent( Event event, boolean singleValue )
+    {
+        return updateEvent( event, singleValue, null );
+    }
+
+    @Override
+    public ImportSummary updateEvent( Event event, boolean singleValue, ImportOptions importOptions )
+    {
+        ImportSummary importSummary = new ImportSummary();
         ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( event.getEvent() );
 
         if ( programStageInstance == null )
         {
-            return;
+            importSummary.getConflicts().add( new ImportConflict( "Invalid Event ID.", event.getEvent() ) );
+            return importSummary;
         }
 
         if ( importOptions == null )
@@ -670,9 +676,13 @@
         for ( DataValue value : event.getDataValues() )
         {
             DataElement dataElement = getDataElement( value.getDataElement() );
-
             TrackedEntityDataValue dataValue = dataValueService.getTrackedEntityDataValue( programStageInstance, dataElement );
 
+            if ( !validateDataValue( dataElement, value.getValue(), importSummary ) )
+            {
+                continue;
+            }
+
             if ( dataValue != null )
             {
                 dataValue.setValue( value.getValue() );
@@ -697,13 +707,14 @@
                 dataValueService.deleteTrackedEntityDataValue( value );
             }
         }
+
+        return importSummary;
     }
 
     @Override
     public void updateEventForNote( Event event )
     {
-        ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance(
-            event.getEvent() );
+        ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( event.getEvent() );
 
         if ( programStageInstance == null )
         {

=== 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-06-02 12:59:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java	2015-09-30 03:35:45 +0000
@@ -89,11 +89,11 @@
     // UPDATE
     // -------------------------------------------------------------------------
 
-    void updateEvent( Event event, boolean singleValue );
-
-    void updateEvents( List<Event> events, boolean singleValue );
-
-    void updateEvent( Event event, boolean singleValue, ImportOptions importOptions );
+    ImportSummary updateEvent( Event event, boolean singleValue );
+
+    ImportSummary updateEvent( Event event, boolean singleValue, ImportOptions importOptions );
+
+    ImportSummaries updateEvents( List<Event> events, boolean singleValue );
 
     void updateEventForNote( Event event );
 

=== 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-09-14 17:39:27 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java	2015-09-30 03:35:45 +0000
@@ -430,8 +430,8 @@
         Event updatedEvent = JacksonUtils.fromXml( request.getInputStream(), Event.class );
         updatedEvent.setEvent( uid );
 
-        eventService.updateEvent( updatedEvent, false, importOptions );
-        webMessageService.send( WebMessageUtils.ok( "Event updated: " + uid ), response, request );
+        ImportSummary importSummary = eventService.updateEvent( updatedEvent, false, importOptions );
+        webMessageService.send( WebMessageUtils.importSummary( importSummary ), response, request );
     }
 
     @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json" )
@@ -448,8 +448,8 @@
         Event updatedEvent = JacksonUtils.fromJson( request.getInputStream(), Event.class );
         updatedEvent.setEvent( uid );
 
-        eventService.updateEvent( updatedEvent, false, importOptions );
-        webMessageService.send( WebMessageUtils.ok( "Event updated: " + uid ), response, request );
+        ImportSummary importSummary = eventService.updateEvent( updatedEvent, false, importOptions );
+        webMessageService.send( WebMessageUtils.importSummary( importSummary ), response, request );
     }
 
     @RequestMapping( value = "/{uid}/{dataElementUid}", method = RequestMethod.PUT, consumes = "application/json" )
@@ -473,8 +473,8 @@
         Event updatedEvent = JacksonUtils.fromJson( request.getInputStream(), Event.class );
         updatedEvent.setEvent( uid );
 
-        eventService.updateEvent( updatedEvent, true );
-        webMessageService.send( WebMessageUtils.ok( "Event updated: " + uid ), response, request );
+        ImportSummary importSummary = eventService.updateEvent( updatedEvent, true );
+        webMessageService.send( WebMessageUtils.importSummary( importSummary ), response, request );
     }
 
     @RequestMapping( value = "/{uid}/addNote", method = RequestMethod.PUT, consumes = "application/json" )