Search in sources :

Example 6 with DataSourceRequest

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;
}
Also used : AddRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddRuleRequest) DataSourceRequest(com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ArrayList(java.util.ArrayList) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) TemplateArgumentRequest(com.webank.wedatasphere.qualitis.rule.request.TemplateArgumentRequest) FileAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest) CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest) AlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest) ExcelTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject)

Example 7 with DataSourceRequest

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;
}
Also used : DataSourceRequest(com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ArrayList(java.util.ArrayList) FileAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup) AddFileRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddFileRuleRequest) ExcelTemplateFileRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateFileRuleByProject)

Example 8 with DataSourceRequest

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);
}
Also used : DataSourceRequest(com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with DataSourceRequest

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;
}
Also used : DataSourceRequest(com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest) DataSourceColumnRequest(com.webank.wedatasphere.qualitis.rule.request.DataSourceColumnRequest) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) ArrayList(java.util.ArrayList)

Aggregations

DataSourceRequest (com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest)9 ArrayList (java.util.ArrayList)8 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)4 DataSourceColumnRequest (com.webank.wedatasphere.qualitis.rule.request.DataSourceColumnRequest)4 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)3 FileAlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest)3 RuleGroup (com.webank.wedatasphere.qualitis.rule.entity.RuleGroup)2 AddFileRuleRequest (com.webank.wedatasphere.qualitis.rule.request.AddFileRuleRequest)2 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)1 ColumnInfoDetail (com.webank.wedatasphere.qualitis.metadata.response.column.ColumnInfoDetail)1 ExcelTemplateFileRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateFileRuleByProject)1 ExcelTemplateRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject)1 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)1 AlarmConfig (com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)1 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)1 AddRuleRequest (com.webank.wedatasphere.qualitis.rule.request.AddRuleRequest)1 AlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest)1 CustomAlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest)1 TemplateArgumentRequest (com.webank.wedatasphere.qualitis.rule.request.TemplateArgumentRequest)1 HashMap (java.util.HashMap)1