use of com.webank.wedatasphere.qualitis.rule.request.multi.AddMultiSourceRuleRequest 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;
}
use of com.webank.wedatasphere.qualitis.rule.request.multi.AddMultiSourceRuleRequest in project Qualitis by WeBankFinTech.
the class RuleBatchServiceImpl method addMultiTemplateRule.
private void addMultiTemplateRule(Map<String, List<ExcelMultiTemplateRuleByProject>> multiRulePartitionedByRuleName, Project project, String userName, boolean aomp) throws UnExpectedRequestException, ClusterInfoNotConfigException, TaskNotExistException, PermissionDeniedRequestException {
Map<String, List<ExcelMultiTemplateRuleByProject>> modifyRulePartitionedByRuleName = new HashMap<>(1);
Map<String, List<ExcelMultiTemplateRuleByProject>> addRulePartitionedByRuleName = new HashMap<>(1);
String localeStr = httpServletRequest.getHeader("Content-Language");
for (Iterator<String> iterator = multiRulePartitionedByRuleName.keySet().iterator(); iterator.hasNext(); ) {
String currentRuleName = iterator.next();
Rule currentRule = ruleDao.findByProjectAndRuleName(project, currentRuleName);
if (currentRule != null) {
modifyRulePartitionedByRuleName.put(currentRuleName, multiRulePartitionedByRuleName.get(currentRuleName));
List<AddMultiSourceRuleRequest> addRuleRequestList = constructAddMultiSourceRuleRequest(modifyRulePartitionedByRuleName, project, localeStr);
ModifyMultiSourceRequest modifyRuleRequest = new ModifyMultiSourceRequest();
modifyRuleRequest.setRuleId(currentRule.getId());
AddMultiSourceRuleRequest addRuleRequest = addRuleRequestList.iterator().next();
BeanUtils.copyProperties(addRuleRequest, modifyRuleRequest);
LOGGER.info("Start to modify multi rule. request: {}", modifyRuleRequest);
if (aomp) {
multiSourceRuleService.modifyRuleDetailForOuter(modifyRuleRequest, userName);
} else {
multiSourceRuleService.modifyMultiSourceRule(modifyRuleRequest);
}
LOGGER.info("Success to modify multi rule.");
modifyRulePartitionedByRuleName.clear();
} else {
addRulePartitionedByRuleName.put(currentRuleName, multiRulePartitionedByRuleName.get(currentRuleName));
List<AddMultiSourceRuleRequest> addRuleRequestList = constructAddMultiSourceRuleRequest(addRulePartitionedByRuleName, project, localeStr);
AddMultiSourceRuleRequest currentAddMultiSourceRuleRequest = addRuleRequestList.iterator().next();
LOGGER.info("Start to add multi rule. request: {}", currentAddMultiSourceRuleRequest);
if (aomp) {
currentAddMultiSourceRuleRequest.setLoginUser(userName);
multiSourceRuleService.addRuleForOuter(currentAddMultiSourceRuleRequest, true);
} else {
multiSourceRuleService.addMultiSourceRuleForUpload(currentAddMultiSourceRuleRequest, true);
}
LOGGER.info("Success to add multi rule.");
addRulePartitionedByRuleName.clear();
}
}
}
Aggregations