From 371cd464b14644dfa1bdba5fab15bd53a69c11ac Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Wed, 23 Feb 2011 21:22:26 +0000 Subject: [PATCH] CSPACE-3598: Media and Blob tests needed to create example media data in the "Nightly" build --- .../services/client/BlobClient.java | 24 ++++- .../services/client/BlobProxy.java | 22 ++++- .../services/client/test/BlobServiceTest.java | 98 +++++++++++++++++-- .../services/blob/BlobResource.java | 34 ++++++- .../blob/nuxeo/BlobDocumentModelHandler.java | 2 +- .../services/client/PoxPayloadIn.java | 9 ++ .../services/client/PoxPayloadOut.java | 11 +++ .../client/test/AbstractServiceTestImpl.java | 35 ++++++- .../services/common/FileUtils.java | 66 ++++++++----- .../services/common/ResourceBase.java | 4 +- .../services/common/blob/BlobInput.java | 7 ++ services/media/client/pom.xml | 5 + .../services/client/MediaClient.java | 26 ++++- .../services/client/MediaProxy.java | 12 ++- .../client/test/MediaServiceTest.java | 29 +++++- .../services/media/MediaResource.java | 8 +- 16 files changed, 335 insertions(+), 57 deletions(-) diff --git a/services/blob/client/src/main/java/org/collectionspace/services/client/BlobClient.java b/services/blob/client/src/main/java/org/collectionspace/services/client/BlobClient.java index 387f9af63..82ac3c5a1 100644 --- a/services/blob/client/src/main/java/org/collectionspace/services/client/BlobClient.java +++ b/services/blob/client/src/main/java/org/collectionspace/services/client/BlobClient.java @@ -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 create(PoxPayloadOut xmlPayload) { return blobProxy.create(xmlPayload.getBytes()); + } + + public ClientResponse createBlobFromFormData(MultipartFormDataOutput formDataOutput) { + return blobProxy.createBlobFromFormData(formDataOutput); } - + + public ClientResponse createBlobFromURI(String blobUri) { + return blobProxy.createBlobFromURI("".getBytes(), blobUri); + } + /** * @param csid * @param blob diff --git a/services/blob/client/src/main/java/org/collectionspace/services/client/BlobProxy.java b/services/blob/client/src/main/java/org/collectionspace/services/client/BlobProxy.java index d6c7ff9d0..b9b2703ce 100644 --- a/services/blob/client/src/main/java/org/collectionspace/services/client/BlobProxy.java +++ b/services/blob/client/src/main/java/org/collectionspace/services/client/BlobProxy.java @@ -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 create(byte[] xmlPayload); + //(C)reate + @POST + ClientResponse createBlobFromURI(byte[] xmlPayload, + @QueryParam(BlobClient.BLOB_URI_PARAM) String blobUri); + + //(C)reate + @POST + @Consumes("multipart/form-data") + ClientResponse createBlobFromFormData(MultipartFormDataOutput formDataOutput); + //(R)ead @GET @Path("/{csid}") diff --git a/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java b/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java index b765a6e33..8867531fc 100644 --- a/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java +++ b/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java @@ -22,30 +22,31 @@ */ 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.

* $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 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 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"}) diff --git a/services/blob/service/src/main/java/org/collectionspace/services/blob/BlobResource.java b/services/blob/service/src/main/java/org/collectionspace/services/blob/BlobResource.java index 98b255c08..a0cdf9a95 100644 --- a/services/blob/service/src/main/java/org/collectionspace/services/blob/BlobResource.java +++ b/services/blob/service/src/main/java/org/collectionspace/services/blob/BlobResource.java @@ -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 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 queryParams = ui.getQueryParameters(); + String blobUri = queryParams.getFirst(BlobClient.BLOB_URI_PARAM); + + try { + if (blobUri != null) { + ServiceContext 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; diff --git a/services/blob/service/src/main/java/org/collectionspace/services/blob/nuxeo/BlobDocumentModelHandler.java b/services/blob/service/src/main/java/org/collectionspace/services/blob/nuxeo/BlobDocumentModelHandler.java index 8cac45583..46ff10703 100644 --- a/services/blob/service/src/main/java/org/collectionspace/services/blob/nuxeo/BlobDocumentModelHandler.java +++ b/services/blob/service/src/main/java/org/collectionspace/services/blob/nuxeo/BlobDocumentModelHandler.java @@ -146,7 +146,7 @@ extends DocHandlerBase { 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(); diff --git a/services/client/src/main/java/org/collectionspace/services/client/PoxPayloadIn.java b/services/client/src/main/java/org/collectionspace/services/client/PoxPayloadIn.java index 585a0f38f..77d8fef81 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/PoxPayloadIn.java +++ b/services/client/src/main/java/org/collectionspace/services/client/PoxPayloadIn.java @@ -17,15 +17,24 @@ import org.dom4j.Element; //import org.dom4j.Namespace; //import org.dom4j.io.SAXReader; //import org.xml.sax.InputSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class PoxPayloadIn extends PoxPayload { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + /* * Parse the POX 'xmlPayload' into individual parts. Each part is saved * as a DOM4j Element and, if possible, a JAXB object instance as well. */ public PoxPayloadIn(String xmlPayload) throws DocumentException { super(xmlPayload); + if (logger.isTraceEnabled() == true) { + logger.trace("\n\n>>>> Payload In : BEGIN >>>>\n" + + xmlPayload + + "\n>>>> Payload In : END >>>>\n"); + } } /* (non-Javadoc) diff --git a/services/client/src/main/java/org/collectionspace/services/client/PoxPayloadOut.java b/services/client/src/main/java/org/collectionspace/services/client/PoxPayloadOut.java index 3bae323df..1b9d08d23 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/PoxPayloadOut.java +++ b/services/client/src/main/java/org/collectionspace/services/client/PoxPayloadOut.java @@ -7,6 +7,8 @@ import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.io.SAXReader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; @@ -19,6 +21,8 @@ import java.util.Iterator; */ public class PoxPayloadOut extends PoxPayload { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + /** * Instantiates a new pox payload out. * @@ -89,6 +93,13 @@ public class PoxPayloadOut extends PoxPayload { } } result = document.asXML(); + + if (logger.isTraceEnabled() == true) { + logger.trace("\n\n<<<< Payload Out : BEGIN <<<<\n" + + result + + "\n<<<< Payload Out : END <<<<\n"); + } + return result; } diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java index cea08b4c7..acd7dae5a 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java +++ b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java @@ -23,18 +23,24 @@ */ 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 allResourceIdsCreated = new ArrayList(); 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 ..."); } diff --git a/services/common/src/main/java/org/collectionspace/services/common/FileUtils.java b/services/common/src/main/java/org/collectionspace/services/common/FileUtils.java index c14be1559..eb4c6e0a2 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/FileUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/FileUtils.java @@ -23,12 +23,26 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +// TODO: Auto-generated Javadoc +/** + * The Class FileUtils. + */ public class FileUtils { /** The Constant logger. */ private static final Logger logger = LoggerFactory.getLogger(FileUtils.class); - private static final String TMP_FILE_PREFIX = "cspace_blob_"; + /** The Constant TMP_FILE_PREFIX. */ + public static final String TMP_BLOB_PREFIX = "cspace_blob_"; + public static final String DEFAULT_BLOB_NAME = "blob"; + private static final String FILE_FORM_FIELD = "file"; + /** + * Creates the tmp file. + * + * @param streamIn the stream in + * @param filePrefix the file prefix + * @return the file + */ static public File createTmpFile(InputStream streamIn, String filePrefix) { File result = null; @@ -57,6 +71,12 @@ public class FileUtils { return result; } + /** + * Look for an uploaded file from the HTTP request of type "multipart/form-data". + * + * @param request the request + * @return the file + */ static public File createTmpFile(HttpServletRequest request) { File result = null; @@ -64,31 +84,33 @@ public class FileUtils { ServletFileUpload upload = new ServletFileUpload(factory); try { - List items = upload.parseRequest(request); - Iterator iter = items.iterator(); + List items = upload.parseRequest(request); + Iterator iter = items.iterator(); while (iter.hasNext()) { - FileItem item = (FileItem) iter.next(); - - if (item.isFormField()) { - if (logger.isDebugEnabled() == true) { - String formFieldName = item.getFieldName(); - logger.debug("FORM FIELD:" + formFieldName); + FileItem item = iter.next(); + String formFieldName = item.getFieldName(); + if (logger.isTraceEnabled() == true) { + logger.trace("HTTP Request form field:" + formFieldName); + } + if (formFieldName.equalsIgnoreCase(FILE_FORM_FIELD)) { + if (item.isFormField() == true) { + logger.warn(FILE_FORM_FIELD + ": part is marked as a form field."); } - } else { - if (!item.isFormField()) { - - String fileName = item.getName(); - System.out.println("File Name:" + fileName); - - File fullFile = new File(item.getName()); - String tmpDir = System.getProperty("java.io.tmpdir"); - File savedFile = new File(tmpDir, fullFile.getName()); - - item.write(savedFile); -// item.getInputStream();//FIXME: We should make a version of this method that returns the input stream - result = savedFile; + String fileName = item.getName(); + if (logger.isTraceEnabled() == true) { + logger.trace("Uploaded File Name:" + (fileName != null ? fileName : "")); } + if (fileName == null) { + fileName = DEFAULT_BLOB_NAME; //if there's no file name then set it to an empty string + logger.warn("File was posted to the services without a file name."); + } + File tmpDir = new File(System.getProperty("java.io.tmpdir")); + File savedFile = File.createTempFile(TMP_BLOB_PREFIX, fileName, tmpDir); + + item.write(savedFile); +// item.getInputStream();//FIXME: REM - We should make a version of this method that returns the input stream + result = savedFile; } } } catch (Exception e) { 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 ab0f3ff65..def456339 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 @@ -22,6 +22,7 @@ import org.nuxeo.ecm.core.api.DocumentModel; import javax.ws.rs.*; import javax.ws.rs.core.*; + import java.util.List; /** @@ -92,7 +93,8 @@ extends AbstractMultiPartCollectionSpaceResourceImpl { //======================= CREATE ==================================================== @POST - public Response create(String xmlPayload) { + public Response create(@Context UriInfo ui, + String xmlPayload) { try { PoxPayloadIn input = new PoxPayloadIn(xmlPayload); ServiceContext ctx = createServiceContext(input); diff --git a/services/common/src/main/java/org/collectionspace/services/common/blob/BlobInput.java b/services/common/src/main/java/org/collectionspace/services/common/blob/BlobInput.java index a7bf2d71e..70b871aff 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/blob/BlobInput.java +++ b/services/common/src/main/java/org/collectionspace/services/common/blob/BlobInput.java @@ -121,6 +121,13 @@ public class BlobInput { File tmpFile = FileUtils.createTmpFile(req); this.setBlobFile(tmpFile); this.setBlobUri(blobUri); + } + + public void createBlobFile(String theBlobUri) { + File theBlobFile = new File(theBlobUri); + this.setBlobFile(theBlobFile); + this.setBlobUri(blobUri); } + } diff --git a/services/media/client/pom.xml b/services/media/client/pom.xml index 3e182abd8..4fad60529 100644 --- a/services/media/client/pom.xml +++ b/services/media/client/pom.xml @@ -41,6 +41,11 @@ org.collectionspace.services org.collectionspace.services.client ${project.version} + + + org.collectionspace.services + org.collectionspace.services.blob.client + ${project.version} org.collectionspace.services diff --git a/services/media/client/src/main/java/org/collectionspace/services/client/MediaClient.java b/services/media/client/src/main/java/org/collectionspace/services/client/MediaClient.java index 436fde70a..a10b34669 100644 --- a/services/media/client/src/main/java/org/collectionspace/services/client/MediaClient.java +++ b/services/media/client/src/main/java/org/collectionspace/services/client/MediaClient.java @@ -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 create(PoxPayloadOut xmlPayload) { return mediaProxy.create(xmlPayload.getBytes()); } + + /** + * @param media + * @return + * + */ + public ClientResponse 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 update(String csid, PoxPayloadOut xmlPayload, String URI) { + return mediaProxy.update(csid, xmlPayload.getBytes()); + + } + /** * @param csid diff --git a/services/media/client/src/main/java/org/collectionspace/services/client/MediaProxy.java b/services/media/client/src/main/java/org/collectionspace/services/client/MediaProxy.java index 8c2534ab9..28d97631e 100644 --- a/services/media/client/src/main/java/org/collectionspace/services/client/MediaProxy.java +++ b/services/media/client/src/main/java/org/collectionspace/services/client/MediaProxy.java @@ -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 create(byte[] xmlPayload); + + @POST + @Path("{csid}") + @Produces("multipart/form-data") + ClientResponsecreateBlob(@PathParam("csid") String csid, + @QueryParam(BlobClient.BLOB_URI_PARAM) String blobUri); //(R)ead @GET diff --git a/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaServiceTest.java b/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaServiceTest.java index aef19334f..84fe26d9a 100644 --- a/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaServiceTest.java +++ b/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaServiceTest.java @@ -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 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"}) 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 3774bea95..4cf0d6607 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 @@ -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; -- 2.47.3