Search in sources :

Example 1 with WriteExcelException

use of com.webank.wedatasphere.qualitis.rule.exception.WriteExcelException in project Qualitis by WeBankFinTech.

the class RuleBatchServiceImpl method writeExcelToOutput.

private void writeExcelToOutput(List<ExcelTemplateRuleByProject> templateRules, List<ExcelCustomRuleByProject> customRules, List<ExcelMultiTemplateRuleByProject> multiTemplateRules, List<ExcelTemplateFileRuleByProject> templateFileRules, OutputStream outputStream) throws WriteExcelException, IOException {
    try {
        LOGGER.info("Start to write excel");
        ExcelWriter writer = new ExcelWriter(outputStream, ExcelTypeEnum.XLSX, true);
        Sheet templateSheet = new Sheet(1, 0, ExcelTemplateRuleByProject.class);
        templateSheet.setSheetName(ExcelSheetName.TEMPLATE_RULE_NAME);
        writer.write(templateRules, templateSheet);
        Sheet customSheet = new Sheet(2, 0, ExcelCustomRuleByProject.class);
        customSheet.setSheetName(ExcelSheetName.CUSTOM_RULE_NAME);
        writer.write(customRules, customSheet);
        Sheet multiTemplateSheet = new Sheet(3, 0, ExcelMultiTemplateRuleByProject.class);
        multiTemplateSheet.setSheetName(ExcelSheetName.MULTI_TEMPLATE_RULE_NAME);
        writer.write(multiTemplateRules, multiTemplateSheet);
        Sheet templateFileSheet = new Sheet(4, 0, ExcelTemplateFileRuleByProject.class);
        templateFileSheet.setSheetName(ExcelSheetName.TEMPLATE_FILE_RULE_NAME);
        writer.write(templateFileRules, templateFileSheet);
        writer.finish();
        LOGGER.info("Finish to write excel");
    } catch (Exception e) {
        throw new WriteExcelException(e.getMessage(), 500);
    } finally {
        outputStream.close();
    }
}
Also used : ExcelWriter(com.alibaba.excel.ExcelWriter) WriteExcelException(com.webank.wedatasphere.qualitis.rule.exception.WriteExcelException) Sheet(com.alibaba.excel.metadata.Sheet) ClusterInfoNotConfigException(com.webank.wedatasphere.qualitis.exception.ClusterInfoNotConfigException) IOException(java.io.IOException) WriteExcelException(com.webank.wedatasphere.qualitis.rule.exception.WriteExcelException) TaskNotExistException(com.webank.wedatasphere.qualitis.exception.TaskNotExistException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) ParseException(org.apache.hadoop.hive.ql.parse.ParseException) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)

Example 2 with WriteExcelException

use of com.webank.wedatasphere.qualitis.rule.exception.WriteExcelException in project Qualitis by WeBankFinTech.

the class RuleBatchServiceImpl method downloadRules.

@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> downloadRules(DownloadRuleRequest request, HttpServletResponse response) throws UnExpectedRequestException, IOException, WriteExcelException, PermissionDeniedRequestException {
    // Check Arguments
    DownloadRuleRequest.checkRequest(request);
    String loginUser = HttpUtils.getUserName(httpServletRequest);
    Boolean projectAllRules = request.getProjectId() != null;
    List<Rule> ruleLists;
    if (projectAllRules) {
        LOGGER.info("Downloading all rules of project. project id: {}", request.getProjectId());
        Project project = projectDao.findById(request.getProjectId());
        if (project == null) {
            throw new UnExpectedRequestException("{&PROJECT_ID} {&DOES_NOT_EXIST}");
        }
        ruleLists = ruleDao.findByProject(project);
    } else {
        LOGGER.info("Downloading all rules. rule ids: {}", request.getRuleIds());
        ruleLists = ruleDao.findByIds(request.getRuleIds());
        List<Long> ruleIds = ruleLists.stream().map(Rule::getId).distinct().collect(Collectors.toList());
        List<Long> notExistRules = request.getRuleIds().stream().filter(l -> !ruleIds.contains(l)).collect(Collectors.toList());
        if (!notExistRules.isEmpty()) {
            throw new UnExpectedRequestException("{&THE_IDS_OF_RULE}: " + notExistRules.toString() + " {&DOES_NOT_EXIST}");
        }
    }
    if (ruleLists == null || ruleLists.isEmpty()) {
        throw new UnExpectedRequestException("{&NO_RULE_CAN_DOWNLOAD}");
    }
    // Check permissions of project
    List<Integer> permissions = new ArrayList<>();
    permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
    projectService.checkProjectPermission(ruleLists.iterator().next().getProject(), loginUser, permissions);
    LOGGER.info("Succeed to find rules that will be downloaded. rule_ids: {}", ruleLists.stream().map(Rule::getId));
    return downloadRulesReal(ruleLists, response, loginUser);
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) ClusterInfoNotConfigException(com.webank.wedatasphere.qualitis.exception.ClusterInfoNotConfigException) FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) Autowired(org.springframework.beans.factory.annotation.Autowired) ExcelRuleListener(com.webank.wedatasphere.qualitis.rule.excel.ExcelRuleListener) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig) RuleMetricDao(com.webank.wedatasphere.qualitis.dao.RuleMetricDao) HttpUtils(com.webank.wedatasphere.qualitis.util.HttpUtils) Map(java.util.Map) LocaleParser(com.webank.wedatasphere.qualitis.parser.LocaleParser) MultiDataSourceConfigRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceConfigRequest) ModifyCustomRuleRequest(com.webank.wedatasphere.qualitis.rule.request.ModifyCustomRuleRequest) 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) ExcelCustomRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelCustomRuleByProject) ExcelReader(com.alibaba.excel.ExcelReader) ProjectUserPermissionEnum(com.webank.wedatasphere.qualitis.project.constant.ProjectUserPermissionEnum) Set(java.util.Set) DataSourceRequest(com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest) FileAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest) TemplateArgumentRequest(com.webank.wedatasphere.qualitis.rule.request.TemplateArgumentRequest) Project(com.webank.wedatasphere.qualitis.project.entity.Project) FastDateFormat(org.apache.commons.lang.time.FastDateFormat) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) TemplateMidTableInputMetaDao(com.webank.wedatasphere.qualitis.rule.dao.TemplateMidTableInputMetaDao) ProjectDao(com.webank.wedatasphere.qualitis.project.dao.ProjectDao) ArrayList(java.util.ArrayList) ExcelWriter(com.alibaba.excel.ExcelWriter) HttpServletRequest(javax.servlet.http.HttpServletRequest) CheckTemplateEnum(com.webank.wedatasphere.qualitis.rule.constant.CheckTemplateEnum) Service(org.springframework.stereotype.Service) RuleBatchService(com.webank.wedatasphere.qualitis.rule.service.RuleBatchService) 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) UserDao(com.webank.wedatasphere.qualitis.dao.UserDao) ModifyFileRuleRequest(com.webank.wedatasphere.qualitis.rule.request.ModifyFileRuleRequest) WriteExcelException(com.webank.wedatasphere.qualitis.rule.exception.WriteExcelException) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) TaskNotExistException(com.webank.wedatasphere.qualitis.exception.TaskNotExistException) TemplateMidTableUtil(com.webank.wedatasphere.qualitis.rule.util.TemplateMidTableUtil) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) 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) AddProjectRequest(com.webank.wedatasphere.qualitis.project.request.AddProjectRequest) ProjectService(com.webank.wedatasphere.qualitis.project.service.ProjectService) AddCustomRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddCustomRuleRequest) AlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest) ProjectEventService(com.webank.wedatasphere.qualitis.project.service.ProjectEventService) ExcelMultiTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject) TemplateOutputMetaDao(com.webank.wedatasphere.qualitis.rule.dao.TemplateOutputMetaDao) MappingOperationEnum(com.webank.wedatasphere.qualitis.rule.constant.MappingOperationEnum) Context(javax.ws.rs.core.Context) InputActionStepEnum(com.webank.wedatasphere.qualitis.rule.constant.InputActionStepEnum) CustomRuleService(com.webank.wedatasphere.qualitis.rule.service.CustomRuleService) Collectors(java.util.stream.Collectors) RuleDataSourceMapping(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceMapping) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) ExcelTypeEnum(com.alibaba.excel.support.ExcelTypeEnum) RuleService(com.webank.wedatasphere.qualitis.rule.service.RuleService) List(java.util.List) Sheet(com.alibaba.excel.metadata.Sheet) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ExcelTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject) BeanUtils(org.springframework.beans.BeanUtils) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup) SpecCharEnum(com.webank.wedatasphere.qualitis.constant.SpecCharEnum) RuleVariable(com.webank.wedatasphere.qualitis.rule.entity.RuleVariable) DownloadRuleRequest(com.webank.wedatasphere.qualitis.rule.request.DownloadRuleRequest) HashMap(java.util.HashMap) AddFileRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddFileRuleRequest) 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) OutputStream(java.io.OutputStream) 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) HttpServletResponse(javax.servlet.http.HttpServletResponse) FunctionTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.FunctionTypeEnum) ModifyMultiSourceRequest(com.webank.wedatasphere.qualitis.rule.request.multi.ModifyMultiSourceRequest) FileOutputNameEnum(com.webank.wedatasphere.qualitis.rule.constant.FileOutputNameEnum) RuleTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.RuleTypeEnum) URLEncoder(java.net.URLEncoder) ExcelSheetName(com.webank.wedatasphere.qualitis.project.constant.ExcelSheetName) 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) StringEscapeUtils(org.apache.commons.lang.StringEscapeUtils) InputStream(java.io.InputStream) Transactional(org.springframework.transaction.annotation.Transactional) ExcelCustomRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelCustomRuleByProject) Project(com.webank.wedatasphere.qualitis.project.entity.Project) ExcelMultiTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject) ExcelTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject) ExcelTemplateFileRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateFileRuleByProject) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ArrayList(java.util.ArrayList) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with WriteExcelException

use of com.webank.wedatasphere.qualitis.rule.exception.WriteExcelException in project Qualitis by WeBankFinTech.

the class ProjectBatchServiceImpl method writeExcelToOutput.

private void writeExcelToOutput(List<ExcelProject> excelProjects, List<ExcelTemplateRuleByProject> excelTemplateRuleByProjects, List<ExcelCustomRuleByProject> excelCustomRuleByProjects, List<ExcelMultiTemplateRuleByProject> excelMultiTemplateRuleByProjects, List<ExcelTemplateFileRuleByProject> excelTemplateFileRuleByProject, OutputStream outputStream) throws WriteExcelException, IOException {
    try {
        LOGGER.info("Start to write excel");
        ExcelWriter writer = new ExcelWriter(outputStream, ExcelTypeEnum.XLSX, true);
        Sheet templateRuleSheet = new Sheet(1, 0, ExcelTemplateRuleByProject.class);
        templateRuleSheet.setSheetName(ExcelSheetName.TEMPLATE_RULE_NAME);
        writer.write(excelTemplateRuleByProjects, templateRuleSheet);
        Sheet projectSheet = new Sheet(2, 0, ExcelProject.class);
        projectSheet.setSheetName(ExcelSheetName.PROJECT_NAME);
        writer.write(excelProjects, projectSheet);
        Sheet customRuleSheet = new Sheet(3, 0, ExcelCustomRuleByProject.class);
        customRuleSheet.setSheetName(ExcelSheetName.CUSTOM_RULE_NAME);
        writer.write(excelCustomRuleByProjects, customRuleSheet);
        Sheet multiRuleSheet = new Sheet(4, 0, ExcelMultiTemplateRuleByProject.class);
        multiRuleSheet.setSheetName(ExcelSheetName.MULTI_TEMPLATE_RULE_NAME);
        writer.write(excelMultiTemplateRuleByProjects, multiRuleSheet);
        Sheet templateFileSheet = new Sheet(5, 0, ExcelTemplateFileRuleByProject.class);
        templateFileSheet.setSheetName(ExcelSheetName.TEMPLATE_FILE_RULE_NAME);
        writer.write(excelTemplateFileRuleByProject, templateFileSheet);
        writer.finish();
        LOGGER.info("Finish to write excel");
    } catch (Exception e) {
        throw new WriteExcelException(e.getMessage());
    } finally {
        outputStream.close();
    }
}
Also used : ExcelWriter(com.alibaba.excel.ExcelWriter) WriteExcelException(com.webank.wedatasphere.qualitis.rule.exception.WriteExcelException) Sheet(com.alibaba.excel.metadata.Sheet) 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)

Example 4 with WriteExcelException

use of com.webank.wedatasphere.qualitis.rule.exception.WriteExcelException in project Qualitis by WeBankFinTech.

the class RuleMetricServiceImpl method download.

@Override
public GeneralResponse<?> download(DownloadRuleMetricRequest request, HttpServletResponse response) throws UnExpectedRequestException, IOException, WriteExcelException, PermissionDeniedRequestException {
    // Check rule metric IDs permission.
    PageRequest pageRequest = new PageRequest(0, Integer.MAX_VALUE);
    List<RuleMetricResponse> ownRuleMetric = getAllRuleMetric(pageRequest).getData().getData().stream().collect(Collectors.toList());
    if (ownRuleMetric.size() <= 0 || ownRuleMetric.size() >= MAX_RULE_METRIC_COUNT) {
        throw new UnExpectedRequestException("The number of metrics is illegal");
    }
    List<Long> downloadIds = request.getRuleMetricIds();
    List<Long> ownIds = ownRuleMetric.stream().map(RuleMetricResponse::getId).collect(Collectors.toList());
    if (ownIds.containsAll(downloadIds)) {
        List<RuleMetricResponse> downloadRuleMetric = ownRuleMetric.stream().filter(ruleMetricResponse -> downloadIds.contains(ruleMetricResponse.getId())).collect(Collectors.toList());
        List<ExcelRuleMetric> excelRuleMetrics = new ArrayList<>(downloadRuleMetric.size());
        for (RuleMetricResponse ruleMetricResponse : downloadRuleMetric) {
            ExcelRuleMetric excelRuleMetric = new ExcelRuleMetric();
            excelRuleMetric.setName(ruleMetricResponse.getName());
            excelRuleMetric.setChName(ruleMetricResponse.getCnName());
            excelRuleMetric.setMetricDesc(ruleMetricResponse.getMetricDesc());
            int bussCode = ruleMetricResponse.getBussCode();
            excelRuleMetric.setDimension(bussCode + "");
            if (RuleMetricBussCodeEnum.SUBSYSTEM.getCode().equals(bussCode)) {
                excelRuleMetric.setFullCnName(ruleMetricResponse.getFullCnName());
                excelRuleMetric.setSubSystemName(ruleMetricResponse.getSubSystemName());
                excelRuleMetric.setSubSystemId(String.valueOf(ruleMetricResponse.getSubSystemId()));
            } else if (RuleMetricBussCodeEnum.PRODUCT.getCode().equals(bussCode)) {
                excelRuleMetric.setProductId(ruleMetricResponse.getProductId());
                excelRuleMetric.setProductName(ruleMetricResponse.getProductName());
            } else if (RuleMetricBussCodeEnum.CUSTOM.getCode().equals(bussCode)) {
                excelRuleMetric.setBussCustom(ruleMetricResponse.getBussCustom());
            }
            excelRuleMetric.setFrequency(String.valueOf(ruleMetricResponse.getFrequency()));
            excelRuleMetric.setDevDepartmentName(ruleMetricResponse.getDevDepartmentName());
            excelRuleMetric.setOpsDepartmentName(ruleMetricResponse.getOpsDepartmentName());
            excelRuleMetric.setDepartmentCode(ruleMetricResponse.getDepartmentCode());
            excelRuleMetric.setDepartmentName(ruleMetricResponse.getDepartmentName());
            excelRuleMetric.setAvailable(ruleMetricResponse.getAvailable());
            excelRuleMetric.setEnCode(ruleMetricResponse.getEnCode());
            excelRuleMetric.setType(ruleMetricResponse.getType());
            excelRuleMetrics.add(excelRuleMetric);
        }
        String fileName = "batch_metrics_export_" + FILE_DATE_FORMATTER.format(new Date());
        fileName = URLEncoder.encode(fileName, "UTF-8");
        response.setContentType("application/octet-stream");
        response.addHeader("Content-Disposition", "attachment;filename*=UTF-8''" + fileName);
        response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
        OutputStream outputStream = response.getOutputStream();
        writeExcelToOutput(excelRuleMetrics, outputStream);
        outputStream.flush();
    } else {
        throw new PermissionDeniedRequestException("HAS_NO_PERMISSION_TO_ACCESS", 403);
    }
    LOGGER.info("Succeed to download all rule metrics in type of excel");
    return null;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) HiveRuleDetail(com.webank.wedatasphere.qualitis.project.response.HiveRuleDetail) RuleMetricValueResponse(com.webank.wedatasphere.qualitis.response.RuleMetricValueResponse) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig) RuleMetricDao(com.webank.wedatasphere.qualitis.dao.RuleMetricDao) HttpUtils(com.webank.wedatasphere.qualitis.util.HttpUtils) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse) RuleMetricBussCodeEnum(com.webank.wedatasphere.qualitis.constant.RuleMetricBussCodeEnum) Context(javax.ws.rs.core.Context) ExcelReader(com.alibaba.excel.ExcelReader) PageRequest(com.webank.wedatasphere.qualitis.request.PageRequest) ModifyRuleMetricRequest(com.webank.wedatasphere.qualitis.request.ModifyRuleMetricRequest) Department(com.webank.wedatasphere.qualitis.entity.Department) Set(java.util.Set) RuleMetricDepartmentUser(com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser) Collectors(java.util.stream.Collectors) ExecutionManagerImpl(com.webank.wedatasphere.qualitis.submitter.impl.ExecutionManagerImpl) ExcelTypeEnum(com.alibaba.excel.support.ExcelTypeEnum) List(java.util.List) RuleMetricResponse(com.webank.wedatasphere.qualitis.response.RuleMetricResponse) Sheet(com.alibaba.excel.metadata.Sheet) CommonChecker(com.webank.wedatasphere.qualitis.project.request.CommonChecker) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) RoleDefaultTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.RoleDefaultTypeEnum) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) FastDateFormat(org.apache.commons.lang.time.FastDateFormat) RuleMetricTypeConfigDao(com.webank.wedatasphere.qualitis.dao.RuleMetricTypeConfigDao) RuleMetricQueryRequest(com.webank.wedatasphere.qualitis.request.RuleMetricQueryRequest) UserRoleDao(com.webank.wedatasphere.qualitis.dao.UserRoleDao) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) ArrayList(java.util.ArrayList) ExcelWriter(com.alibaba.excel.ExcelWriter) RuleMetricConditionResponse(com.webank.wedatasphere.qualitis.response.RuleMetricConditionResponse) RuleMetricLevelEnum(com.webank.wedatasphere.qualitis.constant.RuleMetricLevelEnum) HttpServletRequest(javax.servlet.http.HttpServletRequest) User(com.webank.wedatasphere.qualitis.entity.User) ExcelRuleMetricListener(com.webank.wedatasphere.qualitis.excel.ExcelRuleMetricListener) ExcelRuleMetric(com.webank.wedatasphere.qualitis.project.excel.ExcelRuleMetric) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) RuleMetricService(com.webank.wedatasphere.qualitis.service.RuleMetricService) TaskResult(com.webank.wedatasphere.qualitis.entity.TaskResult) DownloadRuleMetricRequest(com.webank.wedatasphere.qualitis.request.DownloadRuleMetricRequest) RoleService(com.webank.wedatasphere.qualitis.service.RoleService) OutputStream(java.io.OutputStream) Logger(org.slf4j.Logger) RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) HttpServletResponse(javax.servlet.http.HttpServletResponse) RuleMetricTypeConfig(com.webank.wedatasphere.qualitis.entity.RuleMetricTypeConfig) IOException(java.io.IOException) AddRuleMetricRequest(com.webank.wedatasphere.qualitis.request.AddRuleMetricRequest) DataInfo(com.webank.wedatasphere.qualitis.metadata.response.DataInfo) URLEncoder(java.net.URLEncoder) ExcelSheetName(com.webank.wedatasphere.qualitis.project.constant.ExcelSheetName) RuleDao(com.webank.wedatasphere.qualitis.rule.dao.RuleDao) RuleMetricDepartmentUserDao(com.webank.wedatasphere.qualitis.dao.RuleMetricDepartmentUserDao) UserDao(com.webank.wedatasphere.qualitis.dao.UserDao) TaskResultDao(com.webank.wedatasphere.qualitis.dao.TaskResultDao) WriteExcelException(com.webank.wedatasphere.qualitis.rule.exception.WriteExcelException) InputStream(java.io.InputStream) Transactional(org.springframework.transaction.annotation.Transactional) ExcelRuleMetric(com.webank.wedatasphere.qualitis.project.excel.ExcelRuleMetric) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) Date(java.util.Date) RuleMetricResponse(com.webank.wedatasphere.qualitis.response.RuleMetricResponse) PageRequest(com.webank.wedatasphere.qualitis.request.PageRequest)

Example 5 with WriteExcelException

use of com.webank.wedatasphere.qualitis.rule.exception.WriteExcelException in project Qualitis by WeBankFinTech.

the class RuleMetricServiceImpl method writeExcelToOutput.

private void writeExcelToOutput(List<ExcelRuleMetric> excelRuleMetrics, OutputStream outputStream) throws WriteExcelException, IOException {
    try {
        LOGGER.info("Start to write metric excel");
        ExcelWriter writer = new ExcelWriter(outputStream, ExcelTypeEnum.XLSX, true);
        Sheet templateSheet = new Sheet(1, 0, ExcelRuleMetric.class);
        templateSheet.setSheetName(ExcelSheetName.RULE_METRIC_NAME);
        writer.write(excelRuleMetrics, templateSheet);
        writer.finish();
        LOGGER.info("Finish to write metric excel");
    } catch (Exception e) {
        throw new WriteExcelException(e.getMessage());
    } finally {
        outputStream.close();
    }
}
Also used : ExcelWriter(com.alibaba.excel.ExcelWriter) WriteExcelException(com.webank.wedatasphere.qualitis.rule.exception.WriteExcelException) Sheet(com.alibaba.excel.metadata.Sheet) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) IOException(java.io.IOException) WriteExcelException(com.webank.wedatasphere.qualitis.rule.exception.WriteExcelException)

Aggregations

ExcelWriter (com.alibaba.excel.ExcelWriter)5 Sheet (com.alibaba.excel.metadata.Sheet)5 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)5 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)5 WriteExcelException (com.webank.wedatasphere.qualitis.rule.exception.WriteExcelException)5 IOException (java.io.IOException)5 ExcelReader (com.alibaba.excel.ExcelReader)2 ExcelTypeEnum (com.alibaba.excel.support.ExcelTypeEnum)2 RuleMetricDao (com.webank.wedatasphere.qualitis.dao.RuleMetricDao)2 UserDao (com.webank.wedatasphere.qualitis.dao.UserDao)2 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)2 User (com.webank.wedatasphere.qualitis.entity.User)2 ClusterInfoNotConfigException (com.webank.wedatasphere.qualitis.exception.ClusterInfoNotConfigException)2 TaskNotExistException (com.webank.wedatasphere.qualitis.exception.TaskNotExistException)2 MetaDataAcquireFailedException (com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException)2 ExcelSheetName (com.webank.wedatasphere.qualitis.project.constant.ExcelSheetName)2 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)2 ParseException (org.apache.hadoop.hive.ql.parse.ParseException)2 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)2 RuleMetricBussCodeEnum (com.webank.wedatasphere.qualitis.constant.RuleMetricBussCodeEnum)1