← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16692: in typeSummary add new property lastImported, will always contain uid of last object created/upda...

 

------------------------------------------------------------
revno: 16692
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-09-11 13:03:17 +0700
message:
  in typeSummary add new property lastImported, will always contain uid of last object created/updated. In posts in abstract crud controller use this to set location header if imported count is 1.
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportTypeSummary.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.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/metadata/ImportTypeSummary.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportTypeSummary.java	2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportTypeSummary.java	2014-09-11 06:03:17 +0000
@@ -43,7 +43,7 @@
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
-@JacksonXmlRootElement(localName = "typeSummary", namespace = DxfNamespaces.DXF_2_0)
+@JacksonXmlRootElement( localName = "typeSummary", namespace = DxfNamespaces.DXF_2_0 )
 public class ImportTypeSummary
     extends ImportSummary
 {
@@ -53,13 +53,20 @@
 
     private List<ImportConflict> importConflicts = new ArrayList<>();
 
+    /**
+     * This will always have the UID of the latest imported object. This is used for cases where you are only importing a single
+     * object, and want to return the Location header etc to the user. We might extend this in the future, so that we can get all
+     * UIDs of imported objects.
+     */
+    private String lastImported;
+
     public ImportTypeSummary( String type )
     {
         this.type = type;
     }
 
     @JsonProperty
-    @JacksonXmlProperty(isAttribute = true)
+    @JacksonXmlProperty( isAttribute = true )
     public String getType()
     {
         return type;
@@ -71,7 +78,7 @@
     }
 
     @JsonProperty
-    @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public ImportCount getImportCount()
     {
         return importCount;
@@ -83,8 +90,8 @@
     }
 
     @JsonProperty
-    @JacksonXmlElementWrapper(localName = "conflicts", namespace = DxfNamespaces.DXF_2_0)
-    @JacksonXmlProperty(localName = "conflict", namespace = DxfNamespaces.DXF_2_0)
+    @JacksonXmlElementWrapper( localName = "conflicts", namespace = DxfNamespaces.DXF_2_0 )
+    @JacksonXmlProperty( localName = "conflict", namespace = DxfNamespaces.DXF_2_0 )
     public List<ImportConflict> getImportConflicts()
     {
         return importConflicts;
@@ -95,6 +102,18 @@
         this.importConflicts = importConflicts;
     }
 
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public String getLastImported()
+    {
+        return lastImported;
+    }
+
+    public void setLastImported( String lastImported )
+    {
+        this.lastImported = lastImported;
+    }
+
     //-------------------------------------------------------------------------
     // Helpers
     //-------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2014-08-21 10:12:43 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2014-09-11 06:03:17 +0000
@@ -649,6 +649,8 @@
             nonIdentifiableObjects.save( object );
         }
 
+        summaryType.setLastImported( object.getUid() );
+
         log.debug( "Save successful." );
 
         return true;
@@ -730,6 +732,8 @@
             nonIdentifiableObjects.save( persistedObject );
         }
 
+        summaryType.setLastImported( object.getUid() );
+
         log.debug( "Update successful." );
 
         return true;

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java	2014-09-11 05:40:24 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java	2014-09-11 06:03:17 +0000
@@ -335,6 +335,12 @@
         if ( ImportStatus.SUCCESS.equals( summary.getStatus() ) )
         {
             postCreateEntity( parsed );
+
+            if ( summary.getImportCount().getImported() == 1 && summary.getLastImported() != null )
+            {
+                response.setHeader( "Location", contextService.getContextPath() + "/api" + getSchema().getApiEndpoint()
+                    + "/" + summary.getLastImported() );
+            }
         }
 
         renderService.toXml( response.getOutputStream(), summary );
@@ -354,6 +360,12 @@
         if ( ImportStatus.SUCCESS.equals( summary.getStatus() ) )
         {
             postCreateEntity( parsed );
+
+            if ( summary.getImportCount().getImported() == 1 && summary.getLastImported() != null )
+            {
+                response.setHeader( "Location", contextService.getContextPath() + "/api" + getSchema().getApiEndpoint()
+                    + "/" + summary.getLastImported() );
+            }
         }
 
         renderService.toJson( response.getOutputStream(), summary );