← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15910: web-api event note saving

 

------------------------------------------------------------
revno: 15910
committer: Abyot Asalefew Gizaw abyota@xxxxxxxxx
branch nick: dhis2
timestamp: Mon 2014-06-30 13:45:18 +0200
message:
  web-api event note saving
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	2014-06-27 10:55:57 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java	2014-06-30 11:45:18 +0000
@@ -411,9 +411,9 @@
 
         programStageInstanceService.updateProgramStageInstance( programStageInstance );
 
-        ProgramInstance programInstance = programStageInstance.getProgramInstance();
+        //ProgramInstance programInstance = programStageInstance.getProgramInstance();
 
-        saveTrackedEntityCommentFromEvent( programInstance, event, storedBy );
+        saveTrackedEntityComment( programStageInstance, event, storedBy );
 
         Set<TrackedEntityDataValue> dataValues = new HashSet<TrackedEntityDataValue>(
             dataValueService.getTrackedEntityDataValues( programStageInstance ) );
@@ -449,6 +449,20 @@
         }
 
     }
+    
+    public void updateEventForNote( Event event )
+    {
+        ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( event
+            .getEvent() );
+
+        if ( programStageInstance == null )
+        {
+            return;
+        }
+        
+        saveTrackedEntityComment( programStageInstance, event, getStoredBy( event, null ) );
+        
+    }
 
     // -------------------------------------------------------------------------
     // DELETE
@@ -739,7 +753,7 @@
 
             }
 
-            saveTrackedEntityCommentFromEvent( programInstance, event, storedBy );
+            saveTrackedEntityComment( programStageInstance, event, storedBy );
 
             importSummary.setReference( programStageInstance.getUid() );
         }
@@ -774,7 +788,7 @@
         return importSummary;
     }
 
-    private void saveTrackedEntityCommentFromEvent( ProgramInstance programInstance, Event event, String storedBy )
+    private void saveTrackedEntityComment( ProgramStageInstance programStageInstance, Event event, String storedBy )
     {
         for ( Note note : event.getNotes() )
         {
@@ -785,9 +799,9 @@
 
             commentService.addTrackedEntityComment( comment );
 
-            programInstance.getComments().add( comment );
+            programStageInstance.getComments().add( comment );
 
-            programInstanceService.updateProgramInstance( programInstance );
+            programStageInstanceService.updateProgramStageInstance( programStageInstance );
         }
     }
 

=== 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	2014-04-29 11:11:30 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java	2014-06-30 11:45:18 +0000
@@ -98,6 +98,8 @@
     void updateEvent( Event event, boolean singleValue );
 
     void updateEvent( Event event, boolean singleValue, ImportOptions importOptions );
+    
+    void updateEventForNote( Event event );
 
     // -------------------------------------------------------------------------
     // DELETE

=== 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-06-11 20:27:54 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java	2014-06-30 11:45:18 +0000
@@ -407,6 +407,25 @@
         ContextUtils.okResponse( response, "Event updated: " + uid );
 
     }
+    
+    @RequestMapping( value = "/{uid}/addNote", method = RequestMethod.PUT, consumes = "application/json" )
+    @PreAuthorize( "hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')" )
+    public void putJsonEventForNote( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, ImportOptions importOptions ) throws IOException
+    {
+        Event event = eventService.getEvent( uid );
+
+        if ( event == null )
+        {
+            ContextUtils.notFoundResponse( response, "Event not found for uid: " + uid );
+            return;
+        }
+
+        Event updatedEvent = JacksonUtils.fromJson( request.getInputStream(), Event.class );
+        updatedEvent.setEvent( uid );
+
+        eventService.updateEventForNote( updatedEvent );
+        ContextUtils.okResponse( response, "Event updated: " + uid );
+    }
 
     // -------------------------------------------------------------------------
     // DELETE