Commit d7413844 authored by Jonas Waeber's avatar Jonas Waeber

Fix cell value bug

If a cell is numeric the string
value cannot be retrieved directly.
parent 65cc0a8b
Pipeline #10454 passed with stages
in 10 minutes and 18 seconds
......@@ -29,6 +29,7 @@ import org.apache.kafka.streams.StreamsBuilder
import org.apache.kafka.streams.Topology
import org.apache.kafka.streams.kstream.KStream
import org.apache.kafka.streams.kstream.Predicate
import org.apache.poi.ss.usermodel.Cell
import org.apache.poi.ss.usermodel.CellType
import org.apache.poi.ss.usermodel.Row
import org.apache.poi.ss.usermodel.WorkbookFactory
......@@ -303,8 +304,8 @@ class KafkaTopology(private val settings: SettingsLoader) {
if (count <= headerCount) {
if (count == propertyNamesIndex) {
propertiesList.addAll(row.map { cell ->
if (cell.stringCellValue.isNotEmpty()) {
if (cell.stringCellValue.any { char ->
if (retriveCellValue(cell).isNotEmpty()) {
if (retriveCellValue(cell).any { char ->
invalidPropertyNameCharacters.contains(
char
)
......@@ -314,7 +315,7 @@ class KafkaTopology(private val settings: SettingsLoader) {
"The property in cell ${cell.address} contains one or more invalid characters: $invalidPropertyNameCharacters."
)
} else {
cell.stringCellValue
retriveCellValue(cell)
}
} else {
throw InvalidInputException(
......@@ -329,7 +330,7 @@ class KafkaTopology(private val settings: SettingsLoader) {
val rowIdentifier: String = try {
row.getCell(identifierIndex - 1).let { cell ->
if (cell != null) {
when (val cellValue = cell.stringCellValue) {
when (val cellValue = retriveCellValue(cell)) {
"" -> {
throw InvalidInputException(
"CellAddress: $count:$identifierIndex",
......@@ -393,18 +394,22 @@ class KafkaTopology(private val settings: SettingsLoader) {
private fun retrieveCells(row: Row, size: Int): List<String> {
return (0..size).map { i ->
val cell = row.getCell(i)
if (cell != null) {
when (cell.cellType) {
CellType.BLANK -> ""
CellType.BOOLEAN -> cell.booleanCellValue.toString()
CellType._NONE -> ""
CellType.NUMERIC -> cell.numericCellValue.toString()
CellType.STRING -> cell.stringCellValue
CellType.FORMULA -> ""
CellType.ERROR -> ""
else -> ""
}
} else ""
retriveCellValue(cell)
}
}
private fun retriveCellValue(cell: Cell?): String {
return if (cell != null) {
when (cell.cellType) {
CellType.BLANK -> ""
CellType.BOOLEAN -> cell.booleanCellValue.toString()
CellType._NONE -> ""
CellType.NUMERIC -> cell.numericCellValue.toString()
CellType.STRING -> cell.stringCellValue
CellType.FORMULA -> ""
CellType.ERROR -> ""
else -> ""
}
} else ""
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment