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.ArrayList;
20: import java.util.List;
21: import java.util.Map;
22: import java.util.UUID;
23: import java.util.concurrent.ConcurrentHashMap;
24:
25: import javax.jbi.messaging.MessageExchange;
26:
27: import org.bpmscript.IPagedResult;
28: import org.bpmscript.IQuery;
29: import org.bpmscript.PagedResult;
30:
31: public class TaskListStore implements ITaskListStore {
32:
33: private Map<String, Task> tasks = new ConcurrentHashMap<String, Task>();
34: private Map<String, List<ITask>> tasksForInstance = new ConcurrentHashMap<String, List<ITask>>();
35: private Map<String, MessageExchange> messageExchanges = new ConcurrentHashMap<String, MessageExchange>();
36:
37: public ITask getTask(String taskId) {
38: return tasks.get(taskId);
39: }
40:
41: public String createTask(MessageExchange exchange,
42: ITaskRequest request) {
43: Task task = new Task();
44: String id = UUID.randomUUID().toString();
45: task.setId(id);
46: task.setTaskState(TaskState.OPEN);
47: task.setTaskRequest(request);
48: String processInstanceId = request.getProcessInstanceId();
49: if (processInstanceId != null) {
50: List<ITask> tasks = tasksForInstance.get(processInstanceId);
51: if (tasks == null) {
52: tasks = new ArrayList<ITask>();
53: tasksForInstance.put(processInstanceId, tasks);
54: }
55: tasks.add(task);
56: }
57: messageExchanges.put(task.getId(), exchange);
58: tasks.put(task.getId(), task);
59: return id;
60: }
61:
62: public IPagedResult<ITask> getTasks(IQuery query) {
63: // TODO: execute the query
64: List<ITask> result = new ArrayList<ITask>(tasks.values());
65: return new PagedResult<ITask>(result, false, 0);
66: }
67:
68: public MessageExchange getMessageExchange(String taskId) {
69: return messageExchanges.get(taskId);
70: }
71:
72: public void closeTask(String taskId) {
73: Task task = tasks.get(taskId);
74: task.setTaskState(TaskState.CLOSED);
75: }
76:
77: public List<ITask> getTasksForInstance(String processInstanceId)
78: throws TaskListException {
79: return tasksForInstance.get(processInstanceId);
80: }
81:
82: }
|