use of com.webank.wedatasphere.qualitis.rule.entity.Rule in project Qualitis by WeBankFinTech.
the class RuleBatchServiceImpl method downloadRules.
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> downloadRules(DownloadRuleRequest request, HttpServletResponse response) throws UnExpectedRequestException, IOException, WriteExcelException, PermissionDeniedRequestException {
// Check Arguments
DownloadRuleRequest.checkRequest(request);
String loginUser = HttpUtils.getUserName(httpServletRequest);
Boolean projectAllRules = request.getProjectId() != null;
List<Rule> ruleLists;
if (projectAllRules) {
LOGGER.info("Downloading all rules of project. project id: {}", request.getProjectId());
Project project = projectDao.findById(request.getProjectId());
if (project == null) {
throw new UnExpectedRequestException("{&PROJECT_ID} {&DOES_NOT_EXIST}");
}
ruleLists = ruleDao.findByProject(project);
} else {
LOGGER.info("Downloading all rules. rule ids: {}", request.getRuleIds());
ruleLists = ruleDao.findByIds(request.getRuleIds());
List<Long> ruleIds = ruleLists.stream().map(Rule::getId).distinct().collect(Collectors.toList());
List<Long> notExistRules = request.getRuleIds().stream().filter(l -> !ruleIds.contains(l)).collect(Collectors.toList());
if (!notExistRules.isEmpty()) {
throw new UnExpectedRequestException("{&THE_IDS_OF_RULE}: " + notExistRules.toString() + " {&DOES_NOT_EXIST}");
}
}
if (ruleLists == null || ruleLists.isEmpty()) {
throw new UnExpectedRequestException("{&NO_RULE_CAN_DOWNLOAD}");
}
// Check permissions of project
List<Integer> permissions = new ArrayList<>();
permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
projectService.checkProjectPermission(ruleLists.iterator().next().getProject(), loginUser, permissions);
LOGGER.info("Succeed to find rules that will be downloaded. rule_ids: {}", ruleLists.stream().map(Rule::getId));
return downloadRulesReal(ruleLists, response, loginUser);
}
use of com.webank.wedatasphere.qualitis.rule.entity.Rule 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.entity.Rule in project Qualitis by WeBankFinTech.
the class RuleBatchServiceImpl method getFileRule.
@Override
public List<ExcelTemplateFileRuleByProject> getFileRule(Iterable<Rule> rules, String localeStr) {
List<ExcelTemplateFileRuleByProject> lines = new ArrayList<>();
for (Rule rule : rules) {
if (!rule.getRuleType().equals(RuleTypeEnum.FILE_TEMPLATE_RULE.getCode())) {
continue;
}
String ruleName = rule.getName();
String ruleCnName = rule.getCnName();
String ruleDetail = rule.getDetail();
String templateName = rule.getTemplate().getName();
ExcelTemplateFileRuleByProject ruleLinePrefix = new ExcelTemplateFileRuleByProject();
ruleLinePrefix.setRuleName(ruleName);
ruleLinePrefix.setRuleCnName(ruleCnName);
ruleLinePrefix.setRuleDetail(ruleDetail);
ruleLinePrefix.setTemplateName(templateName);
ruleLinePrefix.setProjectName(rule.getProject().getName());
ruleLinePrefix.setAbortOnFailure(rule.getAbortOnFailure());
ruleLinePrefix.setRuleGroupName(rule.getRuleGroup().getRuleGroupName());
ruleLinePrefix.setCreateUser(rule.getCreateUser());
ruleLinePrefix.setCreateTime(rule.getCreateTime());
ruleLinePrefix.setModifyUser(rule.getModifyUser());
ruleLinePrefix.setModifyTime(rule.getModifyTime());
ruleLinePrefix.setDeleteFailCheckResult(rule.getDeleteFailCheckResult());
lines.add(ruleLinePrefix);
for (RuleDataSource ruleDataSource : rule.getRuleDataSources()) {
String clusterName = ruleDataSource.getClusterName();
String databaseName = ruleDataSource.getDbName();
String tableName = ruleDataSource.getTableName();
String filter = ruleDataSource.getFilter();
ExcelTemplateFileRuleByProject tmp = new ExcelTemplateFileRuleByProject(rule.getName());
tmp.setClusterName(clusterName);
tmp.setDatabaseName(databaseName);
tmp.setTableName(tableName);
tmp.setFilter(filter);
LOGGER.info("Collect excel line: {}", tmp);
lines.add(tmp);
}
for (AlarmConfig alarmConfig : rule.getAlarmConfigs()) {
Double threshold = alarmConfig.getThreshold();
String alarmCompareType = CompareTypeEnum.getCompareTypeName(alarmConfig.getCompareType());
String alarmOutputName = FileOutputNameEnum.getFileOutputName(alarmConfig.getFileOutputName(), localeStr);
String checkTemplateName = CheckTemplateEnum.getCheckTemplateName(alarmConfig.getCheckTemplate(), localeStr);
String unit = alarmConfig.getFileOutputUnit() == null ? "" : FileOutputUnitEnum.fileOutputUnit(alarmConfig.getFileOutputUnit());
ExcelTemplateFileRuleByProject tmp = new ExcelTemplateFileRuleByProject(rule.getName());
tmp.setUnit(unit);
tmp.setCompareType(alarmCompareType);
tmp.setAlarmCheckName(alarmOutputName);
tmp.setCheckTemplateName(checkTemplateName);
tmp.setThreshold(String.valueOf(threshold));
RuleMetric ruleMetric = alarmConfig.getRuleMetric();
// Recod rule metric info (unique code).
if (ruleMetric != null) {
String enCode = ruleMetric.getEnCode();
tmp.setRuleMetricEnCode(enCode);
tmp.setRuleMetricName(ruleMetric.getName());
}
LOGGER.info("Collect excel line: {}", tmp);
lines.add(tmp);
}
}
return lines;
}
use of com.webank.wedatasphere.qualitis.rule.entity.Rule in project Qualitis by WeBankFinTech.
the class ProjectBatchServiceImpl method getExcelCustomRuleByProject.
private List<ExcelCustomRuleByProject> getExcelCustomRuleByProject(List<Project> projects, String localeStr) {
List<ExcelCustomRuleByProject> excelCustomRuleByProjects = new ArrayList<>();
for (Project project : projects) {
List<Rule> rules = ruleDao.findByProject(project);
List<ExcelCustomRuleByProject> excelCustomRules = ruleBatchService.getCustomRule(rules, localeStr);
for (ExcelCustomRuleByProject excelCustomRule : excelCustomRules) {
ExcelCustomRuleByProject excelCustomRuleByProject = new ExcelCustomRuleByProject();
BeanUtils.copyProperties(excelCustomRule, excelCustomRuleByProject);
excelCustomRuleByProject.setProjectName(project.getName());
LOGGER.info("Collect excel line of custom rule: {}", excelCustomRuleByProject);
excelCustomRuleByProjects.add(excelCustomRuleByProject);
}
}
return excelCustomRuleByProjects;
}
use of com.webank.wedatasphere.qualitis.rule.entity.Rule in project Qualitis by WeBankFinTech.
the class ProjectBatchServiceImpl method getExcelTemplateFileRuleByProject.
private List<ExcelTemplateFileRuleByProject> getExcelTemplateFileRuleByProject(List<Project> projects, String localeStr) {
List<ExcelTemplateFileRuleByProject> excelTemplateFileRuleByProjects = new ArrayList<>();
for (Project project : projects) {
List<Rule> rules = ruleDao.findByProject(project);
List<ExcelTemplateFileRuleByProject> excelTemplateFileRules = ruleBatchService.getFileRule(rules, localeStr);
for (ExcelTemplateFileRuleByProject excelTemplateFileRule : excelTemplateFileRules) {
ExcelTemplateFileRuleByProject excelTemplateFileRuleByProject = new ExcelTemplateFileRuleByProject();
BeanUtils.copyProperties(excelTemplateFileRule, excelTemplateFileRuleByProject);
excelTemplateFileRuleByProject.setProjectName(project.getName());
LOGGER.info("Collect excel line of template rule: {}", excelTemplateFileRuleByProject);
excelTemplateFileRuleByProjects.add(excelTemplateFileRuleByProject);
}
}
return excelTemplateFileRuleByProjects;
}
Aggregations