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