]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5564: Using Nuxeo's FileManager and Blob support for keeping track of publishe...
authorRichard Millet <richard.millet@berkeley.edu>
Tue, 22 Jan 2013 04:56:54 +0000 (20:56 -0800)
committerRichard Millet <richard.millet@berkeley.edu>
Tue, 22 Jan 2013 04:56:54 +0000 (20:56 -0800)
13 files changed:
services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java
services/article/client/pom.xml
services/article/client/src/main/java/org/collectionspace/services/client/ArticleClient.java
services/article/jaxb/src/main/resources/articles-common.xsd
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
services/client/src/main/java/org/collectionspace/services/client/PoxPayloadOut.java
services/common/pom.xml
services/common/src/main/java/org/collectionspace/services/common/article/ArticleResource.java [moved from services/article/service/src/main/java/org/collectionspace/services/article/ArticleResource.java with 55% similarity]
services/common/src/main/java/org/collectionspace/services/common/article/ArticleUtil.java [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoBlobUtils.java [moved from services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java with 87% similarity]
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java

index 33638e96398c4e94e1c9864ea82c51315745bb92..cfee42fc2474a87af4c500b9d43029d0ebebc747 100644 (file)
@@ -49,7 +49,6 @@ import org.collectionspace.services.contact.ContactResource;
 import org.collectionspace.services.vocabulary.VocabularyResource;
 import org.collectionspace.services.organization.OrgAuthorityResource;
 import org.collectionspace.services.person.PersonAuthorityResource;
-import org.collectionspace.services.article.ArticleResource;
 
 //import org.collectionspace.services.query.QueryResource;
 
@@ -66,6 +65,7 @@ import org.collectionspace.services.common.ResourceBase;
 import org.collectionspace.services.common.ResourceMap;
 import org.collectionspace.services.common.ResourceMapHolder;
 import org.collectionspace.services.common.ResourceMapImpl;
+import org.collectionspace.services.common.article.ArticleResource;
 import org.collectionspace.services.common.relation.RelationResource;
 import org.collectionspace.services.common.security.SecurityInterceptor;
 
index 056998ed31dd324515c57b0bb777719e17f2da3b..53173d3517ec25993b9ed5e8f604e37025f276c1 100644 (file)
@@ -9,7 +9,6 @@
     </parent>
 
     <modelVersion>4.0.0</modelVersion>
-    <groupId>org.collectionspace.services</groupId>
     <artifactId>org.collectionspace.services.article.client</artifactId>
     <name>services.article.client</name>
     
             <artifactId>org.collectionspace.services.jaxb</artifactId>
             <version>${project.version}</version>
         </dependency>
-        <dependency>
-            <groupId>org.collectionspace.services</groupId>
-            <artifactId>org.collectionspace.services.common</artifactId>
-            <optional>true</optional>
-            <version>${project.version}</version>
-        </dependency>
         <dependency>
             <groupId>org.collectionspace.services</groupId>
             <artifactId>org.collectionspace.services.client</artifactId>
@@ -84,7 +77,6 @@
         <dependency>
             <groupId>commons-httpclient</groupId>
             <artifactId>commons-httpclient</artifactId>
-            <version>3.1</version>
         </dependency>
     </dependencies>
     
index 403ab93c2f25baebed1181ed1b1098e6dcf08f41..a6c68eeba1dd3631966c5f117f48d2349f928b9e 100644 (file)
@@ -30,6 +30,7 @@ public class ArticleClient extends AbstractCommonListPoxServiceClientImpl<Articl
     public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT;
     public static final String SERVICE_PATH_PROXY = SERVICE_PATH + "/";
     public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME;
+    public static final String SERVICE_COMMON_PART_NAME = SERVICE_NAME + PART_LABEL_SEPARATOR + PART_COMMON_LABEL;    
 
     /* (non-Javadoc)
      * @see org.collectionspace.services.client.AbstractServiceClientImpl#getServicePathComponent()
index 007363849b62e19460907496463bb3841a6af312..6b277cf988fcd3368f775569e5b58de8e093e0da 100644 (file)
@@ -14,7 +14,7 @@
                <xs:complexType>
                        <xs:sequence>
                                <xs:element name="articleNumber" type="xs:string" />                    <!-- An ID for the article (different than the CSID) -->
-                               <xs:element name="articleContentUrl" type="xs:string" />                <!-- The URL of the article's content -->
+                               <xs:element name="articleContentCsid" type="xs:string" />               <!-- The URL of the article's content -->
                                <xs:element name="articleJobId" type="xs:string" />                             <!-- The asynch job ID -if any -->
                                <xs:element name="articleSource" type="xs:string" />                    <!-- The name of the service/resource that was used to create the article. -->
                                <xs:element name="articlePublisher" type="xs:string" />                 <!-- The user who published the article -->
index bae7885715d164b44a219dcbe4ccba585d0be4f6..a660fc6a2f23c834aa4eb9877b08dfb88689d4d9 100644 (file)
             <artifactId>org.collectionspace.services.blob.client</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.collectionspace.services</groupId>
+            <artifactId>org.collectionspace.services.article.client</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         
         <!-- External dependencies -->        
         <dependency>
index 091b3a6f4ad6c34dc4e86443d8c9cc126f71bcd5..125d1589d11cdea47b7ef85856ca73385e4e41a0 100644 (file)
  */
 package org.collectionspace.services.blob;
 
+import org.collectionspace.services.article.ArticlesCommon;
+import org.collectionspace.services.client.ArticleClient;
 import org.collectionspace.services.client.BlobClient;
 import org.collectionspace.services.client.PoxPayloadIn;
 import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.client.workflow.WorkflowClient;
 import org.collectionspace.services.common.FileUtils;
 import org.collectionspace.services.common.ResourceBase;
 import org.collectionspace.services.common.ResourceMap;
+import org.collectionspace.services.common.ServiceMain;
 import org.collectionspace.services.common.ServiceMessages;
+import org.collectionspace.services.common.article.ArticleResource;
+import org.collectionspace.services.common.article.ArticleUtil;
 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.imaging.nuxeo.NuxeoBlobUtils;
 import org.collectionspace.services.nuxeo.client.java.CommonList;
+import org.collectionspace.services.workflow.WorkflowCommon;
 import org.jboss.resteasy.plugins.providers.multipart.InputPart;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
+import org.nuxeo.ecm.core.api.DocumentModel;
+import org.nuxeo.ecm.core.api.DocumentRef;
+import org.nuxeo.ecm.core.api.IdRef;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
@@ -50,11 +62,15 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.Response.ResponseBuilder;
 import javax.ws.rs.core.UriInfo;
+
+import java.io.File;
 import java.io.InputStream;
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
 
 //FIXME: REM - We should not have Nuxeo dependencies in our resource classes.
 
@@ -110,11 +126,13 @@ public class BlobResource extends ResourceBase {
        return result;
     }
     
-    private InputStream getBlobContent(String csid, String derivativeTerm, StringBuffer outMimeType) throws WebApplicationException {
+    private InputStream getBlobContent(ServiceContext ctx,
+               String csid, 
+               String derivativeTerm, 
+               StringBuffer outMimeType) throws WebApplicationException {
        InputStream result = null;
        
        try {
-               ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext();
                BlobInput blobInput = BlobUtil.getBlobInput(ctx);
                blobInput.setDerivativeTerm(derivativeTerm);
                blobInput.setContentRequested(true);
@@ -236,14 +254,46 @@ public class BlobResource extends ResourceBase {
     @Path("{csid}/content")
     public Response getBlobContent(    @PathParam("csid") String csid) {
        Response result = null;
-
-       StringBuffer mimeType = new StringBuffer();
-       InputStream contentStream = getBlobContent(csid, null /*derivative term*/, mimeType /*will get set*/);
-           Response.ResponseBuilder responseBuilder = Response.ok(contentStream, mimeType.toString());
-           
-       result = responseBuilder.build();
+       ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = null;
+       
+       try {
+               ctx = createServiceContext();
+               
+               StringBuffer mimeType = new StringBuffer();
+               InputStream contentStream = getBlobContent(ctx, csid, null /*derivative term*/, mimeType /*will get set*/);
+                   
+               Response.ResponseBuilder responseBuilder = Response.ok(contentStream, mimeType.toString());
+               result = responseBuilder.build();
+       } catch (Exception e) {
+               throw bigReThrow(e, ServiceMessages.CREATE_FAILED);
+       }
+       
        return result;
     }
+    
+    /*
+     * Publish the blob content.
+     */
+    @GET
+    @Path("{csid}/content/publish")
+    public Response publishBlobContent(
+               @Context ResourceMap resourceMap,
+               @Context UriInfo uriInfo,
+               @PathParam("csid") String csid) {
+       Response result = null;
+       ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = null;
+       
+       try {
+                       ctx = createServiceContext();
+               StringBuffer mimeType = new StringBuffer();
+               InputStream contentStream = getBlobContent(ctx, csid, null /*derivative term*/, mimeType /*will get set*/);             
+               result = ArticleUtil.publishToRepository(resourceMap, uriInfo, this.getRepositoryClient(ctx), ctx, contentStream, csid);
+       } catch (Exception e) {
+               throw bigReThrow(e, ServiceMessages.PUT_FAILED);
+       }
+       
+       return result;
+    }    
 
     @GET
     @Path("{csid}/derivatives/{derivativeTerm}/content")
@@ -251,13 +301,21 @@ public class BlobResource extends ResourceBase {
                @PathParam("csid") String csid,
                @PathParam("derivativeTerm") String derivativeTerm) {
        Response result = null;
+       ServiceContext ctx = null;
        
-       StringBuffer mimeType = new StringBuffer();
-       InputStream contentStream = getBlobContent(csid, derivativeTerm, mimeType);
-           Response.ResponseBuilder responseBuilder = Response.ok(contentStream, mimeType.toString());
-           
-       result = responseBuilder.build();
-       return result;
+               try {
+                       ctx = createServiceContext();
+
+                       StringBuffer mimeType = new StringBuffer();
+                       InputStream contentStream = getBlobContent(ctx, csid, derivativeTerm, mimeType);
+                           Response.ResponseBuilder responseBuilder = Response.ok(contentStream, mimeType.toString());
+                           
+                       result = responseBuilder.build();
+               } catch (Exception e) {
+                       throw bigReThrow(e, ServiceMessages.CREATE_FAILED);
+               }
+               
+           return result;
     }
     
     @GET
index fc0ed020bf67c0433607808c209862b59d8fef16..a9940189511d0d88ab4020ed8f1c8036fd4ddc49 100644 (file)
@@ -35,7 +35,7 @@ import org.collectionspace.services.common.blob.BlobUtil;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentUtils;
 import org.collectionspace.services.common.document.DocumentWrapper;
-import org.collectionspace.services.common.imaging.nuxeo.NuxeoImageUtils;
+import org.collectionspace.services.common.imaging.nuxeo.NuxeoBlobUtils;
 import org.collectionspace.services.config.service.ListResultField;
 import org.collectionspace.services.config.service.ObjectPartType;
 import org.collectionspace.services.jaxb.BlobJAXBSchema;
@@ -148,7 +148,7 @@ extends DocHandlerBase<BlobsCommon> {
                //
                if (blobInput.isDerivativeListRequested() == true) {
                List<ListResultField> resultsFields = getListItemsArray();
-                       CommonList blobsCommonList = NuxeoImageUtils.getBlobDerivatives( //FIXME: REM - Need to replace "NuxeoImageUtils" with something more general like "BlobUtils" since we may support other blob types.
+                       CommonList blobsCommonList = NuxeoBlobUtils.getBlobDerivatives( //FIXME: REM - Need to replace "NuxeoImageUtils" with something more general like "BlobUtils" since we may support other blob types.
                                        repoSession, blobRepositoryId, resultsFields, getDerivativePathBase(docModel));
 //                     ctx.setProperty(BlobInput.BLOB_DERIVATIVE_LIST_KEY, blobsCommonList);
                        blobInput.setDerivativeList(blobsCommonList);
@@ -163,15 +163,15 @@ extends DocHandlerBase<BlobsCommon> {
                //
                if (derivativeTerm != null || getContentFlag == true) {
                        StringBuffer mimeTypeBuffer = new StringBuffer();
-                       BlobOutput blobOutput = NuxeoImageUtils.getBlobOutput(ctx, repoSession,
+                       BlobOutput blobOutput = NuxeoBlobUtils.getBlobOutput(ctx, repoSession,
                                        blobRepositoryId, derivativeTerm, getContentFlag, mimeTypeBuffer);
                        if (getContentFlag == true) {
                                if (blobOutput != null) {
                                        blobInput.setContentStream(blobOutput.getBlobInputStream());
                                } else {
                                        // If we can't find the blob's content, we'll return a "missing document" image
-                                       blobInput.setContentStream(NuxeoImageUtils.getResource(NuxeoImageUtils.DOCUMENT_MISSING_PLACEHOLDER_IMAGE));
-                                       mimeTypeBuffer.append(NuxeoImageUtils.MIME_JPEG);
+                                       blobInput.setContentStream(NuxeoBlobUtils.getResource(NuxeoBlobUtils.DOCUMENT_MISSING_PLACEHOLDER_IMAGE));
+                                       mimeTypeBuffer.append(NuxeoBlobUtils.MIME_JPEG);
                                }
                        }
        
@@ -194,8 +194,8 @@ extends DocHandlerBase<BlobsCommon> {
                        this.setCommonPartProperties(docModel, blobsCommon);
                        // finish extracting the other parts by calling the parent
                } else {
-                       extractMetadata(blobRepositoryId, NuxeoImageUtils.SCHEMA_IMAGE_METADATA);
-                       extractMetadata(blobRepositoryId, NuxeoImageUtils.SCHEMA_IPTC);
+                       extractMetadata(blobRepositoryId, NuxeoBlobUtils.SCHEMA_IMAGE_METADATA);
+                       extractMetadata(blobRepositoryId, NuxeoBlobUtils.SCHEMA_IPTC);
                }
                
                //
@@ -222,7 +222,7 @@ extends DocHandlerBase<BlobsCommon> {
                        DocumentModel documentModel = wrapDoc.getWrappedObject();
                        RepositoryInstance repoSession = this.getRepositorySession();
                
-                       BlobsCommon blobsCommon = NuxeoImageUtils.createBlobInRepository(ctx, repoSession, blobInput, purgeOriginal);
+                       BlobsCommon blobsCommon = NuxeoBlobUtils.createBlobInRepository(ctx, repoSession, blobInput, purgeOriginal);
                        blobInput.setBlobCsid(documentModel.getName()); //Assumption here is that the documentModel "name" field is storing a CSID
 
                PoxPayloadIn input = ctx.getInput();
index 1b9d08d23cc6d63566e63cdc1a12d58468ea2b55..eca3df2c73e3bc82a4b69e5ee6abf396052d098c 100644 (file)
@@ -6,7 +6,6 @@ import org.dom4j.Document;
 import org.dom4j.DocumentException;\r
 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
index 531d9bfb87a9b8456984ab6d550aa34b68851a12..284753867cb724e92343e6464e0466e388582f9b 100644 (file)
             <artifactId>org.collectionspace.services.relation.client</artifactId>\r
             <version>${project.version}</version>\r
         </dependency>\r
+        <dependency>\r
+            <groupId>org.collectionspace.services</groupId>\r
+            <artifactId>org.collectionspace.services.article.client</artifactId>\r
+            <version>${project.version}</version>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>org.collectionspace.services</groupId>\r
+            <artifactId>org.collectionspace.services.article.jaxb</artifactId>\r
+            <version>${project.version}</version>\r
+        </dependency>\r
         <!-- \r
         <dependency>\r
                        <groupId>org.collectionspace.services</groupId>\r
similarity index 55%
rename from services/article/service/src/main/java/org/collectionspace/services/article/ArticleResource.java
rename to services/common/src/main/java/org/collectionspace/services/common/article/ArticleResource.java
index be01fd433b1e8a2ecd056efdcd130d35931e5c1b..836e8d09dc1b1444686730cd1d1f695ef42efd75 100644 (file)
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.collectionspace.services.article;
+package org.collectionspace.services.common.article;
 
+import java.io.InputStream;
+
+import org.collectionspace.services.article.ArticlesCommon;
 import org.collectionspace.services.client.ArticleClient;
+import org.collectionspace.services.client.PayloadOutputPart;
+import org.collectionspace.services.client.PoxPayloadIn;
+import org.collectionspace.services.client.PoxPayloadOut;
 import org.collectionspace.services.common.ResourceBase;
+import org.collectionspace.services.common.ServiceMessages;
+import org.collectionspace.services.common.blob.BlobOutput;
+import org.collectionspace.services.common.context.RemoteServiceContext;
+import org.collectionspace.services.common.imaging.nuxeo.NuxeoBlobUtils;
 import org.jboss.resteasy.core.ResourceMethod;
 import org.jboss.resteasy.spi.HttpRequest;
 
@@ -38,6 +48,7 @@ import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Request;
+import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
 @Path(ArticleClient.SERVICE_PATH)
@@ -71,12 +82,36 @@ public class ArticleResource extends ResourceBase {
        
     @GET
     @Path("/published/{csid}")
-    @Produces("text/plain")
-    public byte[] getPublishedResource(
-            @Context Request request,                  
+    public Response getPublishedResource(
+            @Context Request request,
             @Context UriInfo uriInfo,
             @PathParam("csid") String csid) {
-       return get(request, uriInfo, csid);
+       Response result = null;
+
+        try {
+               //
+               // First, extract the ArticlesCommon instance.
+               //
+                       RemoteServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = (RemoteServiceContext<PoxPayloadIn, PoxPayloadOut>) createServiceContext(uriInfo);
+                       PoxPayloadOut poxPayloadOut = get(csid, ctx);
+                       ArticlesCommon articlesCommon = (ArticlesCommon)poxPayloadOut.getPart(ArticleClient.SERVICE_COMMON_PART_NAME).getBody();
+                       //
+                       // Get the repository blob ID and retrieve the content as a stream
+                       //
+                       String blobContentCsid = articlesCommon.getArticleContentCsid();
+                       StringBuffer outMimeType = new StringBuffer();
+                       BlobOutput blobOutput = NuxeoBlobUtils.getBlobOutput(ctx, getRepositoryClient(ctx), blobContentCsid, outMimeType);
+                       InputStream contentStream = blobOutput.getBlobInputStream();
+                       //
+                       // Return the content stream in the response
+                       //
+               Response.ResponseBuilder responseBuilder = Response.ok(contentStream, outMimeType.toString());
+               result = responseBuilder.build();
+               } catch (Exception e) {
+            throw bigReThrow(e, ServiceMessages.READ_FAILED, csid);
+               }
+
+       return result;
     }
 }
 
diff --git a/services/common/src/main/java/org/collectionspace/services/common/article/ArticleUtil.java b/services/common/src/main/java/org/collectionspace/services/common/article/ArticleUtil.java
new file mode 100644 (file)
index 0000000..f4af10e
--- /dev/null
@@ -0,0 +1,60 @@
+package org.collectionspace.services.common.article;
+
+import java.io.InputStream;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+import org.collectionspace.services.article.ArticlesCommon;
+import org.collectionspace.services.blob.BlobsCommon;
+import org.collectionspace.services.client.ArticleClient;
+import org.collectionspace.services.client.PoxPayloadIn;
+import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.common.ResourceMap;
+import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.document.TransactionException;
+import org.collectionspace.services.common.imaging.nuxeo.NuxeoBlobUtils;
+import org.collectionspace.services.common.repository.RepositoryClient;
+
+public class ArticleUtil {
+       
+       public static Response publishToRepository(ResourceMap resourceMap,
+               UriInfo uriInfo,
+               ServiceContext parentCtx,
+                       PoxPayloadOut poxPayloadOut) {
+               Response result = null;
+               
+       ArticlesCommon articlesCommon = new ArticlesCommon();
+       articlesCommon.setArticlePublisher("Hello, this is a test.");
+       PoxPayloadIn input = new PoxPayloadIn(ArticleClient.SERVICE_PAYLOAD_NAME, articlesCommon, 
+                       ArticleClient.SERVICE_COMMON_PART_NAME);
+               
+       ArticleResource articleResource = new ArticleResource();
+       result = articleResource.create(parentCtx, resourceMap, uriInfo, input.getXmlPayload());
+       
+               return result;
+       }
+       
+       public static Response publishToRepository(ResourceMap resourceMap,
+               UriInfo uriInfo,
+               RepositoryClient repositoryClient,
+               ServiceContext parentCtx,
+                       InputStream inputStream,
+                       String streamName) throws TransactionException {
+               Response result = null;
+               
+       BlobsCommon blobsCommon = NuxeoBlobUtils.createBlobInRepository(parentCtx, repositoryClient, inputStream, streamName);
+               
+       ArticlesCommon articlesCommon = new ArticlesCommon();
+       articlesCommon.setArticlePublisher(parentCtx.getUserId());
+       articlesCommon.setArticleContentCsid(blobsCommon.getRepositoryId());
+       PoxPayloadOut poxPayloadOut = new PoxPayloadOut(ArticleClient.SERVICE_PAYLOAD_NAME);
+       poxPayloadOut.addPart(ArticleClient.SERVICE_COMMON_PART_NAME, articlesCommon);
+       
+       ArticleResource articleResource = new ArticleResource();
+       result = articleResource.create(parentCtx, resourceMap, uriInfo, poxPayloadOut.toXML());
+       
+               return result;
+       }
+
+}
similarity index 87%
rename from services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java
rename to services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoBlobUtils.java
index 113729df2d5324c9d16ae3c07e8b393d2094e709..e82530497f5604a1f164c861aceba66ba89cff75 100644 (file)
@@ -80,6 +80,7 @@ import org.nuxeo.ecm.core.api.blobholder.BlobHolder;
 import org.nuxeo.ecm.core.api.blobholder.DocumentBlobHolder;\r
 import org.nuxeo.ecm.core.api.impl.DocumentModelImpl;\r
 import org.nuxeo.ecm.core.api.impl.blob.FileBlob;\r
+import org.nuxeo.ecm.core.api.impl.blob.InputStreamBlob;\r
 import org.nuxeo.ecm.core.api.impl.blob.StreamingBlob;\r
 import org.nuxeo.ecm.core.api.impl.blob.ByteArrayBlob;\r
 import org.nuxeo.ecm.core.api.repository.RepositoryInstance;\r
@@ -100,6 +101,9 @@ import org.slf4j.LoggerFactory;
 import org.collectionspace.services.common.ServiceMain;\r
 import org.collectionspace.services.common.blob.BlobInput;\r
 import org.collectionspace.services.common.context.ServiceContext;\r
+import org.collectionspace.services.common.document.DocumentException;\r
+import org.collectionspace.services.common.document.TransactionException;\r
+import org.collectionspace.services.common.repository.RepositoryClient;\r
 import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils;\r
 import org.collectionspace.services.blob.BlobsCommon;\r
 import org.collectionspace.services.blob.DimensionSubGroup;\r
@@ -110,6 +114,7 @@ import org.collectionspace.services.blob.MeasuredPartGroupList;
 //import org.collectionspace.services.blob.BlobsCommonList.BlobListItem;\r
 import org.collectionspace.services.jaxb.BlobJAXBSchema;\r
 import org.collectionspace.services.nuxeo.client.java.CommonList;\r
+import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl;\r
 import org.collectionspace.services.nuxeo.extension.thumbnail.ThumbnailConstants;\r
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;\r
 import org.collectionspace.services.common.blob.BlobOutput;\r
@@ -118,13 +123,13 @@ import org.collectionspace.services.config.service.ListResultField;
 \r
 \r
 /**\r
- * The Class NuxeoImageUtils.\r
+ * The Class NuxeoBlobUtils.\r
  */\r
-public class NuxeoImageUtils {\r
+public class NuxeoBlobUtils {\r
                \r
        /** The Constant logger. */\r
        private static final Logger logger = LoggerFactory\r
-                       .getLogger(NuxeoImageUtils.class);\r
+                       .getLogger(NuxeoBlobUtils.class);\r
 \r
        public static final String DOCUMENT_PLACEHOLDER_IMAGE = "documentImage.jpg";\r
        public static final String DOCUMENT_MISSING_PLACEHOLDER_IMAGE = "documentImageMissing.jpg";\r
@@ -186,7 +191,7 @@ public class NuxeoImageUtils {
        /**\r
         * Instantiates a new nuxeo image utils.\r
         */\r
-       NuxeoImageUtils() {\r
+       NuxeoBlobUtils() {\r
                // empty constructor\r
        }\r
 \r
@@ -295,13 +300,16 @@ public class NuxeoImageUtils {
        static private boolean isImageMedia(Blob nuxeoBlob) {\r
                boolean result = false;\r
                \r
-               String mimeType = nuxeoBlob.getMimeType().toLowerCase().trim();\r
-               String[] parts = mimeType.split("/"); // split strings like "application/xml" into an array of two strings\r
-               if (parts.length == 2) {\r
-                       for (String type : imageTypes) {\r
-                               if (parts[1].equalsIgnoreCase(type)) {\r
-                                       result = true;\r
-                                       break;\r
+               String mimeType = nuxeoBlob.getMimeType();\r
+               if (mimeType != null) {\r
+                       mimeType = mimeType.toLowerCase().trim();\r
+                       String[] parts = mimeType.split("/"); // split strings like "application/xml" into an array of two strings\r
+                       if (parts.length == 2) {\r
+                               for (String type : imageTypes) {\r
+                                       if (parts[1].equalsIgnoreCase(type)) {\r
+                                               result = true;\r
+                                               break;\r
+                                       }\r
                                }\r
                        }\r
                }\r
@@ -744,7 +752,68 @@ public class NuxeoImageUtils {
                return result;\r
        }\r
        \r
+       static private RepositoryInstance getRepositorySession(ServiceContext ctx, RepositoryClient repositoryClient) {\r
+               RepositoryInstance result = null;               \r
+               RepositoryJavaClientImpl nuxeoClient = (RepositoryJavaClientImpl)repositoryClient;\r
+               \r
+               try {\r
+                       result = nuxeoClient.getRepositorySession(ctx);\r
+               } catch (Exception e) {\r
+            logger.error("Could not get a repository session to the Nuxeo repository", e);\r
+               }\r
+               \r
+               return result;\r
+       }\r
+       \r
+       static private void releaseRepositorySession(ServiceContext ctx, RepositoryClient repositoryClient, RepositoryInstance repoSession) throws TransactionException {\r
+               RepositoryJavaClientImpl nuxeoClient = (RepositoryJavaClientImpl)repositoryClient;\r
+               nuxeoClient.releaseRepositorySession(ctx, repoSession);\r
+       }\r
+       \r
+       static public BlobsCommon createBlobInRepository(\r
+                       ServiceContext ctx,\r
+                       RepositoryClient repositoryClient,\r
+                       InputStream inputStream,\r
+                       String blobName) throws TransactionException {\r
+               BlobsCommon result = null;\r
+\r
+               boolean repoSessionCleanup = false;\r
+               RepositoryInstance repoSession = (RepositoryInstance)ctx.getCurrentRepositorySession();\r
+               if (repoSession == null) {\r
+                       repoSession = getRepositorySession(ctx, repositoryClient);\r
+                       repoSessionCleanup = true;\r
+               }\r
+               \r
+               String nuxeoWspaceId = ctx.getRepositoryWorkspaceId();\r
+               DocumentRef nuxeoWspace = new IdRef(nuxeoWspaceId);\r
+               \r
+               try {\r
+                       DocumentModel blobLocation = repoSession.getDocument(nuxeoWspace);\r
+                       Blob inputStreamBlob = new InputStreamBlob(inputStream);\r
+                       String digestAlgorithm = getFileManagerService()\r
+                                       .getDigestAlgorithm(); // Only call this because we seem to need some way of initializing Nuxeo's FileManager with a call.\r
+                       \r
+                       logger.debug("Start --> Starting call to Nuxeo to create the blob document."); // For example, see Nuxeo's DefaultPictureAdapter class for details\r
+                       DocumentModel documentModel = getFileManagerService()\r
+                                       .createDocumentFromBlob(repoSession, inputStreamBlob,\r
+                                                       blobLocation.getPathAsString(), true,\r
+                                                       blobName);\r
+                       logger.debug("Stop --> Finished calling Nuxeo to create the blob document.");\r
+\r
+                       result = createBlobsCommon(documentModel, inputStreamBlob); // Now create our metadata resource document\r
 \r
+               } catch (Exception e) {\r
+                       result = null;\r
+                       logger.error("Could not create new Nuxeo blob document.", e); //FIXME: REM - This should probably be re-throwing the exception?\r
+               } finally {\r
+                       if (repoSessionCleanup == true) {\r
+                               releaseRepositorySession(ctx, repositoryClient, repoSession);\r
+                       }\r
+               }\r
+               \r
+               return result;\r
+       }\r
+       \r
        /**\r
         * Creates the picture.\r
         * \r
@@ -800,7 +869,7 @@ public class NuxeoImageUtils {
                \r
                return result;\r
        }\r
-\r
+       \r
        /**\r
         * Creates the image blob.\r
         * \r
@@ -900,6 +969,32 @@ public class NuxeoImageUtils {
                return result;\r
        }\r
 \r
+       static public BlobOutput getBlobOutput(ServiceContext ctx,\r
+                       RepositoryClient repositoryClient,\r
+                       String repositoryId,\r
+                       StringBuffer outMimeType) throws TransactionException {\r
+               BlobOutput result = null;\r
+               \r
+               boolean repoSessionCleanup = false;\r
+               RepositoryInstance repoSession = (RepositoryInstance)ctx.getCurrentRepositorySession();\r
+               if (repoSession == null) {\r
+                       repoSession = getRepositorySession(ctx, repositoryClient);\r
+                       repoSessionCleanup = true;\r
+               }\r
+               \r
+               try {\r
+                       result = getBlobOutput(ctx, repoSession, repositoryId, null, true, outMimeType);\r
+               }\r
+               \r
+               finally {\r
+                       if (repoSessionCleanup == true) {\r
+                               releaseRepositorySession(ctx, repositoryClient, repoSession);\r
+                       }\r
+               }\r
+               \r
+               return result;\r
+       }\r
+       \r
        /**\r
         * Gets the image.\r
         * \r
index 10f39f50b2a6861e5cfaab505a1d18f196b1f723..2a0797a5b8bb2c65c601fa4505872fe3e6402cca 100644 (file)
@@ -68,7 +68,6 @@ import org.nuxeo.runtime.transaction.TransactionRuntimeException;
 //
 import org.apache.chemistry.opencmis.commons.server.CallContext;
 import org.apache.chemistry.opencmis.server.impl.CallContextImpl;
-import org.apache.chemistry.opencmis.server.support.query.CmisQlExtParser_CmisBaseGrammar.boolean_factor_return;
 import org.nuxeo.ecm.core.opencmis.impl.server.NuxeoCmisService;
 import org.nuxeo.ecm.core.opencmis.impl.server.NuxeoRepository;