← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20839: minor API updates in deleteEvent, now returns import summary

 

------------------------------------------------------------
revno: 20839
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-10-22 10:37:00 +0700
message:
  minor API updates in deleteEvent, now returns import summary
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-10-22 03:05:41 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java	2015-10-22 03:37:00 +0000
@@ -805,14 +805,38 @@
     // -------------------------------------------------------------------------
 
     @Override
-    public void deleteEvent( Event event )
+    public ImportSummary deleteEvent( String uid )
     {
-        ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( event.getEvent() );
+        ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( uid );
 
         if ( programStageInstance != null )
         {
             programStageInstanceService.deleteProgramStageInstance( programStageInstance );
-        }
+            return new ImportSummary( ImportStatus.SUCCESS, "Deletion of event " + uid + " was successful." );
+        }
+
+        return new ImportSummary( ImportStatus.ERROR, "ID " + uid + " does not point to a valid event" );
+    }
+
+    @Override
+    public ImportSummaries deleteEvents( List<String> uids )
+    {
+        ImportSummaries importSummaries = new ImportSummaries();
+        int counter = 0;
+
+        for ( String uid : uids )
+        {
+            importSummaries.addImportSummary( deleteEvent( uid ) );
+
+            if ( counter % FLUSH_FREQUENCY == 0 )
+            {
+                dbmsManager.clearSession();
+            }
+
+            counter++;
+        }
+
+        return importSummaries;
     }
 
     // -------------------------------------------------------------------------

=== 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-10-22 03:05:41 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java	2015-10-22 03:37:00 +0000
@@ -28,11 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Date;
-import java.util.List;
-
 import org.hisp.dhis.common.OrganisationUnitSelectionMode;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.dxf2.common.IdSchemes;
@@ -45,6 +40,11 @@
 import org.hisp.dhis.program.ProgramStatus;
 import org.hisp.dhis.scheduling.TaskId;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.List;
+
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
@@ -55,13 +55,13 @@
     // -------------------------------------------------------------------------
 
     Events getEvents( EventSearchParams params );
-    
+
     EventRows getEventRows( EventSearchParams params );
 
     EventSearchParams getFromUrl( String program, String programStage, ProgramStatus programStatus, Boolean followUp, String orgUnit,
-        OrganisationUnitSelectionMode orgUnitSelectionMode, String trackedEntityInstance, Date startDate, Date endDate, 
+        OrganisationUnitSelectionMode orgUnitSelectionMode, String trackedEntityInstance, Date startDate, Date endDate,
         EventStatus status, Date lastUpdated, DataElementCategoryOptionCombo attributeCoc, IdSchemes idSchemes, Integer page, Integer pageSize, boolean totalPages, boolean skipPaging, boolean includeAttributes );
-    
+
     Event getEvent( String uid );
 
     Event getEvent( ProgramStageInstance programStageInstance );
@@ -102,5 +102,7 @@
     // DELETE
     // -------------------------------------------------------------------------
 
-    void deleteEvent( Event event );
+    ImportSummary deleteEvent( String uid );
+
+    ImportSummaries deleteEvents( List<String> uids );
 }

=== 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-10-20 04:15:40 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java	2015-10-22 03:37:00 +0000
@@ -53,6 +53,7 @@
 import org.hisp.dhis.event.EventStatus;
 import org.hisp.dhis.importexport.ImportStrategy;
 import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramStageInstanceService;
 import org.hisp.dhis.program.ProgramStatus;
 import org.hisp.dhis.scheduling.TaskCategory;
 import org.hisp.dhis.scheduling.TaskId;
@@ -125,6 +126,9 @@
     @Autowired
     private RenderService renderService;
 
+    @Autowired
+    private ProgramStageInstanceService programStageInstanceService;
+
     // -------------------------------------------------------------------------
     // READ
     // -------------------------------------------------------------------------
@@ -294,7 +298,7 @@
 
         if ( event == null )
         {
-            throw new WebMessageException( WebMessageUtils.notFound( "Event not found for uid: " + uid ) );
+            throw new WebMessageException( WebMessageUtils.notFound( "Event not found for ID " + uid ) );
         }
 
         if ( options.hasLinks() )
@@ -446,7 +450,7 @@
 
         if ( event == null )
         {
-            throw new WebMessageException( WebMessageUtils.notFound( "Event not found for uid: " + uid ) );
+            throw new WebMessageException( WebMessageUtils.notFound( "Event not found for ID " + uid ) );
         }
 
         Event updatedEvent = renderService.fromXml( request.getInputStream(), Event.class );
@@ -464,7 +468,7 @@
 
         if ( event == null )
         {
-            throw new WebMessageException( WebMessageUtils.notFound( "Event not found for uid: " + uid ) );
+            throw new WebMessageException( WebMessageUtils.notFound( "Event not found for ID " + uid ) );
         }
 
         Event updatedEvent = renderService.fromJson( request.getInputStream(), Event.class );
@@ -482,14 +486,14 @@
 
         if ( event == null )
         {
-            throw new WebMessageException( WebMessageUtils.notFound( "Event not found for uid: " + uid ) );
+            throw new WebMessageException( WebMessageUtils.notFound( "Event not found for ID " + uid ) );
         }
 
         DataElement dataElement = dataElementService.getDataElement( dataElementUid );
 
         if ( dataElement == null )
         {
-            throw new WebMessageException( WebMessageUtils.notFound( "DataElement not found for uid: " + dataElementUid ) );
+            throw new WebMessageException( WebMessageUtils.notFound( "DataElement not found for ID " + dataElementUid ) );
         }
 
         Event updatedEvent = renderService.fromJson( request.getInputStream(), Event.class );
@@ -507,7 +511,7 @@
 
         if ( event == null )
         {
-            throw new WebMessageException( WebMessageUtils.notFound( "Event not found for uid: " + uid ) );
+            throw new WebMessageException( WebMessageUtils.notFound( "Event not found for ID " + uid ) );
         }
 
         Event updatedEvent = renderService.fromJson( request.getInputStream(), Event.class );
@@ -525,14 +529,14 @@
 
         if ( event == null )
         {
-            throw new WebMessageException( WebMessageUtils.notFound( "Event not found for uid: " + uid ) );
+            throw new WebMessageException( WebMessageUtils.notFound( "Event not found for ID " + uid ) );
         }
 
         Event updatedEvent = renderService.fromJson( request.getInputStream(), Event.class );
         updatedEvent.setEvent( uid );
 
         eventService.updateEventForEventDate( updatedEvent );
-        webMessageService.send( WebMessageUtils.ok( "Event updated: " + uid ), response, request );
+        webMessageService.send( WebMessageUtils.ok( "Event updated " + uid ), response, request );
     }
 
     // -------------------------------------------------------------------------
@@ -541,16 +545,15 @@
 
     @RequestMapping( value = "/{uid}", method = RequestMethod.DELETE )
     @PreAuthorize( "hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_DELETE')" )
-    public void deleteEvent( HttpServletResponse response, @PathVariable( "uid" ) String uid ) throws WebMessageException
+    public void deleteEvent( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid ) throws WebMessageException
     {
-        Event event = eventService.getEvent( uid );
-
-        if ( event == null )
+        if ( !programStageInstanceService.programStageInstanceExists( uid ) )
         {
-            throw new WebMessageException( WebMessageUtils.notFound( "Event not found for uid: " + uid ) );
+            throw new WebMessageException( WebMessageUtils.notFound( "Event not found for ID " + uid ) );
         }
 
-        response.setStatus( HttpServletResponse.SC_NO_CONTENT );
-        eventService.deleteEvent( event );
+        response.setStatus( HttpServletResponse.SC_OK );
+        ImportSummary importSummary = eventService.deleteEvent( uid );
+        webMessageService.send( WebMessageUtils.importSummary( importSummary ), response, request );
     }
 }
\ No newline at end of file