Search in sources :

Example 1 with AddRuleRequest

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

the class RuleBatchServiceImpl method addTemplateRule.

private void addTemplateRule(Map<String, List<ExcelTemplateRuleByProject>> rulePartitionedByRuleName, Project project, String userName, boolean aomp) throws UnExpectedRequestException, TaskNotExistException, ClusterInfoNotConfigException, PermissionDeniedRequestException {
    Map<String, List<ExcelTemplateRuleByProject>> modifyRulePartitionedByRuleName = new HashMap<>(1);
    Map<String, List<ExcelTemplateRuleByProject>> addRulePartitionedByRuleName = new HashMap<>(1);
    String localeStr = httpServletRequest.getHeader("Content-Language");
    for (Iterator<String> iterator = rulePartitionedByRuleName.keySet().iterator(); iterator.hasNext(); ) {
        String currentRuleName = iterator.next();
        Rule currentRule = ruleDao.findByProjectAndRuleName(project, currentRuleName);
        if (currentRule != null) {
            modifyRulePartitionedByRuleName.put(currentRuleName, rulePartitionedByRuleName.get(currentRuleName));
            List<AddRuleRequest> addRuleRequestList = constructAddRuleRequest(modifyRulePartitionedByRuleName, project, localeStr);
            ModifyRuleRequest modifyRuleRequest = new ModifyRuleRequest();
            modifyRuleRequest.setRuleId(currentRule.getId());
            AddRuleRequest addRuleRequest = addRuleRequestList.iterator().next();
            BeanUtils.copyProperties(addRuleRequest, modifyRuleRequest);
            LOGGER.info("Start to modify template rule. request: {}", modifyRuleRequest);
            if (aomp) {
                ruleService.modifyRuleDetailForOuter(modifyRuleRequest, userName);
            } else {
                ruleService.modifyRuleDetail(modifyRuleRequest);
            }
            LOGGER.info("Succeed to modify template rule.");
            modifyRulePartitionedByRuleName.clear();
        } else {
            addRulePartitionedByRuleName.put(currentRuleName, rulePartitionedByRuleName.get(currentRuleName));
            List<AddRuleRequest> addRuleRequestList = constructAddRuleRequest(addRulePartitionedByRuleName, project, localeStr);
            AddRuleRequest currentAddRuleRequest = addRuleRequestList.iterator().next();
            LOGGER.info("Start to add template rule. request: {}", currentAddRuleRequest);
            if (aomp) {
                ruleService.addRuleForOuter(currentAddRuleRequest, userName);
            } else {
                ruleService.addRuleForUpload(currentAddRuleRequest);
            }
            LOGGER.info("Succeed to add template rule.");
            addRulePartitionedByRuleName.clear();
        }
    }
}
Also used : AddRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddRuleRequest) HashMap(java.util.HashMap) ModifyRuleRequest(com.webank.wedatasphere.qualitis.rule.request.ModifyRuleRequest) ArrayList(java.util.ArrayList) List(java.util.List) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule)

Example 2 with AddRuleRequest

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

the class RuleNodeServiceImpl method copyRuleByRuleGroupId.

@Override
public GeneralResponse<RuleResponse> copyRuleByRuleGroupId(CopyRuleRequest request) throws UnExpectedRequestException, PermissionDeniedRequestException {
    CopyRuleRequest.checkRequest(request);
    Long ruleGroupId = request.getSourceRuleGroupId();
    RuleGroup ruleGroupInDb = ruleGroupDao.findById(request.getSourceRuleGroupId());
    int totalFinish = 0;
    RuleGroup targetRuleGroup;
    if (request.getTargetRuleGroupId() != null) {
        RuleGroup targetRuleGroupInDb = ruleGroupDao.findById(request.getTargetRuleGroupId());
        if (targetRuleGroupInDb != null) {
            targetRuleGroup = targetRuleGroupInDb;
        } else {
            throw new UnExpectedRequestException("Rule group id is illegal.");
        }
    } else {
        RuleGroup currentRuleGroup = new RuleGroup("Group_" + UUID.randomUUID().toString().replace("-", ""), request.getTargetProjectId() != null ? request.getTargetProjectId() : ruleGroupInDb.getProjectId());
        currentRuleGroup.setVersion(request.getVersion());
        targetRuleGroup = ruleGroupDao.saveRuleGroup(currentRuleGroup);
    }
    if (ruleGroupId != null) {
        LOGGER.info("Start to copy rules of rule group[ID=" + ruleGroupId + "].");
        if (ruleGroupInDb == null) {
            throw new UnExpectedRequestException("Rule group {&DOES_NOT_EXIST}");
        }
        List<Rule> rules = ruleDao.findByRuleGroup(ruleGroupInDb);
        for (Rule rule : rules) {
            switch(rule.getRuleType().intValue()) {
                case 1:
                    AddRuleRequest addRuleRequest = constructSingleRequest(rule, targetRuleGroup);
                    ruleService.addRuleForOuter(addRuleRequest, request.getCreateUser());
                    totalFinish++;
                    break;
                case 2:
                    AddCustomRuleRequest addCustomRuleRequest = constructCustomRequest(rule, targetRuleGroup);
                    customRuleService.addRuleForOuter(addCustomRuleRequest, request.getCreateUser());
                    totalFinish++;
                    break;
                case 3:
                    AddMultiSourceRuleRequest addMultiSourceRuleRequest = constructMultiRequest(rule, targetRuleGroup);
                    addMultiSourceRuleRequest.setLoginUser(request.getCreateUser());
                    multiSourceRuleService.addRuleForOuter(addMultiSourceRuleRequest, false);
                    totalFinish++;
                    break;
                case 4:
                    AddFileRuleRequest addFileRuleRequest = constructFileRequest(rule, targetRuleGroup);
                    fileRuleService.addRuleForOuter(addFileRuleRequest, request.getCreateUser());
                    totalFinish++;
                    break;
                default:
            }
        }
        if (totalFinish != rules.size()) {
            return new GeneralResponse<>("200", "{&COPY_RULE_FAILED}", new RuleResponse(targetRuleGroup.getId()));
        }
    } else if (CollectionUtils.isNotEmpty(request.getSourceRuleIdList())) {
    }
    return new GeneralResponse<>("200", "{&COPY_RULE_SUCCESSFULLY}", new RuleResponse(targetRuleGroup.getId()));
}
Also used : AddRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddRuleRequest) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) AddCustomRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddCustomRuleRequest) AddFileRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddFileRuleRequest) RuleResponse(com.webank.wedatasphere.qualitis.rule.response.RuleResponse) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup) AddMultiSourceRuleRequest(com.webank.wedatasphere.qualitis.rule.request.multi.AddMultiSourceRuleRequest)

Example 3 with AddRuleRequest

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

the class RuleNodeServiceImpl method constructSingleRequest.

private AddRuleRequest constructSingleRequest(Rule rule, RuleGroup ruleGroup) {
    AddRuleRequest addRuleRequest = new AddRuleRequest();
    String newVersion = ruleGroup.getVersion();
    if (StringUtils.isEmpty(newVersion)) {
        String newRuleName = rule.getName() + "_copy_" + ruleGroup.getId();
        LOGGER.info("Single rule start to be copied. Copied rule name: " + newRuleName);
        addRuleRequest.setRuleName(newRuleName);
        if (StringUtils.isNotBlank(rule.getCnName())) {
            addRuleRequest.setRuleCnName(rule.getCnName() + "_副本");
        }
    } else {
        String oldVersion = rule.getRuleGroup().getVersion();
        LOGGER.info("Single rule start to be copied. Copied rule name: " + rule.getName() + "_" + ruleGroup.getVersion());
        if (StringUtils.isNotBlank(oldVersion) && rule.getName().endsWith(oldVersion)) {
            addRuleRequest.setRuleName(rule.getName().replace(oldVersion, newVersion));
            if (StringUtils.isNotBlank(rule.getCnName())) {
                addRuleRequest.setRuleCnName(rule.getCnName().replace(oldVersion, newVersion));
            }
        } else {
            addRuleRequest.setRuleName(rule.getName() + "_" + newVersion);
            if (StringUtils.isNotBlank(rule.getCnName())) {
                addRuleRequest.setRuleCnName(rule.getCnName() + "_" + newVersion);
            }
        }
    }
    addRuleRequest.setRuleDetail(rule.getDetail());
    addRuleRequest.setRuleTemplateId(rule.getTemplate().getId());
    addRuleRequest.setAlarm(true);
    addRuleRequest.setAlarmVariable(constructAlarmConfigRequest(rule.getAlarmConfigs()));
    addRuleRequest.setTemplateArgumentRequests(constructTemplateArgumentRequest(rule));
    addRuleRequest.setDatasource(constructDataSourceRequest(rule.getRuleDataSources()));
    addRuleRequest.setProjectId(ruleGroup.getProjectId());
    addRuleRequest.setRuleGroupId(ruleGroup.getId());
    addRuleRequest.setCsId(rule.getCsId());
    addRuleRequest.setAbortOnFailure(rule.getAbortOnFailure());
    addRuleRequest.setDeleteFailCheckResult(rule.getDeleteFailCheckResult());
    addRuleRequest.setSpecifyStaticStartupParam(rule.getSpecifyStaticStartupParam());
    addRuleRequest.setStaticStartupParam(rule.getStaticStartupParam());
    return addRuleRequest;
}
Also used : AddRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddRuleRequest)

Example 4 with AddRuleRequest

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

the class RuleBatchServiceImpl method constructAddRuleRequest.

private List<AddRuleRequest> constructAddRuleRequest(Map<String, List<ExcelTemplateRuleByProject>> partitionedByRuleName, Project project, String localeStr) throws UnExpectedRequestException {
    List<AddRuleRequest> addRuleRequests = new ArrayList<>();
    for (String ruleName : partitionedByRuleName.keySet()) {
        List<ExcelTemplateRuleByProject> ruleInfos = partitionedByRuleName.get(ruleName);
        ExcelTemplateRuleByProject firstCommonInfo = ruleInfos.get(0);
        AddRuleRequest addRuleRequest = new AddRuleRequest();
        String ruleDetail = firstCommonInfo.getRuleDetail();
        String ruleCnName = firstCommonInfo.getRuleCnName();
        String ruleGroupName = firstCommonInfo.getRuleGroupName();
        String ruleTemplateName = firstCommonInfo.getTemplateName();
        addRuleRequest.setRuleCnName(ruleCnName);
        addRuleRequest.setAbortOnFailure(firstCommonInfo.getAbortOnFailure());
        addRuleRequest.setStaticStartupParam(firstCommonInfo.getStaticStartupParam());
        addRuleRequest.setDeleteFailCheckResult(firstCommonInfo.getDeleteFailCheckResult());
        addRuleRequest.setSpecifyStaticStartupParam(firstCommonInfo.getSpecifyStaticStartupParam());
        if (StringUtils.isBlank(ruleGroupName)) {
            throw new UnExpectedRequestException("RuleGroupName {&CAN_NOT_BE_NULL_OR_EMPTY}");
        }
        Template template = findTemplateByName(ruleTemplateName);
        if (template == null) {
            throw new UnExpectedRequestException("{&TEMPLATE_NAME}: [" + ruleTemplateName + "] {&DOES_NOT_EXIST}");
        }
        boolean alarm = false;
        Long projectId = project.getId();
        List<DataSourceRequest> dataSourceRequests = new ArrayList<>();
        List<AlarmConfigRequest> alarmConfigRequests = new ArrayList<>();
        List<TemplateArgumentRequest> templateArgumentRequests = new ArrayList<>();
        for (ExcelTemplateRuleByProject excelTemplateRuleByProject : ruleInfos) {
            getDataSourceRequest(dataSourceRequests, excelTemplateRuleByProject);
            getTemplateArgument(templateArgumentRequests, excelTemplateRuleByProject, template);
            getAlarmConfig(alarmConfigRequests, excelTemplateRuleByProject, template, localeStr);
        }
        RuleGroup ruleGroupInDb = ruleGroupDao.findByRuleGroupNameAndProjectId(ruleGroupName, projectId);
        if (ruleGroupInDb != null) {
            addRuleRequest.setRuleGroupId(ruleGroupInDb.getId());
        } else {
            RuleGroup ruleGroup = ruleGroupDao.saveRuleGroup(new RuleGroup(ruleGroupName, project.getId()));
            addRuleRequest.setRuleGroupId(ruleGroup.getId());
        }
        // Construct addRuleRequest
        addRuleRequest.setRuleName(ruleName);
        addRuleRequest.setRuleDetail(ruleDetail);
        addRuleRequest.setRuleTemplateId(template.getId());
        if (!alarmConfigRequests.isEmpty()) {
            alarm = true;
        }
        addRuleRequest.setAlarmVariable(alarmConfigRequests);
        addRuleRequest.setDatasource(dataSourceRequests);
        addRuleRequest.setProjectId(projectId);
        addRuleRequest.setAlarm(alarm);
        addRuleRequest.setTemplateArgumentRequests(templateArgumentRequests);
        addRuleRequests.add(addRuleRequest);
    }
    return addRuleRequests;
}
Also used : AddRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddRuleRequest) DataSourceRequest(com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ArrayList(java.util.ArrayList) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) TemplateArgumentRequest(com.webank.wedatasphere.qualitis.rule.request.TemplateArgumentRequest) FileAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest) CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest) AlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest) ExcelTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject)

Aggregations

AddRuleRequest (com.webank.wedatasphere.qualitis.rule.request.AddRuleRequest)4 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)2 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)2 RuleGroup (com.webank.wedatasphere.qualitis.rule.entity.RuleGroup)2 ArrayList (java.util.ArrayList)2 ExcelTemplateRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject)1 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)1 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)1 AddCustomRuleRequest (com.webank.wedatasphere.qualitis.rule.request.AddCustomRuleRequest)1 AddFileRuleRequest (com.webank.wedatasphere.qualitis.rule.request.AddFileRuleRequest)1 AlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest)1 CustomAlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest)1 DataSourceRequest (com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest)1 FileAlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest)1 ModifyRuleRequest (com.webank.wedatasphere.qualitis.rule.request.ModifyRuleRequest)1 TemplateArgumentRequest (com.webank.wedatasphere.qualitis.rule.request.TemplateArgumentRequest)1 AddMultiSourceRuleRequest (com.webank.wedatasphere.qualitis.rule.request.multi.AddMultiSourceRuleRequest)1 RuleResponse (com.webank.wedatasphere.qualitis.rule.response.RuleResponse)1 HashMap (java.util.HashMap)1 List (java.util.List)1