2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
24 package org.collectionspace.services.media.nuxeo;
26 import org.collectionspace.services.MediaJAXBSchema;
27 import org.collectionspace.services.nuxeo.client.java.DocHandlerBase;
28 import org.collectionspace.services.client.BlobClient;
29 import org.collectionspace.services.common.blob.BlobInput;
30 import org.collectionspace.services.common.blob.BlobUtil;
31 import org.collectionspace.services.common.context.ServiceContext;
32 import org.collectionspace.services.common.document.DocumentWrapper;
33 import org.collectionspace.services.jaxb.AbstractCommonList;
34 import org.collectionspace.services.media.MediaCommon;
35 import org.nuxeo.ecm.core.api.DocumentModel;
37 import java.util.ArrayList;
38 import java.util.List;
40 import javax.ws.rs.core.MultivaluedMap;
43 * The Class MediaDocumentModelHandler.
45 public class MediaDocumentModelHandler
46 extends DocHandlerBase<MediaCommon> {
48 //==============================================================================
50 private MediaCommon getCommonPartProperties(DocumentModel docModel) throws Exception {
51 String label = getServiceContext().getCommonPartLabel();
52 MediaCommon result = new MediaCommon();
54 result.setBlobCsid((String)
55 docModel.getProperty(label, MediaJAXBSchema.blobCsid));
61 public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc)
63 ServiceContext ctx = this.getServiceContext();
65 BlobInput blobInput = BlobUtil.getBlobInput(ctx);
66 if (blobInput != null && blobInput.isSchemaRequested()) { //Extract the blob info instead of the media info
67 DocumentModel docModel = wrapDoc.getWrappedObject();
68 MediaCommon mediaCommon = this.getCommonPartProperties(docModel);
69 String blobCsid = mediaCommon.getBlobCsid(); //cache the value to pass to the blob retriever
70 blobInput.setBlobCsid(blobCsid);
72 super.extractAllParts(wrapDoc);
77 public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception {
78 ServiceContext ctx = this.getServiceContext();
79 String blobCsid = null;
81 BlobInput blobInput = BlobUtil.getBlobInput(ctx);
82 if (blobInput != null && blobInput.getBlobCsid() != null) {
83 blobCsid = blobInput.getBlobCsid(); // If getBlobCsid has a value then we just finishing a multipart/form-data file post, created a blob, and now associating it with an existing media resource
85 MultivaluedMap<String, String> queryParams = this.getServiceContext().getQueryParams();
86 blobCsid = queryParams.getFirst(BlobClient.BLOB_CSID_PARAM); // if the blobUri query param is set, it's probably set from the MediaResource.create method -we're creating a blob from a URI and creating a new media resource as well
87 // extract all the other fields from the input payload
88 super.fillAllParts(wrapDoc, action);
92 if (blobCsid != null) {
93 DocumentModel documentModel = wrapDoc.getWrappedObject();
94 documentModel.setProperty(ctx.getCommonPartLabel(), MediaJAXBSchema.blobCsid, blobCsid);