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.common.workflow.service.nuxeo;
26 import java.util.HashMap;
27 import java.util.List;
30 import javax.ws.rs.core.MediaType;
32 import org.collectionspace.services.client.PayloadInputPart;
33 import org.collectionspace.services.client.PoxPayloadIn;
34 import org.collectionspace.services.client.PoxPayloadOut;
35 import org.collectionspace.services.client.workflow.WorkflowClient;
36 import org.collectionspace.services.common.context.MultipartServiceContext;
37 import org.collectionspace.services.common.context.ServiceContext;
38 import org.collectionspace.services.common.document.BadRequestException;
39 import org.collectionspace.services.common.document.DocumentUtils;
40 import org.collectionspace.services.common.document.DocumentWrapper;
41 import org.collectionspace.services.common.document.DocumentHandler.Action;
42 import org.collectionspace.services.common.service.ObjectPartType;
43 import org.collectionspace.services.common.workflow.jaxb.WorkflowJAXBSchema;
44 import org.collectionspace.services.nuxeo.client.java.DocHandlerBase;
45 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
46 import org.collectionspace.services.workflow.WorkflowsCommon;
47 import org.dom4j.Element;
48 import org.nuxeo.ecm.core.api.DocumentModel;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
52 public class WorkflowDocumentModelHandler
53 extends DocHandlerBase<WorkflowsCommon> {
56 private final Logger logger = LoggerFactory.getLogger(WorkflowDocumentModelHandler.class);
59 * Workflow transitions
61 private static final String TRANSITION_DELETE = "delete";
62 private static final String TRANSITION_APPROVE = "approve";
63 private static final String TRANSITION_UNKNOWN = "unknown";
70 protected Map<String, Object> extractPart(DocumentModel docModel,
72 ObjectPartType partMeta,
73 Map<String, Object> addToMap)
75 Map<String, Object> result = null;
77 MediaType mt = MediaType.valueOf(partMeta.getContent().getContentType()); //FIXME: REM - This is no longer needed. Everything is POX
78 if (mt.equals(MediaType.APPLICATION_XML_TYPE)) {
79 Map<String, Object> unQObjectProperties =
80 (addToMap != null) ? addToMap : (new HashMap<String, Object>());
81 unQObjectProperties.put(WorkflowJAXBSchema.WORKFLOW_LIFECYCLEPOLICY, docModel.getLifeCyclePolicy());
82 unQObjectProperties.put(WorkflowJAXBSchema.WORKFLOW_CURRENTLIFECYCLESTATE, docModel.getCurrentLifeCycleState());
83 result = unQObjectProperties;
84 } //TODO: handle other media types
90 public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc)
92 DocumentModel docModel = wrapDoc.getWrappedObject();
93 String[] schemas = {WorkflowClient.SERVICE_COMMONPART_NAME};
94 Map<String, ObjectPartType> partsMetaMap = getServiceContext().getPartsMetadata();
95 for (String schema : schemas) {
96 ObjectPartType partMeta = partsMetaMap.get(schema);
97 if (partMeta == null) {
98 continue; // unknown part, ignore
100 Map<String, Object> unQObjectProperties = extractPart(docModel, schema, partMeta);
101 addOutputPart(unQObjectProperties, schema, partMeta);
105 private String getTransitionFromState(String state) {
106 String result = TRANSITION_UNKNOWN;
107 if (state.equalsIgnoreCase(WorkflowClient.WORKFLOWSTATE_DELETED)) {
108 result = TRANSITION_DELETE;
109 } else if (state.equalsIgnoreCase(WorkflowClient.WORKFLOWSTATE_APPROVED)) {
110 result = TRANSITION_APPROVE;
115 * Handle Update (PUT)
119 protected void fillPart(PayloadInputPart part, DocumentModel docModel,
120 ObjectPartType partMeta, Action action,
121 ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx)
123 WorkflowsCommon workflowsCommon = (WorkflowsCommon)part.getBody();
124 docModel.followTransition(getTransitionFromState(workflowsCommon.getCurrentLifeCycleState()));