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 java.util.List;
28 import org.collectionspace.services.MediaJAXBSchema;
29 import org.collectionspace.services.blob.BlobsCommon;
30 import org.collectionspace.services.common.DocHandlerBase;
31 import org.collectionspace.services.common.blob.BlobInput;
32 import org.collectionspace.services.common.blob.BlobUtil;
33 import org.collectionspace.services.common.context.ServiceContext;
34 import org.collectionspace.services.common.document.DocumentWrapper;
35 import org.collectionspace.services.common.document.DocumentHandler.Action;
36 import org.collectionspace.services.common.imaging.nuxeo.NuxeoImageUtils;
37 import org.collectionspace.services.media.MediaCommon;
38 import org.collectionspace.services.media.MediaCommonList;
39 import org.collectionspace.services.media.MediaCommonList.MediaListItem;
40 import org.collectionspace.services.jaxb.AbstractCommonList;
41 import org.collectionspace.services.jaxb.BlobJAXBSchema;
42 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
43 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
44 import org.nuxeo.ecm.core.api.DocumentModel;
45 import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
48 * The Class MediaDocumentModelHandler.
50 public class MediaDocumentModelHandler
51 extends DocHandlerBase<MediaCommon, AbstractCommonList> {
53 public final String getNuxeoSchemaName(){
57 public String getSummaryFields(AbstractCommonList commonList){
58 return "title|source|filename|identificationNumber|uri|csid";
61 public AbstractCommonList createAbstractCommonListImpl(){
62 return new MediaCommonList();
65 public List createItemsList(AbstractCommonList commonList){
66 List list = ((MediaCommonList)commonList).getMediaListItem();
70 private MediaCommon getCommonPartProperties(DocumentModel docModel) throws Exception {
71 String label = getServiceContext().getCommonPartLabel();
72 MediaCommon result = new MediaCommon();
74 result.setBlobCsid((String)
75 docModel.getProperty(label, MediaJAXBSchema.blobCsid));
80 public Object createItemForCommonList(DocumentModel docModel, String label, String id) throws Exception {
81 MediaListItem item = new MediaListItem();
82 item.setTitle((String) docModel.getProperty(label, MediaJAXBSchema.title));
83 item.setSource((String) docModel.getProperty(label, MediaJAXBSchema.source));
84 item.setFilename((String) docModel.getProperty(label, MediaJAXBSchema.filename));
85 item.setIdentificationNumber((String) docModel.getProperty(label, MediaJAXBSchema.identificationNumber));
86 item.setUri(getServiceContextPath() + id);
92 public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc)
94 ServiceContext ctx = this.getServiceContext();
96 BlobInput blobInput = BlobUtil.getBlobInput(ctx);
97 if (blobInput != null && blobInput.isSchemaRequested()) { //Extract the blob info instead of the media info
98 DocumentModel docModel = wrapDoc.getWrappedObject();
99 MediaCommon mediaCommon = this.getCommonPartProperties(docModel);
100 String blobCsid = mediaCommon.getBlobCsid(); //cache the value to pass to the blob retriever
101 blobInput.setBlobCsid(blobCsid);
103 super.extractAllParts(wrapDoc);
108 public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception {
109 ServiceContext ctx = this.getServiceContext();
110 BlobInput blobInput = BlobUtil.getBlobInput(ctx);
111 if (blobInput != null && blobInput.getBlobCsid() != null) {
112 String blobCsid = blobInput.getBlobCsid();
114 // If getBlobCsid has a value then we just received a multipart/form-data file post
116 DocumentModel documentModel = wrapDoc.getWrappedObject();
117 documentModel.setProperty(ctx.getCommonPartLabel(), MediaJAXBSchema.blobCsid, blobCsid);
119 super.fillAllParts(wrapDoc, action);