Search in sources :

Example 1 with WorkflowApproverEntity

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");
}
Also used : WorkflowApproverEntity(org.apache.inlong.manager.dao.entity.WorkflowApproverEntity)

Example 2 with WorkflowApproverEntity

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);
}
Also used : WorkflowApproverQuery(org.apache.inlong.manager.common.pojo.workflow.WorkflowApproverQuery) WorkflowApprover(org.apache.inlong.manager.common.pojo.workflow.WorkflowApprover) Arrays(java.util.Arrays) EntityStatus(org.apache.inlong.manager.common.enums.EntityStatus) WorkflowApproverEntity(org.apache.inlong.manager.dao.entity.WorkflowApproverEntity) Date(java.util.Date) WorkflowApproverService(org.apache.inlong.manager.service.core.WorkflowApproverService) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) WorkflowEngine(org.apache.inlong.manager.workflow.core.WorkflowEngine) WorkflowProcess(org.apache.inlong.manager.workflow.definition.WorkflowProcess) Objects(java.util.Objects) WorkflowApproverFilterContext(org.apache.inlong.manager.common.pojo.workflow.WorkflowApproverFilterContext) List(java.util.List) WorkflowTask(org.apache.inlong.manager.workflow.definition.WorkflowTask) Preconditions(org.apache.inlong.manager.common.util.Preconditions) UserTask(org.apache.inlong.manager.workflow.definition.UserTask) Service(org.springframework.stereotype.Service) Map(java.util.Map) WorkflowApproverQuery(org.apache.inlong.manager.common.pojo.workflow.WorkflowApproverQuery) Optional(java.util.Optional) FilterKey(org.apache.inlong.manager.common.pojo.workflow.FilterKey) CommonBeanUtils(org.apache.inlong.manager.common.util.CommonBeanUtils) WorkflowApproverEntityMapper(org.apache.inlong.manager.dao.mapper.WorkflowApproverEntityMapper) Objects(java.util.Objects) List(java.util.List) WorkflowApproverEntity(org.apache.inlong.manager.dao.entity.WorkflowApproverEntity) FilterKey(org.apache.inlong.manager.common.pojo.workflow.FilterKey)

Example 3 with WorkflowApproverEntity

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;
}
Also used : WorkflowApprover(org.apache.inlong.manager.common.pojo.workflow.WorkflowApprover) WorkflowTask(org.apache.inlong.manager.workflow.definition.WorkflowTask) WorkflowApproverEntity(org.apache.inlong.manager.dao.entity.WorkflowApproverEntity) WorkflowProcess(org.apache.inlong.manager.workflow.definition.WorkflowProcess)

Example 4 with WorkflowApproverEntity

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);
}
Also used : WorkflowException(org.apache.inlong.manager.common.exceptions.WorkflowException) WorkflowTask(org.apache.inlong.manager.workflow.definition.WorkflowTask) WorkflowTaskEntity(org.apache.inlong.manager.dao.entity.WorkflowTaskEntity) WorkflowApproverEntity(org.apache.inlong.manager.dao.entity.WorkflowApproverEntity) WorkflowApproverQuery(org.apache.inlong.manager.common.pojo.workflow.WorkflowApproverQuery) ProcessDetailResponse(org.apache.inlong.manager.common.pojo.workflow.ProcessDetailResponse) WorkflowProcessEntity(org.apache.inlong.manager.dao.entity.WorkflowProcessEntity) WorkflowProcess(org.apache.inlong.manager.workflow.definition.WorkflowProcess) TaskResponse(org.apache.inlong.manager.common.pojo.workflow.TaskResponse)

Example 5 with WorkflowApproverEntity

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");
}
Also used : UserTask(org.apache.inlong.manager.workflow.definition.UserTask) WorkflowTask(org.apache.inlong.manager.workflow.definition.WorkflowTask) WorkflowProcess(org.apache.inlong.manager.workflow.definition.WorkflowProcess) WorkflowApproverEntity(org.apache.inlong.manager.dao.entity.WorkflowApproverEntity) Date(java.util.Date)

Aggregations

WorkflowApproverEntity (org.apache.inlong.manager.dao.entity.WorkflowApproverEntity)6 WorkflowProcess (org.apache.inlong.manager.workflow.definition.WorkflowProcess)4 WorkflowTask (org.apache.inlong.manager.workflow.definition.WorkflowTask)4 Date (java.util.Date)3 WorkflowApprover (org.apache.inlong.manager.common.pojo.workflow.WorkflowApprover)2 WorkflowApproverQuery (org.apache.inlong.manager.common.pojo.workflow.WorkflowApproverQuery)2 UserTask (org.apache.inlong.manager.workflow.definition.UserTask)2 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 EntityStatus (org.apache.inlong.manager.common.enums.EntityStatus)1 WorkflowException (org.apache.inlong.manager.common.exceptions.WorkflowException)1 FilterKey (org.apache.inlong.manager.common.pojo.workflow.FilterKey)1 ProcessDetailResponse (org.apache.inlong.manager.common.pojo.workflow.ProcessDetailResponse)1 TaskResponse (org.apache.inlong.manager.common.pojo.workflow.TaskResponse)1 WorkflowApproverFilterContext (org.apache.inlong.manager.common.pojo.workflow.WorkflowApproverFilterContext)1