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());
}
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;
}
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;
}
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);
}
}
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);
}
Aggregations