use of com.webank.wedatasphere.qualitis.rule.excel.ExcelRuleListener in project Qualitis by WeBankFinTech.
the class RuleBatchServiceImpl method readExcel.
private ExcelRuleListener readExcel(InputStream inputStream) {
LOGGER.info("Start to read excel");
ExcelRuleListener excelRuleListener = partitionByRuleName(inputStream);
LOGGER.info("Finish to read excel. template rule content: {}", excelRuleListener.getTemplateExcelContent());
LOGGER.info("Finish to read excel. custom rule content: {}", excelRuleListener.getCustomExcelContent());
LOGGER.info("Finish to read excel. multi rule content: {}", excelRuleListener.getMultiTemplateExcelContent());
LOGGER.info("Finish to read excel. template file rule content: {}", excelRuleListener.getTemplateFileExcelContent());
return excelRuleListener;
}
use of com.webank.wedatasphere.qualitis.rule.excel.ExcelRuleListener in project Qualitis by WeBankFinTech.
the class RuleBatchServiceImpl method uploadRulesReal.
private GeneralResponse<?> uploadRulesReal(InputStream fileInputStream, String fileName, String userName, Long projectId, boolean aomp) throws UnExpectedRequestException, ClusterInfoNotConfigException, ParseException, SemanticException, MetaDataAcquireFailedException, TaskNotExistException, IOException, PermissionDeniedRequestException {
if (userName == null) {
return new GeneralResponse<>("401", "{&PLEASE_LOGIN}", null);
}
// Check suffix name of file
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);
}
ExcelRuleListener excelRuleListener = readExcel(fileInputStream);
if (excelRuleListener.getCustomExcelContent().isEmpty() && excelRuleListener.getTemplateExcelContent().isEmpty() && excelRuleListener.getMultiTemplateExcelContent().isEmpty() && excelRuleListener.getTemplateFileExcelContent().isEmpty()) {
throw new UnExpectedRequestException("{&FILE_CAN_NOT_BE_EMPTY_OR_FILE_CAN_NOT_BE_RECOGNIZED}", 422);
}
// Record project event.
List<String> ruleNames = new ArrayList<>(excelRuleListener.getTemplateExcelContent().keySet().size() + excelRuleListener.getCustomExcelContent().keySet().size() + excelRuleListener.getTemplateFileExcelContent().keySet().size() + excelRuleListener.getMultiTemplateExcelContent().keySet().size());
ruleNames.addAll(excelRuleListener.getCustomExcelContent().keySet());
ruleNames.addAll(excelRuleListener.getTemplateExcelContent().keySet());
ruleNames.addAll(excelRuleListener.getTemplateFileExcelContent().keySet());
ruleNames.addAll(excelRuleListener.getMultiTemplateExcelContent().keySet());
if (projectId != null) {
Project projectInDb = projectDao.findById(projectId);
if (projectInDb == null) {
throw new UnExpectedRequestException("{&PROJECT_ID} {&DOES_NOT_EXIST}");
}
// Check permissions of project
List<Integer> permissions = new ArrayList<>();
permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
projectService.checkProjectPermission(projectInDb, userName, permissions);
getAndSaveRule(excelRuleListener.getTemplateExcelContent(), excelRuleListener.getCustomExcelContent(), excelRuleListener.getMultiTemplateExcelContent(), excelRuleListener.getTemplateFileExcelContent(), projectInDb, userName, aomp);
// projectEventService.record(projectInDb.getId(), userName, "upload", "[" + Arrays.toString(ruleNames.toArray()) + "].", EventTypeEnum.MODIFY_PROJECT.getCode());
} else {
// All three rules are derived from the same project.
String projectName = "";
if (CollectionUtils.isNotEmpty(excelRuleListener.getTemplateExcelContent().keySet())) {
projectName = excelRuleListener.getTemplateExcelContent().values().iterator().next().iterator().next().getProjectName();
} else if (CollectionUtils.isNotEmpty(excelRuleListener.getCustomExcelContent().keySet())) {
projectName = excelRuleListener.getCustomExcelContent().values().iterator().next().iterator().next().getProjectName();
} else if (CollectionUtils.isNotEmpty(excelRuleListener.getMultiTemplateExcelContent().keySet())) {
projectName = excelRuleListener.getMultiTemplateExcelContent().values().iterator().next().iterator().next().getProjectName();
} else if (CollectionUtils.isNotEmpty(excelRuleListener.getTemplateFileExcelContent().keySet())) {
projectName = excelRuleListener.getTemplateFileExcelContent().values().iterator().next().iterator().next().getProjectName();
}
Project project = projectDao.findByNameAndCreateUser(projectName, userName);
if (project == null) {
// Auto create project for aomp rules upload.
AddProjectRequest addProjectRequest = new AddProjectRequest();
String currentProjectName = "AOMP_AUTO_PROJECT_" + System.currentTimeMillis();
addProjectRequest.setProjectName(currentProjectName);
addProjectRequest.setDescription("This is for aomp");
User user = userDao.findByUsername(userName);
Long userId = user.getId();
projectService.addProject(addProjectRequest, userId);
project = projectDao.findByNameAndCreateUser(currentProjectName, userName);
}
getAndSaveRule(excelRuleListener.getTemplateExcelContent(), excelRuleListener.getCustomExcelContent(), excelRuleListener.getMultiTemplateExcelContent(), excelRuleListener.getTemplateFileExcelContent(), project, userName, aomp);
// projectEventService.record(project.getId(), userName, "upload", "[" + Arrays.toString(ruleNames.toArray()) + "].", EventTypeEnum.MODIFY_PROJECT.getCode());
}
fileInputStream.close();
return new GeneralResponse<>("200", "{&SUCCEED_TO_UPLOAD_FILE}", null);
}
use of com.webank.wedatasphere.qualitis.rule.excel.ExcelRuleListener in project Qualitis by WeBankFinTech.
the class RuleBatchServiceImpl method partitionByRuleName.
private ExcelRuleListener partitionByRuleName(InputStream inputStream) {
ExcelRuleListener listener = new ExcelRuleListener();
ExcelReader excelReader = new ExcelReader(inputStream, null, listener);
List<Sheet> sheets = excelReader.getSheets();
for (Sheet sheet : sheets) {
if (sheet.getSheetName().equals(ExcelSheetName.TEMPLATE_RULE_NAME)) {
sheet.setClazz(ExcelTemplateRuleByProject.class);
sheet.setHeadLineMun(1);
excelReader.read(sheet);
} else if (sheet.getSheetName().equals(ExcelSheetName.CUSTOM_RULE_NAME)) {
sheet.setClazz(ExcelCustomRuleByProject.class);
sheet.setHeadLineMun(1);
excelReader.read(sheet);
} else if (sheet.getSheetName().equals(ExcelSheetName.MULTI_TEMPLATE_RULE_NAME)) {
sheet.setClazz(ExcelMultiTemplateRuleByProject.class);
sheet.setHeadLineMun(1);
excelReader.read(sheet);
} else if (sheet.getSheetName().equals(ExcelSheetName.TEMPLATE_FILE_RULE_NAME)) {
sheet.setClazz(ExcelTemplateFileRuleByProject.class);
sheet.setHeadLineMun(1);
excelReader.read(sheet);
}
}
return listener;
}
Aggregations