]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
03b808783c1ab97abfae77ed49a4f71e2729d3a9
[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 java.util.List;
27
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;
46
47 /**
48  * The Class MediaDocumentModelHandler.
49  */
50 public class MediaDocumentModelHandler
51         extends DocHandlerBase<MediaCommon, AbstractCommonList> {
52         
53     public final String getNuxeoSchemaName(){
54         return "media";
55     }
56
57     public String getSummaryFields(AbstractCommonList commonList){
58         return "title|source|filename|identificationNumber|uri|csid";
59     }
60
61     public AbstractCommonList createAbstractCommonListImpl(){
62         return new MediaCommonList();
63     }
64
65     public List createItemsList(AbstractCommonList commonList){
66         List list = ((MediaCommonList)commonList).getMediaListItem();
67         return list;
68     }
69     
70         private MediaCommon getCommonPartProperties(DocumentModel docModel) throws Exception {
71                 String label = getServiceContext().getCommonPartLabel();
72                 MediaCommon result = new MediaCommon();
73                 
74                 result.setBlobCsid((String)     
75                                 docModel.getProperty(label, MediaJAXBSchema.blobCsid));
76                 
77                 return result;
78         }
79     
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);
87         item.setCsid(id);
88         return item;
89     }
90     
91         @Override
92         public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc)
93                         throws Exception {
94                 ServiceContext ctx = this.getServiceContext();
95                 
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);
102                 } else {
103                         super.extractAllParts(wrapDoc);
104                 }               
105         }
106     
107         @Override
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();
113                         //
114                         // If getBlobCsid has a value then we just received a multipart/form-data file post
115                         //
116                         DocumentModel documentModel = wrapDoc.getWrappedObject();
117                         documentModel.setProperty(ctx.getCommonPartLabel(), MediaJAXBSchema.blobCsid, blobCsid);
118                 } else {
119                         super.fillAllParts(wrapDoc, action);
120                 }
121         }    
122     
123 }
124