Search in sources :

Example 1 with TemplateMidTableInputMeta

use of com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta 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 TemplateMidTableInputMeta

use of com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta in project Qualitis by WeBankFinTech.

the class AutoArgumentAdapter method generateAndConcatStatement.

private String generateAndConcatStatement(TemplateMidTableInputMeta templateMidTableInputMeta, List<MultiDataSourceJoinConfigRequest> mappings, Rule rule) {
    String concatTemplate = templateMidTableInputMeta.getConcatTemplate();
    Collection<TemplateMidTableInputMeta> children = templateMidTableInputMeta.getChildren();
    List<String> originStatement = new ArrayList<>();
    if (rule.getTemplate().getMidTableAction().contains(DIFF_COUNT)) {
        MultiDataSourceJoinConfigRequest multiDataSourceJoinConfigRequest = new MultiDataSourceJoinConfigRequest();
        MultiDataSourceJoinColumnRequest leftJoinColumnRequest = new MultiDataSourceJoinColumnRequest("tmp1.".concat(DIFF_COUNT), "int");
        MultiDataSourceJoinColumnRequest rightJoinColumnRequest = new MultiDataSourceJoinColumnRequest("tmp2.".concat(DIFF_COUNT), "int");
        multiDataSourceJoinConfigRequest.setOperation(MappingOperationEnum.EQUAL.getCode());
        multiDataSourceJoinConfigRequest.setLeft(Arrays.asList(leftJoinColumnRequest));
        multiDataSourceJoinConfigRequest.setRight(Arrays.asList(rightJoinColumnRequest));
        multiDataSourceJoinConfigRequest.setLeftStatement("tmp1.".concat(DIFF_COUNT));
        multiDataSourceJoinConfigRequest.setRightStatement("tmp2.".concat(DIFF_COUNT));
        mappings.add(multiDataSourceJoinConfigRequest);
    }
    for (MultiDataSourceJoinConfigRequest mapping : mappings) {
        String replacedTemplate = concatTemplate;
        Boolean addedFlag = false;
        for (TemplateMidTableInputMeta child : children) {
            if (child.getInputType().equals(TemplateInputTypeEnum.LEFT_STATEMENT.getCode())) {
                replacedTemplate = replacedTemplate.replace(getPlaceHolder(child.getPlaceholder()), mapping.getLeftStatement());
            } else if (child.getInputType().equals(TemplateInputTypeEnum.OPERATION.getCode())) {
                replacedTemplate = replacedTemplate.replace(getPlaceHolder(child.getPlaceholder()), MappingOperationEnum.getByCode(mapping.getOperation()).getSymbol());
            } else if (child.getInputType().equals(TemplateInputTypeEnum.RIGHT_STATEMENT.getCode())) {
                replacedTemplate = replacedTemplate.replace(getPlaceHolder(child.getPlaceholder()), mapping.getRightStatement());
            } else if (child.getInputType().equals(TemplateInputTypeEnum.SOURCE_FIELD.getCode())) {
                for (MultiDataSourceJoinColumnRequest multiDataSourceJoinColumnRequest : mapping.getLeft()) {
                    String tmp1 = concatTemplate.replace(getPlaceHolder(child.getPlaceholder()), multiDataSourceJoinColumnRequest.getColumnName());
                    originStatement.add(tmp1);
                    addedFlag = true;
                }
            } else if (child.getInputType().equals(TemplateInputTypeEnum.TARGET_FIELD.getCode())) {
                for (MultiDataSourceJoinColumnRequest multiDataSourceJoinColumnRequest : mapping.getRight()) {
                    String tmp1 = concatTemplate.replace(getPlaceHolder(child.getPlaceholder()), multiDataSourceJoinColumnRequest.getColumnName());
                    originStatement.add(tmp1);
                    addedFlag = true;
                }
            }
        }
        if (!addedFlag) {
            originStatement.add(replacedTemplate);
        }
    }
    return generateStatementByConcatStr(originStatement, "AND");
}
Also used : MultiDataSourceJoinConfigRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceJoinConfigRequest) MultiDataSourceJoinColumnRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceJoinColumnRequest) TemplateMidTableInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta)

Example 3 with TemplateMidTableInputMeta

use of com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta 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 4 with TemplateMidTableInputMeta

use of com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta in project Qualitis by WeBankFinTech.

the class RuleNodeServiceImpl method saveRuleInfo.

public void saveRuleInfo(Rule savedRule, Template template, Project projectInDb, Set<AlarmConfig> alarmConfigs, Set<RuleVariable> ruleVariables, Set<RuleDataSource> ruleDataSources, Set<RuleDataSourceMapping> ruleDataSourceMappings) {
    LOGGER.info("Start to save rule Info.");
    List<AlarmConfig> alarmConfigList = new ArrayList<>();
    for (AlarmConfig alarmConfig : alarmConfigs) {
        alarmConfig.setRule(savedRule);
        ruleMetricSycn(alarmConfig);
        alarmConfig.setTemplateOutputMeta(savedRule.getTemplate().getTemplateOutputMetas().iterator().next());
        alarmConfigList.add(alarmConfig);
    }
    List<RuleVariable> ruleVariablesList = new ArrayList<>();
    TemplateStatisticsInputMeta templateStatisticsInputMeta = savedRule.getTemplate().getStatisticAction().iterator().next();
    for (RuleVariable ruleVariable : ruleVariables) {
        ruleVariable.setRule(savedRule);
        ruleVariable.setTemplateStatisticsInputMeta(templateStatisticsInputMeta);
        ruleVariablesList.add(ruleVariable);
    }
    if (template.getId().intValue() != savedRule.getTemplate().getId().intValue()) {
        ruleVariablesList.sort(Comparator.comparing(RuleVariable::getId));
        List<TemplateMidTableInputMeta> templateMidTableInputMetaList = new ArrayList<>();
        if (savedRule.getTemplate().getTemplateMidTableInputMetas() != null) {
            templateMidTableInputMetaList.addAll(savedRule.getTemplate().getTemplateMidTableInputMetas());
            templateMidTableInputMetaList.sort(Comparator.comparing(TemplateMidTableInputMeta::getId));
            Iterator iterator = templateMidTableInputMetaList.iterator();
            for (RuleVariable ruleVariable : ruleVariablesList) {
                ruleVariable.setTemplateMidTableInputMeta((TemplateMidTableInputMeta) iterator.next());
            }
        }
    }
    List<RuleDataSource> ruleDataSourceList = new ArrayList<>();
    for (RuleDataSource ruleDataSource : ruleDataSources) {
        ruleDataSource.setProjectId(projectInDb.getId());
        ruleDataSource.setRule(savedRule);
        ruleDataSourceList.add(ruleDataSource);
    }
    if (RuleTypeEnum.CUSTOM_RULE.getCode().equals(savedRule.getRuleType())) {
        List<AlarmConfig> customAlarmConfigs = new ArrayList<>();
        for (AlarmConfig alarmConfig : alarmConfigList) {
            TemplateOutputMeta templateOutputMetaInDb = savedRule.getTemplate().getTemplateOutputMetas().iterator().next();
            AlarmConfig customAlarmConfig = new AlarmConfig();
            customAlarmConfig.setRule(savedRule);
            customAlarmConfig.setRuleMetric(alarmConfig.getRuleMetric());
            customAlarmConfig.setThreshold(alarmConfig.getThreshold());
            customAlarmConfig.setTemplateOutputMeta(templateOutputMetaInDb);
            customAlarmConfig.setCheckTemplate(alarmConfig.getCheckTemplate());
            Integer checkTemplateCode = alarmConfig.getCheckTemplate();
            if (alarmConfig.getCheckTemplate().equals(CheckTemplateEnum.FIXED_VALUE.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.FULL_YEAR_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.HALF_YEAR_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.SEASON_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.MONTH_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.WEEK_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.DAY_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.HOUR_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.YEAR_ON_YEAR.getCode())) {
                customAlarmConfig.setCompareType(alarmConfig.getCompareType());
            }
            customAlarmConfigs.add(customAlarmConfig);
        }
        savedRule.setAlarmConfigs(new HashSet<>(alarmConfigDao.saveAllAlarmConfig(customAlarmConfigs)));
        savedRule.setRuleDataSources(new HashSet<>(ruleDataSourceDao.saveAllRuleDataSource(ruleDataSourceList)));
    } else {
        savedRule.setAlarmConfigs(new HashSet<>(alarmConfigDao.saveAllAlarmConfig(alarmConfigList)));
        savedRule.setRuleVariables(new HashSet<>(ruleVariableDao.saveAllRuleVariable(ruleVariablesList)));
        savedRule.setRuleDataSources(new HashSet<>(ruleDataSourceDao.saveAllRuleDataSource(ruleDataSourceList)));
        for (RuleDataSourceMapping ruleDataSourceMapping : ruleDataSourceMappings) {
            ruleDataSourceMapping.setRule(savedRule);
            ruleDataSourceMappingDao.saveRuleDataSourceMapping(ruleDataSourceMapping);
        }
    }
}
Also used : RuleDataSourceMapping(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceMapping) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) ArrayList(java.util.ArrayList) TemplateMidTableInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta) TemplateOutputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta) TemplateStatisticsInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateStatisticsInputMeta) Iterator(java.util.Iterator) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig) RuleVariable(com.webank.wedatasphere.qualitis.rule.entity.RuleVariable)

Example 5 with TemplateMidTableInputMeta

use of com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta in project Qualitis by WeBankFinTech.

the class RuleTemplateServiceImpl method getModifyRuleTemplateDetail.

@Override
public RuleTemplateResponse getModifyRuleTemplateDetail(Long templateId) throws UnExpectedRequestException {
    // Check template existence
    Template templateInDb = checkRuleTemplate(templateId);
    RuleTemplateResponse response = new RuleTemplateResponse(templateInDb);
    response.setClusterNum(templateInDb.getClusterNum());
    response.setDbNum(templateInDb.getDbNum());
    response.setTableNum(templateInDb.getTableNum());
    response.setFieldNum(templateInDb.getFieldNum());
    List<TemplateDataSourceType> templateDataSourceTypes = templateDataSourceTypeDao.findByTemplate(templateInDb);
    response.setDatasourceType(templateDataSourceTypes.stream().map(TemplateDataSourceType::getDataSourceTypeId).collect(Collectors.toList()));
    response.setActionType(templateInDb.getActionType());
    response.setMidTableAction(templateInDb.getMidTableAction());
    response.setSaveMidTable(templateInDb.getSaveMidTable());
    List<TemplateOutputMetaResponse> outputMetaResponses = new ArrayList<>(1);
    List<TemplateMidTableInputMetaResponse> midTableInputMetaResponses = new ArrayList<>(2);
    List<TemplateStatisticsInputMetaResponse> statisticsInputMetaResponses = new ArrayList<>(1);
    for (TemplateOutputMeta templateOutputMeta : templateInDb.getTemplateOutputMetas()) {
        TemplateOutputMetaResponse templateOutputMetaResponse = new TemplateOutputMetaResponse();
        templateOutputMetaResponse.setOutputName(templateOutputMeta.getOutputName());
        outputMetaResponses.add(templateOutputMetaResponse);
    }
    response.setTemplateOutputMetaResponses(outputMetaResponses);
    for (TemplateMidTableInputMeta templateMidTableInputMeta : templateInDb.getTemplateMidTableInputMetas()) {
        TemplateMidTableInputMetaResponse templateMidTableInputMetaResponse = new TemplateMidTableInputMetaResponse();
        templateMidTableInputMetaResponse.setName(templateMidTableInputMeta.getName());
        templateMidTableInputMetaResponse.setPlaceholder(templateMidTableInputMeta.getPlaceholder());
        templateMidTableInputMetaResponse.setPlaceholderDescription(templateMidTableInputMeta.getPlaceholderDescription());
        templateMidTableInputMetaResponse.setInputType(templateMidTableInputMeta.getInputType());
        midTableInputMetaResponses.add(templateMidTableInputMetaResponse);
    }
    response.setTemplateMidTableInputMetaResponses(midTableInputMetaResponses);
    for (TemplateStatisticsInputMeta templateStatisticsInputMeta : templateInDb.getStatisticAction()) {
        TemplateStatisticsInputMetaResponse templateStatisticsInputMetaResponse = new TemplateStatisticsInputMetaResponse();
        templateStatisticsInputMetaResponse.setName(templateStatisticsInputMeta.getName());
        templateStatisticsInputMetaResponse.setFuncName(templateStatisticsInputMeta.getFuncName());
        templateStatisticsInputMetaResponse.setValue(templateStatisticsInputMeta.getValue());
        templateStatisticsInputMetaResponse.setValueType(templateStatisticsInputMeta.getValueType());
        statisticsInputMetaResponses.add(templateStatisticsInputMetaResponse);
    }
    response.setTemplateStatisticsInputMetaResponses(statisticsInputMetaResponses);
    return response;
}
Also used : ArrayList(java.util.ArrayList) TemplateMidTableInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta) TemplateStatisticsInputMetaResponse(com.webank.wedatasphere.qualitis.rule.response.TemplateStatisticsInputMetaResponse) TemplateOutputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) TemplateStatisticsInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateStatisticsInputMeta) RuleTemplateResponse(com.webank.wedatasphere.qualitis.rule.response.RuleTemplateResponse) TemplateOutputMetaResponse(com.webank.wedatasphere.qualitis.rule.response.TemplateOutputMetaResponse) TemplateMidTableInputMetaResponse(com.webank.wedatasphere.qualitis.rule.response.TemplateMidTableInputMetaResponse) TemplateDataSourceType(com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType)

Aggregations

TemplateMidTableInputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta)10 ArrayList (java.util.ArrayList)7 TemplateOutputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta)5 TemplateStatisticsInputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateStatisticsInputMeta)4 RuleVariable (com.webank.wedatasphere.qualitis.rule.entity.RuleVariable)3 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)3 TemplateArgumentRequest (com.webank.wedatasphere.qualitis.rule.request.TemplateArgumentRequest)3 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)2 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)2 TemplateDataSourceType (com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType)2 HashSet (java.util.HashSet)2 ExcelTemplateRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject)1 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)1 AlarmConfig (com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)1 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)1 RuleDataSourceMapping (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceMapping)1 TemplateMidTableInputMetaRequest (com.webank.wedatasphere.qualitis.rule.request.TemplateMidTableInputMetaRequest)1 TemplateOutputMetaRequest (com.webank.wedatasphere.qualitis.rule.request.TemplateOutputMetaRequest)1 TemplateStatisticsInputMetaRequest (com.webank.wedatasphere.qualitis.rule.request.TemplateStatisticsInputMetaRequest)1 MultiDataSourceJoinColumnRequest (com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceJoinColumnRequest)1