use of com.webank.wedatasphere.qualitis.excel.ExcelRuleMetricListener in project Qualitis by WeBankFinTech.
the class RuleMetricServiceImpl method upload.
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> upload(InputStream fileInputStream, FormDataContentDisposition fileDisposition) throws UnExpectedRequestException, IOException {
// Check Arguments
if (fileInputStream == null || fileDisposition == null) {
throw new UnExpectedRequestException("{&FILE_CAN_NOT_BE_NULL_OR_EMPTY}");
}
// Check suffix name of file
String fileName = fileDisposition.getFileName();
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 + "]");
}
String userName = HttpUtils.getUserName(httpServletRequest);
LOGGER.info(userName + " start to upload rule metrics.");
ExcelRuleMetricListener listener = new ExcelRuleMetricListener();
List<ExcelRuleMetric> excelRuleMetrics = listener.getRuleMetricContent();
ExcelReader excelReader = new ExcelReader(fileInputStream, null, listener);
List<Sheet> sheets = excelReader.getSheets();
for (Sheet sheet : sheets) {
if (sheet.getSheetName().equals(ExcelSheetName.RULE_METRIC_NAME)) {
sheet.setClazz(ExcelRuleMetric.class);
sheet.setHeadLineMun(1);
excelReader.read(sheet);
}
}
if (CollectionUtils.isEmpty(excelRuleMetrics)) {
throw new UnExpectedRequestException("{&FILE_CAN_NOT_BE_EMPTY_OR_FILE_CAN_NOT_BE_RECOGNIZED}");
}
try {
for (ExcelRuleMetric excelRuleMetric : excelRuleMetrics) {
AddRuleMetricRequest addRuleMetricRequest = new AddRuleMetricRequest();
addRuleMetric(addRuleMetricRequest);
}
LOGGER.info("Succeed to add all rule metrics");
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
} finally {
fileInputStream.close();
}
return new GeneralResponse<>("200", "{&FAILED_TO_UPLOAD_RULE_METRIC}", null);
}
Aggregations