01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.bpmscript.jbi.tasklist;
18:
19: import java.util.List;
20:
21: import javax.jbi.messaging.DeliveryChannel;
22: import javax.jbi.messaging.InOut;
23: import javax.jbi.messaging.MessageExchange;
24: import javax.jbi.messaging.MessagingException;
25: import javax.jbi.messaging.NormalizedMessage;
26:
27: import org.apache.servicemix.jbi.messaging.DefaultMarshaler;
28: import org.apache.servicemix.jbi.messaging.PojoMarshaler;
29: import org.bpmscript.IPagedResult;
30: import org.bpmscript.IQuery;
31: import org.bpmscript.jbi.IDeliveryChannelAware;
32:
33: public class RemoteTaskListManager implements IRemoteTaskListManager,
34: IDeliveryChannelAware {
35:
36: private ITaskListStore taskListStore = null;
37: private DeliveryChannel deliveryChannel = null;
38: private PojoMarshaler marshaler = new DefaultMarshaler();
39:
40: public IPagedResult<ITask> getTasks(IQuery query)
41: throws TaskListException {
42: return taskListStore.getTasks(query);
43: }
44:
45: public ITask getTask(String taskId) throws TaskListException {
46: return taskListStore.getTask(taskId);
47: }
48:
49: public void respondToTask(String taskId, String path,
50: Object response, String user) throws TaskListException {
51: ITask task = taskListStore.getTask(taskId);
52: if (task.getState().equals(TaskState.CLOSED.name())) {
53: throw new TaskListException("Task is closed");
54: }
55: MessageExchange messageExchange = taskListStore
56: .getMessageExchange(taskId);
57: if (messageExchange instanceof InOut) {
58: InOut inOut = (InOut) messageExchange;
59: try {
60: NormalizedMessage message = inOut.createMessage();
61: marshaler.marshal(inOut, message, new TaskResponse(
62: path, response, user));
63: inOut.setOutMessage(message);
64: deliveryChannel.send(inOut);
65: taskListStore.closeTask(taskId);
66: } catch (MessagingException e) {
67: throw new TaskListException(e);
68: }
69: }
70: }
71:
72: public void setDeliveryChannel(DeliveryChannel deliveryChannel) {
73: this .deliveryChannel = deliveryChannel;
74: }
75:
76: public void setMarshaler(PojoMarshaler marshaler) {
77: this .marshaler = marshaler;
78: }
79:
80: public void setTaskListStore(ITaskListStore taskListStore) {
81: this .taskListStore = taskListStore;
82: }
83:
84: public List<ITask> getTasksForInstance(String processInstanceId)
85: throws TaskListException {
86: return taskListStore.getTasksForInstance(processInstanceId);
87: }
88: }
|