Search in sources :

Example 6 with TemplateMidTableInputMeta

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

the class RuleTemplateServiceImpl method createAndSaveTemplateInfo.

private void createAndSaveTemplateInfo(Template savedTemplate, AddRuleTemplateRequest request) {
    // Save template output meta.
    Set<TemplateOutputMeta> templateOutputMetas = new HashSet<>();
    for (TemplateOutputMetaRequest templateOutputMetaRequest : request.getTemplateOutputMetaRequests()) {
        templateOutputMetas.addAll(templateOutputMetaService.getAndSaveTemplateOutputMeta(templateOutputMetaRequest.getOutputName(), FunctionTypeEnum.getFunctionTypeByName(templateOutputMetaRequest.getFieldName()), request.getSaveMidTable(), savedTemplate));
    }
    savedTemplate.setTemplateOutputMetas(templateOutputMetas);
    LOGGER.info("Success to save template output meta. TemplateOutputMetas: {}", savedTemplate.getTemplateOutputMetas());
    // Save template mid_table input meta
    List<TemplateMidTableInputMeta> templateMidTableInputMetas = new ArrayList<>();
    for (TemplateMidTableInputMetaRequest templateMidTableInputMetaRequest : request.getTemplateMidTableInputMetaRequests()) {
        TemplateMidTableInputMeta templateMidTableInputMeta = new TemplateMidTableInputMeta();
        templateMidTableInputMeta.setName(templateMidTableInputMetaRequest.getName());
        templateMidTableInputMeta.setFieldType(templateMidTableInputMetaRequest.getFieldType());
        templateMidTableInputMeta.setInputType(templateMidTableInputMetaRequest.getInputType());
        templateMidTableInputMeta.setPlaceholder(templateMidTableInputMetaRequest.getPlaceholder());
        templateMidTableInputMeta.setPlaceholderDescription(templateMidTableInputMetaRequest.getPlaceholderDescription());
        templateMidTableInputMeta.setRegexpType(templateMidTableInputMetaRequest.getRegexpType());
        templateMidTableInputMeta.setReplaceByRequest(templateMidTableInputMetaRequest.getReplaceByRequest());
        templateMidTableInputMeta.setTemplate(savedTemplate);
        templateMidTableInputMetas.add(templateMidTableInputMeta);
    }
    savedTemplate.setTemplateMidTableInputMetas(templateMidTableInputMetaService.saveAll(templateMidTableInputMetas));
    LOGGER.info("Success to save template mid_table input meta. TemplateMidTableInputMetas: {}", savedTemplate.getTemplateMidTableInputMetas());
    // Save template statistics input meta
    List<TemplateStatisticsInputMeta> templateStatisticsInputMetas = new ArrayList<>();
    for (TemplateStatisticsInputMetaRequest templateStatisticsInputMetaRequest : request.getTemplateStatisticsInputMetaRequests()) {
        TemplateStatisticsInputMeta templateStatisticsInputMeta = new TemplateStatisticsInputMeta();
        templateStatisticsInputMeta.setName(templateStatisticsInputMetaRequest.getName());
        templateStatisticsInputMeta.setFuncName(templateStatisticsInputMetaRequest.getFuncName());
        templateStatisticsInputMeta.setResultType(templateStatisticsInputMetaRequest.getResultType());
        templateStatisticsInputMeta.setValue(templateStatisticsInputMetaRequest.getValue());
        templateStatisticsInputMeta.setValueType(templateStatisticsInputMetaRequest.getValueType());
        templateStatisticsInputMeta.setTemplate(savedTemplate);
        templateStatisticsInputMetas.add(templateStatisticsInputMeta);
    }
    savedTemplate.setStatisticAction(templateStatisticsInputMetaService.saveAll(templateStatisticsInputMetas));
    LOGGER.info("Success to save template statistics input meta. templateStatisticsInputMetas: {}", savedTemplate.getStatisticAction());
}
Also used : TemplateOutputMetaRequest(com.webank.wedatasphere.qualitis.rule.request.TemplateOutputMetaRequest) TemplateStatisticsInputMetaRequest(com.webank.wedatasphere.qualitis.rule.request.TemplateStatisticsInputMetaRequest) TemplateMidTableInputMetaRequest(com.webank.wedatasphere.qualitis.rule.request.TemplateMidTableInputMetaRequest) ArrayList(java.util.ArrayList) TemplateMidTableInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta) TemplateOutputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta) HashSet(java.util.HashSet) TemplateStatisticsInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateStatisticsInputMeta)

Example 7 with TemplateMidTableInputMeta

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

the class RuleBatchServiceImpl method getTemplateRule.

@Override
public List<ExcelTemplateRuleByProject> getTemplateRule(Iterable<Rule> rules, String localeStr) {
    List<ExcelTemplateRuleByProject> lines = new ArrayList<>();
    for (Rule rule : rules) {
        if (!rule.getRuleType().equals(RuleTypeEnum.SINGLE_TEMPLATE_RULE.getCode())) {
            continue;
        }
        // Rule basic info.
        ExcelTemplateRuleByProject ruleLinePrefix = new ExcelTemplateRuleByProject();
        basicInfoToExcel(ruleLinePrefix, rule);
        lines.add(ruleLinePrefix);
        for (RuleDataSource ruleDataSource : rule.getRuleDataSources()) {
            String clusterName = ruleDataSource.getClusterName();
            String databaseName = ruleDataSource.getDbName();
            String tableName = ruleDataSource.getTableName();
            String columnName = ruleDataSource.getColName();
            String filter = ruleDataSource.getFilter();
            ExcelTemplateRuleByProject tmp = new ExcelTemplateRuleByProject(rule.getName());
            tmp.setBlackColName(ruleDataSource.getBlackColName());
            tmp.setProxyUser(ruleDataSource.getProxyUser());
            tmp.setFilter(filter);
            tmp.setCluster(clusterName);
            tmp.setDbName(databaseName);
            tmp.setTableName(tableName);
            tmp.setColumnNames(columnName);
            if (ruleDataSource.getLinkisDataSourceId() != null) {
                tmp.setLinkisDataSourceName(ruleDataSource.getLinkisDataSourceName());
                tmp.setLinkisDataSourceId(String.valueOf(ruleDataSource.getLinkisDataSourceId()));
                tmp.setLinkisDataSourceType(TemplateDataSourceTypeEnum.getMessage(ruleDataSource.getDatasourceType()));
            }
            LOGGER.info("Collect excel line: {}", tmp);
            lines.add(tmp);
        }
        for (TemplateMidTableInputMeta templateMidTableInputMeta : rule.getTemplate().getTemplateMidTableInputMetas()) {
            if (TemplateMidTableUtil.shouldResponse(templateMidTableInputMeta)) {
                for (RuleVariable ruleVariable : rule.getRuleVariables()) {
                    if (ruleVariable.getTemplateMidTableInputMeta().equals(templateMidTableInputMeta)) {
                        ExcelTemplateRuleByProject tmp = new ExcelTemplateRuleByProject(rule.getName());
                        String key = templateMidTableInputMeta.getName();
                        String value = StringEscapeUtils.unescapeJava(ruleVariable.getValue());
                        if (templateMidTableInputMeta.getInputType().equals(TemplateInputTypeEnum.REGEXP.getCode())) {
                            if (templateMidTableInputMeta.getRegexpType() != null) {
                                value = ruleVariable.getOriginValue();
                            }
                        }
                        tmp.setArgumentKey(key);
                        tmp.setArgumentValue(value);
                        LOGGER.info("Collect excel line: {}", tmp);
                        lines.add(tmp);
                    }
                }
            }
        }
        alarmConfigsToExcel(rule, lines, localeStr);
    }
    return lines;
}
Also used : RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) ArrayList(java.util.ArrayList) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) TemplateMidTableInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta) ExcelTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject) RuleVariable(com.webank.wedatasphere.qualitis.rule.entity.RuleVariable)

Example 8 with TemplateMidTableInputMeta

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

Example 9 with TemplateMidTableInputMeta

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

the class RuleNodeServiceImpl method synchroRuleTemplate.

public void synchroRuleTemplate(RuleNodeRequest ruleNodeRequest, Rule rule, Template template, Set<RuleDataSource> ruleDataSources) throws IOException {
    Template templateInDb = ruleTemplateDao.findById(template.getId());
    Template templateNameInDb = null;
    if (StringUtils.isNotBlank(template.getImportExportName())) {
        templateNameInDb = ruleTemplateDao.findByImportExportName(template.getImportExportName());
    }
    if (templateInDb == null && templateNameInDb == null) {
        LOGGER.info("Start to synchronize the rule template. Template: {}", template);
        ObjectMapper objectMapper = new ObjectMapper();
        // Template meta info.
        Set<TemplateOutputMeta> templateOutputMetaSet = objectMapper.readValue(ruleNodeRequest.getTemplateTemplateOutputMetaObject(), new TypeReference<Set<TemplateOutputMeta>>() {
        });
        Set<TemplateMidTableInputMeta> templateMidTableInputMetaSet = objectMapper.readValue(ruleNodeRequest.getTemplateTemplateMidTableInputMetaObject(), new TypeReference<Set<TemplateMidTableInputMeta>>() {
        });
        Set<TemplateStatisticsInputMeta> templateStatisticsInputMetaSet = objectMapper.readValue(ruleNodeRequest.getTemplateTemplateStatisticsInputMetaObject(), new TypeReference<Set<TemplateStatisticsInputMeta>>() {
        });
        Template savedTemplate = ruleTemplateDao.saveTemplate(template);
        Set<TemplateOutputMeta> templateOutputMetas = new HashSet<>();
        for (TemplateOutputMeta outputMeta : templateOutputMetaSet) {
            outputMeta.setTemplate(savedTemplate);
            templateOutputMetas.add(templateOutputMetaDao.saveTemplateOutputMeta(outputMeta));
        }
        savedTemplate.setTemplateOutputMetas(templateOutputMetas);
        LOGGER.info("Success to save template output meta. TemplateOutputMetas: {}", savedTemplate.getTemplateOutputMetas());
        List<TemplateMidTableInputMeta> templateMidTableInputMetas = new ArrayList<>();
        for (TemplateMidTableInputMeta templateMidTableInputMeta : templateMidTableInputMetaSet) {
            templateMidTableInputMeta.setTemplate(savedTemplate);
            templateMidTableInputMetas.add(templateMidTableInputMeta);
        }
        templateMidTableInputMetas.sort(Comparator.comparing(TemplateMidTableInputMeta::getId));
        savedTemplate.setTemplateMidTableInputMetas(templateMidTableInputMetaService.saveAll(templateMidTableInputMetas));
        LOGGER.info("Success to save template mid_table input meta. TemplateMidTableInputMetas: {}", savedTemplate.getTemplateMidTableInputMetas());
        List<TemplateStatisticsInputMeta> templateStatisticsInputMetas = new ArrayList<>();
        for (TemplateStatisticsInputMeta templateStatisticsInputMeta : templateStatisticsInputMetaSet) {
            templateStatisticsInputMeta.setTemplate(savedTemplate);
            templateStatisticsInputMetas.add(templateStatisticsInputMeta);
        }
        savedTemplate.setStatisticAction(templateStatisticsInputMetaService.saveAll(templateStatisticsInputMetas));
        LOGGER.info("Success to save template statistics input meta. templateStatisticsInputMetas: {}", savedTemplate.getStatisticAction());
        Set<Integer> templateDateTypes = ruleDataSources.stream().filter(currRuleDataSource -> currRuleDataSource.getDatasourceType() != null).map(RuleDataSource::getDatasourceType).collect(Collectors.toSet());
        for (Integer templateDataType : templateDateTypes) {
            TemplateDataSourceType templateDataSourceType = new TemplateDataSourceType(templateDataType, savedTemplate);
            templateDataSourceTypeDao.save(templateDataSourceType);
        }
        LOGGER.info("Success to save template data types. Template data types: {}", Arrays.toString(templateDateTypes.toArray()));
        LOGGER.info("Finished to synchronize the rule template. Template: {}", savedTemplate);
        rule.setTemplate(savedTemplate);
    } else if (templateInDb != null) {
        rule.setTemplate(templateInDb);
    } else if (templateNameInDb != null) {
        rule.setTemplate(templateNameInDb);
    } else {
        rule.setTemplate(template);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) TemplateMidTableInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta) TemplateOutputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) TemplateStatisticsInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateStatisticsInputMeta) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) TemplateDataSourceType(com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType) HashSet(java.util.HashSet)

Example 10 with TemplateMidTableInputMeta

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

the class RuleTemplateServiceImpl method getRuleTemplateMeta.

@Override
public GeneralResponse<TemplateMetaResponse> getRuleTemplateMeta(Long ruleTemplateId) throws UnExpectedRequestException {
    // Find rule template by id
    Template templateInDb = ruleTemplateDao.findById(ruleTemplateId);
    if (null == templateInDb) {
        throw new UnExpectedRequestException("rule_template_id {&CAN_NOT_BE_NULL_OR_EMPTY}");
    }
    // Find input meta data by template
    List<TemplateMidTableInputMeta> templateMidTableInputMetas = templateMidTableInputMetaDao.findByRuleTemplate(templateInDb);
    List<TemplateOutputMeta> templateOutputMetas = templateOutputMetaDao.findByRuleTemplate(templateInDb);
    List<Integer> types = templateDataSourceTypeDao.findByTemplate(templateInDb).stream().map(TemplateDataSourceType::getDataSourceTypeId).collect(Collectors.toList());
    TemplateMetaResponse response = new TemplateMetaResponse(templateInDb, templateMidTableInputMetas, templateOutputMetas, types);
    LOGGER.info("Succeed to get rule_template. rule_template_id: {}", ruleTemplateId);
    return new GeneralResponse<>("200", "{&GET_RULE_TEMPLATE_META_SUCCESSFULLY}", response);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) TemplateMidTableInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta) TemplateOutputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) TemplateMetaResponse(com.webank.wedatasphere.qualitis.rule.response.TemplateMetaResponse)

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