You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by "fuweng11 (via GitHub)" <gi...@apache.org> on 2023/04/11 07:15:05 UTC
[GitHub] [inlong] fuweng11 commented on a diff in pull request #7819: [INLONG-7816][Manager] Support validation rules when exporting Excel file
fuweng11 commented on code in PR #7819:
URL: https://github.com/apache/inlong/pull/7819#discussion_r1162383356
##########
inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/tool/excel/ExcelTool.java:
##########
@@ -159,6 +168,59 @@ private static void fillSheetHeader(XSSFRow row, List<String> heads) {
cell.setCellValue(new XSSFRichTextString(heads.get(index)));
});
}
+ /**
+ * Fills the validation constraints for a given sheet based on the provided class and fields.
+ *
+ * @param clazz the class to use for validation constraints
+ * @param sheet the sheet to fill with validation constraints
+ * @param fields the fields to use for validation constraints
+ */
+ private static <T> void fillSheetValidation(Class<T> clazz, XSSFSheet sheet, Field[] fields) {
+ List<Pair<String, ExcelField>> excelFields = new ArrayList<>();
+
+ for (Field field : fields) {
+ field.setAccessible(true);
+ ExcelField excelField = field.getAnnotation(ExcelField.class);
+ if (excelField != null) {
+ excelFields.add(Pair.of(field.getName(), excelField));
+ }
+ }
+
+ int bound = excelFields.size();
+ for (int index = 0; index < bound; index++) {
+ Pair<String, ExcelField> se = excelFields.get(index);
+ Class<? extends ExcelCellValidator> validator = se.getRight().validator();
+
+ Optional<List<String>> optionalList = Optional.ofNullable(validator)
+ .filter(v -> v != ExcelCellValidator.class)
+ .map(v -> {
+ try {
+ return (ExcelCellValidator<?>) v.newInstance();
+ } catch (InstantiationException | IllegalAccessException e) {
+ LOGGER.error("Can not properly create ExcelCellValidator", e);
+ return null;
+ }
+ })
+ .map(ExcelCellValidator::constraint);
Review Comment:
Why call map twice?
##########
inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/tool/excel/ExcelTool.java:
##########
@@ -159,6 +168,59 @@ private static void fillSheetHeader(XSSFRow row, List<String> heads) {
cell.setCellValue(new XSSFRichTextString(heads.get(index)));
});
}
+ /**
+ * Fills the validation constraints for a given sheet based on the provided class and fields.
+ *
+ * @param clazz the class to use for validation constraints
+ * @param sheet the sheet to fill with validation constraints
+ * @param fields the fields to use for validation constraints
+ */
+ private static <T> void fillSheetValidation(Class<T> clazz, XSSFSheet sheet, Field[] fields) {
+ List<Pair<String, ExcelField>> excelFields = new ArrayList<>();
+
+ for (Field field : fields) {
+ field.setAccessible(true);
+ ExcelField excelField = field.getAnnotation(ExcelField.class);
+ if (excelField != null) {
+ excelFields.add(Pair.of(field.getName(), excelField));
+ }
+ }
+
+ int bound = excelFields.size();
+ for (int index = 0; index < bound; index++) {
+ Pair<String, ExcelField> se = excelFields.get(index);
Review Comment:
Why is it named `se`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org