featzhang commented on code in PR #7869:
URL: https://github.com/apache/inlong/pull/7869#discussion_r1168567241
##########
inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/tool/excel/ExcelTool.java:
##########
@@ -372,35 +373,54 @@ public static <E> List<E> read(InputStream is, Class<E>
clazz)
int lastRowNum = sheet.getLastRowNum();
List<E> currentResult = new ArrayList<>(lastRowNum);
-
+ List<String> validateResult = new ArrayList<>(lastRowNum);
for (int rowNum = 1; rowNum <= lastRowNum; ++rowNum) {
XSSFRow row = sheet.getRow(rowNum);
if (row == null) {
continue;
}
+ // Mark the row only if all cells are not null
+ Map<Integer, FieldMeta> positionFieldMetaMap =
classMeta.positionFieldMetaMap;
+ boolean rowNotNull = positionFieldMetaMap.keySet()
+ .stream()
+ .map(colIndex -> row.getCell(colIndex,
+
Row.MissingCellPolicy.RETURN_BLANK_AS_NULL) != null)
+ .reduce(false, (left, right) -> left || right);
+
+ // Skip if all columns are null
+ if (!rowNotNull) {
+ continue;
+ }
+
E instance = null;
+ StringBuilder colValidateResult = new StringBuilder();
boolean hasValueInRow = false;
- for (Map.Entry<Integer, FieldMeta> entry :
classMeta.positionFieldMetaMap.entrySet()) {
+ for (Map.Entry<Integer, FieldMeta> entry :
positionFieldMetaMap.entrySet()) {
Integer colIndex = entry.getKey();
FieldMeta fieldMeta = entry.getValue();
XSSFCell cell = row.getCell(colIndex,
Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
- if (cell == null) {
- continue;
- }
+
hasValueInRow = true;
ExcelCellDataTransfer cellDataTransfer =
fieldMeta.getCellDataTransfer();
Object value = parseCellValue(cellDataTransfer, cell);
if (instance == null) {
instance = clazz.newInstance();
}
+ validateCellValue(fieldMeta, value).ifPresent(info ->
colValidateResult.append("Column ")
+ .append(colIndex +
1).append(":").append(info).append(";"));
fieldMeta.getField().setAccessible(true);
fieldMeta.getField().set(instance, value);
-
}
if (hasValueInRow) {
currentResult.add(instance);
}
+ if (colValidateResult.length() > 0) {
+ String lineValidateResult = "Error in Row " + (rowNum
+ 1) + ", " + colValidateResult;
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]