]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-3245: Committing final Media/Blob artifacts for v1.2 code-freeze. Full CRUD...
authorRichard Millet <richard.millet@berkeley.edu>
Fri, 10 Dec 2010 05:09:49 +0000 (05:09 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Fri, 10 Dec 2010 05:09:49 +0000 (05:09 +0000)
13 files changed:
services/blob/service/src/main/java/org/collectionspace/services/blob/BlobResource.java
services/blob/service/src/main/java/org/collectionspace/services/blob/nuxeo/BlobDocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java
services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java
services/common/src/main/java/org/collectionspace/services/common/blob/BlobInput.java
services/common/src/main/java/org/collectionspace/services/common/blob/BlobUtil.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java
services/media/3rdparty/nuxeo-platform-cs-media/src/main/resources/schemas/media_common.xsd
services/media/jaxb/src/main/java/org/collectionspace/services/MediaJAXBSchema.java
services/media/jaxb/src/main/resources/media_common.xsd
services/media/service/pom.xml
services/media/service/src/main/java/org/collectionspace/services/media/MediaResource.java
services/media/service/src/main/java/org/collectionspace/services/media/nuxeo/MediaDocumentModelHandler.java

index 56fd5187dd751a4c750125889243cebcbba78ce4..3bce784d00c4a075469eb37c5c79ceb042ba6ace 100644 (file)
@@ -29,8 +29,10 @@ import org.collectionspace.services.common.ResourceBase;
 import org.collectionspace.services.common.ServiceMain;
 import org.collectionspace.services.common.ServiceMessages;
 import org.collectionspace.services.common.blob.BlobInput;
+import org.collectionspace.services.common.blob.BlobUtil;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentHandler;
+import org.collectionspace.services.blob.nuxeo.BlobDocumentModelHandler; //FIXEME: A resource class should not have a dependency on a specific DocumentHandler
 import org.collectionspace.services.blob.BlobsCommon;
 import org.collectionspace.services.blob.BlobsCommonList;
 
@@ -64,10 +66,10 @@ import java.util.List;
 @Produces("multipart/mixed")
 public class BlobResource extends ResourceBase {
 
-    @Override
+       @Override
     public String getServiceName(){
-        return "blobs";
-    };
+        return BlobUtil.BLOB_RESOURCE_NAME;
+    }
 
 
     @Override
@@ -97,16 +99,23 @@ public class BlobResource extends ResourceBase {
          return (BlobsCommonList) super.search(queryParams, keywords);
     }
     
-    private BlobsCommonList getDerivativeList(String csid) throws Exception {
+    private BlobsCommonList getDerivativeList(ServiceContext<MultipartInput, MultipartOutput> ctx,
+               String csid) throws Exception {
        BlobsCommonList result = null;
        
-       ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
-       ctx.setProperty(BlobInput.BLOB_DERIVATIVE_LIST_KEY, Boolean.TRUE);
+       BlobInput blobInput = new BlobInput();
+       blobInput.setDerivativeListRequested(true);
+       BlobUtil.setBlobInput(ctx, blobInput);
+
        MultipartOutput response = this.get(csid, ctx);
        if (logger.isDebugEnabled() == true) {
                logger.debug(response.toString());
        }
-       result = (BlobsCommonList)ctx.getProperty(BlobInput.BLOB_DERIVATIVE_LIST_KEY);
+       //
+       // The result of a successful get should have put the results in the
+       // blobInput instance
+       //
+       result = BlobUtil.getBlobInput(ctx).getDerivativeList();
        
        return result;
     }
@@ -116,13 +125,19 @@ public class BlobResource extends ResourceBase {
        
        try {
                ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
-               ctx.setProperty(BlobInput.BLOB_DERIVATIVE_TERM_KEY, derivativeTerm);
-               ctx.setProperty(BlobInput.BLOB_CONTENT_KEY, Boolean.TRUE);
+               BlobInput blobInput = BlobUtil.getBlobInput(ctx);
+               blobInput.setDerivativeTerm(derivativeTerm);
+               blobInput.setContentRequested(true);
+               
                MultipartOutput response = this.get(csid, ctx);
                if (logger.isDebugEnabled() == true) {
                        logger.debug(response.toString());
                }
-               result = (InputStream)ctx.getProperty(BlobInput.BLOB_CONTENT_KEY);
+               //
+               // The result of a successful get should have put the results in the
+               // blobInput instance
+               //              
+               result = BlobUtil.getBlobInput(ctx).getContentStream();
        } catch (Exception e) {
                throw bigReThrow(e, ServiceMessages.CREATE_FAILED);
        }
@@ -136,16 +151,7 @@ public class BlobResource extends ResourceBase {
        
        return result;
     }
-        
-    private BlobInput setBlobInput(ServiceContext<MultipartInput, MultipartOutput> ctx,
-               HttpServletRequest req,
-               String blobUri) {
-       File tmpFile = FileUtils.createTmpFile(req);
-       BlobInput blobInput = new BlobInput(tmpFile, blobUri);
-       ctx.setProperty(BlobInput.class.getName(), blobInput);
-       return blobInput;
-    }
-    
+            
     @POST
     @Consumes("multipart/form-data")
     @Produces("application/xml")
@@ -154,7 +160,8 @@ public class BlobResource extends ResourceBase {
        Response response = null;       
        try {
                ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
-               setBlobInput(ctx, req, blobUri);
+               BlobInput blobInput = BlobUtil.getBlobInput(ctx);
+               blobInput.createBlobFile(req, blobUri);
                response = this.create(null, ctx);
        } catch (Exception e) {
                throw bigReThrow(e, ServiceMessages.CREATE_FAILED);
@@ -174,27 +181,28 @@ public class BlobResource extends ResourceBase {
     }
 
     @GET
-    @Path("{csid}/derivatives/{derivative_term}/content")
+    @Path("{csid}/derivatives/{derivativeTerm}/content")
     @Produces({"image/jpeg", "image/png", "image/tiff"})
     public InputStream getDerivativeContent(
                @PathParam("csid") String csid,
-               @PathParam("derivative_term") String derivative_term) {
+               @PathParam("derivativeTerm") String derivativeTerm) {
        InputStream result = null;
-           result = getBlobContent(csid, derivative_term);
+           result = getBlobContent(csid, derivativeTerm);
            
        return result;
     }
     
     @GET
-    @Path("{csid}/derivatives/{derivative_term}")
+    @Path("{csid}/derivatives/{derivativeTerm}")
     public MultipartOutput getDerivative(@PathParam("csid") String csid,
-               @PathParam("derivative_term") String derivative_term) {
+               @PathParam("derivativeTerm") String derivativeTerm) {
        MultipartOutput result = null;
        
        ensureCSID(csid, READ);
         try {
                ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
-               ctx.setProperty(BlobInput.BLOB_DERIVATIVE_TERM_KEY, derivative_term);
+               BlobInput blobInput = BlobUtil.getBlobInput(ctx);
+               blobInput.setDerivativeTerm(derivativeTerm);
             result = get(csid, ctx);
             if (result == null) {
                 Response response = Response.status(Response.Status.NOT_FOUND).entity(
@@ -218,8 +226,7 @@ public class BlobResource extends ResourceBase {
        ensureCSID(csid, READ);
         try {
                ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
-               ctx.setProperty(BlobInput.BLOB_DERIVATIVE_LIST_KEY, true);
-            result = this.getDerivativeList(csid);
+            result = this.getDerivativeList(ctx, csid);
             if (result == null) {
                 Response response = Response.status(Response.Status.NOT_FOUND).entity(
                     ServiceMessages.READ_FAILED + ServiceMessages.resourceNotFoundMsg(csid)).type("text/plain").build();
index 13f1498a50a9ca5a23c8af7c09fe463b967857be..7fd798f0bac541bc2aaa23321b97c6cb81e4dcd5 100644 (file)
@@ -32,6 +32,7 @@ import org.collectionspace.services.jaxb.BlobJAXBSchema;
 
 import org.collectionspace.services.common.blob.BlobInput;
 import org.collectionspace.services.common.blob.BlobOutput;
+import org.collectionspace.services.common.blob.BlobUtil;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.common.document.DocumentHandler.Action;
@@ -46,6 +47,8 @@ import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
 import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
@@ -62,7 +65,7 @@ extends DocHandlerBase<BlobsCommon, AbstractCommonList> {
 
        /** The logger. */
        private final Logger logger = LoggerFactory.getLogger(BlobDocumentModelHandler.class);
-
+       
        public final String getNuxeoSchemaName(){
                return "blobs";
        }
@@ -79,7 +82,7 @@ extends DocHandlerBase<BlobsCommon, AbstractCommonList> {
                List list = ((BlobsCommonList)commonList).getBlobListItem();
                return list;
        }
-       
+               
        private String getDerivativePathBase(DocumentModel docModel) {
                return getServiceContextPath() + docModel.getName() + "/" +
                        BlobInput.URI_DERIVATIVES_PATH + "/";
@@ -146,24 +149,27 @@ extends DocHandlerBase<BlobsCommon, AbstractCommonList> {
        public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc)
                        throws Exception {
                ServiceContext ctx = this.getServiceContext();
+               BlobInput blobInput = BlobUtil.getBlobInput(ctx);
                RepositoryInstance repoSession = this.getRepositorySession();
                DocumentModel docModel = wrapDoc.getWrappedObject();
                BlobsCommon blobsCommon = this.getCommonPartProperties(docModel);               
                String blobRepositoryId = blobsCommon.getRepositoryId(); //cache the value to pass to the blob retriever
                
-               if (ctx.getProperty(BlobInput.BLOB_DERIVATIVE_LIST_KEY) != null) {
+               if (blobInput.isDerivativeListRequested() == true) {
                        BlobsCommonList blobsCommonList = NuxeoImageUtils.getBlobDerivatives(
                                        repoSession, blobRepositoryId, getDerivativePathBase(docModel));
-                       ctx.setProperty(BlobInput.BLOB_DERIVATIVE_LIST_KEY, blobsCommonList);
+//                     ctx.setProperty(BlobInput.BLOB_DERIVATIVE_LIST_KEY, blobsCommonList);
+                       blobInput.setDerivativeList(blobsCommonList);
                        return;  //FIXME: Don't like this exit point.  Perhaps derivatives should be a sub-resource?
                }               
 
-               String derivativeTerm = (String)ctx.getProperty(BlobInput.BLOB_DERIVATIVE_TERM_KEY);
-               Boolean getContentFlag = ctx.getProperty(BlobInput.BLOB_CONTENT_KEY) != null ? true : false;
+               String derivativeTerm = blobInput.getDerivativeTerm();
+               Boolean getContentFlag = blobInput.isContentRequested();
                BlobOutput blobOutput = NuxeoImageUtils.getBlobOutput(ctx, repoSession,
                                blobRepositoryId, derivativeTerm, getContentFlag);
                if (getContentFlag == true) {
-                       ctx.setProperty(BlobInput.BLOB_CONTENT_KEY, blobOutput.getBlobInputStream());
+                       blobInput.setContentStream(blobOutput.getBlobInputStream());
+//                     ctx.setProperty(BlobInput.BLOB_CONTENT_KEY, blobOutput.getBlobInputStream());
                }
 
                if (derivativeTerm != null) {
@@ -182,17 +188,18 @@ extends DocHandlerBase<BlobsCommon, AbstractCommonList> {
        @Override
        public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception {
                ServiceContext ctx = this.getServiceContext();
-               BlobInput blobInput = (BlobInput)ctx.getProperty(BlobInput.class.getName());
-               if (blobInput == null) {                
-                       super.fillAllParts(wrapDoc, action);
-               } else {
+               BlobInput blobInput = BlobUtil.getBlobInput(ctx);
+               if (blobInput.getBlobFile() != null) {                  
                        //
-                       // If blobInput is set then we just received a multipart/form-data file post
+                       // If blobInput has a file then we just received a multipart/form-data file post
                        //
                        DocumentModel documentModel = wrapDoc.getWrappedObject();
                        RepositoryInstance repoSession = this.getRepositorySession();           
                        BlobsCommon blobsCommon = NuxeoImageUtils.createPicture(ctx, repoSession, blobInput);
                        this.setCommonPartProperties(documentModel, blobsCommon);
+                       blobInput.setBlobCsid(documentModel.getName());
+               } else {
+                       super.fillAllParts(wrapDoc, action);
                }
        }    
 }
index 3fba1cd38d433d36f839b247096d7cba93da86a4..76ec2781f32934a8c9dbe358e43ef3284bc5f1f2 100644 (file)
  */\r
 package org.collectionspace.services.common;\r
 \r
+import java.util.List;\r
+\r
 import javax.ws.rs.GET;\r
 import javax.ws.rs.Path;\r
 import javax.ws.rs.Produces;\r
 import javax.ws.rs.core.MultivaluedMap;\r
+import javax.ws.rs.core.Response;\r
 \r
 import org.collectionspace.services.common.context.ServiceContext;\r
 import org.collectionspace.services.common.context.ServiceContextProperties;\r
@@ -35,6 +38,7 @@ import org.collectionspace.services.common.repository.RepositoryClient;
 import org.collectionspace.services.common.repository.RepositoryClientFactory;\r
 import org.collectionspace.services.common.storage.StorageClient;\r
 import org.collectionspace.services.common.storage.jpa.JpaStorageClientImpl;\r
+import org.jboss.resteasy.client.ClientResponse;\r
 \r
 /**\r
  * The Class AbstractCollectionSpaceResourceImpl.\r
@@ -55,6 +59,20 @@ public abstract class AbstractCollectionSpaceResourceImpl<IT, OT>
     /** The storage client. */\r
     private StorageClient storageClient;\r
 \r
+    /**\r
+     * Extract id.\r
+     *\r
+     * @param res the res\r
+     * @return the string\r
+     */\r
+    protected static String extractId(Response res) {\r
+        MultivaluedMap<String, Object> mvm = res.getMetadata();\r
+        String uri = (String) ((List<Object>) mvm.get("Location")).get(0);\r
+        String[] segments = uri.split("/");\r
+        String id = segments[segments.length - 1];\r
+        return id;\r
+    }    \r
+    \r
     /**\r
      * Instantiates a new abstract collection space resource.\r
      */\r
index b3222b2bb21b6560fad83ec999074beb980ad091..923a51b312f3e919af94a0d4a54adb2810c349da 100644 (file)
@@ -58,32 +58,34 @@ extends AbstractMultiPartCollectionSpaceResourceImpl {
         return bigReThrow(e, serviceMsg, "");\r
     }\r
 \r
-    protected WebApplicationException bigReThrow(Exception e, String serviceMsg, String csid)\r
-        throws WebApplicationException {\r
-                Response response;\r
-        if (logger.isDebugEnabled()) {\r
-             logger.debug(getClass().getName(), e);\r
-        }\r
-        if (e instanceof UnauthorizedException) {\r
-            response = Response.status(Response.Status.UNAUTHORIZED)\r
-                               .entity(serviceMsg + e.getMessage())\r
-                               .type("text/plain")\r
-                               .build();\r
-             return new WebApplicationException(response);\r
-        } else if (e instanceof DocumentNotFoundException) {\r
-            response = Response.status(Response.Status.NOT_FOUND)\r
-                               .entity(serviceMsg + " on "+getClass().getName()+" csid=" + csid)\r
-                               .type("text/plain")\r
-                               .build();\r
-            return new WebApplicationException(response);\r
-        } else {  //e is now instanceof Exception\r
-            response = Response.status(Response.Status.INTERNAL_SERVER_ERROR)\r
-                               .entity(serviceMsg)\r
-                               .type("text/plain")\r
-                               .build();\r
-            return new WebApplicationException(response);\r
-        }\r
-    }\r
+       protected WebApplicationException bigReThrow(Exception e,\r
+                       String serviceMsg, String csid) throws WebApplicationException {\r
+               Response response;\r
+               if (logger.isDebugEnabled()) {\r
+                       logger.debug(getClass().getName(), e);\r
+               }\r
+               if (e instanceof UnauthorizedException) {\r
+                       response = Response.status(Response.Status.UNAUTHORIZED)\r
+                                       .entity(serviceMsg + e.getMessage()).type("text/plain")\r
+                                       .build();\r
+                       return new WebApplicationException(response);\r
+               } else if (e instanceof DocumentNotFoundException) {\r
+                       response = Response\r
+                                       .status(Response.Status.NOT_FOUND)\r
+                                       .entity(serviceMsg + " on " + getClass().getName()\r
+                                                       + " csid=" + csid).type("text/plain").build();\r
+                       return new WebApplicationException(response);\r
+               } else if (e instanceof WebApplicationException) {\r
+                       //\r
+                       // subresource may have already thrown this exception\r
+                       // so just pass it on\r
+                       return (WebApplicationException)e;\r
+               } else { // e is now instanceof Exception\r
+                       response = Response.status(Response.Status.INTERNAL_SERVER_ERROR)\r
+                                       .entity(serviceMsg).type("text/plain").build();\r
+                       return new WebApplicationException(response);\r
+               }\r
+       }\r
 \r
     //======================= CREATE ====================================================\r
 \r
@@ -127,13 +129,22 @@ extends AbstractMultiPartCollectionSpaceResourceImpl {
         ensureCSID(csid, UPDATE);\r
         try {\r
                ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(theUpdate);\r
-            DocumentHandler handler = createDocumentHandler(ctx);\r
-            return update(csid, theUpdate, ctx, handler); //==> CALL implementation method, which subclasses may override.\r
+            return update(csid, theUpdate, ctx); //==> CALL implementation method, which subclasses may override.\r
         } catch (Exception e) {\r
             throw bigReThrow(e, ServiceMessages.UPDATE_FAILED, csid);\r
         }\r
     }\r
 \r
+    /** Subclasses may override this overload, which gets called from #udpate(String,MultipartInput)   */\r
+    protected MultipartOutput update(String csid,\r
+                                     MultipartInput theUpdate,\r
+                                     ServiceContext<MultipartInput, MultipartOutput> ctx)\r
+    throws Exception {\r
+        DocumentHandler handler = createDocumentHandler(ctx);\r
+        getRepositoryClient(ctx).update(ctx, csid, handler);\r
+        return (MultipartOutput) ctx.getOutput();\r
+    }\r
+\r
     /** Subclasses may override this overload, which gets called from #udpate(String,MultipartInput)   */\r
     protected MultipartOutput update(String csid,\r
                                      MultipartInput theUpdate,\r
index c76c06b84a9fadb73fb19362d6ca6feafb80cbb3..c0e565895e09228dfac76b4811b5a6fa049c9283 100644 (file)
 package org.collectionspace.services.common.blob;\r
 \r
 import java.io.File;\r
+import java.io.InputStream;\r
+\r
+import javax.servlet.http.HttpServletRequest;\r
+\r
+import org.collectionspace.services.blob.BlobsCommonList; \r
+import org.collectionspace.services.common.FileUtils;\r
 \r
 public class BlobInput {\r
-       private String mediaCsid;\r
-       private File blobFile;\r
-       private String blobUri;\r
+       private String blobCsid = null;\r
+       private File blobFile = null;\r
+       private String blobUri = null;\r
        \r
-       public static final String URI_CONTENT_PATH = "content";\r
-       public static final String URI_DERIVATIVES_PATH = "derivatives";\r
+       private String derivativeTerm;\r
+       private boolean derivativeListRequested = false;\r
+       private BlobsCommonList derivativeList;\r
+       \r
+       private boolean contentRequested = false;\r
+       private InputStream contentStream;\r
        \r
-       public static final String BLOB_DERIVATIVE_TERM_KEY = "derivative";\r
-       public static final String BLOB_DERIVATIVE_LIST_KEY = "derivative.list";\r
-       public static final String BLOB_CONTENT_KEY = "derivative.content.stream";\r
+       private boolean schemaRequested = false;\r
        \r
+       public static final String URI_CONTENT_PATH = "content";\r
+       public static final String URI_DERIVATIVES_PATH = "derivatives";\r
+\r
+       /*\r
+        * Constructors\r
+        */\r
+       public BlobInput() {\r
+               /* Empty constructor */\r
+       }\r
+               \r
        public BlobInput(File blobFile, String blobUri) {\r
                this.blobFile = blobFile;\r
                this.blobUri = blobUri;\r
        }\r
        \r
-       public String getMediaCsid() {\r
-               return mediaCsid;\r
+       /*\r
+        * Getters and Setters\r
+        */\r
+       public boolean isSchemaRequested() {\r
+               return schemaRequested;\r
        }\r
-       \r
+\r
+       public void setSchemaRequested(boolean schemaRequested) {\r
+               this.schemaRequested = schemaRequested;\r
+       }\r
+\r
+       public String getBlobCsid() {\r
+               return blobCsid;\r
+       }\r
+\r
+       public void setBlobCsid(String blobCsid) {\r
+               this.blobCsid = blobCsid;\r
+       }\r
+\r
        public File getBlobFile() {\r
                return blobFile;\r
        }\r
-       \r
+\r
+       public void setBlobFile(File blobFile) {\r
+               this.blobFile = blobFile;\r
+       }\r
+\r
        public String getBlobUri() {\r
                return blobUri;\r
        }\r
+\r
+       public void setBlobUri(String blobUri) {\r
+               this.blobUri = blobUri;\r
+       }\r
+\r
+       public String getDerivativeTerm() {\r
+               return derivativeTerm;\r
+       }\r
+\r
+       public void setDerivativeTerm(String derivativeTerm) {\r
+               this.derivativeTerm = derivativeTerm;\r
+       }\r
+\r
+       public boolean isDerivativeListRequested() {\r
+               return derivativeListRequested;\r
+       }\r
+\r
+       public void setDerivativeListRequested(boolean derivativesRequested) {\r
+               this.derivativeListRequested = derivativesRequested;\r
+       }\r
+\r
+       public BlobsCommonList getDerivativeList() {\r
+               return derivativeList;\r
+       }\r
+\r
+       public void setDerivativeList(BlobsCommonList derivativeList) {\r
+               this.derivativeList = derivativeList;\r
+       }\r
+\r
+       public InputStream getContentStream() {\r
+               return contentStream;\r
+       }\r
+\r
+       public void setContentStream(InputStream contentStream) {\r
+               this.contentStream = contentStream;\r
+       }\r
+\r
+       public boolean isContentRequested() {\r
+               return contentRequested;\r
+       }\r
+\r
+       public void setContentRequested(boolean contentRequested) {\r
+               this.contentRequested = contentRequested;\r
+       }       \r
+       /*\r
+        * End of setters and getters\r
+        */\r
+       \r
+       public void createBlobFile(HttpServletRequest req, String blobUri) {\r
+       File tmpFile = FileUtils.createTmpFile(req);\r
+       this.setBlobFile(tmpFile);\r
+       this.setBlobUri(blobUri);\r
+       }       \r
 }\r
 \r
index 3cab5df7bc0de7660224fe1e1b6a490c805b3506..3c04bc0d84284d3e6af4b8b19284efb3f1a63f73 100644 (file)
@@ -1,5 +1,34 @@
 package org.collectionspace.services.common.blob;\r
 \r
-public class BlobUtil {\r
+import org.collectionspace.services.common.context.ServiceContext;\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
 \r
+public class BlobUtil {\r
+       //FIXME: REM - We should have a class/interface in common that has constant defs for the names of all the services.\r
+       public static String BLOB_RESOURCE_NAME = "blobs";\r
+       private static final Logger logger = LoggerFactory.getLogger(BlobUtil.class);\r
+       \r
+    public static BlobInput getBlobInput(ServiceContext<MultipartInput, MultipartOutput> ctx) {\r
+       BlobInput result = (BlobInput)ctx.getProperty(BlobInput.class.getName());\r
+       if (result == null) {\r
+               result = new BlobInput();\r
+               setBlobInput(ctx, result);\r
+       }\r
+       return result;\r
+       }\r
+    \r
+    public static BlobInput resetBlobInput(ServiceContext<MultipartInput, MultipartOutput> ctx) {\r
+       BlobInput blobInput = new BlobInput();\r
+       setBlobInput(ctx, blobInput);\r
+       return blobInput;\r
+    }\r
+    \r
+    public static void setBlobInput(ServiceContext<MultipartInput, MultipartOutput> ctx,\r
+               BlobInput blobInput) {\r
+       ctx.setProperty(BlobInput.class.getName(), blobInput);                  \r
+       }       \r
+    \r
 }\r
index 83750d475d7d015ea39152f7e71f772328c97815..d8d02f4b28cac7d67d3623706033f6a99c03f9ef 100644 (file)
@@ -97,13 +97,21 @@ public abstract class RemoteDocumentModelHandlerImpl<T, TL>
         //return at least those document part(s) that were received
         Map<String, ObjectPartType> partsMetaMap = getServiceContext().getPartsMetadata();
         MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
-        List<InputPart> inputParts = ctx.getInput().getParts();
-        for (InputPart part : inputParts) {
-            String partLabel = part.getHeaders().getFirst("label");
-            ObjectPartType partMeta = partsMetaMap.get(partLabel);
-//            extractPart(docModel, partLabel, partMeta);
-            Map<String, Object> unQObjectProperties = extractPart(docModel, partLabel, partMeta);
-            addOutputPart(unQObjectProperties, partLabel, partMeta);
+        MultipartInput input = ctx.getInput();
+        if (input != null) {
+               List<InputPart> inputParts = ctx.getInput().getParts();
+               for (InputPart part : inputParts) {
+                   String partLabel = part.getHeaders().getFirst("label");
+                   ObjectPartType partMeta = partsMetaMap.get(partLabel);
+       //            extractPart(docModel, partLabel, partMeta);
+                   Map<String, Object> unQObjectProperties = extractPart(docModel, partLabel, partMeta);
+                   addOutputPart(unQObjectProperties, partLabel, partMeta);
+               }
+        } else {
+               if (logger.isWarnEnabled() == true) {
+                       logger.warn("MultipartInput part was null for document id = " +
+                                       docModel.getName());
+               }
         }
     }
 
index 004c53e4ef59bc98c93e966d4b3e80de67417d5c..23b789183037daf9eb44c398e1dc14b2450c678a 100644 (file)
@@ -68,5 +68,6 @@
     <xs:element name="title" type="xs:string"/>\r
     <xs:element name="type" type="xs:string"/>\r
     <xs:element name="uri" type="xs:string" />\r
+    <xs:element name="blobCsid" type="xs:string" />\r
 \r
 </xs:schema>\r
index a982ef65fedc7b541d36066823945728bb4e2cc7..0a41337ce584f6173f6f6d584130d19ea966a36d 100644 (file)
@@ -26,4 +26,5 @@ public interface MediaJAXBSchema {
     final static String title = "title";
     final static String type = "type";
     final static String uri = "uri";
+    final static String blobCsid = "blobCsid";
 }
index 124f3ee8c0ecd3a0d8042686806dd6792547e50b..2e581577d68aeb929879b658df6e7d58c09d1c9d 100644 (file)
@@ -54,6 +54,7 @@
                 <xs:element name="title" type="xs:string"/>
                 <xs:element name="type" type="xs:string"/>
                 <xs:element name="uri" type="xs:string" />
+                <xs:element name="blobCsid" type="xs:string" />
             </xs:sequence>
         </xs:complexType>
     </xs:element>
index 62bc6c0d8d3f146cdfcb2ad1719e8f1d923ccf9a..648ea35292819237b266a3a8a019dab1bb292bad 100644 (file)
             <artifactId>org.collectionspace.services.common</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.collectionspace.services</groupId>
+            <artifactId>org.collectionspace.services.jaxb</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.collectionspace.services</groupId>
+            <artifactId>org.collectionspace.services.blob.service</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.collectionspace.services</groupId>
             <artifactId>org.collectionspace.services.media.jaxb</artifactId>
index f392b4888ea2e7737fb00abc28cb3345e0417b0b..97446a576da8184cb40fbc9cbecd4848713d5176 100644 (file)
@@ -26,11 +26,33 @@ package org.collectionspace.services.media;
 import org.collectionspace.services.common.ResourceBase;
 import org.collectionspace.services.common.ClientType;
 import org.collectionspace.services.common.ServiceMain;
+import org.collectionspace.services.common.ServiceMessages;
+import org.collectionspace.services.common.blob.BlobInput;
+import org.collectionspace.services.common.blob.BlobUtil;
+import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.document.DocumentHandler;
+import org.collectionspace.services.blob.BlobsCommon;
+import org.collectionspace.services.blob.BlobsCommonList;
+import org.collectionspace.services.blob.nuxeo.BlobDocumentModelHandler;
+import org.collectionspace.services.blob.BlobResource;
 
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
+
+import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
 import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+
+import java.io.InputStream;
 import java.util.List;
 
 @Path("/media")
@@ -41,8 +63,41 @@ public class MediaResource extends ResourceBase {
     @Override
     public String getServiceName(){
         return "media";
-    };
+    }
+    
+    private BlobResource blobResource = new BlobResource();
+    BlobResource getBlobResource() {
+       return blobResource;
+    }
+    
+//     /*
+//      * This member is used to get and set context for the blob document handler
+//      */
+//     private BlobInput blobInput = new BlobInput();
+//     
+//    public BlobInput getBlobInput(ServiceContext<MultipartInput, MultipartOutput> ctx) {
+//     //
+//     // Publish the blobInput to the current context on every get.  Even though
+//     // it might already be published.
+//     //
+//     BlobUtil.setBlobInput(ctx, blobInput);
+//             return blobInput;
+//     }
 
+       private String getBlobCsid(String mediaCsid) throws Exception {
+               String result = null;
+               
+       ServiceContext<MultipartInput, MultipartOutput> mediaContext = createServiceContext();
+       BlobInput blobInput = BlobUtil.getBlobInput(mediaContext);
+       blobInput.setSchemaRequested(true);
+        get(mediaCsid, mediaContext); //this call sets the blobInput.blobCsid field for us
+        result = blobInput.getBlobCsid();
+       ensureCSID(result, READ);
+               
+        return result;
+       }
+       
+    
     //FIXME retrieve client type from configuration
     final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType();
 
@@ -57,6 +112,124 @@ public class MediaResource extends ResourceBase {
        return MediaCommon.class;
     }
 
+    @POST
+    @Path("{csid}")
+    @Consumes("multipart/form-data")
+    @Produces("application/xml")
+    public Response createBlob(@Context HttpServletRequest req,
+               @QueryParam("blobUri") String blobUri,
+               @PathParam("csid") String csid) {
+       MultipartInput input = null;
+       Response response = null;       
+       try {
+               //
+               // First, create the blob
+               //
+               ServiceContext<MultipartInput, MultipartOutput> blobContext = createServiceContext(BlobUtil.BLOB_RESOURCE_NAME, input);
+               BlobInput blobInput = BlobUtil.getBlobInput(blobContext);
+               blobInput.createBlobFile(req, blobUri);
+               response = this.create(input, blobContext);
+               //
+               // Next, update the Media record to be linked to the blob
+               //
+               ServiceContext<MultipartInput, MultipartOutput> mediaContext = createServiceContext();
+               BlobUtil.setBlobInput(mediaContext, blobInput); //and put the blobInput into the Media context
+               this.update(csid, input, mediaContext);
 
+       } catch (Exception e) {
+               throw bigReThrow(e, ServiceMessages.CREATE_FAILED);
+       }
+                       
+               return response;
+    }    
+
+    @GET
+    @Path("{csid}/blob")
+    public MultipartOutput getBlobInfo(@PathParam("csid") String csid) {
+       MultipartOutput result = null;
+       
+           try {
+               String blobCsid = this.getBlobCsid(csid);
+               ServiceContext<MultipartInput, MultipartOutput> blobContext = createServiceContext(BlobUtil.BLOB_RESOURCE_NAME);
+               result = this.get(blobCsid, blobContext);               
+           } catch (Exception e) {
+               throw bigReThrow(e, ServiceMessages.READ_FAILED, csid);
+           }
+           
+           return result;
+    }
     
+    @GET
+    @Path("{csid}/blob/content")
+    @Produces({"image/jpeg", "image/png", "image/tiff"})
+    public InputStream getBlobContent(
+               @PathParam("csid") String csid) {
+       InputStream result = null;
+       
+           try {
+               ensureCSID(csid, READ);
+               String blobCsid = this.getBlobCsid(csid);
+               result = getBlobResource().getBlobContent(blobCsid);            
+           } catch (Exception e) {
+               throw bigReThrow(e, ServiceMessages.READ_FAILED, csid);
+           }
+           
+       return result;
+    }
+    
+    @GET
+    @Path("{csid}/blob/derivatives/{derivativeTerm}/content")
+    @Produces({"image/jpeg", "image/png", "image/tiff"})
+    public InputStream getDerivativeContent(
+               @PathParam("csid") String csid,
+               @PathParam("derivativeTerm") String derivativeTerm) {
+       InputStream result = null;
+       
+           try {
+               ensureCSID(csid, READ);
+               String blobCsid = this.getBlobCsid(csid);
+               result = getBlobResource().getDerivativeContent(blobCsid, derivativeTerm);              
+           } catch (Exception e) {
+               throw bigReThrow(e, ServiceMessages.READ_FAILED, csid);
+           }
+           
+       return result;
+    }
+            
+    @GET
+    @Path("{csid}/blob/derivatives/{derivativeTerm}")
+    public MultipartOutput getDerivative(@PathParam("csid") String csid,
+               @PathParam("derivativeTerm") String derivativeTerm) {
+       MultipartOutput result = null;
+
+           try {
+               ensureCSID(csid, READ);
+               String blobCsid = this.getBlobCsid(csid);
+               ServiceContext<MultipartInput, MultipartOutput> blobContext = createServiceContext(BlobUtil.BLOB_RESOURCE_NAME);
+               result = getBlobResource().getDerivative(blobCsid, derivativeTerm);             
+           } catch (Exception e) {
+               throw bigReThrow(e, ServiceMessages.READ_FAILED, csid);
+           }
+           
+       return result;
+    }
+    
+    @GET
+    @Path("{csid}/blob/derivatives")
+    @Produces("application/xml")    
+    public BlobsCommonList getDerivatives(
+               @PathParam("csid") String csid) {
+       BlobsCommonList result = null;
+
+           try {
+               ensureCSID(csid, READ);
+               String blobCsid = this.getBlobCsid(csid);
+               ServiceContext<MultipartInput, MultipartOutput> blobContext = createServiceContext(BlobUtil.BLOB_RESOURCE_NAME);
+               result = getBlobResource().getDerivatives(blobCsid);            
+           } catch (Exception e) {
+               throw bigReThrow(e, ServiceMessages.READ_FAILED, csid);
+           }
+           
+       return result;
+    }
 }
index 3f3edeb81d1fb37ad260e3cb9139e87d2353c4e7..03b808783c1ab97abfae77ed49a4f71e2729d3a9 100644 (file)
@@ -26,19 +26,30 @@ package org.collectionspace.services.media.nuxeo;
 import java.util.List;
 
 import org.collectionspace.services.MediaJAXBSchema;
+import org.collectionspace.services.blob.BlobsCommon;
 import org.collectionspace.services.common.DocHandlerBase;
+import org.collectionspace.services.common.blob.BlobInput;
+import org.collectionspace.services.common.blob.BlobUtil;
+import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.document.DocumentWrapper;
+import org.collectionspace.services.common.document.DocumentHandler.Action;
+import org.collectionspace.services.common.imaging.nuxeo.NuxeoImageUtils;
 import org.collectionspace.services.media.MediaCommon;
 import org.collectionspace.services.media.MediaCommonList;
 import org.collectionspace.services.media.MediaCommonList.MediaListItem;
 import org.collectionspace.services.jaxb.AbstractCommonList;
+import org.collectionspace.services.jaxb.BlobJAXBSchema;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 import org.nuxeo.ecm.core.api.DocumentModel;
+import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
 
 /**
  * The Class MediaDocumentModelHandler.
  */
 public class MediaDocumentModelHandler
         extends DocHandlerBase<MediaCommon, AbstractCommonList> {
-
+       
     public final String getNuxeoSchemaName(){
         return "media";
     }
@@ -55,7 +66,17 @@ public class MediaDocumentModelHandler
         List list = ((MediaCommonList)commonList).getMediaListItem();
         return list;
     }
-
+    
+       private MediaCommon getCommonPartProperties(DocumentModel docModel) throws Exception {
+               String label = getServiceContext().getCommonPartLabel();
+               MediaCommon result = new MediaCommon();
+               
+               result.setBlobCsid((String)     
+                               docModel.getProperty(label, MediaJAXBSchema.blobCsid));
+               
+               return result;
+       }
+    
     public Object createItemForCommonList(DocumentModel docModel, String label, String id) throws Exception {
         MediaListItem item = new MediaListItem();
         item.setTitle((String) docModel.getProperty(label, MediaJAXBSchema.title));
@@ -66,5 +87,38 @@ public class MediaDocumentModelHandler
         item.setCsid(id);
         return item;
     }
+    
+       @Override
+       public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc)
+                       throws Exception {
+               ServiceContext ctx = this.getServiceContext();
+               
+               BlobInput blobInput = BlobUtil.getBlobInput(ctx);
+               if (blobInput != null && blobInput.isSchemaRequested()) { //Extract the blob info instead of the media info
+                       DocumentModel docModel = wrapDoc.getWrappedObject();
+                       MediaCommon mediaCommon = this.getCommonPartProperties(docModel);               
+                       String blobCsid = mediaCommon.getBlobCsid(); //cache the value to pass to the blob retriever
+                       blobInput.setBlobCsid(blobCsid);
+               } else {
+                       super.extractAllParts(wrapDoc);
+               }               
+       }
+    
+       @Override
+       public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception {
+               ServiceContext ctx = this.getServiceContext();
+               BlobInput blobInput = BlobUtil.getBlobInput(ctx);
+               if (blobInput != null && blobInput.getBlobCsid() != null) {
+                       String blobCsid = blobInput.getBlobCsid();
+                       //
+                       // If getBlobCsid has a value then we just received a multipart/form-data file post
+                       //
+                       DocumentModel documentModel = wrapDoc.getWrappedObject();
+                       documentModel.setProperty(ctx.getCommonPartLabel(), MediaJAXBSchema.blobCsid, blobCsid);
+               } else {
+                       super.fillAllParts(wrapDoc, action);
+               }
+       }    
+    
 }