0

Or more precisely - is there a way to remove a participant from subsequent iterations if it was "deleted" at the first iteration?

What I mean...

For example, there is a some parallel workflow. I choose 10 participants and initiated this business process. Thus, 10 tasks were created, one for each participant. But then I decided to delete a few participants.

As far as I know, I can't remove the task. But I can to complete these tasks by using WebScript. For example, as follows. I know the workflowId and taskId:

...
Map<String, String> templateArgs = req.getServiceMatch().getTemplateVars();

// String workflowId = templateArgs.get("workflowId");
String taskId = templateArgs.get("taskId");

Map<QName, Serializable> updatedProperties = new HashMap<>();
updatedProperties.put(TaskRemoverModel.REVIEW_OUTCOME_PROPERTY, "Approve"); 
updatedProperties.put(TaskRemoverModel.COMMENT_PROPERTY, 
    "The user was excluded from the list of participants.");

workflowService.updateTask(taskId, updatedProperties, null, null);
workflowService.endTask(taskId, null);
...

But the problem is that at the stage of revise, the initiator can send for approval again. Then tasks for excluded participants will be created again.

Is there a way to "mark" these participants, so that no tasks were created for them in the future?

I would be very grateful for the information. Thanks to all.

4

2 回答 2

0

您可以从受让人列表中删除人员。当您完成任务时,如果您使用 bpm:assignees 进行关联,请使用以下代码使用 javascript从列表中删除人员。

bpm_assignees.remove(人); // 其中 person 是当前登录的人。

您可以使用 nodeService 在 java 中删除关联。

于 2017-12-11T05:51:23.300 回答
0

解决方案可以表示如下。

在 WebScript 中,需要更新任务属性并完成该任务。在任务属性中添加引用排除参与者(所有者)的新属性:

...
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);
...

complete任务的事件添加监听器。此侦听器将在 WebScript 中的此调用之后工作:

...
workflowService.endTask(taskId, null);
...

在侦听器中,找到这个新属性,其中引用了被排除的参与者。然后从该列表中获取bpm_assignees并删除该参与者的引用并bpm_assignees再次设置变量:

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);
            }            
        }
    }
}

之后,可以在运行时删除参与者的任务,并且在重新提交这些参与者之后不会生成任务。

于 2017-12-11T19:28:28.653 回答