use of com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest 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;
}
use of com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest in project Qualitis by WeBankFinTech.
the class RuleBatchServiceImpl method constructAddFileRuleRequest.
private List<AddFileRuleRequest> constructAddFileRuleRequest(Map<String, List<ExcelTemplateFileRuleByProject>> fileRulePartitionedByRuleName, Project project, String localeStr) throws UnExpectedRequestException {
List<AddFileRuleRequest> addFileRuleRequests = new ArrayList<>();
for (String ruleName : fileRulePartitionedByRuleName.keySet()) {
List<ExcelTemplateFileRuleByProject> ruleInfos = fileRulePartitionedByRuleName.get(ruleName);
ExcelTemplateFileRuleByProject firstCommonInfo = ruleInfos.get(0);
AddFileRuleRequest addFileRuleRequest = new AddFileRuleRequest();
String ruleGroupName = firstCommonInfo.getRuleGroupName();
if (StringUtils.isBlank(ruleGroupName)) {
throw new UnExpectedRequestException("RuleGroupName {&CAN_NOT_BE_NULL_OR_EMPTY}");
}
boolean alarm = false;
List<FileAlarmConfigRequest> alarmConfigRequests = new ArrayList<>();
DataSourceRequest dataSourceRequest = new DataSourceRequest();
Long projectId = project.getId();
for (ExcelTemplateFileRuleByProject excelTemplateFileRule : ruleInfos) {
getDataFileSourceRequest(dataSourceRequest, excelTemplateFileRule);
getFileAlarmConfig(alarmConfigRequests, excelTemplateFileRule, localeStr);
}
RuleGroup ruleGroupInDb = ruleGroupDao.findByRuleGroupNameAndProjectId(ruleGroupName, projectId);
if (ruleGroupInDb != null) {
addFileRuleRequest.setRuleGroupId(ruleGroupInDb.getId());
} else {
RuleGroup ruleGroup = ruleGroupDao.saveRuleGroup(new RuleGroup(ruleGroupName, project.getId()));
addFileRuleRequest.setRuleGroupId(ruleGroup.getId());
}
// Construct addRuleRequest
addFileRuleRequest.setRuleName(ruleName);
addFileRuleRequest.setRuleDetail(firstCommonInfo.getRuleDetail());
addFileRuleRequest.setAbortOnFailure(firstCommonInfo.getAbortOnFailure());
if (!alarmConfigRequests.isEmpty()) {
alarm = true;
}
addFileRuleRequest.setAlarm(alarm);
addFileRuleRequest.setAlarmVariable(alarmConfigRequests);
addFileRuleRequest.setDatasource(dataSourceRequest);
addFileRuleRequest.setProjectId(projectId);
addFileRuleRequests.add(addFileRuleRequest);
}
return addFileRuleRequests;
}
use of com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest in project Qualitis by WeBankFinTech.
the class RuleDataSourceServiceImpl method checkAndSaveRuleDataSource.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public List<RuleDataSource> checkAndSaveRuleDataSource(List<DataSourceRequest> requests, Rule rule, boolean cs, String loginUser) throws UnExpectedRequestException {
List<RuleDataSource> ruleDataSources = new ArrayList<>();
for (DataSourceRequest request : requests) {
RuleDataSource newRuleDataSource = new RuleDataSource();
// Check Arguments
DataSourceRequest.checkRequest(request, cs, false);
if (StringUtils.isNotBlank(request.getLinkisDataSourceType())) {
newRuleDataSource.setDatasourceType(TemplateDataSourceTypeEnum.getCode(request.getLinkisDataSourceType()));
newRuleDataSource.setLinkisDataSourceVersionId(request.getLinkisDataSourceVersionId());
newRuleDataSource.setLinkisDataSourceName(request.getLinkisDataSourceName());
newRuleDataSource.setLinkisDataSourceId(request.getLinkisDataSourceId());
}
newRuleDataSource.setClusterName(request.getClusterName());
newRuleDataSource.setTableName(request.getTableName());
newRuleDataSource.setDbName(request.getDbName());
newRuleDataSource.setFilter(request.getFilter());
// Saved as: field1: type1, field2: type2
newRuleDataSource.setBlackColName(request.getBlackList());
newRuleDataSource.setProxyUser(request.getProxyUser());
String joinCols = joinColNames(request.getColNames());
newRuleDataSource.setColName(joinCols);
newRuleDataSource.setRule(rule);
if (rule.getTemplate().getTemplateType().equals(RuleTemplateTypeEnum.MULTI_SOURCE_TEMPLATE.getCode())) {
newRuleDataSource.setDatasourceIndex(request.getDatasourceIndex());
}
newRuleDataSource.setProjectId(rule.getProject().getId());
ruleDataSources.add(newRuleDataSource);
LOGGER.info("Succeed to save rule_datasource. rule_datasource: {}", newRuleDataSource);
}
LOGGER.info("Succeed to save all rule_datasource.");
return ruleDatasourceDao.saveAllRuleDataSource(ruleDataSources);
}
use of com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest in project Qualitis by WeBankFinTech.
the class RuleNodeServiceImpl method constructDataSourceRequest.
private List<DataSourceRequest> constructDataSourceRequest(Set<RuleDataSource> ruleDataSources) {
List<DataSourceRequest> dataSourceRequests = new ArrayList<>(ruleDataSources.size());
for (RuleDataSource ruleDataSource : ruleDataSources) {
DataSourceRequest dataSourceRequest = new DataSourceRequest();
if (ruleDataSource.getLinkisDataSourceId() != null) {
dataSourceRequest.setLinkisDataSourceId(ruleDataSource.getLinkisDataSourceId());
dataSourceRequest.setLinkisDataSourceName(ruleDataSource.getLinkisDataSourceName());
dataSourceRequest.setLinkisDataSourceType(TemplateDataSourceTypeEnum.getMessage(ruleDataSource.getDatasourceType()));
}
dataSourceRequest.setClusterName(ruleDataSource.getClusterName());
dataSourceRequest.setBlackList(ruleDataSource.getBlackColName());
dataSourceRequest.setProxyUser(ruleDataSource.getProxyUser());
dataSourceRequest.setTableName(ruleDataSource.getTableName());
dataSourceRequest.setDbName(ruleDataSource.getDbName());
dataSourceRequest.setFilter(ruleDataSource.getFilter());
String colNamesOrigin = ruleDataSource.getColName();
List<DataSourceColumnRequest> dataSourceColumnRequests = new ArrayList<>();
if (!StringUtils.isBlank(colNamesOrigin)) {
String[] colNamesSplit = colNamesOrigin.split(SpecCharEnum.VERTICAL_BAR.getValue());
for (String str : colNamesSplit) {
DataSourceColumnRequest dataSourceColumnRequest = new DataSourceColumnRequest();
dataSourceColumnRequest.setColumnName(str.split(":")[0]);
dataSourceColumnRequest.setDataType(str.split(":")[1]);
dataSourceColumnRequests.add(dataSourceColumnRequest);
}
}
dataSourceRequest.setColNames(dataSourceColumnRequests);
dataSourceRequests.add(dataSourceRequest);
}
return dataSourceRequests;
}
Aggregations