This is an automated email from the ASF dual-hosted git repository.
exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new d46aa89788 NIFI-8005 Added warning message for Excel sheets not found
d46aa89788 is described below
commit d46aa89788266411c84e260b46e1820c65e4a965
Author: dan-s1
AuthorDate: Fri Jan 27 14:48:14 2023 +
NIFI-8005 Added warning message for Excel sheets not found
This closes #6897
Signed-off-by: David Handermann
---
.../processors/poi/ConvertExcelToCSVProcessor.java | 21 +
.../poi/ConvertExcelToCSVProcessorTest.java | 2 ++
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git
a/nifi-nar-bundles/nifi-poi-bundle/nifi-poi-processors/src/main/java/org/apache/nifi/processors/poi/ConvertExcelToCSVProcessor.java
b/nifi-nar-bundles/nifi-poi-bundle/nifi-poi-processors/src/main/java/org/apache/nifi/processors/poi/ConvertExcelToCSVProcessor.java
index 9e9183f444..32a4d11a65 100644
---
a/nifi-nar-bundles/nifi-poi-bundle/nifi-poi-processors/src/main/java/org/apache/nifi/processors/poi/ConvertExcelToCSVProcessor.java
+++
b/nifi-nar-bundles/nifi-poi-bundle/nifi-poi-processors/src/main/java/org/apache/nifi/processors/poi/ConvertExcelToCSVProcessor.java
@@ -23,10 +23,13 @@ import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import java.util.stream.Collectors;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
@@ -96,7 +99,7 @@ public class ConvertExcelToCSVProcessor
.displayName("Sheets to Extract")
.description("Comma separated list of Excel document sheet names
that should be extracted from the excel document. If this property" +
" is left blank then all of the sheets will be extracted
from the Excel document. The list of names is case in-sensitive. Any sheets not
" +
-"specified in this value will be ignored.")
+"specified in this value will be ignored. A bulletin will
be generated if a specified sheet(s) are not found.")
.required(false)
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
@@ -240,25 +243,35 @@ public class ConvertExcelToCSVProcessor
.split(desiredSheetsDelimited,
DESIRED_SHEETS_DELIMITER);
if (desiredSheets != null) {
+Map sheetsFound =
Arrays.stream(desiredSheets)
+.collect(Collectors.toMap(key -> key,
value -> Boolean.FALSE));
while (iter.hasNext()) {
InputStream sheet = iter.next();
String sheetName = iter.getSheetName();
-for (int i = 0; i < desiredSheets.length;
i++) {
+for (String desiredSheet : desiredSheets) {
//If the sheetName is a desired one
parse it
-if
(sheetName.equalsIgnoreCase(desiredSheets[i])) {
+if
(sheetName.equalsIgnoreCase(desiredSheet)) {
ExcelSheetReadConfig readConfig =
new ExcelSheetReadConfig(columnsToSkip, firstRow, sheetName, formatValues, sst,
styles);
handleExcelSheet(session,
flowFile, sheet, readConfig, csvFormat);
+sheetsFound.put(desiredSheet,
Boolean.TRUE);
break;
}
}
}
+String sheetsNotFound =
sheetsFound.entrySet().stream()
+.filter(entry -> !entry.getValue())
+.map(Map.Entry::getKey)
+.collect(Collectors.joining(","));
+if (!sheetsNotFound.isEmpty()) {
+getLogger().warn("Excel sheets not found:
{}", sheetsNotFound);
+}
} else {
getLogger().debug("Excel document was parsed
but no sheets with the specified desired names were found.");
}
} else {
-