Reputation: 7117
I'm trying to assign task to candidate group in Activiti following the next scenario: User closes his own task and task have to move forward to candidate group.
In Activiti properties this task has no assignees/candidate groups. I'm adding candidate group to this task in java code:
public void assignTaskToCandidateGroup(Long entityId) {
ProcessInstance processInstance = super.findProcessInstance(entity);
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
if (task != null) {
taskService.complete(task.getId());
}
// Get next task after previos closed and add Candidate group
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
taskService.addCandidateGroup(task.getId(), "candidateGroup");
}
public List<Task> getTaskForCandidateGroup() {
return taskService.createTaskQuery().taskCandidateGroup("candidateGroup").list();
}
public void claimTaskCandidate(String taskId, User user) {
Task task = super.findTaskById(taskId);
List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("candidateGroup").list();
if (!tasks.contains(task))
throw new UnsupportedOperationException(String.format("Task with id [%s] is not intended for [%s]",
task.getId(), "candidateGroup"));
// ... check services and exception handing omitted
taskService.claim(task.getId(), user.getUsername());
}
I get the following Exception when calling getTaskForCandidateGroup():
"org.springframework.http.converter.HttpMessageNotWritableException",
"message": "Could not write content: lazy loading outside command context (through reference chain: java.util.ArrayList[0]->org.activiti.engine.impl.persistence.entity.TaskEntity[\"variableInstances\"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: lazy loading outside command context (through reference chain: java.util.ArrayList[0]->org.activiti.engine.impl.persistence.entity.TaskEntity[\"variableInstances\"])", "path": "/teuis-api/workflow-bps06/getTasksDirectorDeputyGroup"
Can someone suggest another solution to implement this task?
Upvotes: 0
Views: 1930
Reputation: 7117
The problem is solved.
I've tried to call the service and return List directly, but it was cause of the error.
@RequestMapping(value = "/getTaskForCandidateGroup")
public List<Task> getTaskForCandidateGroup() {
return getTaskForCandidateGroup();
}
New method:
@RequestMapping(value = "/getTaskForCandidateGroup")
public List<Map<String, Object>> getTaskForCandidateGroup() {
List<Tasks> taskList = getTaskForCandidateGroup();
List<Map<String, Object>> customTaskList = new ArrayList<>();
for (Task task : taskList) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("taskId", task.getId());
map.put("taskDefinitionKey", task.getTaskDefinitionKey());
map.put("taskName", task.getName());
customTaskList.add(map);
}
return customTaskList;
Upvotes: 2
Reputation: 3240
Use a listener associated with the assign event. Assign is executed before create specifically to handle this scenario.
Upvotes: 0