01: /*
02: * Copyright 2007 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.outerj.daisy.workflow.serverimpl.httpconnector.handlers;
17:
18: import org.outerj.daisy.httpconnector.spi.HttpUtil;
19: import org.outerj.daisy.httpconnector.spi.RequestHandlerSupport;
20: import org.outerj.daisy.repository.Repository;
21: import org.outerj.daisy.workflow.WorkflowManager;
22: import org.outerj.daisy.workflow.WfExecutionPath;
23: import org.outerj.daisy.workflow.WfProcessInstance;
24: import org.outerj.daisy.util.HttpConstants;
25:
26: import javax.servlet.http.HttpServletRequest;
27: import javax.servlet.http.HttpServletResponse;
28: import java.util.Map;
29: import java.util.Locale;
30:
31: public class ProcessInstanceHandler extends
32: AbstractWorkflowRequestHandler {
33: public void handleRequest(Map matchMap, HttpServletRequest request,
34: HttpServletResponse response, Repository repository,
35: RequestHandlerSupport support) throws Exception {
36: String id = (String) matchMap.get("1");
37: WorkflowManager workflowManager = (WorkflowManager) repository
38: .getExtension("WorkflowManager");
39: Locale locale = WfHttpUtil.getLocale(request);
40:
41: if (request.getMethod().equals(HttpConstants.GET)) {
42: workflowManager.getProcess(id, locale).getXml().save(
43: response.getOutputStream());
44: } else if (request.getMethod().equals(HttpConstants.POST)) {
45: String action = HttpUtil.getStringParam(request, "action");
46: if (action.equals("signal")) {
47: String executionPathName = HttpUtil.getStringParam(
48: request, "executionPath");
49: String transitionName = request
50: .getParameter("transitionName"); // not required
51: WfExecutionPath executionPath = workflowManager.signal(
52: id, executionPathName, transitionName, locale);
53: executionPath.getXml().save(response.getOutputStream());
54: } else if (action.equals("suspend")) {
55: WfProcessInstance processInstance = workflowManager
56: .suspendProcess(id, locale);
57: processInstance.getXml().save(
58: response.getOutputStream());
59: } else if (action.equals("resume")) {
60: WfProcessInstance processInstance = workflowManager
61: .resumeProcess(id, locale);
62: processInstance.getXml().save(
63: response.getOutputStream());
64: } else {
65: HttpUtil
66: .sendCustomError(
67: "Invalid value for action parameter: "
68: + action,
69: HttpConstants._400_Bad_Request,
70: response);
71: }
72: } else if (request.getMethod().equals(HttpConstants.DELETE)) {
73: workflowManager.deleteProcess(id);
74: } else {
75: response.sendError(HttpConstants._405_Method_Not_Allowed);
76: }
77: }
78:
79: public String getPathPattern() {
80: return "/process/*";
81: }
82: }
|