02-07-2017 09:48 PM
I'm trying to modify Activiti 5.22 source code in order to link a task, created with the method newTask from the class TaskService, to a process instance, so that when I'm calling historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).finished().orderByHistoricActivityInstanceEndTime().asc().list() the list contains also the task that I added during execution.
In some way I managed to do that modifying the class NewTaskCmd in this way:
public class NewTaskCmd implements Command<Task>, Serializable {
private static final long serialVersionUID = 1L;
protected String taskId;
protected String processInstanceId;
protected String processDefinitionId;
protected String executionId;
public NewTaskCmd(String taskId, String processInstanceId, String processDefinitionId) {
this.taskId = taskId;
this.processInstanceId = processInstanceId;
this.processDefinitionId = processDefinitionId;
this.executionId = processInstanceId;
}
public Task execute(CommandContext commandContext) {
Date currentTime = commandContext.getProcessEngineConfiguration().getClock().getCurrentTime();
TaskEntity task = TaskEntity.create(currentTime);
task.setId(taskId);
task.setProcessInstanceId(processInstanceId);
task.setProcessDefinitionId(processDefinitionId);
task.setExecutionId(processInstanceId);
return task;
}
}
If I set the executionId in that way the following exception is throwed calling the complete method on any of the task of the process, even the ones included in the process definition:
ERROR org.activiti.engine.impl.interceptor.CommandContext - Error while closing command context org.activiti.engine.ActivitiException: UserTask should not be signalled before complete
Although, if I do not set the executionId the history service query will not contain the new task that I created.
What am I doing wrong? How can I avoid the signal error?
Thanks in advance to everyone that will answer.
02-09-2017 04:34 AM
I haven't tried to create a new execution for now. So i cannot answer your question.
Yeah there is an option to change the process definition dynamically. The two following links can help for this approach.
But i have another question. Would it be enough to create subtasks? These can be queried in the history.
02-21-2017 05:29 AM
Design by doing it's the correct solution.
I'm sorry if I didn't let you know if it worked, but I never had the chance to try it until now.
Explore our Alfresco products with the links below. Use labels to filter content by product module.