Search in sources :

Example 1 with TemplateArgumentRequest

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

the class RuleBatchServiceImpl method getTemplateArgument.

private void getTemplateArgument(List<TemplateArgumentRequest> templateArgumentRequests, ExcelTemplateRuleByProject excelTemplateRule, Template template) throws UnExpectedRequestException {
    String argumentKey = excelTemplateRule.getArgumentKey();
    if (!StringUtils.isBlank(argumentKey)) {
        TemplateArgumentRequest templateArgumentRequest = new TemplateArgumentRequest();
        templateArgumentRequest.setArgumentStep(InputActionStepEnum.TEMPLATE_INPUT_META.getCode());
        String argumentValue = excelTemplateRule.getArgumentValue();
        templateArgumentRequest.setArgumentValue(argumentValue);
        TemplateMidTableInputMeta templateMidTableInputMeta = findByTemplateAndName(template, argumentKey);
        if (templateMidTableInputMeta == null) {
            throw new UnExpectedRequestException("{&TEMPLATE_ARGUMENT}: [" + argumentKey + "] {&DOES_NOT_EXIST}");
        }
        templateArgumentRequest.setArgumentId(templateMidTableInputMeta.getId());
        templateArgumentRequests.add(templateArgumentRequest);
    }
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) TemplateMidTableInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta) TemplateArgumentRequest(com.webank.wedatasphere.qualitis.rule.request.TemplateArgumentRequest)

Example 2 with TemplateArgumentRequest

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

the class AddRuleRequestBuilder method templateArgumentSetting.

private void templateArgumentSetting(List<TemplateArgumentRequest> templateArgumentRequests, String condition1, String condition2) {
    List<TemplateMidTableInputMeta> templateMidTableInputMetaList = new ArrayList<>(2);
    for (TemplateMidTableInputMeta templateMidTableInputMeta : template.getTemplateMidTableInputMetas()) {
        if (TemplateMidTableUtil.shouldResponse(templateMidTableInputMeta)) {
            templateMidTableInputMetaList.add(templateMidTableInputMeta);
        }
    }
    Collections.sort(templateMidTableInputMetaList, new Comparator<TemplateMidTableInputMeta>() {

        @Override
        public int compare(TemplateMidTableInputMeta templateMidTableInputMetaFront, TemplateMidTableInputMeta templateMidTableInputMetaBack) {
            return Long.compare(templateMidTableInputMetaFront.getId(), templateMidTableInputMetaBack.getId());
        }
    });
    templateArgumentRequests.add(new TemplateArgumentRequest(templateMidTableInputMetaList.get(0).getId(), InputActionStepEnum.TEMPLATE_INPUT_META.getCode(), condition1));
    templateArgumentRequests.add(new TemplateArgumentRequest(templateMidTableInputMetaList.get(1).getId(), InputActionStepEnum.TEMPLATE_INPUT_META.getCode(), condition2));
    addRuleRequest.setTemplateArgumentRequests(templateArgumentRequests);
}
Also used : ArrayList(java.util.ArrayList) TemplateMidTableInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta) TemplateArgumentRequest(com.webank.wedatasphere.qualitis.rule.request.TemplateArgumentRequest)

Example 3 with TemplateArgumentRequest

use of com.webank.wedatasphere.qualitis.rule.request.TemplateArgumentRequest 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)

Example 4 with TemplateArgumentRequest

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

the class RuleNodeServiceImpl method constructTemplateArgumentRequest.

private List<TemplateArgumentRequest> constructTemplateArgumentRequest(Rule rule) {
    List<TemplateArgumentRequest> templateArgumentRequests = new ArrayList<>(rule.getTemplate().getTemplateMidTableInputMetas().size());
    for (TemplateMidTableInputMeta templateMidTableInputMeta : rule.getTemplate().getTemplateMidTableInputMetas()) {
        if (TemplateMidTableUtil.shouldResponse(templateMidTableInputMeta)) {
            for (RuleVariable ruleVariable : rule.getRuleVariables()) {
                TemplateArgumentRequest templateArgumentRequest = new TemplateArgumentRequest();
                if (ruleVariable.getTemplateMidTableInputMeta().equals(templateMidTableInputMeta)) {
                    String value = StringEscapeUtils.unescapeJava(ruleVariable.getValue());
                    if (templateMidTableInputMeta.getInputType().equals(TemplateInputTypeEnum.REGEXP.getCode())) {
                        if (templateMidTableInputMeta.getRegexpType() != null) {
                            value = ruleVariable.getOriginValue();
                        }
                    }
                    templateArgumentRequest.setArgumentStep(InputActionStepEnum.TEMPLATE_INPUT_META.getCode());
                    templateArgumentRequest.setArgumentId(templateMidTableInputMeta.getId());
                    templateArgumentRequest.setArgumentValue(value);
                    templateArgumentRequests.add(templateArgumentRequest);
                }
            }
        }
    }
    return templateArgumentRequests;
}
Also used : ArrayList(java.util.ArrayList) TemplateMidTableInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta) TemplateArgumentRequest(com.webank.wedatasphere.qualitis.rule.request.TemplateArgumentRequest) RuleVariable(com.webank.wedatasphere.qualitis.rule.entity.RuleVariable)

Aggregations

TemplateArgumentRequest (com.webank.wedatasphere.qualitis.rule.request.TemplateArgumentRequest)4 TemplateMidTableInputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta)3 ArrayList (java.util.ArrayList)3 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)2 ExcelTemplateRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject)1 RuleGroup (com.webank.wedatasphere.qualitis.rule.entity.RuleGroup)1 RuleVariable (com.webank.wedatasphere.qualitis.rule.entity.RuleVariable)1 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)1 AddRuleRequest (com.webank.wedatasphere.qualitis.rule.request.AddRuleRequest)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