Search in sources :

Example 1 with WorkflowApproverQuery

use of org.apache.inlong.manager.common.pojo.workflow.WorkflowApproverQuery 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 2 with WorkflowApproverQuery

use of org.apache.inlong.manager.common.pojo.workflow.WorkflowApproverQuery 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)

Aggregations

WorkflowApproverQuery (org.apache.inlong.manager.common.pojo.workflow.WorkflowApproverQuery)2 WorkflowApproverEntity (org.apache.inlong.manager.dao.entity.WorkflowApproverEntity)2 WorkflowProcess (org.apache.inlong.manager.workflow.definition.WorkflowProcess)2 WorkflowTask (org.apache.inlong.manager.workflow.definition.WorkflowTask)2 Arrays (java.util.Arrays)1 Date (java.util.Date)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 WorkflowApprover (org.apache.inlong.manager.common.pojo.workflow.WorkflowApprover)1 WorkflowApproverFilterContext (org.apache.inlong.manager.common.pojo.workflow.WorkflowApproverFilterContext)1 CommonBeanUtils (org.apache.inlong.manager.common.util.CommonBeanUtils)1