From: Patrick Schmitz Date: Fri, 28 Sep 2012 21:43:03 +0000 (-0700) Subject: CSPACE-5537 Added support to set external blob csid on update as well as on create. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=77bbb7605a2d0821a91224162905c329eac69215;p=tmp%2Fjakarta-migration.git CSPACE-5537 Added support to set external blob csid on update as well as on create. --- diff --git a/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java b/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java index 499149492..0db2fc879 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java +++ b/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java @@ -157,12 +157,23 @@ public abstract class ResourceBase @Context UriInfo uriInfo, @PathParam("csid") String csid, String xmlPayload) { + return this.update(null, resourceMap, uriInfo, csid, xmlPayload); + } + + public byte[] update(ServiceContext parentCtx, // REM: 8/13/2012 - Some sub-classes will override this method -e.g., MediaResource does. + @Context ResourceMap resourceMap, + @Context UriInfo uriInfo, + @PathParam("csid") String csid, + String xmlPayload) { PoxPayloadOut result = null; ensureCSID(csid, UPDATE); try { PoxPayloadIn theUpdate = new PoxPayloadIn(xmlPayload); ServiceContext ctx = createServiceContext(theUpdate, uriInfo); ctx.setResourceMap(resourceMap); + if (parentCtx != null && parentCtx.getCurrentRepositorySession() != null) { + ctx.setCurrentRepositorySession(parentCtx.getCurrentRepositorySession()); // Reuse the current repo session if one exists + } result = update(csid, theUpdate, ctx); //==> CALL implementation method, which subclasses may override. } catch (Exception e) { throw bigReThrow(e, ServiceMessages.UPDATE_FAILED, csid); diff --git a/services/media/service/src/main/java/org/collectionspace/services/media/MediaResource.java b/services/media/service/src/main/java/org/collectionspace/services/media/MediaResource.java index 4e44778b6..ad1dbede8 100644 --- a/services/media/service/src/main/java/org/collectionspace/services/media/MediaResource.java +++ b/services/media/service/src/main/java/org/collectionspace/services/media/MediaResource.java @@ -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 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 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. */