Search in sources :

Example 1 with GroupExecutionRequest

use of com.webank.wedatasphere.qualitis.request.GroupExecutionRequest in project Qualitis by WeBankFinTech.

the class OuterExecutionServiceImpl method generalExecution.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> generalExecution(GeneralExecutionRequest request) throws UnExpectedRequestException, PermissionDeniedRequestException {
    // Generator application information
    GeneralExecutionRequest.checkRequest(request);
    if (request.getDyNamicPartitionPrefix() == null) {
        request.setDyNamicPartitionPrefix("");
    }
    if (request.getProjectId() != null) {
        ProjectExecutionRequest projectExecutionRequest = new ProjectExecutionRequest();
        BeanUtils.copyProperties(request, projectExecutionRequest);
        return projectExecution(projectExecutionRequest, InvokeTypeEnum.BDP_CLIENT_API_INVOKE.getCode());
    } else if (CollectionUtils.isNotEmpty(request.getRuleList())) {
        RuleListExecutionRequest ruleListExecutionRequest = new RuleListExecutionRequest();
        BeanUtils.copyProperties(request, ruleListExecutionRequest);
        return ruleListExecution(ruleListExecutionRequest, InvokeTypeEnum.BDP_CLIENT_API_INVOKE.getCode());
    } else if (request.getGroupId() != null) {
        GroupExecutionRequest groupExecutionRequest = new GroupExecutionRequest();
        BeanUtils.copyProperties(request, groupExecutionRequest);
        return groupExecution(groupExecutionRequest, InvokeTypeEnum.FLOW_API_INVOKE.getCode());
    } else if (StringUtils.isNotBlank(request.getProjectName())) {
        Project projectInDb = projectDao.findByNameAndCreateUser(request.getProjectName(), request.getCreateUser());
        if (projectInDb == null) {
            List<Integer> permissions = new ArrayList<>();
            permissions.add(ProjectUserPermissionEnum.CREATOR.getCode());
            permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
            List<Project> projects = projectUserDao.findByUsernameAndPermission(request.getExecutionUser(), permissions);
            if (CollectionUtils.isEmpty(projects)) {
                throw new UnExpectedRequestException("Pick project has no permissions.");
            }
            List<Project> execProject = projects.stream().filter(project -> project.getName().equals(request.getProjectName())).collect(Collectors.toList());
            if (CollectionUtils.isEmpty(execProject)) {
                throw new UnExpectedRequestException("Pick project has no permissions.");
            } else if (execProject.size() > 1) {
                throw new UnExpectedRequestException("Pick project has dubplicate names.");
            }
            projectInDb = execProject.iterator().next();
        }
        if (CollectionUtils.isNotEmpty(request.getRuleNameList())) {
            List<Long> ruleIds = new ArrayList<>(request.getRuleNameList().size());
            for (String ruleName : request.getRuleNameList()) {
                Rule rule = ruleDao.findByProjectAndRuleName(projectInDb, ruleName);
                ruleIds.add(rule.getId());
            }
            request.setRuleList(ruleIds);
            RuleListExecutionRequest ruleListExecutionRequest = new RuleListExecutionRequest();
            BeanUtils.copyProperties(request, ruleListExecutionRequest);
            return ruleListExecution(ruleListExecutionRequest, InvokeTypeEnum.BDP_CLIENT_API_INVOKE.getCode());
        } else {
            request.setProjectId(projectInDb.getId());
            ProjectExecutionRequest projectExecutionRequest = new ProjectExecutionRequest();
            BeanUtils.copyProperties(request, projectExecutionRequest);
            return projectExecution(projectExecutionRequest, InvokeTypeEnum.BDP_CLIENT_API_INVOKE.getCode());
        }
    } else if (StringUtils.isNotBlank(request.getCluster())) {
        DataSourceExecutionRequest dataSourceExecutionRequest = new DataSourceExecutionRequest();
        BeanUtils.copyProperties(request, dataSourceExecutionRequest);
        return dataSourceExecution(dataSourceExecutionRequest);
    } else {
        LOGGER.error("Can not resolve the request: " + request);
        throw new UnExpectedRequestException("{&CAN_NOT_RESOLVE_THE_REQUEST}");
    }
}
Also used : Project(com.webank.wedatasphere.qualitis.project.entity.Project) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) RuleListExecutionRequest(com.webank.wedatasphere.qualitis.request.RuleListExecutionRequest) ProjectExecutionRequest(com.webank.wedatasphere.qualitis.request.ProjectExecutionRequest) ArrayList(java.util.ArrayList) List(java.util.List) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) DataSourceExecutionRequest(com.webank.wedatasphere.qualitis.request.DataSourceExecutionRequest) GroupExecutionRequest(com.webank.wedatasphere.qualitis.request.GroupExecutionRequest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)1 Project (com.webank.wedatasphere.qualitis.project.entity.Project)1 DataSourceExecutionRequest (com.webank.wedatasphere.qualitis.request.DataSourceExecutionRequest)1 GroupExecutionRequest (com.webank.wedatasphere.qualitis.request.GroupExecutionRequest)1 ProjectExecutionRequest (com.webank.wedatasphere.qualitis.request.ProjectExecutionRequest)1 RuleListExecutionRequest (com.webank.wedatasphere.qualitis.request.RuleListExecutionRequest)1 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Transactional (org.springframework.transaction.annotation.Transactional)1