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();
}
}
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);
}
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();
}
}
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;
}
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();
}
}
Aggregations