← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14493: Event report, put/delete

 

------------------------------------------------------------
revno: 14493
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-03-27 15:54:30 +0100
message:
  Event report, put/delete
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/eventreport/EventReportService.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/eventreport/DefaultEventReportService.java
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/eventreport/EventReportServiceTest.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventReportController.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-api/src/main/java/org/hisp/dhis/eventreport/EventReportService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/eventreport/EventReportService.java	2014-03-26 21:55:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/eventreport/EventReportService.java	2014-03-27 14:54:30 +0000
@@ -43,5 +43,7 @@
     
     EventReport getEventReport( String uid );
     
+    void deleteEventReport( EventReport report );
+    
     List<EventReport> getAllEventReprots();
 }

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/eventreport/DefaultEventReportService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/eventreport/DefaultEventReportService.java	2014-03-26 21:55:22 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/eventreport/DefaultEventReportService.java	2014-03-27 14:54:30 +0000
@@ -71,6 +71,11 @@
         return eventReportStore.getByUid( uid );
     }
     
+    public void deleteEventReport( EventReport report )
+    {
+        eventReportStore.delete( report );
+    }
+    
     public List<EventReport> getAllEventReprots()
     {
         return eventReportStore.getAll();

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/eventreport/EventReportServiceTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/eventreport/EventReportServiceTest.java	2014-03-27 13:53:54 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/eventreport/EventReportServiceTest.java	2014-03-27 14:54:30 +0000
@@ -28,7 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
 
 import org.hisp.dhis.DhisSpringTest;
 import org.hisp.dhis.program.Program;
@@ -75,4 +75,41 @@
         assertEquals( "erB", eventReportService.getEventReport( idB ).getName() );
         assertEquals( "erC", eventReportService.getEventReport( idC ).getName() );
     }
+    
+    @Test
+    public void testDelete()
+    {
+        EventReport erA = new EventReport( "erA" );
+        erA.setProgram( prA );
+        EventReport erB = new EventReport( "erB" );
+        erB.setProgram( prA );
+        EventReport erC = new EventReport( "erC" );
+        erC.setProgram( prA );
+        
+        int idA = eventReportService.saveEventReport( erA );
+        int idB = eventReportService.saveEventReport( erB );
+        int idC = eventReportService.saveEventReport( erC );
+        
+        assertNotNull( eventReportService.getEventReport( idA ) );
+        assertNotNull( eventReportService.getEventReport( idB ) );
+        assertNotNull( eventReportService.getEventReport( idC ) );
+        
+        eventReportService.deleteEventReport( erA );
+
+        assertNull( eventReportService.getEventReport( idA ) );
+        assertNotNull( eventReportService.getEventReport( idB ) );
+        assertNotNull( eventReportService.getEventReport( idC ) );
+
+        eventReportService.deleteEventReport( erB );
+
+        assertNull( eventReportService.getEventReport( idA ) );
+        assertNull( eventReportService.getEventReport( idB ) );
+        assertNotNull( eventReportService.getEventReport( idC ) );
+
+        eventReportService.deleteEventReport( erC );
+
+        assertNull( eventReportService.getEventReport( idA ) );
+        assertNull( eventReportService.getEventReport( idB ) );
+        assertNull( eventReportService.getEventReport( idC ) );        
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventReportController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventReportController.java	2014-03-27 14:00:01 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventReportController.java	2014-03-27 14:54:30 +0000
@@ -44,9 +44,12 @@
 import org.hisp.dhis.program.ProgramService;
 import org.hisp.dhis.program.ProgramStageService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
 import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseStatus;
 
 /**
  * @author Lars Helge Overland
@@ -86,6 +89,55 @@
         
         ContextUtils.createdResponse( response, "Event report created", RESOURCE_PATH + "/" + report.getUid() );
     }
+
+    @Override
+    @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json" )
+    @ResponseStatus( value = HttpStatus.NO_CONTENT )
+    public void putJsonObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, InputStream input ) throws Exception
+    {
+        EventReport report = eventReportService.getEventReport( uid );
+
+        if ( report == null )
+        {
+            ContextUtils.notFoundResponse( response, "Event report does not exist: " + uid );
+            return;
+        }
+
+        EventReport newReport = JacksonUtils.fromJson( input, EventReport.class );
+        
+        mergeEventReport( newReport );
+        
+        report.mergeWith( newReport );
+        
+        eventReportService.updateEventReport( report );
+    }
+
+    @Override
+    @RequestMapping( value = "/{uid}", method = RequestMethod.DELETE )
+    @ResponseStatus( value = HttpStatus.NO_CONTENT )
+    public void deleteObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid ) throws Exception
+    {
+        EventReport report = eventReportService.getEventReport( uid );
+
+        if ( report == null )
+        {
+            ContextUtils.notFoundResponse( response, "Event report does not exist: " + uid );
+            return;
+        }
+
+        eventReportService.deleteEventReport( report );
+    }        
+        
+    //--------------------------------------------------------------------------
+    // Hooks
+    //--------------------------------------------------------------------------
+
+    @Override
+    protected void postProcessEntity( EventReport report ) 
+        throws Exception
+    {
+        report.populateAnalyticalProperties();
+    }
     
     //--------------------------------------------------------------------------
     // Supportive methods