]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-3245: Committing more functionality to the the Blob service. REQUIRES full...
authorRichard Millet <richard.millet@berkeley.edu>
Wed, 8 Dec 2010 18:21:35 +0000 (18:21 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Wed, 8 Dec 2010 18:21:35 +0000 (18:21 +0000)
12 files changed:
services/blob/3rdparty/nuxeo-platform-cs-blob/src/main/resources/OSGI-INF/core-types-contrib.xml
services/blob/3rdparty/nuxeo-platform-cs-blob/src/main/resources/OSGI-INF/layouts-contrib.xml
services/blob/3rdparty/nuxeo-platform-cs-blob/src/main/resources/schemas/blobs_common.xsd [moved from services/blob/3rdparty/nuxeo-platform-cs-blob/src/main/resources/schemas/blob_common.xsd with 87% similarity]
services/blob/client/pom.xml
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/BlobAuthRefsTest.java
services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java
services/blob/jaxb/src/main/resources/blobs_common_deprecated.xsd [moved from services/blob/jaxb/src/main/resources/blob_common.xsd with 90% similarity]
services/blob/service/pom.xml
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

index 8c9cfe3f54e31777ba5a3258dbfa67bfca12f289..788d1fdfd81b4c5d86e718a9a1a4bec0a24b5508 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>
 <component name="org.collectionspace.blob.coreTypes">
   <extension target="org.nuxeo.ecm.core.schema.TypeService" point="schema">
-    <schema name="blob_common" prefix="blob_common" src="schemas/blob_common.xsd"/>
+    <schema name="blobs_common" prefix="blobs_common" src="schemas/blobs_common.xsd"/>
   </extension>
   
   <extension target="org.nuxeo.ecm.core.schema.TypeService" point="doctype">
@@ -9,7 +9,7 @@
       <schema name="common"/>
       <schema name="dublincore"/>
       <schema name="collectionspace_core"/>
-      <schema name="blob_common"/>
+      <schema name="blobs_common"/>
     </doctype>
   </extension>
 </component>
index e72031eef7b2372e3d51ad0ab4e92fef3495380a..9813a793f3ad098e73a3be8698fe9cc6b7fbe758 100644 (file)
@@ -57,7 +57,7 @@ $LastChangedDate: $
                 </labels>
                 <translated>true</translated>
                 <fields>
-                    <field schema="blob_common">blobNumber</field>
+                    <field schema="blobs_common">blobNumber</field>
                 </fields>
                 <properties widgetMode="edit">
                     <property name="styleClass">dataInputText</property>
@@ -70,7 +70,7 @@ $LastChangedDate: $
                 </labels>
                 <translated>true</translated>
                 <fields>
-                    <field schema="blob_common">borrower</field>
+                    <field schema="blobs_common">borrower</field>
                 </fields>
                 <properties widgetMode="edit">
                     <property name="styleClass">dataInputText</property>
@@ -83,7 +83,7 @@ $LastChangedDate: $
                 </labels>
                 <translated>true</translated>
                 <fields>
-                    <field schema="blob_common">borrowersContact</field>
+                    <field schema="blobs_common">borrowersContact</field>
                 </fields>
                 <properties widgetMode="edit">
                     <property name="styleClass">dataInputText</property>
@@ -96,7 +96,7 @@ $LastChangedDate: $
                 </labels>
                 <translated>true</translated>
                 <fields>
-                    <field schema="blob_common">lendersAuthorizer</field>
+                    <field schema="blobs_common">lendersAuthorizer</field>
                 </fields>
                 <properties widgetMode="edit">
                     <property name="styleClass">dataInputText</property>
@@ -109,7 +109,7 @@ $LastChangedDate: $
                 </labels>
                 <translated>true</translated>
                 <fields>
-                    <field schema="blob_common">lendersAuthorizationDate</field>
+                    <field schema="blobs_common">lendersAuthorizationDate</field>
                 </fields>
                 <properties widgetMode="edit">
                     <property name="styleClass">dataInputText</property>
@@ -122,7 +122,7 @@ $LastChangedDate: $
                 </labels>
                 <translated>true</translated>
                 <fields>
-                    <field schema="blob_common">lendersContact</field>
+                    <field schema="blobs_common">lendersContact</field>
                 </fields>
                 <properties widgetMode="edit">
                     <property name="styleClass">dataInputText</property>
@@ -135,7 +135,7 @@ $LastChangedDate: $
                 </labels>
                 <translated>true</translated>
                 <fields>
-                    <field schema="blob_common">blobDate</field>
+                    <field schema="blobs_common">blobDate</field>
                 </fields>
                 <properties widgetMode="edit">
                     <property name="styleClass">dataInputText</property>
@@ -148,7 +148,7 @@ $LastChangedDate: $
                 </labels>
                 <translated>true</translated>
                 <fields>
-                    <field schema="blob_common">loanReturnDate</field>
+                    <field schema="blobs_common">loanReturnDate</field>
                 </fields>
                 <properties widgetMode="edit">
                     <property name="styleClass">dataInputText</property>
@@ -161,7 +161,7 @@ $LastChangedDate: $
                 </labels>
                 <translated>true</translated>
                 <fields>
-                    <field schema="blob_common">loanRenewalApplicationDate</field>
+                    <field schema="blobs_common">loanRenewalApplicationDate</field>
                 </fields>
                 <properties widgetMode="edit">
                     <property name="styleClass">dataInputText</property>
@@ -174,7 +174,7 @@ $LastChangedDate: $
                 </labels>
                 <translated>true</translated>
                 <fields>
-                    <field schema="blob_common">specialConditionsOfLoan</field>
+                    <field schema="blobs_common">specialConditionsOfLoan</field>
                 </fields>
                 <properties widgetMode="edit">
                     <property name="styleClass">dataInputText</property>
@@ -187,7 +187,7 @@ $LastChangedDate: $
                 </labels>
                 <translated>true</translated>
                 <fields>
-                    <field schema="blob_common">blobNote</field>
+                    <field schema="blobs_common">blobNote</field>
                 </fields>
                 <properties widgetMode="edit">
                     <property name="styleClass">dataInputText</property>
@@ -200,7 +200,7 @@ $LastChangedDate: $
                 </labels>
                 <translated>true</translated>
                 <fields>
-                    <field schema="blob_common">loanPurpose</field>
+                    <field schema="blobs_common">loanPurpose</field>
                 </fields>
                 <properties widgetMode="edit">
                     <property name="styleClass">dataInputText</property>
similarity index 87%
rename from services/blob/3rdparty/nuxeo-platform-cs-blob/src/main/resources/schemas/blob_common.xsd
rename to services/blob/3rdparty/nuxeo-platform-cs-blob/src/main/resources/schemas/blobs_common.xsd
index 144ca2e812abf5737ddc292530435a876a736a53..becb46d22962f728efcb4b4f7f61bc81b6146242 100644 (file)
 \r
     <!--  Blob Information Group -->\r
     <xs:element name="encoding" type="xs:string" />\r
-    <xs:element name="mime-type" type="xs:string" />\r
+    <xs:element name="mimeType" type="xs:string" />\r
     <xs:element name="data" type="xs:string" />\r
     <xs:element name="name" type="xs:string" />\r
     <xs:element name="length" type="xs:string" />\r
     <xs:element name="digest" type="xs:string" />\r
     <xs:element name="uri" type="xs:string" />\r
+    <xs:element name="repositoryId" type="xs:string" />\r
 </xs:schema>\r
index 620fff1c9692a3e13d30fc402950ae9d1b8ee6e7..8e24890f70a611a382ef67151e9e23498ae79fb1 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.jaxb</artifactId>
-            <version>${project.version}</version>
         </dependency>
         <dependency>
             <groupId>org.collectionspace.services</groupId>
index 1823a6dca6939f3c2e3a1c99bd450f69ecdab6ea..9c7e20af8a67173fd919a57d43dc4c355f257f02 100644 (file)
@@ -21,7 +21,7 @@ import javax.ws.rs.core.Response;
 
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
 //import org.collectionspace.services.common.context.ServiceContext;
-import org.collectionspace.services.blob.BlobCommonList;
+import org.collectionspace.services.blob.BlobsCommonList;
 
 import org.jboss.resteasy.client.ProxyFactory;
 import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
@@ -44,7 +44,7 @@ public class BlobClient extends AbstractServiceClientImpl {
      * @see org.collectionspace.services.client.AbstractServiceClientImpl#getServicePathComponent()
      */
     public String getServicePathComponent() {
-        return "blob"; //Laramie20100824 was blobs, but label was a mismatch.
+        return "blobs"; //Laramie20100824 was blobs, but label was a mismatch.
     }
     /**
      *
@@ -97,7 +97,7 @@ public class BlobClient extends AbstractServiceClientImpl {
      * @return
      * @see org.collectionspace.services.client.BlobProxy#getBlob()
      */
-    public ClientResponse<BlobCommonList> readList() {
+    public ClientResponse<BlobsCommonList> readList() {
         return blobProxy.readList();
     }
     
index 31bc0d5802bdde0e203f1692be8a1b031541f2ec..40797d269ceb7a88633a8f409ca5c55df1e49866 100644 (file)
@@ -11,7 +11,7 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.core.Response;
 
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
-import org.collectionspace.services.blob.BlobCommonList;
+import org.collectionspace.services.blob.BlobsCommonList;
 import org.jboss.resteasy.client.ClientResponse;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
@@ -19,7 +19,7 @@ import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 /**
  * @version $Revision: 2108 $
  */
-@Path("/blob/")
+@Path("/blobs/")
 @Produces({"multipart/mixed"})
 @Consumes({"multipart/mixed"})
 public interface BlobProxy extends CollectionSpaceProxy {
@@ -46,7 +46,7 @@ public interface BlobProxy extends CollectionSpaceProxy {
     // List
     @GET
     @Produces({"application/xml"})
-    ClientResponse<BlobCommonList> readList();
+    ClientResponse<BlobsCommonList> readList();
 
     // List Authority References
     @GET
index ebe3e38eecd663cd66297ef09497e2243d84b9af..b689d0f685d77d1e082a04d230d9400545d49504 100644 (file)
@@ -37,7 +37,7 @@ import org.collectionspace.services.client.PersonAuthorityClient;
 import org.collectionspace.services.client.PersonAuthorityClientUtils;
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
 import org.collectionspace.services.jaxb.AbstractCommonList;
-import org.collectionspace.services.blob.BlobCommon;
+import org.collectionspace.services.blob.BlobsCommon;
 
 import org.jboss.resteasy.client.ClientResponse;
 
@@ -87,13 +87,13 @@ public class BlobAuthRefsTest extends BaseServiceTest {
     private MultipartOutput createBlobInstance(String depositorRefName) {
         this.depositorRefName = depositorRefName;
         this.blobName = "testblob-"+createIdentifier();
-        BlobCommon blob = new BlobCommon();
+        BlobsCommon blob = new BlobsCommon();
         blob.setName(this.blobName);
 
         MultipartOutput multipart = new MultipartOutput();
         OutputPart commonPart = multipart.addPart(blob, MediaType.APPLICATION_XML_TYPE);
         commonPart.getHeaders().add("label", new BlobClient().getCommonPartName());
-        logger.debug("to be created, blob common: " + objectAsXmlString(blob, BlobCommon.class));
+        logger.debug("to be created, blob common: " + objectAsXmlString(blob, BlobsCommon.class));
         return multipart;
     }
 
@@ -161,9 +161,9 @@ public class BlobAuthRefsTest extends BaseServiceTest {
         ClientResponse<MultipartInput> res = blobClient.read(knownResourceId);
         assertStatusCode(res, testName);
         MultipartInput input = (MultipartInput) res.getEntity();
-        BlobCommon blob = (BlobCommon) extractPart(input, blobClient.getCommonPartName(), BlobCommon.class);
+        BlobsCommon blob = (BlobsCommon) extractPart(input, blobClient.getCommonPartName(), BlobsCommon.class);
         Assert.assertNotNull(blob);
-        logger.debug(objectAsXmlString(blob, BlobCommon.class));
+        logger.debug(objectAsXmlString(blob, BlobsCommon.class));
 
         // Check a couple of fields
         Assert.assertEquals(blob.getName(), blobName);
index bc22df0fb1c69b35ec0c0ef5007b64aaa4fcd62c..64249d0153a1eff9fb67bc6dab84a19c7c9d7115 100644 (file)
@@ -29,8 +29,8 @@ import javax.ws.rs.core.Response;
 import org.collectionspace.services.client.CollectionSpaceClient;
 import org.collectionspace.services.client.BlobClient;
 import org.collectionspace.services.jaxb.AbstractCommonList;
-import org.collectionspace.services.blob.BlobCommon;
-import org.collectionspace.services.blob.BlobCommonList;
+import org.collectionspace.services.blob.BlobsCommon;
+import org.collectionspace.services.blob.BlobsCommonList;
 
 import org.jboss.resteasy.client.ClientResponse;
 
@@ -52,7 +52,7 @@ public class BlobServiceTest extends AbstractServiceTestImpl {
 
     private final String CLASS_NAME = BlobServiceTest.class.getName();
     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
-    final String SERVICE_PATH_COMPONENT = "blob";
+    final String SERVICE_PATH_COMPONENT = "blobs";
     private String knownResourceId = null;
 
     @Override
@@ -62,7 +62,7 @@ public class BlobServiceTest extends AbstractServiceTestImpl {
 
     @Override
     protected AbstractCommonList getAbstractCommonList(ClientResponse<AbstractCommonList> response) {
-        return response.getEntity(BlobCommonList.class);
+        return response.getEntity(BlobsCommonList.class);
     }
 
     @Override
@@ -99,7 +99,7 @@ public class BlobServiceTest extends AbstractServiceTestImpl {
         ClientResponse<MultipartInput> res = client.read(knownResourceId);
         assertStatusCode(res, testName);
         MultipartInput input = (MultipartInput) res.getEntity();
-        BlobCommon blob = (BlobCommon) extractPart(input, client.getCommonPartName(), BlobCommon.class);
+        BlobsCommon blob = (BlobsCommon) extractPart(input, client.getCommonPartName(), BlobsCommon.class);
         Assert.assertNotNull(blob);
     }
 
@@ -109,13 +109,13 @@ public class BlobServiceTest extends AbstractServiceTestImpl {
         logger.debug(testBanner(testName, CLASS_NAME));
         setupReadList();
         BlobClient client = new BlobClient();
-        ClientResponse<BlobCommonList> res = client.readList();
-        BlobCommonList list = res.getEntity();
+        ClientResponse<BlobsCommonList> res = client.readList();
+        BlobsCommonList list = res.getEntity();
         assertStatusCode(res, testName);
         if (logger.isDebugEnabled()) {
-            List<BlobCommonList.BlobListItem> items = list.getBlobListItem();
+            List<BlobsCommonList.BlobListItem> items = list.getBlobListItem();
             int i = 0;
-            for (BlobCommonList.BlobListItem item : items) {
+            for (BlobsCommonList.BlobListItem item : items) {
                 logger.debug(testName + ": list-item[" + i + "] csid=" + item.getCsid());
                 logger.debug(testName + ": list-item[" + i + "] blob.name=" + item.getName());
                 logger.debug(testName + ": list-item[" + i + "] URI=" + item.getUri());
@@ -134,18 +134,18 @@ public class BlobServiceTest extends AbstractServiceTestImpl {
         assertStatusCode(res, testName);
         logger.debug("got object to update with ID: " + knownResourceId);
         MultipartInput input = (MultipartInput) res.getEntity();
-        BlobCommon blob = (BlobCommon) extractPart(input, client.getCommonPartName(), BlobCommon.class);
+        BlobsCommon blob = (BlobsCommon) extractPart(input, client.getCommonPartName(), BlobsCommon.class);
         Assert.assertNotNull(blob);
 
         blob.setName("updated-" + blob.getName());
-        logger.debug("Object to be updated:"+objectAsXmlString(blob, BlobCommon.class));
+        logger.debug("Object to be updated:"+objectAsXmlString(blob, BlobsCommon.class));
         MultipartOutput output = new MultipartOutput();
         OutputPart commonPart = output.addPart(blob, MediaType.APPLICATION_XML_TYPE);
         commonPart.getHeaders().add("label", client.getCommonPartName());
         res = client.update(knownResourceId, output);
         assertStatusCode(res, testName);
         input = (MultipartInput) res.getEntity();
-        BlobCommon updatedBlob = (BlobCommon) extractPart(input, client.getCommonPartName(), BlobCommon.class);
+        BlobsCommon updatedBlob = (BlobsCommon) extractPart(input, client.getCommonPartName(), BlobsCommon.class);
         Assert.assertNotNull(updatedBlob);
     }
 
@@ -251,7 +251,7 @@ public class BlobServiceTest extends AbstractServiceTestImpl {
 
     private MultipartOutput createBlobInstance(String exitNumber) {
         String identifier = "blobNumber-" + exitNumber;
-        BlobCommon blob = new BlobCommon();
+        BlobsCommon blob = new BlobsCommon();
         blob.setName(identifier);
         MultipartOutput multipart = new MultipartOutput();
         OutputPart commonPart = multipart.addPart(blob, MediaType.APPLICATION_XML_TYPE);
@@ -259,7 +259,7 @@ public class BlobServiceTest extends AbstractServiceTestImpl {
 
         if (logger.isDebugEnabled()) {
             logger.debug("to be created, blob common");
-            logger.debug(objectAsXmlString(blob, BlobCommon.class));
+            logger.debug(objectAsXmlString(blob, BlobsCommon.class));
         }
 
         return multipart;
similarity index 90%
rename from services/blob/jaxb/src/main/resources/blob_common.xsd
rename to services/blob/jaxb/src/main/resources/blobs_common_deprecated.xsd
index 64775a89f12fff0611a18511f6944571f0dab595..5f1cd8571fd71a9f7266d9692a84990597f8b548 100644 (file)
@@ -28,7 +28,7 @@
 <!-- See http://wiki.collectionspace.org/display/collectionspace/Loans+Out+Schema -->    
     
     <!-- blob -->
-    <xs:element name="blob_common">
+    <xs:element name="blobs_common_deprecated">
         <xs:complexType>
             <xs:sequence>
                 <xs:element name="encoding" type="xs:string" />
@@ -38,6 +38,7 @@
                 <xs:element name="length" type="xs:string" />
                 <xs:element name="digest" type="xs:string" />
                 <xs:element name="uri" type="xs:string" />
+                <xs:element name="id" type="xs:string" />
           </xs:sequence>
         </xs:complexType>
     </xs:element>
     </xs:complexType>
     
     <!-- blob records, as in nuxeo repository -->
-    <xs:element name="blob_common_list">
+    <xs:element name="blobs_common_deprecated_list">
         <xs:complexType>
             <xs:complexContent>
                 <xs:extension base="abstractCommonList">                    
                     <xs:sequence>
-                        <xs:element name="blob_list_item" maxOccurs="unbounded">
+                        <xs:element name="blobs_common_deprecated_list_item" maxOccurs="unbounded">
                             <xs:complexType>
                                 <xs:sequence>
                                     <xs:element name="name" type="xs:string"   minOccurs="1" />
@@ -65,7 +66,7 @@
                                     <xs:element name="encoding" type="xs:string" minOccurs="1" />
                                     <xs:element name="length" type="xs:string" minOccurs="1" />
                                     <xs:element name="uri" type="xs:string" />
-                                    <xs:element name="csid" type="xs:string"         minOccurs="1" />
+                                    <xs:element name="csid" type="xs:string" minOccurs="1" />
                                 </xs:sequence>
                             </xs:complexType>
                         </xs:element>
index 5b229ad97e9f7afb4244f4a97753f1f4fa7386f0..6007e40c8d6e6b06d3d40c1e0e4857e6bfe3e9d6 100644 (file)
         </dependency>
         <dependency>
             <groupId>org.collectionspace.services</groupId>
-            <artifactId>org.collectionspace.services.blob.jaxb</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.collectionspace.services</groupId>
-            <artifactId>org.collectionspace.services.collectionobject.jaxb</artifactId>
+            <artifactId>org.collectionspace.services.jaxb</artifactId>
             <version>${project.version}</version>
         </dependency>
         <!-- External dependencies -->        
index 6eeb42e9a9d19a0c00f34bf6180676e75a401e51..8c2001d83d6f60f22f0e5f9337b8ad05290d0eda 100644 (file)
  */
 package org.collectionspace.services.blob;
 
+import org.collectionspace.services.common.FileUtils;
 import org.collectionspace.services.common.ResourceBase;
-import org.collectionspace.services.common.ClientType;
+//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.context.ServiceContext;
+import org.collectionspace.services.blob.BlobsCommon;
+import org.collectionspace.services.blob.BlobsCommonList;
 
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
+
+//FIXME: REM - We should not have Nuxeo dependencies in our resource classes.
+import org.collectionspace.services.common.imaging.nuxeo.NuxeoImageUtils;
+import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
+
+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.File;
+import java.io.InputStream;
 import java.util.List;
 
-@Path("/blob")
+@Path("/blobs")
 @Consumes("multipart/mixed")
 @Produces("multipart/mixed")
 public class BlobResource extends ResourceBase {
 
     @Override
     public String getServiceName(){
-        return "blob";
+        return "blobs";
     };
 
 
@@ -51,8 +75,93 @@ public class BlobResource extends ResourceBase {
     }
 
     @Override
-    public Class<BlobCommon> getCommonPartClass() {
-       return BlobCommon.class;
+    public Class<BlobsCommon> getCommonPartClass() {
+       return BlobsCommon.class;
+    }
+
+    public BlobsCommonList getBlobList(MultivaluedMap<String, String> queryParams) {
+        return (BlobsCommonList)getList(queryParams);
+    }
+
+    @Deprecated
+    public BlobsCommonList getBlobList(List<String> csidList) {
+        return (BlobsCommonList) getList(csidList);
+    }
+
+    protected BlobsCommonList search(MultivaluedMap<String,String> queryParams,String keywords) {
+         return (BlobsCommonList) super.search(queryParams, keywords);
+    }
+    
+    private InputStream getBlobContent(String csid, String derivativeTerm) throws WebApplicationException {
+       InputStream result = null;
+       
+       try {
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
+               ctx.setProperty(BlobInput.DERIVATIVE_TERM_KEY, derivativeTerm);
+               MultipartOutput response = this.get(csid, ctx);
+               if (logger.isDebugEnabled() == true) {
+                       logger.debug(response.toString());
+               }
+               result = (InputStream)ctx.getProperty(BlobInput.DERIVATIVE_CONTENT_KEY);
+       } catch (Exception e) {
+               throw bigReThrow(e, ServiceMessages.CREATE_FAILED);
+       }
+       
+       if (result == null) {
+               Response response = Response.status(
+                       Response.Status.INTERNAL_SERVER_ERROR).entity(
+                                       "Index failed. Could not get the contents for the Blob.").type("text/plain").build();
+               throw new WebApplicationException(response);
+       }
+       
+       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")
+    public Response createBlob(@Context HttpServletRequest req,
+               @QueryParam("blobUri") String blobUri) {
+       Response response = null;       
+       try {
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
+               setBlobInput(ctx, req, blobUri);
+               response = this.create(null, ctx);
+       } catch (Exception e) {
+               throw bigReThrow(e, ServiceMessages.CREATE_FAILED);
+       }
+                       
+               return response;
+    }    
+    
+    @GET
+    @Path("{csid}/content")
+    @Produces({"image/jpeg", "image/png", "image/tiff"})
+    public InputStream getPicture(
+               @PathParam("csid") String csid) {
+       InputStream result = null;
+           result = getBlobContent(csid, BlobInput.DERIVATIVE_ORIGINAL_VALUE);         
+       return result;
+    }
+
+    @GET
+    @Path("{csid}/derivatives/{derivative_term}/content")
+    @Produces({"image/jpeg", "image/png", "image/tiff"})
+    public InputStream getDerivativeContent(
+               @PathParam("csid") String csid,
+               @PathParam("derivative_term") String derivative_term) {
+       InputStream result = null;
+           result = getBlobContent(csid, derivative_term);     
+       return result;
     }
     
 }
index 777955134ed2baf7f9b6fac93115cdfadbce3984..f3b250a66fa66537a5c98f6d88c8bc421044a2da 100644 (file)
  */
 package org.collectionspace.services.blob.nuxeo;
 
+import java.io.InputStream;
 import java.util.Iterator;
 import java.util.List;
 
-import org.collectionspace.services.BlobJAXBSchema;
-import org.collectionspace.services.common.DocHandlerBase;
-import org.collectionspace.services.blob.BlobCommon;
-import org.collectionspace.services.blob.BlobCommonList;
-import org.collectionspace.services.blob.BlobCommonList.BlobListItem;
 import org.collectionspace.services.jaxb.AbstractCommonList;
+import org.collectionspace.services.jaxb.BlobJAXBSchema;
+
+import org.collectionspace.services.common.blob.BlobInput;
+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.common.DocHandlerBase;
+
+import org.collectionspace.services.blob.BlobsCommonList;
+import org.collectionspace.services.blob.BlobsCommon;
+import org.collectionspace.services.blob.BlobsCommonList.BlobListItem;
+
+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.nuxeo.ecm.core.api.DocumentModel;
+import org.nuxeo.ecm.core.api.DocumentModelList;
+import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
+import org.nuxeo.ecm.core.api.ClientException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+/**
+ * The Class BlobDocumentModelHandler.
+ */
 public class BlobDocumentModelHandler
-        extends DocHandlerBase<BlobCommon, AbstractCommonList> {
-
-    public final String getNuxeoSchemaName(){
-        return "blob";
-    }
-
-    public String getSummaryFields(AbstractCommonList commonList){
-        return "name|mimeType|encoding|length|uri|csid";
-    }
-
-    public AbstractCommonList createAbstractCommonListImpl(){
-        return new BlobCommonList();
-    }
-
-    public List createItemsList(AbstractCommonList commonList){
-        List list = ((BlobCommonList)commonList).getBlobListItem();
-        return list;
-    }
-
-    public Object createItemForCommonList(DocumentModel docModel, String label, String id) throws Exception {
-        BlobListItem item = new BlobListItem();
-        item.setEncoding((String) docModel.getProperty(label, BlobJAXBSchema.encoding));
-        item.setMimeType((String) docModel.getProperty(label, BlobJAXBSchema.mimeType));
-        //String theData = (String) docModel.getProperty(label, BlobJAXBSchema.data);
-        item.setName((String) docModel.getProperty(label, BlobJAXBSchema.name));
-        item.setLength((String) docModel.getProperty(label, BlobJAXBSchema.length));
-        item.setUri(getServiceContextPath() + id);
-        item.setCsid(id);
-        return item;
-    }
+extends DocHandlerBase<BlobsCommon, AbstractCommonList> {
+
+       /** The logger. */
+       private final Logger logger = LoggerFactory.getLogger(BlobDocumentModelHandler.class);
+
+       public final String getNuxeoSchemaName(){
+               return "blobs";
+       }
+
+       public String getSummaryFields(AbstractCommonList commonList){
+               return "name|mimeType|encoding|length|uri|csid";
+       }
+
+       public AbstractCommonList createAbstractCommonListImpl(){
+               return new BlobsCommonList();
+       }
+
+       public List createItemsList(AbstractCommonList commonList){
+               List list = ((BlobsCommonList)commonList).getBlobListItem();
+               return list;
+       }
+
+       public Object createItemForCommonList(DocumentModel docModel, String label, String id) throws Exception {
+               BlobListItem item = new BlobListItem();
+               item.setEncoding((String)
+                               docModel.getProperty(label, BlobJAXBSchema.encoding));
+               item.setMimeType((String)
+                               docModel.getProperty(label, BlobJAXBSchema.mimeType));
+               //String theData = (String)
+               docModel.getProperty(label, BlobJAXBSchema.data);
+               item.setName((String)
+                               docModel.getProperty(label, BlobJAXBSchema.name));
+               item.setLength((String)
+                               docModel.getProperty(label, BlobJAXBSchema.length));
+               item.setUri(getServiceContextPath() + id);
+               item.setCsid(id);
+               return item;
+       }
+
+       private BlobsCommon getCommonPartProperties(DocumentModel docModel) throws Exception {
+               String label = getServiceContext().getCommonPartLabel();
+               BlobsCommon result = new BlobsCommon();
+               
+               result.setData((String) 
+                               docModel.getProperty(label, BlobJAXBSchema.data));
+               result.setDigest((String)
+                               docModel.getProperty(label, BlobJAXBSchema.digest));
+               result.setEncoding((String)
+                               docModel.getProperty(label, BlobJAXBSchema.encoding));
+               result.setLength((String)
+                               docModel.getProperty(label, BlobJAXBSchema.length));
+               result.setMimeType((String)
+                               docModel.getProperty(label, BlobJAXBSchema.mimeType));
+               result.setName((String)
+                               docModel.getProperty(label, BlobJAXBSchema.name));
+               result.setRepositoryId((String)
+                               docModel.getProperty(label, BlobJAXBSchema.repositoryId));
+               result.setUri(getServiceContextPath() + docModel.getName() + "/content");
+               
+               return result;
+       }
+       
+       private void setCommonPartProperties(DocumentModel documentModel,
+                       BlobsCommon blobsCommon) throws ClientException {
+               String label = getServiceContext().getCommonPartLabel();
+               documentModel.setProperty(label, BlobJAXBSchema.data, blobsCommon.getData());
+               documentModel.setProperty(label, BlobJAXBSchema.digest, blobsCommon.getDigest());
+               documentModel.setProperty(label, BlobJAXBSchema.encoding, blobsCommon.getEncoding());
+               documentModel.setProperty(label, BlobJAXBSchema.length, blobsCommon.getLength());
+               documentModel.setProperty(label, BlobJAXBSchema.mimeType, blobsCommon.getMimeType());
+               documentModel.setProperty(label, BlobJAXBSchema.name, blobsCommon.getName());
+               documentModel.setProperty(label, BlobJAXBSchema.uri, blobsCommon.getUri());
+               documentModel.setProperty(label, BlobJAXBSchema.repositoryId, blobsCommon.getRepositoryId());
+       }
+
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractAllParts(org.collectionspace.services.common.document.DocumentWrapper)
+        */
+       @Override
+       public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc)
+                       throws Exception {
+               ServiceContext ctx = this.getServiceContext();
+               DocumentModel docModel = wrapDoc.getWrappedObject();
+               //
+               // Setup of the content URL's
+               //
+               BlobsCommon blobsCommon = this.getCommonPartProperties(docModel);
+               String derivativeTerm = (String)ctx.getProperty(BlobInput.DERIVATIVE_TERM_KEY);
+               if (derivativeTerm != null  && !derivativeTerm.equalsIgnoreCase(BlobInput.DERIVATIVE_ORIGINAL_VALUE)) {
+                       blobsCommon.setUri(getServiceContextPath() + docModel.getName() + "/derivatives/" +
+                                       derivativeTerm + "/content");
+               }
+               blobsCommon.setRepositoryId(null); //hide the repository id from the GET results since it is private
+               this.setCommonPartProperties(docModel, blobsCommon);
+               
+               super.extractAllParts(wrapDoc);
+               //
+               // If the derivativeTerm is set then we need to get the blob stream
+               //
+               if (derivativeTerm != null) {
+                       RepositoryInstance repoSession = this.getRepositorySession();
+                       InputStream blobStream = NuxeoImageUtils.getPicture(ctx, repoSession, blobsCommon.getRepositoryId(), derivativeTerm);
+                       ctx.setProperty(BlobInput.DERIVATIVE_CONTENT_KEY, blobStream);
+               }
+       }
+
+       @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 {
+                       //
+                       // If blobInput is set 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);
+               }
+       }    
 }