]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5537 Added support to set external blob csid on update as well as on create.
authorPatrick Schmitz <pschmitz@berkeley.edu>
Fri, 28 Sep 2012 21:43:03 +0000 (14:43 -0700)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Fri, 28 Sep 2012 21:43:03 +0000 (14:43 -0700)
services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java
services/media/service/src/main/java/org/collectionspace/services/media/MediaResource.java

index 499149492c05a61665a509d7089834d55de7ccb7..0db2fc8791f8879ac2b6762e6d3869543a998526 100644 (file)
@@ -157,12 +157,23 @@ public abstract class ResourceBase
                @Context UriInfo uriInfo,\r
                @PathParam("csid") String csid,\r
                String xmlPayload) {\r
+        return this.update(null, resourceMap, uriInfo, csid, xmlPayload); \r
+    }\r
+\r
+    public byte[] update(ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx, // REM: 8/13/2012 - Some sub-classes will override this method -e.g., MediaResource does.\r
+               @Context ResourceMap resourceMap,\r
+               @Context UriInfo uriInfo,\r
+               @PathParam("csid") String csid,\r
+               String xmlPayload) {\r
         PoxPayloadOut result = null;\r
         ensureCSID(csid, UPDATE);\r
         try {\r
             PoxPayloadIn theUpdate = new PoxPayloadIn(xmlPayload);\r
             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(theUpdate, uriInfo);\r
             ctx.setResourceMap(resourceMap);\r
+            if (parentCtx != null && parentCtx.getCurrentRepositorySession() != null) {\r
+               ctx.setCurrentRepositorySession(parentCtx.getCurrentRepositorySession()); // Reuse the current repo session if one exists\r
+            }            \r
             result = update(csid, theUpdate, ctx); //==> CALL implementation method, which subclasses may override.\r
         } catch (Exception e) {\r
             throw bigReThrow(e, ServiceMessages.UPDATE_FAILED, csid);\r
index 4e44778b6dc0a36a2e8abe2dec5568b2cf210623..ad1dbede8fedb810d54227a58883ea7a8e87a98d 100644 (file)
@@ -47,6 +47,7 @@ import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
@@ -164,7 +165,25 @@ public class MediaResource extends ResourceBase {
         return result;
     }
     
-    
+    @Override
+    public byte[] update(ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx,
+               @Context ResourceMap resourceMap,
+               @Context UriInfo ui,
+               @PathParam("csid") String csid,
+               String xmlPayload) {
+       //
+       // If we find a "blobUri" query param, then we need to create a blob resource/record first and then the media resource/record
+       //
+        MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
+        String blobUri = queryParams.getFirst(BlobClient.BLOB_URI_PARAM);
+        if (blobUri != null && blobUri.isEmpty() == false) {
+               Response blobresult = createBlobWithUri(resourceMap, ui, xmlPayload, blobUri); // uses the blob resource and doc handler to create the blob
+               String blobCsid = CollectionSpaceClientUtils.extractId(blobresult);
+               queryParams.add(BlobClient.BLOB_CSID_PARAM, blobCsid); // Add the new blob's csid as an artificial query param -the media doc handler will look for this
+        }
+               return super.update(parentCtx, resourceMap, ui, csid, xmlPayload); // Now call the parent to finish the media resource POST request
+    }
+
     /*
      * Creates a new blob (using a URL pointing to a media file/resource) and associates it with an existing media record/resource.
      */