use of org.apache.inlong.manager.dao.entity.WorkflowApproverEntity in project incubator-inlong by apache.
the class WorkflowApproverServiceImpl method delete.
@Override
public void delete(Integer id, String operator) {
WorkflowApproverEntity entity = workflowApproverMapper.selectByPrimaryKey(id);
Preconditions.checkNotNull(entity, "not exist with id:" + id);
int success = this.workflowApproverMapper.deleteByPrimaryKey(id, operator);
Preconditions.checkTrue(success == 1, "delete failed");
}
use of org.apache.inlong.manager.dao.entity.WorkflowApproverEntity in project incubator-inlong by apache.
the class WorkflowApproverServiceImpl method getApprovers.
@Override
public List<String> getApprovers(String processName, String taskName, WorkflowApproverFilterContext context) {
WorkflowApproverQuery approverQuery = WorkflowApproverQuery.builder().processName(processName).taskName(taskName).build();
List<WorkflowApproverEntity> configs = workflowApproverMapper.selectByQuery(approverQuery);
Map<String, List<WorkflowApproverEntity>> groupByFilterKey = configs.stream().collect(Collectors.groupingBy(WorkflowApproverEntity::getFilterKey));
Map<FilterKey, String> filterKey2ValueMap = context.toFilterKeyMap();
return FilterKey.getFilterKeyByOrder().stream().map(FilterKey::name).map(groupByFilterKey::get).filter(Objects::nonNull).flatMap(List::stream).filter(config -> checkFilterCondition(filterKey2ValueMap, config)).findFirst().map(WorkflowApproverEntity::getApprovers).map(approvers -> Arrays.asList(approvers.split(","))).orElse(null);
}
use of org.apache.inlong.manager.dao.entity.WorkflowApproverEntity in project incubator-inlong by apache.
the class WorkflowApproverServiceImpl method list.
@Override
public List<WorkflowApprover> list(WorkflowApproverQuery query) {
List<WorkflowApproverEntity> entityList = workflowApproverMapper.selectByQuery(query);
List<WorkflowApprover> approverList = CommonBeanUtils.copyListProperties(entityList, WorkflowApprover::new);
approverList.forEach(config -> {
WorkflowProcess process = workflowEngine.processDefinitionService().getByName(config.getProcessName());
if (process != null) {
config.setProcessDisplayName(process.getDisplayName());
config.setTaskDisplayName(Optional.ofNullable(process.getTaskByName(config.getTaskName())).map(WorkflowTask::getDisplayName).orElse(null));
}
});
return approverList;
}
use of org.apache.inlong.manager.dao.entity.WorkflowApproverEntity in project incubator-inlong by apache.
the class WorkflowQueryServiceImpl method detail.
@Override
public ProcessDetailResponse detail(Integer processId, Integer taskId, String operator) {
WorkflowProcessEntity processEntity = this.getProcessEntity(processId);
if (processEntity == null) {
return null;
}
WorkflowTaskEntity taskEntity = null;
if (taskId == null) {
if (!operator.equals(processEntity.getApplicant())) {
throw new WorkflowException("current user is not the applicant of the process");
}
} else {
taskEntity = this.getTaskEntity(taskId);
List<String> taskApprovers = Arrays.asList(taskEntity.getApprovers().split(","));
if (!taskApprovers.contains(operator)) {
WorkflowApproverQuery query = new WorkflowApproverQuery();
query.setProcessName(processEntity.getName());
List<WorkflowApproverEntity> approverList = approverMapper.selectByQuery(query);
boolean match = approverList.stream().anyMatch(approverEntity -> {
String[] approverArr = approverEntity.getApprovers().split(",");
for (String approver : approverArr) {
if (Objects.equals(approver, operator)) {
return true;
}
}
return false;
});
if (!match) {
throw new WorkflowException("current user is not the approver of the process");
}
}
}
WorkflowProcess process = definitionRepository.get(processEntity.getName());
TaskResponse currentTask = null;
if (taskEntity != null) {
currentTask = WorkflowBeanUtils.fromTaskEntity(taskEntity);
if (process != null && TaskStatus.PENDING.equals(currentTask.getStatus())) {
WorkflowTask task = process.getTaskByName(currentTask.getName());
currentTask.setFormData(this.getEmptyTaskForm(task));
}
if (!processId.equals(currentTask.getProcessId())) {
throw new WorkflowException("task [" + taskId + "] not belongs to process [" + processId + "]");
}
}
ProcessDetailResponse detailResponse = this.getProcessDetail(processId, processEntity);
detailResponse.setCurrentTask(currentTask);
if (process == null || process.getProcessDetailHandler() == null) {
return detailResponse;
}
return process.getProcessDetailHandler().handle(detailResponse);
}
use of org.apache.inlong.manager.dao.entity.WorkflowApproverEntity in project incubator-inlong by apache.
the class WorkflowApproverServiceImpl method add.
@Override
public void add(WorkflowApprover approver, String operator) {
Date now = new Date();
approver.setCreateTime(now);
approver.setModifyTime(now);
approver.setModifier(operator);
approver.setCreator(operator);
WorkflowProcess process = workflowEngine.processDefinitionService().getByName(approver.getProcessName());
Preconditions.checkNotNull(process, "process not exit with name: " + approver.getProcessName());
WorkflowTask task = process.getTaskByName(approver.getTaskName());
Preconditions.checkNotNull(task, "task not exit with name: " + approver.getTaskName());
Preconditions.checkTrue(task instanceof UserTask, "task should be UserTask");
List<WorkflowApproverEntity> exist = this.workflowApproverMapper.selectByQuery(WorkflowApproverQuery.builder().processName(approver.getProcessName()).taskName(approver.getTaskName()).filterKey(approver.getFilterKey().name()).filterValue(approver.getFilterValue()).build());
Preconditions.checkEmpty(exist, "already exit the same config");
WorkflowApproverEntity entity = CommonBeanUtils.copyProperties(approver, WorkflowApproverEntity::new);
entity.setIsDeleted(EntityStatus.UN_DELETED.getCode());
int success = this.workflowApproverMapper.insert(entity);
Preconditions.checkTrue(success == 1, "add failed");
}
Aggregations