Activityのタスクのロールバック
4009 ワード
1,JumpTaskCmd.java
2,ロールバックの実装方法例
public class JumpTaskCmd implements Command<Comment>
{
protected List<String> executionIds;
protected String activityId;
public JumpTaskCmd(List<String> executionIds, String activityId)
{
this.executionIds = executionIds;
this.activityId = activityId;
}
public Comment execute(CommandContext commandContext)
{
for (String executionId : executionIds)
{
for (TaskEntity taskEntity : Context.getCommandContext().getTaskEntityManager()
.findTasksByExecutionId(executionId))
{
Context.getCommandContext().getTaskEntityManager().deleteTask(taskEntity, "jump", false);
}
}
ExecutionEntity executionEntity = Context.getCommandContext().getExecutionEntityManager()
.findExecutionById(executionIds.get(0));
ProcessDefinitionImpl processDefinition = executionEntity.getProcessDefinition();
ActivityImpl activity = processDefinition.findActivity(activityId);
executionEntity.executeActivity(activity);
return null;
}
}
2,ロールバックの実装方法例
@Override
public void updateTaskJumpByAssignee(String procInsId, String activityId, String userId)
{
List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(procInsId).list();
if (executions.size() > 0)
{
String executionId = executions.get(0).getId();
List<String> executionIds = new ArrayList<>();
for (Execution execution : executions)
{
executionIds.add(execution.getId());
}
TaskServiceImpl taskServiceImpl = (TaskServiceImpl) taskService;
taskServiceImpl.getCommandExecutor().execute(new JumpTaskCmd(executionIds, activityId));
for (Task task : taskService.createTaskQuery().executionId(executionId).list())
{
taskService.setAssignee(task.getId(), userId);
}
}
else
{
throw new OperationException(" id{" + procInsId + "} !");
}
}
@Override
public boolean updateTaskTurnBackByAssignee(String taskId, String procInstId, String approvers, String type,
String message)
{
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
if (null == task)
{
throw new RuntimeException(" ID:" + taskId + " !");
}
// , catagory IS_RETURN_BACK_TASK
List<HistoricTaskInstance> historicTaskInstances = historyService.createHistoricTaskInstanceQuery()
.processInstanceId(procInstId).orderByHistoricTaskInstanceEndTime().desc().list();
HistoricTaskInstance turnBackTask = null;
for (HistoricTaskInstance historicTaskInstance : historicTaskInstances)
{
String catagory = historicTaskInstance.getCategory();
if (IS_RETURN_BACK_TASK.equals(catagory) || historicTaskInstance.getId().equals(taskId)
|| historicTaskInstance.getTaskDefinitionKey().equals(task.getTaskDefinitionKey()))
{
continue;
}
else
{
turnBackTask = historicTaskInstance;
break;
}
}
if (null == turnBackTask)
{
throw new RuntimeException(" !");
}
else
{
task.setCategory(IS_RETURN_BACK_TASK);
taskService.saveTask(task);
//
if (StringUtil.isEmpty(approvers))
{
approvers = "";
List<HistoricIdentityLink> historicIdentityLinks = historyService
.getHistoricIdentityLinksForTask(turnBackTask.getId());
for (HistoricIdentityLink historicIdentityLink : historicIdentityLinks)
{
approvers += historicIdentityLink.getUserId() + ",";
}
if (approvers.length() > 0)
{
approvers = approvers.substring(0, approvers.length() - 1);
}
}
if (StringUtil.isEmpty(approvers))
{
throw new OperationException(" !");
}
try
{
this.updateTaskJumpByAssignee(procInstId, turnBackTask.getTaskDefinitionKey(), approvers);
}
catch (Exception e)
{
logger.error("WorkflowTaskService.updateTaskTurnBackByAssignee: " + e.getMessage(), e);
throw new OperationException(e.getMessage());
}
}
return true;
}