← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17372: check for empty import summaries (no teis given) in tei controller

 

------------------------------------------------------------
revno: 17372
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-11-06 20:22:10 +0700
message:
  check for empty import summaries (no teis given) in tei controller
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.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-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.java	2014-10-23 08:26:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.java	2014-11-06 13:22:10 +0000
@@ -257,11 +257,22 @@
         else
         {
             response.setStatus( HttpServletResponse.SC_CREATED );
-            ImportSummary importSummary = importSummaries.getImportSummaries().get( 0 );
-
-            if ( !importSummary.getStatus().equals( ImportStatus.ERROR ) )
-            {
-                response.setHeader( "Location", getResourcePath( request, importSummary ) );
+            ImportSummary importSummary;
+
+            if ( !importSummaries.getImportSummaries().isEmpty() )
+            {
+                importSummary = importSummaries.getImportSummaries().get( 0 );
+
+                if ( !importSummary.getStatus().equals( ImportStatus.ERROR ) )
+                {
+                    response.setHeader( "Location", getResourcePath( request, importSummary ) );
+                }
+            }
+            else
+            {
+                importSummary = new ImportSummary( ImportStatus.SUCCESS, "Empty list of tracked entity instances given." );
+                importSummary.setDataValueCount( null );
+                importSummary.setImportCount( null );
             }
 
             JacksonUtils.toXml( response.getOutputStream(), importSummary );
@@ -284,11 +295,22 @@
         else
         {
             response.setStatus( HttpServletResponse.SC_CREATED );
-            ImportSummary importSummary = importSummaries.getImportSummaries().get( 0 );
-
-            if ( !importSummary.getStatus().equals( ImportStatus.ERROR ) )
-            {
-                response.setHeader( "Location", getResourcePath( request, importSummary ) );
+            ImportSummary importSummary;
+
+            if ( !importSummaries.getImportSummaries().isEmpty() )
+            {
+                importSummary = importSummaries.getImportSummaries().get( 0 );
+
+                if ( !importSummary.getStatus().equals( ImportStatus.ERROR ) )
+                {
+                    response.setHeader( "Location", getResourcePath( request, importSummary ) );
+                }
+            }
+            else
+            {
+                importSummary = new ImportSummary( ImportStatus.SUCCESS, "Empty list of tracked entity instances given." );
+                importSummary.setDataValueCount( null );
+                importSummary.setImportCount( null );
             }
 
             JacksonUtils.toJson( response.getOutputStream(), importSummary );