Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[plugin-excel] Add handling for null cells #5166

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@ private Map<String, List<String>> parseRowsWithHeader(CellRangeAddress address)
for (int rowIndex = address.getFirstRow() + 1; rowIndex <= address.getLastRow(); rowIndex++)
{
Row row = sheet.getRow(rowIndex);
columnsData.add(getCellValue(row.getCell(colIndex)));
String cellValue = Optional.ofNullable(row.getCell(colIndex))
.map(this::getCellValue)
.orElse(null);
columnsData.add(cellValue);
}
data.put(columnName, columnsData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
private List<String> replaceLineBreaks(List<String> list, String lineBreakReplacement)
{
return list.stream()
.map(e -> e.replace("\n", lineBreakReplacement))
.map(e -> e == null ? e : e.replace("\n", lineBreakReplacement))

Check notice on line 134 in vividus-plugin-excel/src/main/java/org/vividus/excel/transformer/ExcelTableTransformer.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Constant values

Value `e` is always 'null'
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -248,9 +249,13 @@ void testGetDataFromTableRangeWithDiffTypes()
expectedData.put("Number", List.of(ONE_AS_STRING, TWO_AS_STRING));
expectedData.put("String", List.of("STRING", "string"));
expectedData.put("Formula", List.of(THREE_AS_STRING, ""));
List<String> nulls = new ArrayList<>();
nulls.add(null);
nulls.add(null);
expectedData.put("Null", nulls);

sheetParser = new ExcelSheetParser(extractor.getSheet("DifferentTypes").get(), false);
var data = sheetParser.getDataAsTable("A1:D3");
var data = sheetParser.getDataAsTable("A1:E3");
assertEquals(expectedData, data);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ void beforeEach()
properties.getProperties().setProperty(SHEET, "RepeatingData");
}

@Test
void shouldNotReplaceLinebreaksForNullCells()
{
properties.getProperties().setProperty(SHEET, "DifferentTypes");
properties.getProperties().setProperty(RANGE, "E1:E3");
var actualResult = transformer.transform("", null, properties);
assertEquals("|Null|\n|null|\n|null|", actualResult);
}

@Test
void testCheckConcurrentConditionsWithTwoPropertiesThrowException()
{
Expand Down
Binary file modified vividus-plugin-excel/src/test/resources/TestTemplate.xlsx
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ Meta:
When I initialize scenario variable `expectedTable` with values:
|StringValue|NumericValue|BooleanValue|FormulaValue|FormulaErrorValue|
|City |17 |FALSE |289 |#VALUE! |
|Country |19 |TRUE |361 |null |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
|Country |19 |TRUE |361 |null |
|Country |19 |TRUE |361 |#{null} |

Then `${expectedTable}` is equal to table:
{transformer=FROM_EXCEL, path=/data/excel.xlsx, sheet=DifferentTypes, range=A1:E2}
{transformer=FROM_EXCEL, path=/data/excel.xlsx, sheet=DifferentTypes, range=A1:E3}

Scenario: Check FROM_EXCEL transformer with multiple ranges (separate ranges for header and data)
Meta:
Expand Down
Loading