Search in sources :

Example 1 with RuleMetric

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

the class RuleBatchServiceImpl method getAlarmConfig.

private void getAlarmConfig(List<AlarmConfigRequest> alarmConfigRequests, ExcelTemplateRuleByProject excelTemplateRule, Template template, String localeStr) throws UnExpectedRequestException {
    String templateOutputName = excelTemplateRule.getAlarmCheckName();
    if (!StringUtils.isBlank(templateOutputName)) {
        String checkTemplateName = excelTemplateRule.getCheckTemplateName();
        String compareTypeName = excelTemplateRule.getCompareType();
        String threshold = excelTemplateRule.getThreshold();
        TemplateOutputMeta templateOutputMeta = findTemplateOutputMetaByTemplateAndOutputName(template, templateOutputName);
        if (templateOutputMeta == null) {
            throw new UnExpectedRequestException("{&TEMPLATE_OUTPUT_NAME} {&DOES_NOT_EXIST}");
        }
        AlarmConfigRequest alarmConfigRequest = new AlarmConfigRequest();
        alarmConfigRequest.setCheckTemplate(CheckTemplateEnum.getCheckTemplateCode(checkTemplateName, localeStr));
        alarmConfigRequest.setCompareType(CompareTypeEnum.getCompareTypeCode(compareTypeName));
        alarmConfigRequest.setThreshold(Double.valueOf(threshold));
        alarmConfigRequest.setOutputMetaId(templateOutputMeta.getId());
        // Rule Metric.
        String ruleMetricEnCode = excelTemplateRule.getRuleMetricEnCode();
        if (StringUtils.isNotBlank(ruleMetricEnCode)) {
            // xx_xx_xx_encode, index is 3.
            RuleMetric ruleMetricInDb = ruleMetricDao.findByEnCode(ruleMetricEnCode);
            if (ruleMetricInDb == null) {
                throw new UnExpectedRequestException("Rule metric[Code=" + ruleMetricEnCode + "] " + "{&DOES_NOT_EXIST}");
            }
            String code = ruleMetricInDb.getEnCode();
            alarmConfigRequest.setRuleMetricEnCode(code);
        }
        alarmConfigRequest.setUploadRuleMetricValue(excelTemplateRule.getUploadRuleMetricValue());
        alarmConfigRequest.setUploadAbnormalValue(excelTemplateRule.getUploadAbnormalValue());
        alarmConfigRequests.add(alarmConfigRequest);
    }
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) FileAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest) CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest) AlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest) TemplateOutputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta)

Example 2 with RuleMetric

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

the class RuleBatchServiceImpl method getFileRule.

@Override
public List<ExcelTemplateFileRuleByProject> getFileRule(Iterable<Rule> rules, String localeStr) {
    List<ExcelTemplateFileRuleByProject> lines = new ArrayList<>();
    for (Rule rule : rules) {
        if (!rule.getRuleType().equals(RuleTypeEnum.FILE_TEMPLATE_RULE.getCode())) {
            continue;
        }
        String ruleName = rule.getName();
        String ruleCnName = rule.getCnName();
        String ruleDetail = rule.getDetail();
        String templateName = rule.getTemplate().getName();
        ExcelTemplateFileRuleByProject ruleLinePrefix = new ExcelTemplateFileRuleByProject();
        ruleLinePrefix.setRuleName(ruleName);
        ruleLinePrefix.setRuleCnName(ruleCnName);
        ruleLinePrefix.setRuleDetail(ruleDetail);
        ruleLinePrefix.setTemplateName(templateName);
        ruleLinePrefix.setProjectName(rule.getProject().getName());
        ruleLinePrefix.setAbortOnFailure(rule.getAbortOnFailure());
        ruleLinePrefix.setRuleGroupName(rule.getRuleGroup().getRuleGroupName());
        ruleLinePrefix.setCreateUser(rule.getCreateUser());
        ruleLinePrefix.setCreateTime(rule.getCreateTime());
        ruleLinePrefix.setModifyUser(rule.getModifyUser());
        ruleLinePrefix.setModifyTime(rule.getModifyTime());
        ruleLinePrefix.setDeleteFailCheckResult(rule.getDeleteFailCheckResult());
        lines.add(ruleLinePrefix);
        for (RuleDataSource ruleDataSource : rule.getRuleDataSources()) {
            String clusterName = ruleDataSource.getClusterName();
            String databaseName = ruleDataSource.getDbName();
            String tableName = ruleDataSource.getTableName();
            String filter = ruleDataSource.getFilter();
            ExcelTemplateFileRuleByProject tmp = new ExcelTemplateFileRuleByProject(rule.getName());
            tmp.setClusterName(clusterName);
            tmp.setDatabaseName(databaseName);
            tmp.setTableName(tableName);
            tmp.setFilter(filter);
            LOGGER.info("Collect excel line: {}", tmp);
            lines.add(tmp);
        }
        for (AlarmConfig alarmConfig : rule.getAlarmConfigs()) {
            Double threshold = alarmConfig.getThreshold();
            String alarmCompareType = CompareTypeEnum.getCompareTypeName(alarmConfig.getCompareType());
            String alarmOutputName = FileOutputNameEnum.getFileOutputName(alarmConfig.getFileOutputName(), localeStr);
            String checkTemplateName = CheckTemplateEnum.getCheckTemplateName(alarmConfig.getCheckTemplate(), localeStr);
            String unit = alarmConfig.getFileOutputUnit() == null ? "" : FileOutputUnitEnum.fileOutputUnit(alarmConfig.getFileOutputUnit());
            ExcelTemplateFileRuleByProject tmp = new ExcelTemplateFileRuleByProject(rule.getName());
            tmp.setUnit(unit);
            tmp.setCompareType(alarmCompareType);
            tmp.setAlarmCheckName(alarmOutputName);
            tmp.setCheckTemplateName(checkTemplateName);
            tmp.setThreshold(String.valueOf(threshold));
            RuleMetric ruleMetric = alarmConfig.getRuleMetric();
            // Recod rule metric info (unique code).
            if (ruleMetric != null) {
                String enCode = ruleMetric.getEnCode();
                tmp.setRuleMetricEnCode(enCode);
                tmp.setRuleMetricName(ruleMetric.getName());
            }
            LOGGER.info("Collect excel line: {}", tmp);
            lines.add(tmp);
        }
    }
    return lines;
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) ArrayList(java.util.ArrayList) ExcelTemplateFileRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateFileRuleByProject) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)

Example 3 with RuleMetric

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

the class ProjectBatchServiceImpl method uploadProjectsReal.

private GeneralResponse<?> uploadProjectsReal(InputStream fileInputStream, String fileName, String userName, boolean aomp) throws IOException, UnExpectedRequestException, PermissionDeniedRequestException, RoleNotFoundException {
    String suffixName = fileName.substring(fileName.lastIndexOf('.'));
    if (!suffixName.equals(SUPPORT_EXCEL_SUFFIX_NAME)) {
        throw new UnExpectedRequestException("{&DO_NOT_SUPPORT_SUFFIX_NAME}: [" + suffixName + "]. {&ONLY_SUPPORT} [" + SUPPORT_EXCEL_SUFFIX_NAME + "]", 422);
    }
    if (userName == null) {
        return new GeneralResponse<>("401", "{&PLEASE_LOGIN}", null);
    }
    User user = userDao.findByUsername(userName);
    Long userId = user.getId();
    // Read file and create project
    ExcelProjectListener listener = readExcel(fileInputStream);
    // Check if excel file is empty
    if (listener.getExcelProjectContent().isEmpty() && listener.getExcelRuleContent().isEmpty() && listener.getExcelCustomRuleContent().isEmpty() && listener.getExcelMultiRuleContent().isEmpty() && listener.getTemplateFileExcelContent().isEmpty() && listener.getExcelMetricContent().isEmpty()) {
        throw new UnExpectedRequestException("{&FILE_CAN_NOT_BE_EMPTY_OR_FILE_CAN_NOT_BE_RECOGNIZED}", 422);
    }
    for (ExcelProject excelProject : listener.getExcelProjectContent()) {
        Project project = projectDao.findByNameAndCreateUser(excelProject.getProjectName(), userName);
        if (project != null) {
            if (!aomp) {
                LOGGER.info("hint for user to decide to override or not.");
            }
            // Means update project.
            LOGGER.info("Start to update project[name={}] with upload project file.", project.getName());
            ModifyProjectDetailRequest request = convertExcelProjectToModifyProjectRequest(excelProject, project, userName);
            projectService.modifyProjectDetail(request, false);
        } else {
            // Check excel project arguments is valid or not
            AddProjectRequest request = convertExcelProjectToAddProjectRequest(excelProject);
            projectService.addProject(request, userId);
        }
    }
    for (ExcelRuleMetric excelRuleMetric : listener.getExcelMetricContent()) {
        RuleMetric ruleMetric = ruleMetricDao.findByName(excelRuleMetric.getName());
        if (ruleMetric != null) {
            if (!aomp) {
                LOGGER.info("hint for user to decide to override or not.");
            }
            LOGGER.info("Start to update rule metric[name={}] with upload rule metric file.", ruleMetric.getName());
            modifyRuleMetric(excelRuleMetric, ruleMetric, userName);
        } else {
            addRuleMetric(excelRuleMetric, userName);
        }
    }
    // Create rules according to excel sheet
    Map<String, Map<String, List<ExcelTemplateRuleByProject>>> excelTemplateRulePartitionedByProject = listener.getExcelRuleContent();
    Map<String, Map<String, List<ExcelCustomRuleByProject>>> excelCustomRulePartitionedByProject = listener.getExcelCustomRuleContent();
    Map<String, Map<String, List<ExcelMultiTemplateRuleByProject>>> excelMultiTemplateRulePartitionedByProject = listener.getExcelMultiRuleContent();
    Map<String, Map<String, List<ExcelTemplateFileRuleByProject>>> excelTemplateFileRulePartitionedByProject = listener.getTemplateFileExcelContent();
    Set<String> allProjects = new HashSet<>();
    allProjects.addAll(excelTemplateRulePartitionedByProject.keySet());
    allProjects.addAll(excelCustomRulePartitionedByProject.keySet());
    allProjects.addAll(excelMultiTemplateRulePartitionedByProject.keySet());
    allProjects.addAll(excelTemplateFileRulePartitionedByProject.keySet());
    for (String projectName : allProjects) {
        try {
            Project projectInDb = projectDao.findByNameAndCreateUser(projectName, userName);
            if (projectInDb == null) {
                throw new UnExpectedRequestException("{&PROJECT}: [" + projectName + "] {&DOES_NOT_EXIST}");
            }
            ruleBatchService.getAndSaveRule(excelTemplateRulePartitionedByProject.get(projectName), excelCustomRulePartitionedByProject.get(projectName), excelMultiTemplateRulePartitionedByProject.get(projectName), excelTemplateFileRulePartitionedByProject.get(projectName), projectInDb, userName, aomp);
        } catch (Exception e) {
            throw new UnExpectedRequestException(e.getMessage());
        }
    }
    fileInputStream.close();
    return new GeneralResponse<>("200", "{&SUCCEED_TO_UPLOAD_FILE}", null);
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ExcelMultiTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject) RuleMetricDepartmentUser(com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser) User(com.webank.wedatasphere.qualitis.entity.User) AddProjectRequest(com.webank.wedatasphere.qualitis.project.request.AddProjectRequest) ExcelCustomRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelCustomRuleByProject) ModifyProjectDetailRequest(com.webank.wedatasphere.qualitis.project.request.ModifyProjectDetailRequest) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) ZipException(net.lingala.zip4j.exception.ZipException) RoleNotFoundException(javax.management.relation.RoleNotFoundException) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) IOException(java.io.IOException) WriteExcelException(com.webank.wedatasphere.qualitis.rule.exception.WriteExcelException) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) ExcelMultiTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject) ExcelCustomRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelCustomRuleByProject) ExcelTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject) Project(com.webank.wedatasphere.qualitis.project.entity.Project) ExcelProjectListener(com.webank.wedatasphere.qualitis.project.excel.ExcelProjectListener) ExcelTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject)

Example 4 with RuleMetric

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

the class AddMultiRuleRequestBuilder method addRuleMetric.

@Override
public AddRequestBuilder addRuleMetric(String ruleMetricName) throws UnExpectedRequestException {
    RuleMetric ruleMetricInDb = ruleMetricDao.findByName(ruleMetricName);
    if (ruleMetricInDb != null) {
        setRuleMetricEnCode(ruleMetricInDb.getEnCode());
        return this;
    }
    String[] infos = ruleMetricName.split(SpecCharEnum.BOTTOM_BAR.getValue());
    if (infos.length != FOUR) {
        throw new UnExpectedRequestException("The metric name does not meet specifications");
    }
    String en = infos[2];
    List<String> ruleMetricNames = new ArrayList<>(1);
    ruleMetricNames.add(ruleMetricName);
    addMultiSourceRuleRequest.setRuleMetricNamesForBdpClient(ruleMetricNames);
    setRuleMetricEnCode(en);
    return this;
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ArrayList(java.util.ArrayList)

Example 5 with RuleMetric

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

the class RuleBatchServiceImpl method alarmConfigsToExcel.

private void alarmConfigsToExcel(Rule rule, List<ExcelTemplateRuleByProject> lines, String localeStr) {
    for (AlarmConfig alarmConfig : rule.getAlarmConfigs()) {
        Double threshold = alarmConfig.getThreshold();
        String alarmOutputName = alarmConfig.getTemplateOutputMeta().getOutputName();
        String alarmCompareType = CompareTypeEnum.getCompareTypeName(alarmConfig.getCompareType());
        String checkTemplateName = CheckTemplateEnum.getCheckTemplateName(alarmConfig.getCheckTemplate(), localeStr);
        ExcelTemplateRuleByProject tmp = new ExcelTemplateRuleByProject(rule.getName());
        tmp.setCheckTemplateName(checkTemplateName);
        tmp.setThreshold(String.valueOf(threshold));
        tmp.setAlarmCheckName(alarmOutputName);
        tmp.setCompareType(alarmCompareType);
        RuleMetric ruleMetric = alarmConfig.getRuleMetric();
        if (ruleMetric != null) {
            String enCode = ruleMetric.getEnCode();
            tmp.setRuleMetricEnCode(enCode);
            tmp.setRuleMetricName(ruleMetric.getName());
        }
        tmp.setUploadRuleMetricValue(alarmConfig.getUploadRuleMetricValue());
        tmp.setUploadAbnormalValue(alarmConfig.getUploadAbnormalValue());
        LOGGER.info("Collect excel line: {}", tmp);
        lines.add(tmp);
    }
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) ExcelTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)

Aggregations

RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)36 ArrayList (java.util.ArrayList)23 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)19 AlarmConfig (com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)15 RuleMetricDepartmentUser (com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser)10 User (com.webank.wedatasphere.qualitis.entity.User)10 Department (com.webank.wedatasphere.qualitis.entity.Department)9 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)9 List (java.util.List)9 ExcelRuleMetric (com.webank.wedatasphere.qualitis.project.excel.ExcelRuleMetric)8 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)8 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)7 TemplateOutputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta)7 CustomAlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest)7 FileAlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest)7 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)6 RuleMetricResponse (com.webank.wedatasphere.qualitis.response.RuleMetricResponse)6 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)5 Date (java.util.Date)5 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)4