]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
dc622c4adf17626a61dfa2b85c25297055917aeb
[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.common.workflow.service.nuxeo;
25
26 import java.util.HashMap;
27 import java.util.Map;
28
29 import javax.ws.rs.core.MediaType;
30
31 import org.collectionspace.services.common.document.DocumentWrapper;
32 import org.collectionspace.services.common.service.ObjectPartType;
33 import org.collectionspace.services.common.workflow.client.WorkflowClient;
34 import org.collectionspace.services.common.workflow.jaxb.WorkflowJAXBSchema;
35 import org.collectionspace.services.nuxeo.client.java.DocHandlerBase;
36 import org.collectionspace.services.workflow.WorkflowsCommon;
37 import org.nuxeo.ecm.core.api.DocumentModel;
38
39 public class WorkflowDocumentModelHandler 
40         extends DocHandlerBase<WorkflowsCommon> {
41         
42         @Override
43     protected Map<String, Object> extractPart(DocumentModel docModel, 
44             String schema,
45             ObjectPartType partMeta,
46             Map<String, Object> addToMap)
47                 throws Exception {
48         Map<String, Object> result = null;
49
50         MediaType mt = MediaType.valueOf(partMeta.getContent().getContentType()); //FIXME: REM - This is no longer needed.  Everything is POX
51         if (mt.equals(MediaType.APPLICATION_XML_TYPE)) {
52             Map<String, Object> unQObjectProperties =
53                     (addToMap != null) ? addToMap : (new HashMap<String, Object>());
54             unQObjectProperties.put(WorkflowJAXBSchema.WORKFLOW_LIFECYCLEPOLICY, docModel.getLifeCyclePolicy());
55             unQObjectProperties.put(WorkflowJAXBSchema.WORKFLOW_CURRENTLIFECYCLESTATE, docModel.getCurrentLifeCycleState());
56             result = unQObjectProperties;
57         } //TODO: handle other media types
58
59         return result;
60     }
61         
62     @Override
63     public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc)
64             throws Exception {
65
66         DocumentModel docModel = wrapDoc.getWrappedObject();
67         String[] schemas = {WorkflowClient.SERVICE_COMMONPART_NAME};
68         Map<String, ObjectPartType> partsMetaMap = getServiceContext().getPartsMetadata();
69         for (String schema : schemas) {
70             ObjectPartType partMeta = partsMetaMap.get(schema);
71             if (partMeta == null) {
72                 continue; // unknown part, ignore
73             }
74             Map<String, Object> unQObjectProperties = extractPart(docModel, schema, partMeta);
75             addOutputPart(unQObjectProperties, schema, partMeta);
76         }
77     }
78         
79 }
80