The solution can be represented as follows.
In the WebScript it's needed to update the task properties and complete that task. To the task properties add the new property with the reference to the excluded participant (who was the owner):
...
Map<String, String> templateArgs = req.getServiceMatch().getTemplateVars();
String taskId = templateArgs.get("taskId");
Map<QName, Serializable> updatedProperties = new HashMap<>();
updatedProperties.put(TaskRemoverModel.WORKFLOW_CONFIRM_MODEL_CONFIRMOUTCOME_PROPERTY,
"Approve");
updatedProperties.put(TaskRemoverModel.WORKFLOW_MODEL_LASTCOMMENT_PROPERTY,
I18NUtil.getMessage("task.comment.excluded"));
WorkflowTask workflowTask = workflowService.getTaskById(taskId);
Iterator taskProperties = workflowTask.getProperties().entrySet().iterator();
while(taskProperties.hasNext()) {
Map.Entry taskProperty = (Map.Entry)taskProperties.next();
if(TaskRemoverModel.CONTENT_MODEL_OWNER_PROPERTY.toString().equals(
taskProperty.getKey().toString())) {
updatedProperties.put(TaskRemoverModel.TASK_WAS_EXCLUDED_SIGN,
personService.getPerson(taskProperty.getValue().toString()));
}
}
workflowService.updateTask(taskId, updatedProperties, null, null);
workflowService.endTask(taskId, null);
...
For the complete
event of the task add the listener. This listener will work after this call in the WebScript:
...
workflowService.endTask(taskId, null);
...
In the listener, find this new property, in which the reference to the excluded participant. Then get the list of bpm_assignees
and delete the reference for this participant from that list and set variable bpm_assignees
again:
public class TaskCompleteListener implements TaskListener {
private Map<Object, Object> registeredBeans =
Context.getProcessEngineConfiguration().getBeans();
private ServiceRegistry registry =
(ServiceRegistry) registeredBeans.get(
ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
private WorkflowService workflowService = registry.getWorkflowService();
@Override
public void notify(DelegateTask delegateTask) {
WorkflowTask workflowTask =
workflowService.getTaskById("activiti$" + delegateTask.getId());
Map<QName, Serializable> taskProperties = workflowTask.getProperties();
Iterator iterator = taskProperties.entrySet().iterator();
while(iterator.hasNext()) {
Map.Entry taskProperty = (Map.Entry)iterator.next();
if(taskProperty.getKey().toString().equals(
ContractsApprovalModel.TASK_WAS_EXCLUDED_SIGN)) {
ActivitiScriptNodeList assignees =
(ActivitiScriptNodeList) delegateTask.getVariable("bpm_assignees");
for(ActivitiScriptNode personNode : assignees) {
if(personNode.getNodeRef().toString().equals(
taskProperty.getValue().toString())) {
assignees.remove(personNode);
}
}
delegateTask.setVariable("bpm_assignees", assignees);
}
}
}
}
After that it becomes possible to delete the tasks of the participants in runtime and after the resubmit for these participants tasks are not generated.