You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by "featzhang (via GitHub)" <gi...@apache.org> on 2023/04/10 11:48:29 UTC

[GitHub] [inlong] featzhang opened a new pull request, #7819: [INLONG-7816][Manager] Support validation rules when exporting Excel file

featzhang opened a new pull request, #7819:
URL: https://github.com/apache/inlong/pull/7819

   Fixes #7816 
   
   
   ## Validation results
   
   <img width="721" alt="image" src="https://user-images.githubusercontent.com/5709212/230895779-b0711515-0acf-4266-bd5c-c2c426797ebf.png">
   


-- 
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


[GitHub] [inlong] dockerzhang merged pull request #7819: [INLONG-7816][Manager] Support validation rules when exporting Excel file

Posted by "dockerzhang (via GitHub)" <gi...@apache.org>.
dockerzhang merged PR #7819:
URL: https://github.com/apache/inlong/pull/7819


-- 
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


[GitHub] [inlong] featzhang commented on a diff in pull request #7819: [INLONG-7816][Manager] Support validation rules when exporting Excel file

Posted by "featzhang (via GitHub)" <gi...@apache.org>.
featzhang commented on code in PR #7819:
URL: https://github.com/apache/inlong/pull/7819#discussion_r1162460841


##########
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:
   Fixed



-- 
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


[GitHub] [inlong] featzhang commented on a diff in pull request #7819: [INLONG-7816][Manager] Support validation rules when exporting Excel file

Posted by "featzhang (via GitHub)" <gi...@apache.org>.
featzhang commented on code in PR #7819:
URL: https://github.com/apache/inlong/pull/7819#discussion_r1162462584


##########
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:
   The first map is used to generate the ExcelCellValidator instance, it may be null. 
   the second map to get constraints from ExcelCellValidator if not null



-- 
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


[GitHub] [inlong] healchow commented on a diff in pull request #7819: [INLONG-7816][Manager] Support validation rules when exporting Excel file

Posted by "healchow (via GitHub)" <gi...@apache.org>.
healchow commented on code in PR #7819:
URL: https://github.com/apache/inlong/pull/7819#discussion_r1161699634


##########
inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/tool/excel/ExcelTool.java:
##########
@@ -159,6 +168,54 @@ 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 = Arrays.stream(fields).map(field -> {
+            field.setAccessible(true);
+            return Pair.of(field.getName(), field.getAnnotation(ExcelField.class));
+        }).filter(p -> p.getRight() != null).collect(Collectors.toList());
+
+        IntStream.range(0, excelFields.size())

Review Comment:
   Is a for-loop enough?



-- 
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


[GitHub] [inlong] fuweng11 commented on a diff in pull request #7819: [INLONG-7816][Manager] Support validation rules when exporting Excel file

Posted by "fuweng11 (via GitHub)" <gi...@apache.org>.
fuweng11 commented on code in PR #7819:
URL: https://github.com/apache/inlong/pull/7819#discussion_r1162475755


##########
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> excelFieldPair = excelFields.get(index);
+            Class<? extends ExcelCellValidator> validator = excelFieldPair.getRight().validator();
+
+            Optional<List<String>> optionalList = Optional.ofNullable(validator)

Review Comment:
   `Optional.ofNullable(validator)` maybe is null.



-- 
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


[GitHub] [inlong] featzhang commented on a diff in pull request #7819: [INLONG-7816][Manager] Support validation rules when exporting Excel file

Posted by "featzhang (via GitHub)" <gi...@apache.org>.
featzhang commented on code in PR #7819:
URL: https://github.com/apache/inlong/pull/7819#discussion_r1162494687


##########
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> excelFieldPair = excelFields.get(index);
+            Class<? extends ExcelCellValidator> validator = excelFieldPair.getRight().validator();
+
+            Optional<List<String>> optionalList = Optional.ofNullable(validator)
+                    .filter(v -> v != ExcelCellValidator.class)

Review Comment:
   ExcelCellValidator is the default implements, which is not settled by user. If it settled, get the constraint. The `filter` method applies this function to the element in the Optional object, and if the function returns true, it returns an Optional object containing the original element. Otherwise, it returns an empty Optional object.



-- 
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


[GitHub] [inlong] fuweng11 commented on a diff in pull request #7819: [INLONG-7816][Manager] Support validation rules when exporting Excel file

Posted by "fuweng11 (via GitHub)" <gi...@apache.org>.
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


[GitHub] [inlong] fuweng11 commented on a diff in pull request #7819: [INLONG-7816][Manager] Support validation rules when exporting Excel file

Posted by "fuweng11 (via GitHub)" <gi...@apache.org>.
fuweng11 commented on code in PR #7819:
URL: https://github.com/apache/inlong/pull/7819#discussion_r1162466726


##########
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> excelFieldPair = excelFields.get(index);
+            Class<? extends ExcelCellValidator> validator = excelFieldPair.getRight().validator();
+
+            Optional<List<String>> optionalList = Optional.ofNullable(validator)
+                    .filter(v -> v != ExcelCellValidator.class)

Review Comment:
   Is this statement valid?



-- 
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


[GitHub] [inlong] featzhang commented on a diff in pull request #7819: [INLONG-7816][Manager] Support validation rules when exporting Excel file

Posted by "featzhang (via GitHub)" <gi...@apache.org>.
featzhang commented on code in PR #7819:
URL: https://github.com/apache/inlong/pull/7819#discussion_r1161800287


##########
inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/tool/excel/ExcelTool.java:
##########
@@ -159,6 +168,54 @@ 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 = Arrays.stream(fields).map(field -> {
+            field.setAccessible(true);
+            return Pair.of(field.getName(), field.getAnnotation(ExcelField.class));
+        }).filter(p -> p.getRight() != null).collect(Collectors.toList());
+
+        IntStream.range(0, excelFields.size())

Review Comment:
   Fixed



-- 
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


[GitHub] [inlong] featzhang commented on a diff in pull request #7819: [INLONG-7816][Manager] Support validation rules when exporting Excel file

Posted by "featzhang (via GitHub)" <gi...@apache.org>.
featzhang commented on code in PR #7819:
URL: https://github.com/apache/inlong/pull/7819#discussion_r1162498335


##########
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> excelFieldPair = excelFields.get(index);
+            Class<? extends ExcelCellValidator> validator = excelFieldPair.getRight().validator();
+
+            Optional<List<String>> optionalList = Optional.ofNullable(validator)

Review Comment:
   It maybe null, default will return empty List.



-- 
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