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.common.blob.BlobInput;
29 import org.collectionspace.services.common.blob.BlobUtil;
30 import org.collectionspace.services.common.context.ServiceContext;
31 import org.collectionspace.services.common.document.DocumentWrapper;
32 import org.collectionspace.services.jaxb.AbstractCommonList;
33 import org.collectionspace.services.media.MediaCommon;
34 import org.nuxeo.ecm.core.api.DocumentModel;
36 import java.util.ArrayList;
37 import java.util.List;
40 * The Class MediaDocumentModelHandler.
42 public class MediaDocumentModelHandler
43 extends DocHandlerBase<MediaCommon> {
45 //==============================================================================
47 private MediaCommon getCommonPartProperties(DocumentModel docModel) throws Exception {
48 String label = getServiceContext().getCommonPartLabel();
49 MediaCommon result = new MediaCommon();
51 result.setBlobCsid((String)
52 docModel.getProperty(label, MediaJAXBSchema.blobCsid));
58 public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc)
60 ServiceContext ctx = this.getServiceContext();
62 BlobInput blobInput = BlobUtil.getBlobInput(ctx);
63 if (blobInput != null && blobInput.isSchemaRequested()) { //Extract the blob info instead of the media info
64 DocumentModel docModel = wrapDoc.getWrappedObject();
65 MediaCommon mediaCommon = this.getCommonPartProperties(docModel);
66 String blobCsid = mediaCommon.getBlobCsid(); //cache the value to pass to the blob retriever
67 blobInput.setBlobCsid(blobCsid);
69 super.extractAllParts(wrapDoc);
74 public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception {
75 ServiceContext ctx = this.getServiceContext();
76 BlobInput blobInput = BlobUtil.getBlobInput(ctx);
77 if (blobInput != null && blobInput.getBlobCsid() != null) {
78 String blobCsid = blobInput.getBlobCsid();
80 // If getBlobCsid has a value then we just received a multipart/form-data file post
82 DocumentModel documentModel = wrapDoc.getWrappedObject();
83 documentModel.setProperty(ctx.getCommonPartLabel(), MediaJAXBSchema.blobCsid, blobCsid);
85 super.fillAllParts(wrapDoc, action);