Search in sources :

Example 11 with Template

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

the class RuleBatchServiceImpl method constructAddMultiSourceRuleRequest.

private List<AddMultiSourceRuleRequest> constructAddMultiSourceRuleRequest(Map<String, List<ExcelMultiTemplateRuleByProject>> multiRulePartitionedByRuleName, Project project, String localeStr) throws UnExpectedRequestException {
    List<AddMultiSourceRuleRequest> addMultiSourceRuleRequests = new ArrayList<>();
    for (String ruleName : multiRulePartitionedByRuleName.keySet()) {
        List<ExcelMultiTemplateRuleByProject> ruleInfos = multiRulePartitionedByRuleName.get(ruleName);
        ExcelMultiTemplateRuleByProject firstCommonInfo = ruleInfos.get(0);
        AddMultiSourceRuleRequest addMultiSourceRuleRequest = new AddMultiSourceRuleRequest();
        String ruleTemplateName = firstCommonInfo.getTemplateName();
        String ruleGroupName = firstCommonInfo.getRuleGroupName();
        addMultiSourceRuleRequest.setSpecifyStaticStartupParam(firstCommonInfo.getSpecifyStaticStartupParam());
        addMultiSourceRuleRequest.setDeleteFailCheckResult(firstCommonInfo.getDeleteFailCheckResult());
        addMultiSourceRuleRequest.setStaticStartupParam(firstCommonInfo.getStaticStartupParam());
        addMultiSourceRuleRequest.setAbortOnFailure(firstCommonInfo.getAbortOnFailure());
        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}");
        }
        String filter = null;
        boolean alarm = false;
        String clusterName = firstCommonInfo.getClusterName();
        MultiDataSourceConfigRequest sourceConfigRequest = new MultiDataSourceConfigRequest();
        MultiDataSourceConfigRequest targetConfigRequest = new MultiDataSourceConfigRequest();
        List<MultiDataSourceJoinConfigRequest> mappings = new ArrayList<>();
        List<AlarmConfigRequest> alarmConfigRequests = new ArrayList<>();
        for (ExcelMultiTemplateRuleByProject excelMultiTemplateRule : ruleInfos) {
            if (StringUtils.isNotBlank(excelMultiTemplateRule.getWhereFilter())) {
                filter = excelMultiTemplateRule.getWhereFilter();
            }
            getAlarmConfig(alarmConfigRequests, excelMultiTemplateRule, template, localeStr);
            getMultiDataSourceRequest(sourceConfigRequest, excelMultiTemplateRule, 0);
            getMultiDataSourceRequest(targetConfigRequest, excelMultiTemplateRule, 1);
            getMultiDataSourceJoinRequest(mappings, excelMultiTemplateRule);
        }
        if (alarmConfigRequests.size() != 0) {
            alarm = true;
        }
        RuleGroup ruleGroupInDb = ruleGroupDao.findByRuleGroupNameAndProjectId(ruleGroupName, project.getId());
        if (ruleGroupInDb != null) {
            addMultiSourceRuleRequest.setRuleGroupId(ruleGroupInDb.getId());
        } else {
            RuleGroup ruleGroup = ruleGroupDao.saveRuleGroup(new RuleGroup(ruleGroupName, project.getId()));
            addMultiSourceRuleRequest.setRuleGroupId(ruleGroup.getId());
        }
        addMultiSourceRuleRequest.setRuleName(ruleName);
        addMultiSourceRuleRequest.setClusterName(clusterName);
        addMultiSourceRuleRequest.setProjectId(project.getId());
        addMultiSourceRuleRequest.setRuleDetail(firstCommonInfo.getRuleDetail());
        addMultiSourceRuleRequest.setMultiSourceRuleTemplateId(template.getId());
        addMultiSourceRuleRequest.setAlarmVariable(alarmConfigRequests);
        addMultiSourceRuleRequests.add(addMultiSourceRuleRequest);
        addMultiSourceRuleRequest.setSource(sourceConfigRequest);
        addMultiSourceRuleRequest.setTarget(targetConfigRequest);
        addMultiSourceRuleRequest.setMappings(mappings);
        addMultiSourceRuleRequest.setFilter(filter);
        addMultiSourceRuleRequest.setAlarm(alarm);
    }
    return addMultiSourceRuleRequests;
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ExcelMultiTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject) ArrayList(java.util.ArrayList) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) MultiDataSourceJoinConfigRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceJoinConfigRequest) FileAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest) CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest) AlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest) MultiDataSourceConfigRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceConfigRequest) AddMultiSourceRuleRequest(com.webank.wedatasphere.qualitis.rule.request.multi.AddMultiSourceRuleRequest)

Example 12 with Template

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

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

the class RuleNodeServiceImpl method importRuleReal.

private void importRuleReal(RuleNodeRequest ruleNodeRequest, Rule ruleInDb, Rule rule, Project projectInDb, Template template, RuleGroup ruleGroup, Set<AlarmConfig> alarmConfigs, Set<RuleVariable> ruleVariables, Set<RuleDataSource> ruleDataSources, Set<RuleDataSourceMapping> ruleDataSourceMappings) throws IOException, UnExpectedRequestException {
    if (ruleInDb == null) {
        LOGGER.info("Import in first time. That means adding.");
        rule.setProject(projectInDb);
        ruleGroup.setProjectId(projectInDb.getId());
        if (RuleTypeEnum.CUSTOM_RULE.getCode().equals(rule.getRuleType())) {
            Template saveTemplate = ruleTemplateDao.saveTemplate(template);
            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, saveTemplate);
                templateDataSourceTypeDao.save(templateDataSourceType);
            }
            Set<TemplateStatisticsInputMeta> templateStatisticsInputMetas = new HashSet<>();
            Set<TemplateOutputMeta> templateOutputMetaSet = new HashSet<>();
            if (rule.getOutputName() != null && rule.getFunctionType() != null && rule.getFunctionContent() != null) {
                templateStatisticsInputMetas = templateStatisticsInputMetaService.getAndSaveTemplateStatisticsInputMeta(rule.getOutputName(), rule.getFunctionType(), rule.getFunctionContent(), saveTemplate.getSaveMidTable(), saveTemplate);
                templateOutputMetaSet = templateOutputMetaService.getAndSaveTemplateOutputMeta(rule.getOutputName(), rule.getFunctionType(), saveTemplate.getSaveMidTable(), saveTemplate);
            } else {
                List<RuleMetric> ruleMetrics = alarmConfigs.stream().map(AlarmConfig::getRuleMetric).collect(Collectors.toList());
                for (RuleMetric ruleMetric : ruleMetrics) {
                    templateStatisticsInputMetas.addAll(templateStatisticsInputMetaService.getAndSaveTemplateStatisticsInputMeta(ruleMetric.getName(), FunctionTypeEnum.MAX_FUNCTION.getCode(), ruleMetric.getName(), saveTemplate.getSaveMidTable(), saveTemplate));
                    templateOutputMetaSet.addAll(templateOutputMetaService.getAndSaveTemplateOutputMeta(ruleMetric.getName(), FunctionTypeEnum.MAX_FUNCTION.getCode(), saveTemplate.getSaveMidTable(), saveTemplate));
                }
            }
            saveTemplate.setStatisticAction(templateStatisticsInputMetas);
            saveTemplate.setTemplateOutputMetas(templateOutputMetaSet);
            rule.setTemplate(saveTemplate);
        } else if (RuleTypeEnum.FILE_TEMPLATE_RULE.getCode().equals(rule.getRuleType())) {
            LOGGER.info("Start to import file rule. {}", rule.getName());
            // Save file rule template.
            rule.setTemplate(ruleTemplateDao.saveTemplate(template));
            // Save file rule group
            rule.setRuleGroup(ruleGroup);
            Rule savedRule = ruleDao.saveRule(rule);
            // Save file alarmconfig
            List<AlarmConfig> alarmConfigList = new ArrayList<>();
            for (AlarmConfig alarmConfig : alarmConfigs) {
                ruleMetricSycn(alarmConfig);
                alarmConfig.setRule(savedRule);
                alarmConfigList.add(alarmConfig);
            }
            List<RuleDataSource> ruleDataSourceList = new ArrayList<>();
            for (RuleDataSource ruleDataSource : ruleDataSources) {
                ruleDataSource.setProjectId(projectInDb.getId());
                ruleDataSource.setRule(savedRule);
                ruleDataSourceList.add(ruleDataSource);
            }
            savedRule.setAlarmConfigs(new HashSet<>(alarmConfigDao.saveAllAlarmConfig(alarmConfigList)));
            savedRule.setRuleDataSources(new HashSet<>(ruleDataSourceDao.saveAllRuleDataSource(ruleDataSourceList)));
            LOGGER.info("Finish to import file rule. {}", rule.getName());
            return;
        } else {
            // When trying out the newly created rule template in the development center, the production center needs to synchronize the rule template.
            synchroRuleTemplate(ruleNodeRequest, rule, template, ruleDataSources);
        }
        rule.setRuleGroup(ruleGroup);
        Rule savedRule = ruleDao.saveRule(rule);
        saveRuleInfo(savedRule, template, projectInDb, alarmConfigs, ruleVariables, ruleDataSources, ruleDataSourceMappings);
        if (ruleNodeRequest.getChildRuleObject() != null) {
            importChildRule(savedRule, ruleGroup, ruleNodeRequest, projectInDb);
        }
    } else {
        LOGGER.info("Import multiple times. That is to update.");
        if (RuleTypeEnum.FILE_TEMPLATE_RULE.getCode().equals(rule.getRuleType())) {
            LOGGER.info("Start to update import file rule. {}", rule.getName());
            Set<AlarmConfig> alarmConfigList = new HashSet<>();
            for (AlarmConfig alarmConfig : alarmConfigs) {
                ruleMetricSycn(alarmConfig);
                alarmConfig.setRule(ruleInDb);
                alarmConfigList.add(alarmConfig);
            }
            updateImportedFileRule(rule, ruleInDb, ruleGroup, alarmConfigList, ruleDataSources);
            LOGGER.info("Finish to update import file rule. {}", rule.getName());
            return;
        }
        updateImportedRule(rule, ruleInDb, ruleGroup, ruleNodeRequest, template, alarmConfigs, ruleVariables, ruleDataSources, ruleDataSourceMappings);
    }
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) TemplateOutputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) TemplateStatisticsInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateStatisticsInputMeta) ArrayList(java.util.ArrayList) List(java.util.List) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) TemplateDataSourceType(com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType) HashSet(java.util.HashSet) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)

Example 14 with Template

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

the class RuleNodeServiceImpl method updateImportedRule.

public void updateImportedRule(Rule rule, Rule ruleInDb, RuleGroup ruleGroup, RuleNodeRequest ruleNodeRequest, Template template, Set<AlarmConfig> alarmConfigs, Set<RuleVariable> ruleVariables, Set<RuleDataSource> ruleDataSources, Set<RuleDataSourceMapping> ruleDataSourceMappings) throws UnExpectedRequestException, IOException {
    ruleInDb.setRuleGroup(ruleGroup);
    ruleInDb.setAlarm(rule.getAlarm());
    ruleInDb.setAbortOnFailure(rule.getAbortOnFailure());
    ruleInDb.setFromContent(rule.getFromContent());
    ruleInDb.setWhereContent(rule.getWhereContent());
    ruleInDb.setRuleType(rule.getRuleType());
    ruleInDb.setRuleTemplateName(template.getName());
    ruleInDb.setOutputName(rule.getOutputName());
    ruleInDb.setFunctionType(rule.getFunctionType());
    ruleInDb.setFunctionContent(rule.getFunctionContent());
    ruleInDb.setDeleteFailCheckResult(rule.getDeleteFailCheckResult());
    if (RuleTypeEnum.CUSTOM_RULE.getCode().equals(rule.getRuleType())) {
        ruleTemplateService.deleteCustomTemplate(ruleInDb.getTemplate());
        Template savedTemplate = ruleTemplateDao.saveTemplate(template);
        Set<TemplateStatisticsInputMeta> templateStatisticsInputMetas = new HashSet<>();
        Set<TemplateOutputMeta> templateOutputMetaSet = new HashSet<>();
        if (rule.getOutputName() != null && rule.getFunctionType() != null && rule.getFunctionContent() != null) {
            templateStatisticsInputMetas = templateStatisticsInputMetaService.getAndSaveTemplateStatisticsInputMeta(rule.getOutputName(), rule.getFunctionType(), rule.getFunctionContent(), savedTemplate.getSaveMidTable(), savedTemplate);
            templateOutputMetaSet = templateOutputMetaService.getAndSaveTemplateOutputMeta(rule.getOutputName(), rule.getFunctionType(), savedTemplate.getSaveMidTable(), savedTemplate);
        } else {
            List<RuleMetric> ruleMetrics = alarmConfigs.stream().map(AlarmConfig::getRuleMetric).collect(Collectors.toList());
            for (RuleMetric ruleMetric : ruleMetrics) {
                templateStatisticsInputMetas.addAll(templateStatisticsInputMetaService.getAndSaveTemplateStatisticsInputMeta(ruleMetric.getName(), FunctionTypeEnum.MAX_FUNCTION.getCode(), ruleMetric.getName(), savedTemplate.getSaveMidTable(), savedTemplate));
                templateOutputMetaSet.addAll(templateOutputMetaService.getAndSaveTemplateOutputMeta(ruleMetric.getName(), FunctionTypeEnum.MAX_FUNCTION.getCode(), savedTemplate.getSaveMidTable(), savedTemplate));
            }
        }
        savedTemplate.setStatisticAction(templateStatisticsInputMetas);
        savedTemplate.setTemplateOutputMetas(templateOutputMetaSet);
        ruleInDb.setTemplate(savedTemplate);
    } else {
        synchroRuleTemplate(ruleNodeRequest, ruleInDb, template, ruleDataSources);
    }
    alarmConfigService.deleteByRule(ruleInDb);
    LOGGER.info("Succeed to delete all alarm_config. rule_id: {}", ruleInDb.getId());
    Integer ruleType = ruleInDb.getRuleType();
    if (RuleTypeEnum.SINGLE_TEMPLATE_RULE.getCode().equals(ruleType) || RuleTypeEnum.MULTI_TEMPLATE_RULE.getCode().equals(ruleType)) {
        ruleVariableService.deleteByRule(ruleInDb);
        LOGGER.info("Succeed to delete all rule_variable. rule_id: {}", ruleInDb.getId());
        if (RuleTypeEnum.MULTI_TEMPLATE_RULE.getCode().equals(ruleType)) {
            ruleDataSourceMappingService.deleteByRule(ruleInDb);
            LOGGER.info("Succeed to delete all rule_dataSource_mapping. rule_id: {}", ruleInDb.getId());
        }
    }
    ruleDataSourceService.deleteByRule(ruleInDb);
    LOGGER.info("Succeed to delete all rule_dataSources. rule_id: {}", ruleInDb.getId());
    Rule updateRule = ruleDao.saveRule(ruleInDb);
    saveRuleInfo(updateRule, template, updateRule.getProject(), alarmConfigs, ruleVariables, ruleDataSources, ruleDataSourceMappings);
    updateImportedChildRule(updateRule, ruleNodeRequest);
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) TemplateOutputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) TemplateStatisticsInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateStatisticsInputMeta) HashSet(java.util.HashSet)

Example 15 with Template

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

the class RuleNodeServiceImpl method importChildRule.

private void importChildRule(Rule parentRule, RuleGroup ruleGroup, RuleNodeRequest ruleNodeRequest, Project projectInDb) throws IOException {
    LOGGER.info("Start to import child rule.");
    ObjectMapper objectMapper = new ObjectMapper();
    Rule childRule = objectMapper.readValue(ruleNodeRequest.getChildRuleObject(), Rule.class);
    Template childTemplate = objectMapper.readValue(ruleNodeRequest.getChildTemplateObject(), Template.class);
    Set<RuleDataSource> childRuleDataSources = objectMapper.readValue(ruleNodeRequest.getChildRuleDataSourcesObject(), new TypeReference<Set<RuleDataSource>>() {
    });
    Set<RuleDataSourceMapping> childRuleDataSourceMappings = objectMapper.readValue(ruleNodeRequest.getChildRuleDataSourceMappingsObject(), new TypeReference<Set<RuleDataSourceMapping>>() {
    });
    Set<AlarmConfig> childAlarmConfigs = objectMapper.readValue(ruleNodeRequest.getChildAlarmConfigsObject(), new TypeReference<Set<AlarmConfig>>() {
    });
    Set<RuleVariable> childRuleVariables = objectMapper.readValue(ruleNodeRequest.getChildRuleVariablesObject(), new TypeReference<Set<RuleVariable>>() {
    });
    childRule.setProject(projectInDb);
    childRule.setTemplate(childTemplate);
    childRule.setRuleGroup(ruleGroup);
    Rule savedRule = ruleDao.saveRule(childRule);
    LOGGER.info("Succeed to save child rule. Rule info is {}", savedRule.toString());
    List<AlarmConfig> alarmConfigList = new ArrayList<>();
    for (AlarmConfig alarmConfig : childAlarmConfigs) {
        alarmConfig.setRule(savedRule);
        alarmConfigList.add(alarmConfig);
    }
    List<RuleVariable> ruleVariablesList = new ArrayList<>();
    for (RuleVariable ruleVariable : childRuleVariables) {
        ruleVariable.setRule(savedRule);
        ruleVariablesList.add(ruleVariable);
    }
    List<RuleDataSource> ruleDataSourceList = new ArrayList<>();
    for (RuleDataSource ruleDataSource : childRuleDataSources) {
        ruleDataSource.setProjectId(projectInDb.getId());
        ruleDataSource.setRule(savedRule);
        ruleDataSourceList.add(ruleDataSource);
    }
    savedRule.setAlarmConfigs(new HashSet<>(alarmConfigDao.saveAllAlarmConfig(alarmConfigList)));
    savedRule.setRuleVariables(new HashSet<>(ruleVariableDao.saveAllRuleVariable(ruleVariablesList)));
    savedRule.setRuleDataSources(new HashSet<>(ruleDataSourceDao.saveAllRuleDataSource(ruleDataSourceList)));
    for (RuleDataSourceMapping ruleDataSourceMapping : childRuleDataSourceMappings) {
        ruleDataSourceMapping.setRule(savedRule);
        ruleDataSourceMappingDao.saveRuleDataSourceMapping(ruleDataSourceMapping);
    }
    savedRule.setParentRule(parentRule);
    parentRule.setChildRule(savedRule);
    LOGGER.info("Succeed to import child rule.");
}
Also used : RuleDataSourceMapping(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceMapping) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig) RuleVariable(com.webank.wedatasphere.qualitis.rule.entity.RuleVariable)

Aggregations

Template (com.webank.wedatasphere.qualitis.rule.entity.Template)29 ArrayList (java.util.ArrayList)17 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)13 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)11 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)10 AlarmConfig (com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)9 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)9 TemplateDataSourceType (com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType)9 HashSet (java.util.HashSet)8 TemplateOutputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta)7 TemplateStatisticsInputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateStatisticsInputMeta)6 RuleTemplateResponse (com.webank.wedatasphere.qualitis.rule.response.RuleTemplateResponse)6 List (java.util.List)6 User (com.webank.wedatasphere.qualitis.entity.User)5 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)5 TemplateUser (com.webank.wedatasphere.qualitis.rule.entity.TemplateUser)5 Date (java.util.Date)5 Set (java.util.Set)5 Transactional (org.springframework.transaction.annotation.Transactional)5 Department (com.webank.wedatasphere.qualitis.entity.Department)4