← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11346: Include href in importSummary (used for events). Use 'Location:' header when there is only one re...

 

------------------------------------------------------------
revno: 11346
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-07-05 11:48:41 +0700
message:
  Include href in importSummary (used for events). Use 'Location:' header when there is only one result in the importSummaries.
modified:
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/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-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java	2013-07-04 06:19:49 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java	2013-07-05 04:48:41 +0000
@@ -51,6 +51,8 @@
 
     private String reference;
 
+    private String href;
+
     public ImportSummary()
     {
     }
@@ -133,4 +135,16 @@
     {
         this.reference = reference;
     }
+
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public String getHref()
+    {
+        return href;
+    }
+
+    public void setHref( String href )
+    {
+        this.href = href;
+    }
 }

=== 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	2013-07-05 04:25:13 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java	2013-07-05 04:48:41 +0000
@@ -32,6 +32,7 @@
 import org.hisp.dhis.dxf2.event.Event;
 import org.hisp.dhis.dxf2.event.EventService;
 import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
+import org.hisp.dhis.dxf2.importsummary.ImportSummary;
 import org.hisp.dhis.dxf2.utils.JacksonUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -96,6 +97,18 @@
     public void postXmlObject( HttpServletResponse response, HttpServletRequest request ) throws Exception
     {
         ImportSummaries importSummaries = eventService.saveEventsXml( request.getInputStream() );
+
+        for ( ImportSummary importSummary : importSummaries.getImportSummaries() )
+        {
+            importSummary.setHref( ContextUtils.getRootPath( request ) + RESOURCE_PATH + "/" + importSummary.getReference() );
+        }
+
+        if ( importSummaries.getImportSummaries().size() == 1 )
+        {
+            ImportSummary importSummary = importSummaries.getImportSummaries().get( 0 );
+            response.setHeader( "Location", ContextUtils.getRootPath( request ) + RESOURCE_PATH + "/" + importSummary.getReference() );
+        }
+
         JacksonUtils.toXml( response.getOutputStream(), importSummaries );
     }
 
@@ -104,6 +117,18 @@
     public void postJsonObject( HttpServletResponse response, HttpServletRequest request ) throws Exception
     {
         ImportSummaries importSummaries = eventService.saveEventsJson( request.getInputStream() );
+
+        for ( ImportSummary importSummary : importSummaries.getImportSummaries() )
+        {
+            importSummary.setHref( ContextUtils.getRootPath( request ) + RESOURCE_PATH + "/" + importSummary.getReference() );
+        }
+
+        if ( importSummaries.getImportSummaries().size() == 1 )
+        {
+            ImportSummary importSummary = importSummaries.getImportSummaries().get( 0 );
+            response.setHeader( "Location", ContextUtils.getRootPath( request ) + RESOURCE_PATH + "/" + importSummary.getReference() );
+        }
+
         JacksonUtils.toJson( response.getOutputStream(), importSummaries );
     }