]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
7b10a27faea414ce576640b241bee8c8c2dc33aa
[tmp/jakarta-migration.git] /
1 /**
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:
5
6  *  http://www.collectionspace.org
7  *  http://wiki.collectionspace.org
8
9  *  Copyright 2009 University of California at Berkeley
10
11  *  Licensed under the Educational Community License (ECL), Version 2.0.
12  *  You may not use this file except in compliance with this License.
13
14  *  You may obtain a copy of the ECL 2.0 License at
15
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
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.
23  */
24 package org.collectionspace.services.media.nuxeo;
25
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;
35
36 import java.util.ArrayList;
37 import java.util.List;
38
39 /**
40  * The Class MediaDocumentModelHandler.
41  */
42 public class MediaDocumentModelHandler
43         extends DocHandlerBase<MediaCommon, AbstractCommonList> {
44
45     //==============================================================================
46
47         private MediaCommon getCommonPartProperties(DocumentModel docModel) throws Exception {
48                 String label = getServiceContext().getCommonPartLabel();
49                 MediaCommon result = new MediaCommon();
50                 
51                 result.setBlobCsid((String)     
52                                 docModel.getProperty(label, MediaJAXBSchema.blobCsid));
53                 
54                 return result;
55         }
56     
57     @Override
58         public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc)
59                         throws Exception {
60                 ServiceContext ctx = this.getServiceContext();
61                 
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);
68                 } else {
69                         super.extractAllParts(wrapDoc);
70                 }               
71         }
72     
73         @Override
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();
79                         //
80                         // If getBlobCsid has a value then we just received a multipart/form-data file post
81                         //
82                         DocumentModel documentModel = wrapDoc.getWrappedObject();
83                         documentModel.setProperty(ctx.getCommonPartLabel(), MediaJAXBSchema.blobCsid, blobCsid);
84                 } else {
85                         super.fillAllParts(wrapDoc, action);
86                 }
87         }    
88     
89 }
90