]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-3598: Media and Blob tests needed to create example media data in the "Nightly...
authorRichard Millet <richard.millet@berkeley.edu>
Wed, 23 Feb 2011 21:22:26 +0000 (21:22 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Wed, 23 Feb 2011 21:22:26 +0000 (21:22 +0000)
16 files changed:
services/blob/client/src/main/java/org/collectionspace/services/client/BlobClient.java
services/blob/client/src/main/java/org/collectionspace/services/client/BlobProxy.java
services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java
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/client/src/main/java/org/collectionspace/services/client/PoxPayloadIn.java
services/client/src/main/java/org/collectionspace/services/client/PoxPayloadOut.java
services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java
services/common/src/main/java/org/collectionspace/services/common/FileUtils.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/media/client/pom.xml
services/media/client/src/main/java/org/collectionspace/services/client/MediaClient.java
services/media/client/src/main/java/org/collectionspace/services/client/MediaProxy.java
services/media/client/src/test/java/org/collectionspace/services/client/test/MediaServiceTest.java
services/media/service/src/main/java/org/collectionspace/services/media/MediaResource.java

index 387f9af63e937699a11d21ad145b53fdef878caa..82ac3c5a10eadf05db67c7dbb1dfebb65b8502dd 100644 (file)
@@ -27,6 +27,13 @@ import org.jboss.resteasy.client.ClientResponse;
 import org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor;
 import org.jboss.resteasy.spi.ResteasyProviderFactory;
 
+import org.jboss.resteasy.plugins.providers.multipart.InputPart;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataOutput;
+
+
 /**
  * BlobClient.java
  *
@@ -40,6 +47,10 @@ public class BlobClient extends AbstractServiceClientImpl {
        public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT;
        public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME;
 
+       //HTTP query param string for specifying a URI source to blob bits.
+       public static final String BLOB_URI_PARAM = "blobUri";
+       
+
        @Override
        public String getServiceName() {
                return SERVICE_NAME;
@@ -73,7 +84,8 @@ public class BlobClient extends AbstractServiceClientImpl {
     /**
      * allow to reset proxy as per security needs
      */
-    public void setProxy() {
+    @Override
+       public void setProxy() {
         if (useAuth()) {
             blobProxy = ProxyFactory.create(BlobProxy.class,
                     getBaseURL(), new ApacheHttpClientExecutor(getHttpClient()));
@@ -126,8 +138,16 @@ public class BlobClient extends AbstractServiceClientImpl {
      */
     public ClientResponse<Response> create(PoxPayloadOut xmlPayload) {
         return blobProxy.create(xmlPayload.getBytes());
+    }    
+    
+    public ClientResponse<Response> createBlobFromFormData(MultipartFormDataOutput formDataOutput) {
+        return blobProxy.createBlobFromFormData(formDataOutput);
     }
-
+    
+    public ClientResponse<Response> createBlobFromURI(String blobUri) {
+        return blobProxy.createBlobFromURI("".getBytes(), blobUri);
+    }
+    
     /**
      * @param csid
      * @param blob
index d6c7ff9d094df57c72596e99456016ea0d841502..b9b2703ceda83893717c9ff952fa5bb4c8d26f81 100644 (file)
@@ -8,24 +8,42 @@ import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Response;
 
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
 import org.collectionspace.services.jaxb.AbstractCommonList;
 import org.jboss.resteasy.client.ClientResponse;
 
+import org.jboss.resteasy.plugins.providers.multipart.InputPart;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataOutput;
+
+
 /**
  * @version $Revision: 2108 $
  */
 @Path(BlobClient.SERVICE_PATH + "/")
-@Produces({"application/xml"})
-@Consumes({"application/xml"})
+@Produces("application/xml")
+@Consumes("application/xml")
 public interface BlobProxy extends CollectionSpaceProxy {
 
     //(C)reate
     @POST
     ClientResponse<Response> create(byte[] xmlPayload);
 
+    //(C)reate
+    @POST
+    ClientResponse<Response> createBlobFromURI(byte[] xmlPayload, 
+               @QueryParam(BlobClient.BLOB_URI_PARAM) String blobUri);
+
+    //(C)reate
+    @POST
+    @Consumes("multipart/form-data")
+    ClientResponse<Response> createBlobFromFormData(MultipartFormDataOutput formDataOutput);
+    
     //(R)ead
     @GET
     @Path("/{csid}")
index b765a6e336cde3f9573850435d6780bd456adfb1..8867531fc36abf162d374caf6f1b76386cdb4c22 100644 (file)
  */
 package org.collectionspace.services.client.test;
 
+import java.io.File;
 import java.util.List;
+
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 
 import org.collectionspace.services.client.CollectionSpaceClient;
 import org.collectionspace.services.client.BlobClient;
-import org.collectionspace.services.client.ContactClient;
 import org.collectionspace.services.client.PayloadOutputPart;
 import org.collectionspace.services.client.PoxPayloadIn;
 import org.collectionspace.services.client.PoxPayloadOut;
 import org.collectionspace.services.jaxb.AbstractCommonList;
 import org.collectionspace.services.blob.BlobsCommon;
 
-import org.jboss.resteasy.client.ClientResponse;
-
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
-import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import org.jboss.resteasy.client.ClientResponse;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataOutput;
+import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
+
 /**
  * BlobServiceTest, carries out tests against a deployed and running Blob Service. <p/>
  * $LastChangedRevision:  $
@@ -56,6 +57,9 @@ public class BlobServiceTest extends AbstractServiceTestImpl {
     private final String CLASS_NAME = BlobServiceTest.class.getName();
     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
     private String knownResourceId = null;
+    private static final String BLOBS_DIR = "blobs";
+    
+    private boolean blobCleanup = true;
 
     @Override
        public String getServicePathComponent() {
@@ -77,6 +81,25 @@ public class BlobServiceTest extends AbstractServiceTestImpl {
         return response.getEntity(AbstractCommonList.class);
     }
 
+    /**
+     * Sets up create tests.
+     */
+    @Override
+       protected void setupCreate() {
+        super.setupCreate();
+        String noBlobCleanup = System.getProperty(NO_BLOB_CLEANUP);
+       if(Boolean.TRUE.toString().equalsIgnoreCase(noBlobCleanup)) {
+               //
+               // Don't delete the blobs that we created during the test cycle
+               //
+            this.blobCleanup = false;
+       }
+    }
+    
+    private boolean blobCleanup() {
+       return blobCleanup;
+    }
+    
     @Override
     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
     public void create(String testName) throws Exception {
@@ -92,6 +115,69 @@ public class BlobServiceTest extends AbstractServiceTestImpl {
         }
         allResourceIdsCreated.add(extractId(res)); // Store the IDs from every resource created by tests so they can be deleted after tests have been run.
     }
+    
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"})
+    public void createBlobFromURI(String testName) throws Exception {
+        logger.debug(testBanner(testName, CLASS_NAME));
+        setupCreate();
+        BlobClient client = new BlobClient();
+        
+        String currentDir = this.getResourceDir();
+        String blobsDirPath = currentDir + File.separator + BLOBS_DIR;
+        File blobsDir = new File(blobsDirPath);
+        if (blobsDir != null && blobsDir.exists()) {
+               File[] children = blobsDir.listFiles();
+               if (children != null && children.length > 0) {
+                       for (File child : children) {
+                               String mimeType = this.getMimeType(child);
+                               logger.debug("Processing file URI: " + child.getAbsolutePath());
+                               logger.debug("MIME type is: " + mimeType);
+                           ClientResponse<Response> res = client.createBlobFromURI(child.getAbsolutePath());
+                           assertStatusCode(res, testName);
+                           if (blobCleanup == true) {
+                               allResourceIdsCreated.add(extractId(res));
+                           }
+                       }
+               } else {
+                       logger.debug("Directory: " + blobsDirPath + " is empty or cannot be read.");
+               }
+        } else {
+               logger.debug("Directory: " + blobsDirPath + " is missing or cannot be read.");
+        }        
+    }
+    
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+               dependsOnMethods = {"createBlobFromURI"})
+    public void createBlobwithPost(String testName) throws Exception {
+        logger.debug(testBanner(testName, CLASS_NAME));
+        setupCreate();
+        BlobClient client = new BlobClient();
+        
+        String currentDir = this.getResourceDir();
+        String blobsDirPath = currentDir + File.separator + BLOBS_DIR;
+        File blobsDir = new File(blobsDirPath);
+        if (blobsDir != null && blobsDir.exists()) {
+               File[] children = blobsDir.listFiles();
+               if (children != null && children.length > 0) {
+                       for (File child : children) {
+                               String mimeType = this.getMimeType(child);
+                               logger.debug("Posting file: " + child.getAbsolutePath());
+                               logger.debug("MIME type is: " + mimeType);
+                           MultipartFormDataOutput form = new MultipartFormDataOutput();
+                           OutputPart outputPart = form.addFormData("file", child, MediaType.valueOf(mimeType));
+                           ClientResponse<Response> res = client.createBlobFromFormData(form);
+                           assertStatusCode(res, testName);
+                           if (blobCleanup == true) {
+                               allResourceIdsCreated.add(extractId(res));
+                           }
+                       }
+               } else {
+                       logger.debug("Directory: " + blobsDirPath + " is empty or cannot be read.");
+               }
+        } else {
+               logger.debug("Directory: " + blobsDirPath + " is missing or cannot be read.");
+        }
+    }
 
     @Override
     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"})
index 98b255c08ea909eac1f4786f81e3e62bda8756eb..a0cdf9a95316116960439167b3a7c148c86df772 100644 (file)
@@ -48,6 +48,7 @@ import javax.xml.parsers.ParserConfigurationException;
 import org.jboss.resteasy.plugins.providers.multipart.InputPart;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
 
 //FIXME: REM - We should not have Nuxeo dependencies in our resource classes.
 import org.collectionspace.services.common.imaging.nuxeo.NuxeoImageUtils;
@@ -66,18 +67,18 @@ import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
 import javax.ws.rs.core.Response.ResponseBuilder;
 import javax.ws.rs.core.MediaType;
 
-import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
 
 import java.io.File;
 import java.io.InputStream;
 import java.util.List;
 
 @Path(BlobClient.SERVICE_PATH)
-@Consumes({"multipart/mixed", "application/xml"})
-@Produces({"multipart/mixed", "application/xml"})
+@Consumes("application/xml")
+@Produces("application/xml")
 public class BlobResource extends ResourceBase {
 
        @Override
@@ -209,7 +210,7 @@ public class BlobResource extends ResourceBase {
     @Consumes("multipart/form-data")
     @Produces("application/xml")
     public Response createBlob(@Context HttpServletRequest req,
-               @QueryParam("blobUri") String blobUri) {
+               @QueryParam(BlobClient.BLOB_URI_PARAM) String blobUri) {
        Response response = null;       
        try {
                ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext();
@@ -220,6 +221,30 @@ public class BlobResource extends ResourceBase {
                throw bigReThrow(e, ServiceMessages.CREATE_FAILED);
        }
                        
+               return response;
+    }
+    
+    @POST
+    @Override
+    public Response create(@Context UriInfo ui,
+               String xmlPayload) {
+       Response response = null;
+       MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
+       String blobUri = queryParams.getFirst(BlobClient.BLOB_URI_PARAM);
+       
+       try {
+               if (blobUri != null) {
+                       ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext();
+                       BlobInput blobInput = BlobUtil.getBlobInput(ctx);
+                       blobInput.createBlobFile(blobUri);
+                       response = this.create(null, ctx);
+               } else {
+                       response = super.create(ui, xmlPayload);
+               }
+       } catch (Exception e) {
+               throw bigReThrow(e, ServiceMessages.CREATE_FAILED);
+       }
+                       
                return response;
     }    
     
@@ -271,7 +296,6 @@ public class BlobResource extends ResourceBase {
         
     @GET
     @Path("{csid}/derivatives")
-    @Produces("application/xml")
     public CommonList getDerivatives(
                @PathParam("csid") String csid) {
        CommonList result = null;
index 8cac45583d6fe9a95992e35a74ab3b561ba3d5e7..46ff10703b9d0381362543a90dbc70314b520d07 100644 (file)
@@ -146,7 +146,7 @@ extends DocHandlerBase<BlobsCommon> {
                BlobInput blobInput = BlobUtil.getBlobInput(ctx);
                if (blobInput.getBlobFile() != null) {                  
                        //
-                       // If blobInput has a file 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 or a URI query parameter
                        //
                        DocumentModel documentModel = wrapDoc.getWrappedObject();
                        RepositoryInstance repoSession = this.getRepositorySession();           
index 585a0f38f7f01fee2f4a5bbc40d7f734d7596de7..77d8fef81fac9201802c1fa5f863f3f1eb08e1a0 100644 (file)
@@ -17,15 +17,24 @@ import org.dom4j.Element;
 //import org.dom4j.Namespace;\r
 //import org.dom4j.io.SAXReader;\r
 //import org.xml.sax.InputSource;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
 \r
 public class PoxPayloadIn extends PoxPayload<PayloadInputPart> {\r
 \r
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());\r
+\r
        /*\r
         * Parse the POX 'xmlPayload' into individual parts.  Each part is saved\r
         * as a DOM4j Element and, if possible, a JAXB object instance as well.\r
         */\r
        public PoxPayloadIn(String xmlPayload) throws DocumentException {\r
                super(xmlPayload);\r
+               if (logger.isTraceEnabled() == true) {\r
+                       logger.trace("\n\n>>>> Payload In : BEGIN >>>>\n" +\r
+                                       xmlPayload +\r
+                                       "\n>>>> Payload In : END   >>>>\n");\r
+               }\r
        }\r
        \r
        /* (non-Javadoc)\r
index 3bae323df798812bd82e108d7ab019a7211b5190..1b9d08d23cc6d63566e63cdc1a12d58468ea2b55 100644 (file)
@@ -7,6 +7,8 @@ import org.dom4j.DocumentException;
 import org.dom4j.DocumentHelper;\r
 import org.dom4j.Element;\r
 import org.dom4j.io.SAXReader;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
 \r
 import java.io.File;\r
 import java.io.IOException;\r
@@ -19,6 +21,8 @@ import java.util.Iterator;
  */\r
 public class PoxPayloadOut extends PoxPayload<PayloadOutputPart> {\r
                        \r
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());\r
+       \r
        /**\r
         * Instantiates a new pox payload out.\r
         *\r
@@ -89,6 +93,13 @@ public class PoxPayloadOut extends PoxPayload<PayloadOutputPart> {
                        }\r
                }\r
                result = document.asXML();\r
+               \r
+               if (logger.isTraceEnabled() == true) {\r
+                       logger.trace("\n\n<<<< Payload Out : BEGIN <<<<\n" +\r
+                                       result +\r
+                                       "\n<<<< Payload Out : END   <<<<\n");\r
+               }\r
+               \r
                return result;\r
        }\r
                \r
index cea08b4c7e8ecdc80754f2a2119b018af930abfd..acd7dae5afca02a2828746abbff40076196fcbee 100644 (file)
  */
 package org.collectionspace.services.client.test;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 
 import org.collectionspace.services.jaxb.AbstractCommonList;
 import org.collectionspace.services.client.CollectionSpaceClient;
 import org.jboss.resteasy.client.ClientResponse;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+
 import org.testng.Assert;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.Test;
 
+import javax.activation.MimetypesFileTypeMap;
+
+
 /**
  * AbstractServiceTestImpl
  *
@@ -60,7 +66,24 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements
     /** The Constant DEFAULT_LIST_SIZE. */
     static protected final int DEFAULT_LIST_SIZE = 10;
     static protected final int DEFAULT_PAGINATEDLIST_SIZE = 10;
+    static protected final String RESOURCE_PATH = "src" + File.separator +
+       "test" + File.separator +
+       "resources";
+    static protected final String DEFAULT_MIME = "application/octet-stream; charset=ISO-8859-1";
+    static private final String NO_TEST_CLEANUP = "noTestCleanup";
+    static protected final String NO_BLOB_CLEANUP = "noBlobCleanup";
+
+    protected String getMimeType(File theFile) {
+       String result = null;
+       result = new MimetypesFileTypeMap().getContentType(theFile);
+       if (result == null) {
+               logger.debug("Could not get MIME type for file at: " + theFile.getAbsolutePath());
+               result = DEFAULT_MIME;
+       }
+       
+       return result;
 
+    }
     /* Use this to keep track of resources to delete */
     protected List<String> allResourceIdsCreated = new ArrayList<String>();
     private String EMPTY_SORT_BY_ORDER = "";
@@ -74,6 +97,14 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements
        return this.logger;
     }
 
+    protected String getResourceDir() {
+       String result = null;
+        String currentDirectory = System.getProperty("user.dir");
+        result = currentDirectory + File.separator + RESOURCE_PATH;
+        return result;
+    }
+    
+    
     // ---------------------------------------------------------------
     // CRUD tests : CREATE tests
     //
@@ -365,8 +396,8 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements
      */
     @AfterClass(alwaysRun=true)
     public void cleanUp() {
-        String noTest = System.getProperty("noTestCleanup");
-       if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
+        String noTestCleanup = System.getProperty(NO_TEST_CLEANUP);
+       if(Boolean.TRUE.toString().equalsIgnoreCase(noTestCleanup)) {
             if (logger.isDebugEnabled()) {
                 logger.debug("Skipping Cleanup phase ...");
             }
index c14be1559d3217d876565cb199ad9ecb7abf5af2..eb4c6e0a25d55e8da51da6da66cd897eada5ac7e 100644 (file)
@@ -23,12 +23,26 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory;
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 \r
+// TODO: Auto-generated Javadoc\r
+/**\r
+ * The Class FileUtils.\r
+ */\r
 public class FileUtils {\r
        /** The Constant logger. */\r
        private static final Logger logger = LoggerFactory.getLogger(FileUtils.class);\r
        \r
-       private static final String TMP_FILE_PREFIX = "cspace_blob_";\r
+       /** The Constant TMP_FILE_PREFIX. */\r
+       public static final String TMP_BLOB_PREFIX = "cspace_blob_";\r
+       public static final String DEFAULT_BLOB_NAME = "blob";\r
+       private static final String FILE_FORM_FIELD = "file";\r
        \r
+       /**\r
+        * Creates the tmp file.\r
+        *\r
+        * @param streamIn the stream in\r
+        * @param filePrefix the file prefix\r
+        * @return the file\r
+        */\r
        static public File createTmpFile(InputStream streamIn,\r
                        String filePrefix) {\r
                File result = null;\r
@@ -57,6 +71,12 @@ public class FileUtils {
                return result;\r
        }\r
        \r
+       /**\r
+        * Look for an uploaded file from the HTTP request of type "multipart/form-data".\r
+        *\r
+        * @param request the request\r
+        * @return the file\r
+        */\r
        static public File createTmpFile(HttpServletRequest request) {\r
                File result = null;\r
                \r
@@ -64,31 +84,33 @@ public class FileUtils {
                ServletFileUpload upload = new ServletFileUpload(factory);\r
 \r
                try {\r
-                       List  items = upload.parseRequest(request);\r
-                       Iterator iter = items.iterator();\r
+                       List<FileItem>  items = upload.parseRequest(request);\r
+                       Iterator<FileItem> iter = items.iterator();\r
 \r
                        while (iter.hasNext()) {\r
-                               FileItem item = (FileItem) iter.next();\r
-\r
-                               if (item.isFormField()) {\r
-                                       if (logger.isDebugEnabled() == true) {\r
-                                               String formFieldName = item.getFieldName();\r
-                                               logger.debug("FORM FIELD:" + formFieldName);\r
+                               FileItem item = iter.next();\r
+                               String formFieldName = item.getFieldName();\r
+                               if (logger.isTraceEnabled() == true) {\r
+                                       logger.trace("HTTP Request form field:" + formFieldName);\r
+                               }\r
+                               if (formFieldName.equalsIgnoreCase(FILE_FORM_FIELD)) {\r
+                                       if (item.isFormField() == true) {\r
+                                               logger.warn(FILE_FORM_FIELD + ": part is marked as a form field.");\r
                                        }\r
-                               } else {\r
-                                       if (!item.isFormField()) {\r
-\r
-                                               String fileName = item.getName();\r
-                                               System.out.println("File Name:" + fileName);\r
-\r
-                                               File fullFile  = new File(item.getName());\r
-                                               String tmpDir = System.getProperty("java.io.tmpdir");\r
-                                               File savedFile = new File(tmpDir, fullFile.getName());\r
-\r
-                                               item.write(savedFile);\r
-//                                             item.getInputStream();//FIXME: We should make a version of this method that returns the input stream\r
-                                               result = savedFile;\r
+                                       String fileName = item.getName();\r
+                                       if (logger.isTraceEnabled() == true) {\r
+                                               logger.trace("Uploaded File Name:" + (fileName != null ? fileName : "<empty>"));\r
                                        }\r
+                                       if (fileName == null) {\r
+                                               fileName = DEFAULT_BLOB_NAME; //if there's no file name then set it to an empty string\r
+                                               logger.warn("File was posted to the services without a file name.");\r
+                                       }                                       \r
+                                       File tmpDir = new File(System.getProperty("java.io.tmpdir"));\r
+                                       File savedFile = File.createTempFile(TMP_BLOB_PREFIX, fileName, tmpDir);\r
+\r
+                                       item.write(savedFile);\r
+//                                             item.getInputStream();//FIXME: REM - We should make a version of this method that returns the input stream\r
+                                       result = savedFile;\r
                                }\r
                        }\r
                } catch (Exception e) {\r
index ab0f3ff6550357e68cdccd4f66b16e3d39c72e3a..def456339c0abad5223cba66f016f4e22bb133cb 100644 (file)
@@ -22,6 +22,7 @@ import org.nuxeo.ecm.core.api.DocumentModel;
 \r
 import javax.ws.rs.*;\r
 import javax.ws.rs.core.*;\r
+\r
 import java.util.List;\r
 \r
 /**\r
@@ -92,7 +93,8 @@ extends AbstractMultiPartCollectionSpaceResourceImpl {
     //======================= CREATE ====================================================\r
 \r
     @POST\r
-    public Response create(String xmlPayload) {\r
+    public Response create(@Context UriInfo ui,\r
+               String xmlPayload) {\r
         try {\r
                PoxPayloadIn input = new PoxPayloadIn(xmlPayload);\r
                ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(input);\r
index a7bf2d71eff0f7c510393a03bbc78a2240f64cae..70b871aff76aaa1c8b566cf4a413640ebad79f74 100644 (file)
@@ -121,6 +121,13 @@ public class BlobInput {
        File tmpFile = FileUtils.createTmpFile(req);\r
        this.setBlobFile(tmpFile);\r
        this.setBlobUri(blobUri);\r
+       }\r
+       \r
+       public void createBlobFile(String theBlobUri) {\r
+       File theBlobFile = new File(theBlobUri);\r
+       this.setBlobFile(theBlobFile);\r
+       this.setBlobUri(blobUri);\r
        }       \r
+       \r
 }\r
 \r
index 3e182abd817d5ee52f31e98d5a8915f90c4eaf0d..4fad60529517a0a0a0ab95fc46610ed30f39ee14 100644 (file)
             <groupId>org.collectionspace.services</groupId>
             <artifactId>org.collectionspace.services.client</artifactId>
             <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.collectionspace.services</groupId>
+            <artifactId>org.collectionspace.services.blob.client</artifactId>
+            <version>${project.version}</version>
         </dependency>
          <dependency>
             <groupId>org.collectionspace.services</groupId>
index 436fde70aa9710045e64817b8444a5b51fb79f6b..a10b346693a74dcbb2615ebfabd6e241c473a889 100644 (file)
@@ -26,8 +26,8 @@ import org.jboss.resteasy.client.ProxyFactory;
 import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
 import org.jboss.resteasy.client.ClientResponse;
 import org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
+//import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+//import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 import org.jboss.resteasy.spi.ResteasyProviderFactory;
 
 /**
@@ -42,7 +42,7 @@ public class MediaClient extends AbstractServiceClientImpl {
        public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;       
        public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT;
        public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME;
-
+       
        @Override
        public String getServiceName() {
                return SERVICE_NAME;
@@ -122,6 +122,15 @@ public class MediaClient extends AbstractServiceClientImpl {
     public ClientResponse<Response> create(PoxPayloadOut xmlPayload) {
         return mediaProxy.create(xmlPayload.getBytes());
     }
+    
+    /**
+     * @param media
+     * @return
+     *
+     */
+    public ClientResponse<Response> createBlob(String csid, String blobUri) {
+        return mediaProxy.createBlob(csid, blobUri);
+    }    
 
     /**
      * @param csid
@@ -132,6 +141,17 @@ public class MediaClient extends AbstractServiceClientImpl {
         return mediaProxy.update(csid, xmlPayload.getBytes());
 
     }
+    
+    /**
+     * @param csid
+     * @param media
+     * @return
+     */
+    public ClientResponse<String> update(String csid, PoxPayloadOut xmlPayload, String URI) {
+        return mediaProxy.update(csid, xmlPayload.getBytes());
+
+    }
+    
 
     /**
      * @param csid
index 8c2534ab96926026f0d4c128b2353b5cd8bf285b..28d97631e1372b2ca20a364a2cf18e2b1bc1c611 100644 (file)
@@ -1,5 +1,6 @@
 package org.collectionspace.services.client;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
@@ -8,13 +9,14 @@ import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Response;
 
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
 import org.collectionspace.services.jaxb.AbstractCommonList;
+import org.collectionspace.services.client.BlobClient;
 import org.jboss.resteasy.client.ClientResponse;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 
 /**
  * @version $Revision: 2108 $
@@ -27,6 +29,12 @@ public interface MediaProxy extends CollectionSpaceProxy {
     //(C)reate
     @POST
     ClientResponse<Response> create(byte[] xmlPayload);
+    
+    @POST
+    @Path("{csid}")
+    @Produces("multipart/form-data")    
+    ClientResponse<Response>createBlob(@PathParam("csid") String csid,
+               @QueryParam(BlobClient.BLOB_URI_PARAM) String blobUri);
 
     //(R)ead
     @GET
index aef19334f10380d559d42a5b4cdb0f71f2a2092a..84fe26d9ac42da5b43040d37539d63258fb0b72c 100644 (file)
@@ -27,7 +27,6 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
 import org.collectionspace.services.client.CollectionSpaceClient;
-import org.collectionspace.services.client.ContactClient;
 import org.collectionspace.services.client.MediaClient;
 import org.collectionspace.services.client.PayloadOutputPart;
 import org.collectionspace.services.client.PoxPayloadIn;
@@ -37,9 +36,6 @@ import org.collectionspace.services.media.MediaCommon;
 
 import org.jboss.resteasy.client.ClientResponse;
 
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
-import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
@@ -54,7 +50,7 @@ import org.slf4j.LoggerFactory;
 public class MediaServiceTest extends AbstractServiceTestImpl {
 
     private final String CLASS_NAME = MediaServiceTest.class.getName();
-    private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
+    private final Logger logger = LoggerFactory.getLogger(MediaServiceTest.class);
     private String knownResourceId = null;
 
     @Override
@@ -92,6 +88,29 @@ public class MediaServiceTest extends AbstractServiceTestImpl {
         }
         allResourceIdsCreated.add(extractId(res)); // Store the IDs from every resource created by tests so they can be deleted after tests have been run.
     }
+    
+//    String noTest = System.getProperty("noTestCleanup");
+//     if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
+//        if (logger.isDebugEnabled()) {
+//            logger.debug("Skipping Cleanup phase ...");
+//        }
+//        return;
+//     }
+    
+//    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update"})
+//    public void updateWithBlob(String testName) throws Exception {
+//        logger.debug(testBanner(testName, CLASS_NAME));
+//        setupCreate();
+//        MediaClient client = new MediaClient();
+//        PoxPayloadOut multipart = createMediaInstance(createIdentifier());
+//        ClientResponse<Response> res = client.create(multipart);
+//        assertStatusCode(res, testName);
+//        String csid = extractId(res);
+//        
+//        
+//        allResourceIdsCreated.add(extractId(res)); // Store the IDs from every resource created by tests so they can be deleted after tests have been run.
+//    }
+    
 
     @Override
     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"})
index 3774bea950067dcdcdefbad06bd560efb8707e23..4cf0d66070b94b546077378caa2d2c16b315abd3 100644 (file)
@@ -23,6 +23,7 @@
  */
 package org.collectionspace.services.media;
 
+import org.collectionspace.services.client.BlobClient;
 import org.collectionspace.services.client.MediaClient;
 import org.collectionspace.services.client.PoxPayloadIn;
 import org.collectionspace.services.client.PoxPayloadOut;
@@ -33,14 +34,9 @@ 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.nuxeo.BlobDocumentModelHandler;
 import org.collectionspace.services.blob.BlobResource;
 import org.collectionspace.services.nuxeo.client.java.CommonList;
 
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -123,7 +119,7 @@ public class MediaResource extends ResourceBase {
     @Consumes("multipart/form-data")
     @Produces("application/xml")
     public Response createBlob(@Context HttpServletRequest req,
-               @QueryParam("blobUri") String blobUri,
+               @QueryParam(BlobClient.BLOB_URI_PARAM) String blobUri,
                @PathParam("csid") String csid) {
        PoxPayloadIn input = null;
        Response response = null;