Commit d7413844 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

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 ...@@ -29,6 +29,7 @@ import org.apache.kafka.streams.StreamsBuilder
import org.apache.kafka.streams.Topology import org.apache.kafka.streams.Topology
import org.apache.kafka.streams.kstream.KStream import org.apache.kafka.streams.kstream.KStream
import org.apache.kafka.streams.kstream.Predicate 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.CellType
import org.apache.poi.ss.usermodel.Row import org.apache.poi.ss.usermodel.Row
import org.apache.poi.ss.usermodel.WorkbookFactory import org.apache.poi.ss.usermodel.WorkbookFactory
...@@ -303,8 +304,8 @@ class KafkaTopology(private val settings: SettingsLoader) { ...@@ -303,8 +304,8 @@ class KafkaTopology(private val settings: SettingsLoader) {
if (count <= headerCount) { if (count <= headerCount) {
if (count == propertyNamesIndex) { if (count == propertyNamesIndex) {
propertiesList.addAll(row.map { cell -> propertiesList.addAll(row.map { cell ->
if (cell.stringCellValue.isNotEmpty()) { if (retriveCellValue(cell).isNotEmpty()) {
if (cell.stringCellValue.any { char -> if (retriveCellValue(cell).any { char ->
invalidPropertyNameCharacters.contains( invalidPropertyNameCharacters.contains(
char char
) )
...@@ -314,7 +315,7 @@ class KafkaTopology(private val settings: SettingsLoader) { ...@@ -314,7 +315,7 @@ class KafkaTopology(private val settings: SettingsLoader) {
"The property in cell ${cell.address} contains one or more invalid characters: $invalidPropertyNameCharacters." "The property in cell ${cell.address} contains one or more invalid characters: $invalidPropertyNameCharacters."
) )
} else { } else {
cell.stringCellValue retriveCellValue(cell)
} }
} else { } else {
throw InvalidInputException( throw InvalidInputException(
...@@ -329,7 +330,7 @@ class KafkaTopology(private val settings: SettingsLoader) { ...@@ -329,7 +330,7 @@ class KafkaTopology(private val settings: SettingsLoader) {
val rowIdentifier: String = try { val rowIdentifier: String = try {
row.getCell(identifierIndex - 1).let { cell -> row.getCell(identifierIndex - 1).let { cell ->
if (cell != null) { if (cell != null) {
when (val cellValue = cell.stringCellValue) { when (val cellValue = retriveCellValue(cell)) {
"" -> { "" -> {
throw InvalidInputException( throw InvalidInputException(
"CellAddress: $count:$identifierIndex", "CellAddress: $count:$identifierIndex",
...@@ -393,7 +394,12 @@ class KafkaTopology(private val settings: SettingsLoader) { ...@@ -393,7 +394,12 @@ class KafkaTopology(private val settings: SettingsLoader) {
private fun retrieveCells(row: Row, size: Int): List<String> { private fun retrieveCells(row: Row, size: Int): List<String> {
return (0..size).map { i -> return (0..size).map { i ->
val cell = row.getCell(i) val cell = row.getCell(i)
if (cell != null) { retriveCellValue(cell)
}
}
private fun retriveCellValue(cell: Cell?): String {
return if (cell != null) {
when (cell.cellType) { when (cell.cellType) {
CellType.BLANK -> "" CellType.BLANK -> ""
CellType.BOOLEAN -> cell.booleanCellValue.toString() CellType.BOOLEAN -> cell.booleanCellValue.toString()
...@@ -406,5 +412,4 @@ class KafkaTopology(private val settings: SettingsLoader) { ...@@ -406,5 +412,4 @@ class KafkaTopology(private val settings: SettingsLoader) {
} }
} else "" } else ""
} }
}
} }
Supports Markdown
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