]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
9389ba30ddcc1818b09c4fcba75864cbdbb9b3d9
[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.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;
36
37 import java.util.ArrayList;
38 import java.util.List;
39
40 import javax.ws.rs.core.MultivaluedMap;
41
42 /**
43  * The Class MediaDocumentModelHandler.
44  */
45 public class MediaDocumentModelHandler
46         extends DocHandlerBase<MediaCommon> {
47
48     //==============================================================================
49
50         private MediaCommon getCommonPartProperties(DocumentModel docModel) throws Exception {
51                 String label = getServiceContext().getCommonPartLabel();
52                 MediaCommon result = new MediaCommon();
53                 
54                 result.setBlobCsid((String)     
55                                 docModel.getProperty(label, MediaJAXBSchema.blobCsid));
56                 
57                 return result;
58         }
59     
60     @Override
61         public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc)
62                         throws Exception {
63                 ServiceContext ctx = this.getServiceContext();
64                 
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);
71                 } else {
72                         super.extractAllParts(wrapDoc);
73                 }               
74         }
75     
76         @Override
77         public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception {
78                 ServiceContext ctx = this.getServiceContext();
79                 String blobCsid = null;
80                 
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 
84                 } else {
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);
89                 }
90                 
91                 //
92                 if (blobCsid != null) {
93                         DocumentModel documentModel = wrapDoc.getWrappedObject();
94                         documentModel.setProperty(ctx.getCommonPartLabel(), MediaJAXBSchema.blobCsid, blobCsid);
95                 }
96         }    
97     
98 }
99