use of com.webank.wedatasphere.qualitis.rule.request.AddRuleRequest in project Qualitis by WeBankFinTech.
the class RuleBatchServiceImpl method addTemplateRule.
private void addTemplateRule(Map<String, List<ExcelTemplateRuleByProject>> rulePartitionedByRuleName, Project project, String userName, boolean aomp) throws UnExpectedRequestException, TaskNotExistException, ClusterInfoNotConfigException, PermissionDeniedRequestException {
Map<String, List<ExcelTemplateRuleByProject>> modifyRulePartitionedByRuleName = new HashMap<>(1);
Map<String, List<ExcelTemplateRuleByProject>> addRulePartitionedByRuleName = new HashMap<>(1);
String localeStr = httpServletRequest.getHeader("Content-Language");
for (Iterator<String> iterator = rulePartitionedByRuleName.keySet().iterator(); iterator.hasNext(); ) {
String currentRuleName = iterator.next();
Rule currentRule = ruleDao.findByProjectAndRuleName(project, currentRuleName);
if (currentRule != null) {
modifyRulePartitionedByRuleName.put(currentRuleName, rulePartitionedByRuleName.get(currentRuleName));
List<AddRuleRequest> addRuleRequestList = constructAddRuleRequest(modifyRulePartitionedByRuleName, project, localeStr);
ModifyRuleRequest modifyRuleRequest = new ModifyRuleRequest();
modifyRuleRequest.setRuleId(currentRule.getId());
AddRuleRequest addRuleRequest = addRuleRequestList.iterator().next();
BeanUtils.copyProperties(addRuleRequest, modifyRuleRequest);
LOGGER.info("Start to modify template rule. request: {}", modifyRuleRequest);
if (aomp) {
ruleService.modifyRuleDetailForOuter(modifyRuleRequest, userName);
} else {
ruleService.modifyRuleDetail(modifyRuleRequest);
}
LOGGER.info("Succeed to modify template rule.");
modifyRulePartitionedByRuleName.clear();
} else {
addRulePartitionedByRuleName.put(currentRuleName, rulePartitionedByRuleName.get(currentRuleName));
List<AddRuleRequest> addRuleRequestList = constructAddRuleRequest(addRulePartitionedByRuleName, project, localeStr);
AddRuleRequest currentAddRuleRequest = addRuleRequestList.iterator().next();
LOGGER.info("Start to add template rule. request: {}", currentAddRuleRequest);
if (aomp) {
ruleService.addRuleForOuter(currentAddRuleRequest, userName);
} else {
ruleService.addRuleForUpload(currentAddRuleRequest);
}
LOGGER.info("Succeed to add template rule.");
addRulePartitionedByRuleName.clear();
}
}
}
use of com.webank.wedatasphere.qualitis.rule.request.AddRuleRequest in project Qualitis by WeBankFinTech.
the class RuleNodeServiceImpl method copyRuleByRuleGroupId.
@Override
public GeneralResponse<RuleResponse> copyRuleByRuleGroupId(CopyRuleRequest request) throws UnExpectedRequestException, PermissionDeniedRequestException {
CopyRuleRequest.checkRequest(request);
Long ruleGroupId = request.getSourceRuleGroupId();
RuleGroup ruleGroupInDb = ruleGroupDao.findById(request.getSourceRuleGroupId());
int totalFinish = 0;
RuleGroup targetRuleGroup;
if (request.getTargetRuleGroupId() != null) {
RuleGroup targetRuleGroupInDb = ruleGroupDao.findById(request.getTargetRuleGroupId());
if (targetRuleGroupInDb != null) {
targetRuleGroup = targetRuleGroupInDb;
} else {
throw new UnExpectedRequestException("Rule group id is illegal.");
}
} else {
RuleGroup currentRuleGroup = new RuleGroup("Group_" + UUID.randomUUID().toString().replace("-", ""), request.getTargetProjectId() != null ? request.getTargetProjectId() : ruleGroupInDb.getProjectId());
currentRuleGroup.setVersion(request.getVersion());
targetRuleGroup = ruleGroupDao.saveRuleGroup(currentRuleGroup);
}
if (ruleGroupId != null) {
LOGGER.info("Start to copy rules of rule group[ID=" + ruleGroupId + "].");
if (ruleGroupInDb == null) {
throw new UnExpectedRequestException("Rule group {&DOES_NOT_EXIST}");
}
List<Rule> rules = ruleDao.findByRuleGroup(ruleGroupInDb);
for (Rule rule : rules) {
switch(rule.getRuleType().intValue()) {
case 1:
AddRuleRequest addRuleRequest = constructSingleRequest(rule, targetRuleGroup);
ruleService.addRuleForOuter(addRuleRequest, request.getCreateUser());
totalFinish++;
break;
case 2:
AddCustomRuleRequest addCustomRuleRequest = constructCustomRequest(rule, targetRuleGroup);
customRuleService.addRuleForOuter(addCustomRuleRequest, request.getCreateUser());
totalFinish++;
break;
case 3:
AddMultiSourceRuleRequest addMultiSourceRuleRequest = constructMultiRequest(rule, targetRuleGroup);
addMultiSourceRuleRequest.setLoginUser(request.getCreateUser());
multiSourceRuleService.addRuleForOuter(addMultiSourceRuleRequest, false);
totalFinish++;
break;
case 4:
AddFileRuleRequest addFileRuleRequest = constructFileRequest(rule, targetRuleGroup);
fileRuleService.addRuleForOuter(addFileRuleRequest, request.getCreateUser());
totalFinish++;
break;
default:
}
}
if (totalFinish != rules.size()) {
return new GeneralResponse<>("200", "{©_RULE_FAILED}", new RuleResponse(targetRuleGroup.getId()));
}
} else if (CollectionUtils.isNotEmpty(request.getSourceRuleIdList())) {
}
return new GeneralResponse<>("200", "{©_RULE_SUCCESSFULLY}", new RuleResponse(targetRuleGroup.getId()));
}
use of com.webank.wedatasphere.qualitis.rule.request.AddRuleRequest in project Qualitis by WeBankFinTech.
the class RuleNodeServiceImpl method constructSingleRequest.
private AddRuleRequest constructSingleRequest(Rule rule, RuleGroup ruleGroup) {
AddRuleRequest addRuleRequest = new AddRuleRequest();
String newVersion = ruleGroup.getVersion();
if (StringUtils.isEmpty(newVersion)) {
String newRuleName = rule.getName() + "_copy_" + ruleGroup.getId();
LOGGER.info("Single rule start to be copied. Copied rule name: " + newRuleName);
addRuleRequest.setRuleName(newRuleName);
if (StringUtils.isNotBlank(rule.getCnName())) {
addRuleRequest.setRuleCnName(rule.getCnName() + "_副本");
}
} else {
String oldVersion = rule.getRuleGroup().getVersion();
LOGGER.info("Single rule start to be copied. Copied rule name: " + rule.getName() + "_" + ruleGroup.getVersion());
if (StringUtils.isNotBlank(oldVersion) && rule.getName().endsWith(oldVersion)) {
addRuleRequest.setRuleName(rule.getName().replace(oldVersion, newVersion));
if (StringUtils.isNotBlank(rule.getCnName())) {
addRuleRequest.setRuleCnName(rule.getCnName().replace(oldVersion, newVersion));
}
} else {
addRuleRequest.setRuleName(rule.getName() + "_" + newVersion);
if (StringUtils.isNotBlank(rule.getCnName())) {
addRuleRequest.setRuleCnName(rule.getCnName() + "_" + newVersion);
}
}
}
addRuleRequest.setRuleDetail(rule.getDetail());
addRuleRequest.setRuleTemplateId(rule.getTemplate().getId());
addRuleRequest.setAlarm(true);
addRuleRequest.setAlarmVariable(constructAlarmConfigRequest(rule.getAlarmConfigs()));
addRuleRequest.setTemplateArgumentRequests(constructTemplateArgumentRequest(rule));
addRuleRequest.setDatasource(constructDataSourceRequest(rule.getRuleDataSources()));
addRuleRequest.setProjectId(ruleGroup.getProjectId());
addRuleRequest.setRuleGroupId(ruleGroup.getId());
addRuleRequest.setCsId(rule.getCsId());
addRuleRequest.setAbortOnFailure(rule.getAbortOnFailure());
addRuleRequest.setDeleteFailCheckResult(rule.getDeleteFailCheckResult());
addRuleRequest.setSpecifyStaticStartupParam(rule.getSpecifyStaticStartupParam());
addRuleRequest.setStaticStartupParam(rule.getStaticStartupParam());
return addRuleRequest;
}
use of com.webank.wedatasphere.qualitis.rule.request.AddRuleRequest 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;
}
Aggregations