Search in sources :

Example 1 with RuleDataSourceCount

use of com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceCount in project Qualitis by WeBankFinTech.

the class RuleDataSourceServiceImpl method updateRuleDataSourceCount.

@Override
public void updateRuleDataSourceCount(Rule ruleInDb, Integer varyAmount) {
    Set<RuleDataSource> ruleDataSources = ruleInDb.getRuleDataSources();
    if (ruleDataSources == null || ruleDataSources.isEmpty()) {
        LOGGER.error("Rule does not have ruledatasource.");
        return;
    }
    for (RuleDataSource ruleDataSource : ruleDataSources) {
        StringBuffer datasourceName = new StringBuffer();
        if (StringUtils.isEmpty(ruleDataSource.getTableName()) || StringUtils.isEmpty(ruleDataSource.getColName())) {
            continue;
        }
        if (StringUtils.isNotBlank(ruleDataSource.getColName())) {
            String[] cols = ruleDataSource.getColName().split(SpecCharEnum.VERTICAL_BAR.getValue());
            for (String col : cols) {
                datasourceName.append(ruleDataSource.getClusterName()).append("-").append(ruleDataSource.getDbName()).append("-").append(ruleDataSource.getTableName()).append("-").append(col);
                Long userId = userDao.findByUsername(ruleInDb.getCreateUser()).getId();
                RuleDataSourceCount ruleDataSourceCount = ruleDataSourceCountRepository.findByDatasourceNameAndUserId(datasourceName.toString(), userId);
                if (ruleDataSourceCount == null) {
                    if (varyAmount > 0) {
                        ruleDataSourceCount = new RuleDataSourceCount(datasourceName.toString(), userId);
                        ruleDataSourceCountRepository.save(ruleDataSourceCount);
                    } else {
                        LOGGER.error("Rule datasource ddes not have related rules.");
                    }
                } else {
                    ruleDataSourceCount.setDatasourceCount(ruleDataSourceCount.getDatasourceCount() + varyAmount);
                    ruleDataSourceCountRepository.save(ruleDataSourceCount);
                    LOGGER.info("Rule [{}] count of datasource is: {}", ruleInDb.getName(), ruleDataSourceCount.getDatasourceCount());
                }
                datasourceName.delete(0, datasourceName.length());
            }
        }
    }
}
Also used : RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) RuleDataSourceCount(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceCount)

Aggregations

RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)1 RuleDataSourceCount (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceCount)1