← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14078: minor change to event controller to allow updating of single value

 

------------------------------------------------------------
revno: 14078
committer: Abyot Asalefew Gizaw abyota@xxxxxxxxx
branch nick: dhis2
timestamp: Thu 2014-02-20 11:21:30 +0100
message:
  minor change to event controller to allow updating of single value
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-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/NoRegistrationSingleEventServiceTest.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java
  dhis-2/dhis-web/pom.xml


--
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-02-07 20:25:49 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java	2014-02-20 10:21:30 +0000
@@ -434,7 +434,7 @@
     // -------------------------------------------------------------------------
 
     @Override
-    public void updateEvent( Event event )
+    public void updateEvent( Event event, boolean singleValue )
     {
         ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( event
             .getEvent() );
@@ -518,13 +518,17 @@
                     value.getProvidedElsewhere() );
             }
         }
-
-        for ( TrackedEntityDataValue value : dataValues )
+        
+        if( !singleValue )
         {
-            dataValueService.deleteTrackedEntityDataValue( value );
+            for ( TrackedEntityDataValue value : dataValues )
+            {
+                dataValueService.deleteTrackedEntityDataValue( value );
+            }   
         }
+        
     }
-
+    
     // -------------------------------------------------------------------------
     // DELETE
     // -------------------------------------------------------------------------

=== 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	2013-12-30 11:47:50 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java	2014-02-20 10:21:30 +0000
@@ -112,7 +112,7 @@
     // UPDATE
     // -------------------------------------------------------------------------
 
-    void updateEvent( Event event );
+    void updateEvent( Event event, boolean singleValue );
 
     // -------------------------------------------------------------------------
     // DELETE

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/NoRegistrationSingleEventServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/NoRegistrationSingleEventServiceTest.java	2013-12-30 11:47:50 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/NoRegistrationSingleEventServiceTest.java	2014-02-20 10:21:30 +0000
@@ -228,7 +228,7 @@
 
         event = eventService.getEvent( importSummary.getReference() );
         event.getDataValues().get( 0 ).setValue( "254" );
-        eventService.updateEvent( event );
+        eventService.updateEvent( event, false );
 
         event = eventService.getEvent( importSummary.getReference() );
         assertEquals( "254", event.getDataValues().get( 0 ).getValue() );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java	2014-02-15 04:00:45 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java	2014-02-20 10:21:30 +0000
@@ -73,6 +73,8 @@
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementService;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -104,6 +106,9 @@
 
     @Autowired
     private OrganisationUnitService organisationUnitService;
+    
+    @Autowired
+    private DataElementService dataElementService;
 
     // -------------------------------------------------------------------------
     // READ
@@ -336,7 +341,7 @@
         Event updatedEvent = JacksonUtils.fromXml( request.getInputStream(), Event.class );
         updatedEvent.setEvent( uid );
 
-        eventService.updateEvent( updatedEvent );
+        eventService.updateEvent( updatedEvent, false );
         ContextUtils.okResponse( response, "Event updated: " + uid );
     }
 
@@ -355,9 +360,37 @@
         Event updatedEvent = JacksonUtils.fromJson( request.getInputStream(), Event.class );
         updatedEvent.setEvent( uid );
 
-        eventService.updateEvent( updatedEvent );
+        eventService.updateEvent( updatedEvent, false );
         ContextUtils.okResponse( response, "Event updated: " + uid );
     }
+    
+    @RequestMapping( value = "/{uid}/{dataElementUid}", method = RequestMethod.PUT, consumes = "application/json" )
+    @PreAuthorize( "hasRole('ALL') or hasRole('F_PATIENT_DATAVALUE_ADD')" )
+    public void putJsonEventSingleValue( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, @PathVariable( "dataElementUid" ) String dataElementUid ) throws IOException
+    {
+        Event event = eventService.getEvent( uid );
+
+        if ( event == null )
+        {
+            ContextUtils.notFoundResponse( response, "Event not found for uid: " + uid );
+            return;
+        }
+        
+        DataElement dataElement = dataElementService.getDataElement( dataElementUid );
+        
+        if( dataElement == null )
+        {
+            ContextUtils.notFoundResponse( response, "DataElement not found for uid: " + dataElementUid );
+            return;
+        }
+
+        Event updatedEvent = JacksonUtils.fromJson( request.getInputStream(), Event.class );
+        updatedEvent.setEvent( uid );
+
+        eventService.updateEvent( updatedEvent, true );
+        ContextUtils.okResponse( response, "Event updated: " + uid );        
+        
+    }
 
     // -------------------------------------------------------------------------
     // DELETE

=== modified file 'dhis-2/dhis-web/pom.xml'
--- dhis-2/dhis-web/pom.xml	2014-02-14 10:59:22 +0000
+++ dhis-2/dhis-web/pom.xml	2014-02-20 10:21:30 +0000
@@ -15,7 +15,6 @@
     <module>dhis-web-commons</module>
     <module>dhis-web-commons-resources</module>
     <module>dhis-web-api-mobile</module>
-    <module>dhis-web-api</module>
     <module>dhis-web-ohie</module>
     <module>dhis-web-maintenance</module>
     <module>dhis-web-dataentry</module>