Search in sources :

Example 6 with Rule

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

the class ProjectServiceImpl method deleteProject.

@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deleteProject(DeleteProjectRequest request) throws UnExpectedRequestException, PermissionDeniedRequestException {
    // Check Arguments
    DeleteProjectRequest.checkRequest(request);
    // Check existence of project
    Project projectInDb = projectDao.findById(request.getProjectId());
    if (projectInDb == null) {
        throw new UnExpectedRequestException("project_id {&DOES_NOT_EXIST}");
    }
    Long userId = HttpUtils.getUserId(httpServletRequest);
    User user = null;
    if (userId == null) {
        user = userDao.findByUsername(request.getUsername());
        if (user == null) {
            throw new UnExpectedRequestException(String.format("{&FAILED_TO_FIND_USER} %s", request.getUsername()));
        }
    } else {
        user = userDao.findById(userId);
    }
    // Check project permission
    List<Integer> permissions = new ArrayList<>();
    permissions.add(ProjectUserPermissionEnum.CREATOR.getCode());
    checkProjectPermission(projectInDb, user.getUserName(), permissions);
    List<Rule> rules = ruleDao.findByProject(projectInDb);
    deleteAllRules(rules);
    // Delete project
    projectDao.deleteProject(projectInDb);
    LOGGER.info("Succeed to delete project. project_id: {}", request.getProjectId());
    return new GeneralResponse<>("200", "{&DELETE_PROJECT_SUCCESSFULLY}", null);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) Project(com.webank.wedatasphere.qualitis.project.entity.Project) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) User(com.webank.wedatasphere.qualitis.entity.User) ProjectUser(com.webank.wedatasphere.qualitis.project.entity.ProjectUser) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with Rule

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

the class CustomRuleServiceImpl method getCustomRuleDetail.

@Override
public GeneralResponse<CustomRuleDetailResponse> getCustomRuleDetail(Long ruleId) throws UnExpectedRequestException {
    // Check existence of rule
    Rule ruleInDb = ruleDao.findById(ruleId);
    if (ruleInDb == null) {
        throw new UnExpectedRequestException("rule_id [" + ruleId + "] {&DOES_NOT_EXIST}");
    }
    if (!ruleInDb.getRuleType().equals(RuleTypeEnum.CUSTOM_RULE.getCode())) {
        throw new UnExpectedRequestException("rule(id: [" + ruleId + "]) {&IS_NOT_A_CUSTOM_RULE}");
    }
    Long projectInDbId = ruleInDb.getProject().getId();
    String loginUser = HttpUtils.getUserName(httpServletRequest);
    projectService.checkProjectExistence(projectInDbId, loginUser);
    LOGGER.info("Succeed to find rule. rule_id: {}", ruleInDb.getId());
    CustomRuleDetailResponse response = new CustomRuleDetailResponse(ruleInDb);
    LOGGER.info("Succeed to get custom rule detail. response: {}", response);
    return new GeneralResponse<>("200", "{&SUCCEED_TO_GET_CUSTOM_RULE_DETAIL}", response);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) CustomRuleDetailResponse(com.webank.wedatasphere.qualitis.rule.response.CustomRuleDetailResponse) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule)

Example 8 with Rule

use of com.webank.wedatasphere.qualitis.rule.entity.Rule 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 9 with Rule

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

the class FileRuleServiceImpl method deleteRule.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deleteRule(DeleteFileRuleRequest request) throws UnExpectedRequestException, PermissionDeniedRequestException {
    // Check Arguments
    DeleteFileRuleRequest.checkRequest(request);
    // Check existence of rule
    Rule ruleInDb = ruleDao.findById(request.getRuleId());
    if (ruleInDb == null || !ruleInDb.getRuleType().equals(RuleTypeEnum.FILE_TEMPLATE_RULE.getCode())) {
        throw new UnExpectedRequestException("Rule id [" + request.getRuleId() + "]) {&IS_NOT_A_RULE_WITH_TEMPLATE}");
    }
    ruleDataSourceService.updateRuleDataSourceCount(ruleInDb, -1);
    String loginUser = HttpUtils.getUserName(httpServletRequest);
    Project projectInDb = projectService.checkProjectExistence(ruleInDb.getProject().getId(), loginUser);
    // Check permissions of project
    List<Integer> permissions = new ArrayList<>();
    permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
    projectService.checkProjectPermission(projectInDb, loginUser, permissions);
    // Update rule count of datasource
    ruleDataSourceService.updateRuleDataSourceCount(ruleInDb, -1);
    return deleteRuleReal(ruleInDb);
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Project(com.webank.wedatasphere.qualitis.project.entity.Project) ArrayList(java.util.ArrayList) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with Rule

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

the class RuleQueryServiceImpl method putIntoRuleOfProject.

private void putIntoRuleOfProject(RuleDataSource ds, RuleQueryProject queryProject) {
    Rule rule = ds.getRule();
    Long ruleId = rule.getId();
    if (queryProject.getDataMap().containsKey(ruleId)) {
        RuleQueryRule queryRule = queryProject.getDataMap().get(ruleId);
        putIntoClusterOfRule(ds, queryRule);
        return;
    }
    // If not contain
    RuleQueryRule ruleSrc = newRuleQueryRule(rule, ds);
    queryProject.addRuleQueryRule(ruleSrc);
}
Also used : RuleQueryRule(com.webank.wedatasphere.qualitis.query.response.RuleQueryRule) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) RuleQueryRule(com.webank.wedatasphere.qualitis.query.response.RuleQueryRule)

Aggregations

Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)61 ArrayList (java.util.ArrayList)41 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)35 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)25 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)25 Project (com.webank.wedatasphere.qualitis.project.entity.Project)23 AlarmConfig (com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)21 Date (java.util.Date)20 List (java.util.List)20 Transactional (org.springframework.transaction.annotation.Transactional)19 HashMap (java.util.HashMap)18 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)15 IOException (java.io.IOException)15 Set (java.util.Set)14 RuleGroup (com.webank.wedatasphere.qualitis.rule.entity.RuleGroup)13 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)13 HashSet (java.util.HashSet)13 Collectors (java.util.stream.Collectors)13 Logger (org.slf4j.Logger)13 MetaDataAcquireFailedException (com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException)12