dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #38435
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19573: wrapped more importSummaries in WebMessage/Response
------------------------------------------------------------
revno: 19573
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-07-08 11:33:58 +0700
message:
wrapped more importSummaries in WebMessage/Response
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportStatus.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EnrollmentController.java
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/TrackedEntityInstanceController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/WebMessageUtils.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/importsummary/ImportStatus.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportStatus.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportStatus.java 2015-07-08 04:33:58 +0000
@@ -31,5 +31,6 @@
public enum ImportStatus
{
SUCCESS,
+ WARNING,
ERROR
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EnrollmentController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EnrollmentController.java 2015-07-08 03:04:42 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EnrollmentController.java 2015-07-08 04:33:58 +0000
@@ -46,7 +46,9 @@
import org.hisp.dhis.program.ProgramStatus;
import org.hisp.dhis.webapi.controller.exception.NotFoundException;
import org.hisp.dhis.webapi.service.ContextService;
+import org.hisp.dhis.webapi.service.WebMessageService;
import org.hisp.dhis.webapi.utils.ContextUtils;
+import org.hisp.dhis.webapi.utils.WebMessageUtils;
import org.hisp.dhis.webapi.webdomain.WebOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
@@ -91,6 +93,9 @@
@Autowired
protected ContextService contextService;
+ @Autowired
+ private WebMessageService webMessageService;
+
// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
@@ -170,7 +175,7 @@
response.setHeader( "Location", getResourcePath( request, importSummary ) );
}
- JacksonUtils.toXml( response.getOutputStream(), importSummary );
+ webMessageService.send( WebMessageUtils.importSummaries( importSummaries ), response, request );
}
}
@@ -196,7 +201,7 @@
response.setHeader( "Location", getResourcePath( request, importSummary ) );
}
- JacksonUtils.toJson( response.getOutputStream(), importSummary );
+ webMessageService.send( WebMessageUtils.importSummaries( importSummaries ), response, request );
}
}
@@ -209,9 +214,7 @@
public void updateEnrollmentXml( @PathVariable String id, HttpServletRequest request, HttpServletResponse response ) throws IOException
{
ImportSummary importSummary = enrollmentService.updateEnrollmentXml( id, request.getInputStream() );
- response.setContentType( MediaType.APPLICATION_XML_VALUE );
-
- JacksonUtils.toXml( response.getOutputStream(), importSummary );
+ webMessageService.send( WebMessageUtils.importSummary( importSummary ), response, request );
}
@RequestMapping( value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE )
@@ -219,9 +222,7 @@
public void updateEnrollmentJson( @PathVariable String id, HttpServletRequest request, HttpServletResponse response ) throws IOException
{
ImportSummary importSummary = enrollmentService.updateEnrollmentJson( id, request.getInputStream() );
- response.setContentType( MediaType.APPLICATION_JSON_VALUE );
-
- JacksonUtils.toJson( response.getOutputStream(), importSummary );
+ webMessageService.send( WebMessageUtils.importSummary( importSummary ), response, request );
}
@RequestMapping( value = "/{id}/cancelled", method = RequestMethod.PUT )
=== 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-07-08 04:02:09 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java 2015-07-08 04:33:58 +0000
@@ -333,7 +333,7 @@
}
}
- JacksonUtils.toXml( response.getOutputStream(), importSummaries );
+ webMessageService.send( WebMessageUtils.importSummaries( importSummaries ), response, request );
}
else
{
@@ -379,7 +379,7 @@
}
}
- JacksonUtils.toJson( response.getOutputStream(), importSummaries );
+ webMessageService.send( WebMessageUtils.importSummaries( importSummaries ), response, request );
}
else
{
@@ -404,7 +404,7 @@
if ( !importOptions.isAsync() )
{
ImportSummaries importSummaries = eventService.addEvents( events.getEvents(), importOptions, null );
- JacksonUtils.toJson( response.getOutputStream(), importSummaries );
+ webMessageService.send( WebMessageUtils.importSummaries( importSummaries ), response, request );
}
else
{
=== 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 2015-07-08 04:24:08 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.java 2015-07-08 04:33:58 +0000
@@ -31,7 +31,6 @@
import com.google.common.collect.Lists;
import org.hisp.dhis.common.DxfNamespaces;
import org.hisp.dhis.common.Grid;
-import org.hisp.dhis.common.IllegalQueryException;
import org.hisp.dhis.common.OrganisationUnitSelectionMode;
import org.hisp.dhis.dxf2.common.JacksonUtils;
import org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance;
@@ -51,15 +50,16 @@
import org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams;
import org.hisp.dhis.webapi.controller.exception.NotFoundException;
import org.hisp.dhis.webapi.service.ContextService;
+import org.hisp.dhis.webapi.service.WebMessageService;
import org.hisp.dhis.webapi.utils.ContextUtils;
import org.hisp.dhis.webapi.utils.ContextUtils.CacheStrategy;
+import org.hisp.dhis.webapi.utils.WebMessageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -97,6 +97,9 @@
@Autowired
private ContextService contextService;
+ @Autowired
+ private WebMessageService webMessageService;
+
// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
@@ -342,7 +345,7 @@
importSummary.setImportCount( null );
}
- JacksonUtils.toXml( response.getOutputStream(), importSummary );
+ webMessageService.send( WebMessageUtils.importSummaries( importSummaries ), response, request );
}
}
@@ -379,7 +382,7 @@
importSummary.setImportCount( null );
}
- JacksonUtils.toJson( response.getOutputStream(), importSummary );
+ webMessageService.send( WebMessageUtils.importSummaries( importSummaries ), response, request );
}
}
@@ -393,9 +396,7 @@
throws IOException
{
ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstanceXml( id, request.getInputStream() );
-
- response.setContentType( MediaType.APPLICATION_XML_VALUE );
- JacksonUtils.toXml( response.getOutputStream(), importSummary );
+ webMessageService.send( WebMessageUtils.importSummary( importSummary ), response, request );
}
@RequestMapping( value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE )
@@ -404,9 +405,7 @@
throws IOException
{
ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstanceJson( id, request.getInputStream() );
-
- response.setContentType( MediaType.APPLICATION_JSON_VALUE );
- JacksonUtils.toJson( response.getOutputStream(), importSummary );
+ webMessageService.send( WebMessageUtils.importSummary( importSummary ), response, request );
}
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/WebMessageUtils.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/WebMessageUtils.java 2015-07-08 04:24:08 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/WebMessageUtils.java 2015-07-08 04:33:58 +0000
@@ -29,6 +29,8 @@
*/
import org.hisp.dhis.dxf2.importsummary.ImportStatus;
+import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
+import org.hisp.dhis.dxf2.importsummary.ImportSummary;
import org.hisp.dhis.dxf2.metadata.ImportTypeSummary;
import org.hisp.dhis.dxf2.webmessage.WebMessage;
import org.hisp.dhis.dxf2.webmessage.WebMessageResponse;
@@ -180,16 +182,19 @@
if ( importTypeSummary.isStatus( ImportStatus.ERROR ) )
{
+ webMessage.setMessage( "An error occurred, please check import summary." );
webMessage.setStatus( WebMessageStatus.ERROR );
webMessage.setHttpStatusCode( HttpServletResponse.SC_CONFLICT );
}
- else if ( importTypeSummary.isStatus( ImportStatus.SUCCESS ) && !importTypeSummary.getConflicts().isEmpty() )
+ else if ( !importTypeSummary.getConflicts().isEmpty() )
{
+ webMessage.setMessage( "One more conflicts encountered, please check import summary." );
webMessage.setStatus( WebMessageStatus.WARNING );
webMessage.setHttpStatusCode( HttpServletResponse.SC_CONFLICT );
}
else
{
+ webMessage.setMessage( "Import was successful." );
webMessage.setStatus( WebMessageStatus.OK );
webMessage.setHttpStatusCode( HttpServletResponse.SC_OK );
}
@@ -199,6 +204,56 @@
return webMessage;
}
+ public static WebMessage importSummary( ImportSummary importSummary )
+ {
+ WebMessage webMessage = new WebMessage();
+
+ if ( importSummary.isStatus( ImportStatus.ERROR ) )
+ {
+ webMessage.setMessage( "An error occurred, please check import summary." );
+ webMessage.setStatus( WebMessageStatus.ERROR );
+ webMessage.setHttpStatusCode( HttpServletResponse.SC_CONFLICT );
+ }
+ else if ( !importSummary.getConflicts().isEmpty() )
+ {
+ webMessage.setMessage( "One more conflicts encountered, please check import summary." );
+ webMessage.setStatus( WebMessageStatus.WARNING );
+ webMessage.setHttpStatusCode( HttpServletResponse.SC_CONFLICT );
+ }
+ else
+ {
+ webMessage.setMessage( "Import was successful." );
+ webMessage.setStatus( WebMessageStatus.OK );
+ webMessage.setHttpStatusCode( HttpServletResponse.SC_OK );
+ }
+
+ webMessage.setResponse( importSummary );
+
+ return webMessage;
+ }
+
+ public static WebMessage importSummaries( ImportSummaries importSummaries )
+ {
+ WebMessage webMessage = new WebMessage();
+
+ if ( importSummaries.getIgnored() > 0 )
+ {
+ webMessage.setMessage( "One more conflicts encountered, please check import summary." );
+ webMessage.setStatus( WebMessageStatus.WARNING );
+ webMessage.setHttpStatusCode( HttpServletResponse.SC_CONFLICT );
+ }
+ else
+ {
+ webMessage.setMessage( "Import was successful." );
+ webMessage.setStatus( WebMessageStatus.OK );
+ webMessage.setHttpStatusCode( HttpServletResponse.SC_OK );
+ }
+
+ webMessage.setResponse( importSummaries );
+
+ return webMessage;
+ }
+
private WebMessageUtils()
{
}