Search in sources :

Example 1 with RuleGroup

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

the class FileRuleServiceImpl method addRuleReal.

private GeneralResponse<RuleResponse> addRuleReal(AddFileRuleRequest request, String loginUser) throws UnExpectedRequestException, PermissionDeniedRequestException {
    // Check Arguments
    AddFileRuleRequest.checkRequest(request, false);
    // Generate Template, TemplateOutputMeta and save
    Template template = ruleTemplateService.addFileTemplate(request);
    // Check existence of project
    Project projectInDb = projectService.checkProjectExistence(request.getProjectId(), loginUser);
    String nowDate = ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date());
    // Check permissions of project
    List<Integer> permissions = new ArrayList<>();
    permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
    projectService.checkProjectPermission(projectInDb, loginUser, permissions);
    // Check unique of rule name
    ruleService.checkRuleName(request.getRuleName(), projectInDb, null);
    // Check cluster support
    ruleDataSourceService.checkDataSourceClusterSupport(request.getDatasource().getClusterName());
    RuleGroup ruleGroup;
    if (request.getRuleGroupId() != null) {
        ruleGroup = ruleGroupDao.findById(request.getRuleGroupId());
        if (ruleGroup == null) {
            throw new UnExpectedRequestException(String.format("Rule Group: %s {&DOES_NOT_EXIST}", request.getRuleGroupId()));
        }
    } else {
        ruleGroup = ruleGroupDao.saveRuleGroup(new RuleGroup("Group_" + UUID.randomUUID().toString().replace("-", ""), projectInDb.getId()));
    }
    // Save rule.
    Rule newRule = new Rule();
    newRule.setRuleType(RuleTypeEnum.FILE_TEMPLATE_RULE.getCode());
    newRule.setTemplate(template);
    newRule.setName(request.getRuleName());
    newRule.setCnName(request.getRuleCnName());
    newRule.setDetail(request.getRuleDetail());
    newRule.setAlarm(request.getAlarm());
    newRule.setProject(projectInDb);
    newRule.setRuleTemplateName(template.getName());
    newRule.setRuleGroup(ruleGroup);
    newRule.setAbortOnFailure(request.getAbortOnFailure());
    newRule.setCreateUser(loginUser);
    newRule.setCreateTime(nowDate);
    String csId = request.getCsId();
    boolean cs = false;
    if (StringUtils.isNotBlank(csId)) {
        newRule.setCsId(csId);
        cs = true;
    }
    Rule savedRule = ruleDao.saveRule(newRule);
    LOGGER.info("Succeed to save file rule, rule_id: {}", savedRule.getId());
    List<AlarmConfig> savedAlarmConfigs = new ArrayList<>();
    if (request.getAlarm()) {
        savedAlarmConfigs = alarmConfigService.checkAndSaveFileAlarmVariable(request.getAlarmVariable(), savedRule);
        LOGGER.info("Succeed to save alarm_configs, alarm_configs: {}", savedAlarmConfigs);
    }
    List<RuleDataSource> ruleDataSources = new ArrayList<>();
    ruleDataSources.add(ruleDataSourceService.checkAndSaveFileRuleDataSource(request.getDatasource(), savedRule, cs));
    savedRule.setAlarmConfigs(new HashSet<>(savedAlarmConfigs));
    savedRule.setRuleDataSources(new HashSet<>(ruleDataSources));
    // Update rule count of datasource
    ruleDataSourceService.updateRuleDataSourceCount(savedRule, 1);
    RuleResponse response = new RuleResponse(savedRule);
    LOGGER.info("Succeed to add file rule, rule_id: {}", savedRule.getId());
    return new GeneralResponse<>("200", "{&SUCCEED_TO_ADD_FILE_RULE}", response);
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) RuleResponse(com.webank.wedatasphere.qualitis.rule.response.RuleResponse) ArrayList(java.util.ArrayList) Date(java.util.Date) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) Project(com.webank.wedatasphere.qualitis.project.entity.Project) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)

Example 2 with RuleGroup

use of com.webank.wedatasphere.qualitis.rule.entity.RuleGroup 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", "{&COPY_RULE_FAILED}", new RuleResponse(targetRuleGroup.getId()));
        }
    } else if (CollectionUtils.isNotEmpty(request.getSourceRuleIdList())) {
    }
    return new GeneralResponse<>("200", "{&COPY_RULE_SUCCESSFULLY}", new RuleResponse(targetRuleGroup.getId()));
}
Also used : AddRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddRuleRequest) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) AddCustomRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddCustomRuleRequest) AddFileRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddFileRuleRequest) RuleResponse(com.webank.wedatasphere.qualitis.rule.response.RuleResponse) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup) AddMultiSourceRuleRequest(com.webank.wedatasphere.qualitis.rule.request.multi.AddMultiSourceRuleRequest)

Example 3 with RuleGroup

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

the class RuleNodeServiceImpl method importRuleGroup.

@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<RuleResponse> importRuleGroup(RuleNodeRequests ruleNodeRequests) throws UnExpectedRequestException, IOException, PermissionDeniedRequestException {
    // Project, rule group.
    Project projectInDb = projectDao.findById(ruleNodeRequests.getNewProjectId());
    ObjectMapper objectMapper = new ObjectMapper();
    RuleGroup ruleGroup = objectMapper.readValue(ruleNodeRequests.getRuleNodeRequests().iterator().next().getRuleGroupObject(), RuleGroup.class);
    RuleGroup ruleGroupInDb = ruleGroupDao.saveRuleGroup(new RuleGroup(ruleGroup.getRuleGroupName(), projectInDb.getId()));
    if (DEV_CENTER.equals(localConfig.getCenter())) {
        CopyRuleRequest copyRuleRequest = new CopyRuleRequest();
        copyRuleRequest.setSourceRuleGroupId(ruleGroup.getId());
        copyRuleRequest.setCreateUser(projectInDb.getCreateUser());
        copyRuleRequest.setTargetRuleGroupId(ruleGroupInDb.getId());
        copyRuleRequest.setTargetProjectId(ruleNodeRequests.getNewProjectId());
        copyRuleByRuleGroupId(copyRuleRequest);
        return new GeneralResponse<>("200", "{&IMPORT_RULE_SUCCESSFULLY}", new RuleResponse(ruleGroupInDb.getId()));
    }
    if (projectInDb != null) {
        LOGGER.info("Project info : {}", projectInDb.toString());
    } else {
        // For special case:
        // A project already exists in DSS. when creating a workflow in this project and publish it, Qualitis service cannot find the project.
        // Because Qualitis did not run when this project had been created in DSS.
        LOGGER.info("Start to create workflow project. Project[id = {}] is not exist.", ruleNodeRequests.getNewProjectId());
        String userName = ruleNodeRequests.getUserName();
        User currentUser = userDao.findByUsername(userName);
        if (currentUser == null) {
            LOGGER.info("Start to create user. User name is {}", userName);
            try {
                userService.autoAddUser(userName);
                currentUser = userDao.findByUsername(userName);
            } catch (RoleNotFoundException e) {
                LOGGER.error("Role cannot be found. Exception: {}", e);
            }
        }
        Project newProject = projectService.addProjectReal(currentUser.getId(), currentUser.getUserName() + "_project_" + UUID.randomUUID().toString(), currentUser.getUserName() + "_项目_" + UUID.randomUUID().toString(), "Auto created.");
        newProject.setProjectType(ProjectTypeEnum.WORKFLOW_PROJECT.getCode());
        projectInDb = projectDao.saveProject(newProject);
        LOGGER.info("Succeed to create project. New project: {}", projectInDb.toString());
    }
    for (RuleNodeRequest request : ruleNodeRequests.getRuleNodeRequests()) {
        importRule(request, projectInDb, ruleGroupInDb, objectMapper);
    }
    return new GeneralResponse<>("200", "{&IMPORT_RULE_SUCCESSFULLY}", new RuleResponse(ruleGroupInDb.getId()));
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) Project(com.webank.wedatasphere.qualitis.project.entity.Project) ExcelMultiTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject) ExcelTemplateFileRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateFileRuleByProject) User(com.webank.wedatasphere.qualitis.entity.User) RuleNodeRequest(com.webank.wedatasphere.qualitis.rule.request.RuleNodeRequest) RuleResponse(com.webank.wedatasphere.qualitis.rule.response.RuleResponse) RoleNotFoundException(javax.management.relation.RoleNotFoundException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup) CopyRuleRequest(com.webank.wedatasphere.qualitis.rule.request.CopyRuleRequest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with RuleGroup

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

the class RuleNodeServiceImpl method constructMultiRequest.

private AddMultiSourceRuleRequest constructMultiRequest(Rule rule, RuleGroup ruleGroup) {
    AddMultiSourceRuleRequest addMultiSourceRuleRequest = new AddMultiSourceRuleRequest();
    String newVersion = ruleGroup.getVersion();
    if (StringUtils.isEmpty(newVersion)) {
        String newRuleName = rule.getName() + "_copy_" + ruleGroup.getId();
        LOGGER.info("Multi rule start to be copied. Copied rule name: " + newRuleName);
        addMultiSourceRuleRequest.setRuleName(newRuleName);
        if (StringUtils.isNotBlank(rule.getCnName())) {
            addMultiSourceRuleRequest.setRuleCnName(rule.getCnName() + "_副本");
        }
    } else {
        String oldVersion = rule.getRuleGroup().getVersion();
        LOGGER.info("Multi rule start to be copied. Copied rule name: " + rule.getName() + "_" + ruleGroup.getVersion());
        if (StringUtils.isNotBlank(oldVersion) && rule.getName().endsWith(oldVersion)) {
            addMultiSourceRuleRequest.setRuleName(rule.getName().replace(oldVersion, newVersion));
            if (StringUtils.isNotBlank(rule.getCnName())) {
                addMultiSourceRuleRequest.setRuleCnName(rule.getCnName().replace(oldVersion, newVersion));
            }
        } else {
            addMultiSourceRuleRequest.setRuleName(rule.getName() + "_" + newVersion);
            if (StringUtils.isNotBlank(rule.getCnName())) {
                addMultiSourceRuleRequest.setRuleCnName(rule.getCnName() + "_" + newVersion);
            }
        }
    }
    String ruleDetail = rule.getDetail();
    String clusterName = rule.getRuleDataSources().iterator().next().getClusterName();
    addMultiSourceRuleRequest.setAbortOnFailure(rule.getAbortOnFailure());
    addMultiSourceRuleRequest.setClusterName(clusterName);
    addMultiSourceRuleRequest.setRuleDetail(ruleDetail);
    addMultiSourceRuleRequest.setCsId(rule.getCsId());
    addMultiSourceRuleRequest.setSpecifyStaticStartupParam(rule.getSpecifyStaticStartupParam());
    addMultiSourceRuleRequest.setDeleteFailCheckResult(rule.getDeleteFailCheckResult());
    addMultiSourceRuleRequest.setMultiSourceRuleTemplateId(rule.getTemplate().getId());
    addMultiSourceRuleRequest.setStaticStartupParam(rule.getStaticStartupParam());
    addMultiSourceRuleRequest.setProjectId(ruleGroup.getProjectId());
    addMultiSourceRuleRequest.setRuleGroupId(ruleGroup.getId());
    List<RuleVariable> filterRuleVariable = rule.getRuleVariables().stream().filter(ruleVariable -> ruleVariable.getTemplateMidTableInputMeta().getInputType().equals(TemplateInputTypeEnum.CONDITION.getCode())).collect(Collectors.toList());
    if (filterRuleVariable != null && filterRuleVariable.size() != 0) {
        addMultiSourceRuleRequest.setFilter(filterRuleVariable.iterator().next().getValue());
    }
    // Data source request
    for (RuleDataSource ruleDataSource : rule.getRuleDataSources()) {
        String databaseName = ruleDataSource.getDbName();
        String tableName = ruleDataSource.getTableName();
        String filter = ruleDataSource.getFilter();
        Integer datasourceIndex = ruleDataSource.getDatasourceIndex();
        MultiDataSourceConfigRequest dataSourceConfigRequest = new MultiDataSourceConfigRequest();
        dataSourceConfigRequest.setDbName(databaseName);
        dataSourceConfigRequest.setTableName(tableName);
        dataSourceConfigRequest.setFilter(filter);
        dataSourceConfigRequest.setProxyUser(ruleDataSource.getProxyUser());
        if (ruleDataSource.getLinkisDataSourceId() != null) {
            dataSourceConfigRequest.setLinkisDataSourceType(TemplateDataSourceTypeEnum.getMessage(ruleDataSource.getDatasourceType()));
            dataSourceConfigRequest.setLinkisDataSourceName(ruleDataSource.getLinkisDataSourceName());
            dataSourceConfigRequest.setLinkisDataSourceId(ruleDataSource.getLinkisDataSourceId());
        }
        if (datasourceIndex == 0) {
            addMultiSourceRuleRequest.setSource(dataSourceConfigRequest);
        } else {
            addMultiSourceRuleRequest.setTarget(dataSourceConfigRequest);
        }
    }
    // Mapping
    List<MultiDataSourceJoinConfigRequest> mappings = new ArrayList<>();
    for (RuleDataSourceMapping mapping : rule.getRuleDataSourceMappings()) {
        MultiDataSourceJoinConfigRequest multiDataSourceJoinConfigRequest = new MultiDataSourceJoinConfigRequest();
        multiDataSourceJoinConfigRequest.setOperation(mapping.getOperation());
        multiDataSourceJoinConfigRequest.setLeftStatement(mapping.getLeftStatement());
        multiDataSourceJoinConfigRequest.setRightStatement(mapping.getRightStatement());
        List<MultiDataSourceJoinColumnRequest> left = getMultiDataSourceJoinColumnRequest(mapping.getLeftColumnNames(), mapping.getLeftColumnTypes());
        List<MultiDataSourceJoinColumnRequest> right = getMultiDataSourceJoinColumnRequest(mapping.getRightColumnNames(), mapping.getLeftColumnTypes());
        multiDataSourceJoinConfigRequest.setLeft(left);
        multiDataSourceJoinConfigRequest.setRight(right);
        mappings.add(multiDataSourceJoinConfigRequest);
    }
    addMultiSourceRuleRequest.setMappings(mappings);
    List<AlarmConfigRequest> alarmConfigRequests = constructAlarmConfigRequest(rule.getAlarmConfigs());
    addMultiSourceRuleRequest.setAlarm(true);
    addMultiSourceRuleRequest.setAlarmVariable(alarmConfigRequests);
    return addMultiSourceRuleRequest;
}
Also used : RuleDataSourceMappingDao(com.webank.wedatasphere.qualitis.rule.dao.RuleDataSourceMappingDao) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) TemplateOutputMetaService(com.webank.wedatasphere.qualitis.rule.service.TemplateOutputMetaService) Autowired(org.springframework.beans.factory.annotation.Autowired) JsonProcessingException(org.codehaus.jackson.JsonProcessingException) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig) RuleMetricDao(com.webank.wedatasphere.qualitis.dao.RuleMetricDao) DeleteRuleRequest(com.webank.wedatasphere.qualitis.rule.request.DeleteRuleRequest) OuterWorkflowService(com.webank.wedatasphere.qualitis.project.service.OuterWorkflowService) MultiDataSourceConfigRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceConfigRequest) RuleNodeRequests(com.webank.wedatasphere.qualitis.rule.request.RuleNodeRequests) FileOutputUnitEnum(com.webank.wedatasphere.qualitis.rule.constant.FileOutputUnitEnum) TemplateMidTableInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta) AddMultiSourceRuleRequest(com.webank.wedatasphere.qualitis.rule.request.multi.AddMultiSourceRuleRequest) Set(java.util.Set) TemplateDataSourceType(com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType) DataSourceRequest(com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest) TemplateMidTableInputMetaService(com.webank.wedatasphere.qualitis.rule.service.TemplateMidTableInputMetaService) TypeReference(org.codehaus.jackson.type.TypeReference) RuleDataSourceMappingService(com.webank.wedatasphere.qualitis.rule.service.RuleDataSourceMappingService) RuleNodeRequest(com.webank.wedatasphere.qualitis.rule.request.RuleNodeRequest) TemplateStatisticsInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateStatisticsInputMeta) FileAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest) TemplateArgumentRequest(com.webank.wedatasphere.qualitis.rule.request.TemplateArgumentRequest) Project(com.webank.wedatasphere.qualitis.project.entity.Project) RuleDataSourceDao(com.webank.wedatasphere.qualitis.rule.dao.RuleDataSourceDao) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) ProjectDao(com.webank.wedatasphere.qualitis.project.dao.ProjectDao) ArrayList(java.util.ArrayList) TemplateDataSourceTypeDao(com.webank.wedatasphere.qualitis.rule.dao.TemplateDataSourceTypeDao) CheckTemplateEnum(com.webank.wedatasphere.qualitis.rule.constant.CheckTemplateEnum) Service(org.springframework.stereotype.Service) TemplateStatisticsInputMetaService(com.webank.wedatasphere.qualitis.rule.service.TemplateStatisticsInputMetaService) RuleTemplateService(com.webank.wedatasphere.qualitis.rule.service.RuleTemplateService) RuleVariableService(com.webank.wedatasphere.qualitis.rule.service.RuleVariableService) RoleService(com.webank.wedatasphere.qualitis.service.RoleService) DataSourceColumnRequest(com.webank.wedatasphere.qualitis.rule.request.DataSourceColumnRequest) CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest) IOException(java.io.IOException) FileRuleService(com.webank.wedatasphere.qualitis.rule.service.FileRuleService) TemplateInputTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.TemplateInputTypeEnum) MultiSourceRuleService(com.webank.wedatasphere.qualitis.rule.service.MultiSourceRuleService) TemplateDataSourceTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.TemplateDataSourceTypeEnum) RuleMetricDepartmentUserDao(com.webank.wedatasphere.qualitis.dao.RuleMetricDepartmentUserDao) UserDao(com.webank.wedatasphere.qualitis.dao.UserDao) RuleNodeService(com.webank.wedatasphere.qualitis.rule.service.RuleNodeService) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) LocalConfig(com.webank.wedatasphere.qualitis.LocalConfig) LoggerFactory(org.slf4j.LoggerFactory) TemplateMidTableUtil(com.webank.wedatasphere.qualitis.rule.util.TemplateMidTableUtil) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) JsonNode(org.codehaus.jackson.JsonNode) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) ParseException(org.apache.hadoop.hive.ql.parse.ParseException) RuleGroupDao(com.webank.wedatasphere.qualitis.rule.dao.RuleGroupDao) ProjectService(com.webank.wedatasphere.qualitis.project.service.ProjectService) AddCustomRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddCustomRuleRequest) AlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest) ExcelMultiTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject) TemplateOutputMetaDao(com.webank.wedatasphere.qualitis.rule.dao.TemplateOutputMetaDao) MappingOperationEnum(com.webank.wedatasphere.qualitis.rule.constant.MappingOperationEnum) InputActionStepEnum(com.webank.wedatasphere.qualitis.rule.constant.InputActionStepEnum) CustomRuleService(com.webank.wedatasphere.qualitis.rule.service.CustomRuleService) UuidGenerator(com.webank.wedatasphere.qualitis.util.UuidGenerator) CopyRuleRequest(com.webank.wedatasphere.qualitis.rule.request.CopyRuleRequest) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) RuleDataSourceMapping(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceMapping) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) RuleService(com.webank.wedatasphere.qualitis.rule.service.RuleService) List(java.util.List) RoleNotFoundException(javax.management.relation.RoleNotFoundException) AlarmConfigDao(com.webank.wedatasphere.qualitis.rule.dao.AlarmConfigDao) CommonChecker(com.webank.wedatasphere.qualitis.project.request.CommonChecker) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) RuleNodeResponses(com.webank.wedatasphere.qualitis.rule.response.RuleNodeResponses) RuleNodeResponse(com.webank.wedatasphere.qualitis.rule.response.RuleNodeResponse) AlarmConfigService(com.webank.wedatasphere.qualitis.rule.service.AlarmConfigService) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup) SpecCharEnum(com.webank.wedatasphere.qualitis.constant.SpecCharEnum) RuleVariableDao(com.webank.wedatasphere.qualitis.rule.dao.RuleVariableDao) RuleVariable(com.webank.wedatasphere.qualitis.rule.entity.RuleVariable) RuleDataSourceService(com.webank.wedatasphere.qualitis.rule.service.RuleDataSourceService) UserRoleDao(com.webank.wedatasphere.qualitis.dao.UserRoleDao) AddFileRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddFileRuleRequest) HashSet(java.util.HashSet) User(com.webank.wedatasphere.qualitis.entity.User) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) RuleTemplateDao(com.webank.wedatasphere.qualitis.rule.dao.RuleTemplateDao) TemplateOutputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta) CompareTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.CompareTypeEnum) MultiDataSourceJoinColumnRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceJoinColumnRequest) AddRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddRuleRequest) Logger(org.slf4j.Logger) ExcelTemplateFileRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateFileRuleByProject) Iterator(java.util.Iterator) RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) ProjectTypeEnum(com.webank.wedatasphere.qualitis.project.constant.ProjectTypeEnum) RuleResponse(com.webank.wedatasphere.qualitis.rule.response.RuleResponse) FunctionTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.FunctionTypeEnum) UserService(com.webank.wedatasphere.qualitis.service.UserService) FileOutputNameEnum(com.webank.wedatasphere.qualitis.rule.constant.FileOutputNameEnum) RuleTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.RuleTypeEnum) RuleDao(com.webank.wedatasphere.qualitis.rule.dao.RuleDao) MultiDataSourceJoinConfigRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceJoinConfigRequest) ModifyRuleRequest(com.webank.wedatasphere.qualitis.rule.request.ModifyRuleRequest) Comparator(java.util.Comparator) StringEscapeUtils(org.apache.commons.lang.StringEscapeUtils) Transactional(org.springframework.transaction.annotation.Transactional) RuleDataSourceMapping(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceMapping) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) MultiDataSourceJoinColumnRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceJoinColumnRequest) ArrayList(java.util.ArrayList) MultiDataSourceJoinConfigRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceJoinConfigRequest) FileAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest) CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest) AlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest) MultiDataSourceConfigRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceConfigRequest) AddMultiSourceRuleRequest(com.webank.wedatasphere.qualitis.rule.request.multi.AddMultiSourceRuleRequest) RuleVariable(com.webank.wedatasphere.qualitis.rule.entity.RuleVariable)

Example 5 with RuleGroup

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

the class RuleNodeServiceImpl method exportRuleByGroupId.

@Override
public GeneralResponse<RuleNodeResponses> exportRuleByGroupId(Long ruleGroupId) throws UnExpectedRequestException {
    // Check existence of ruleGroup
    RuleGroup ruleGroup = ruleGroupDao.findById(ruleGroupId);
    if (ruleGroup == null) {
        throw new UnExpectedRequestException("Rule group [Id = " + ruleGroupId + "] does not exist.");
    }
    LOGGER.info("Succeed to find rule group. Rule group id: {}.", ruleGroup.getId());
    List<RuleNodeResponse> responses = new ArrayList<>();
    try {
        List<Rule> rules = ruleDao.findByRuleGroup(ruleGroup);
        if (CollectionUtils.isEmpty(rules)) {
            throw new UnExpectedRequestException("Rule group [id = " + ruleGroup.getId() + "] does not have rules.");
        }
        for (Rule rule : rules) {
            responses.add(ruleNodeResponse(rule));
        }
    } catch (IOException e) {
        LOGGER.error("Failed to export rule because of JSON serialization opeartions.", e);
        return new GeneralResponse<>("500", "{&FAILED_TO_EXPORT_RULE}", null);
    }
    LOGGER.info("Succeed to export rule. Rule info: {}", Arrays.toString(responses.toArray()));
    RuleNodeResponses ruleNodeResponses = new RuleNodeResponses(responses);
    return new GeneralResponse<>("200", "{&EXPORT_RULE_SUCCESSFULLY}", ruleNodeResponses);
}
Also used : RuleNodeResponses(com.webank.wedatasphere.qualitis.rule.response.RuleNodeResponses) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) RuleNodeResponse(com.webank.wedatasphere.qualitis.rule.response.RuleNodeResponse) ArrayList(java.util.ArrayList) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) IOException(java.io.IOException) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup)

Aggregations

RuleGroup (com.webank.wedatasphere.qualitis.rule.entity.RuleGroup)16 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)15 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)12 ArrayList (java.util.ArrayList)12 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)10 Project (com.webank.wedatasphere.qualitis.project.entity.Project)8 IOException (java.io.IOException)6 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)5 MetaDataAcquireFailedException (com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException)5 AlarmConfig (com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)5 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)5 Date (java.util.Date)5 ArgumentException (com.webank.wedatasphere.qualitis.exception.ArgumentException)4 BothNullDatasourceException (com.webank.wedatasphere.qualitis.exception.BothNullDatasourceException)4 ClusterInfoNotConfigException (com.webank.wedatasphere.qualitis.exception.ClusterInfoNotConfigException)4 ConvertException (com.webank.wedatasphere.qualitis.exception.ConvertException)4 DataQualityTaskException (com.webank.wedatasphere.qualitis.exception.DataQualityTaskException)4 DataSourceMoveException (com.webank.wedatasphere.qualitis.exception.DataSourceMoveException)4 DataSourceOverSizeException (com.webank.wedatasphere.qualitis.exception.DataSourceOverSizeException)4 JobKillException (com.webank.wedatasphere.qualitis.exception.JobKillException)4