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

Update / Normalize report messages across the service.

parent 3832c509
...@@ -29,6 +29,7 @@ import org.apache.kafka.streams.Topology ...@@ -29,6 +29,7 @@ import org.apache.kafka.streams.Topology
import org.apache.kafka.streams.kstream.Predicate import org.apache.kafka.streams.kstream.Predicate
import org.memobase.models.Formats import org.memobase.models.Formats
import org.memobase.models.Message import org.memobase.models.Message
import org.memobase.models.ReportMessages
class KafkaTopology(private val settings: SettingsLoader) { class KafkaTopology(private val settings: SettingsLoader) {
private val step = settings.appSettings.getProperty(Service.reportingStepNamePropName) private val step = settings.appSettings.getProperty(Service.reportingStepNamePropName)
...@@ -79,7 +80,7 @@ class KafkaTopology(private val settings: SettingsLoader) { ...@@ -79,7 +80,7 @@ class KafkaTopology(private val settings: SettingsLoader) {
Message("", ""), Report( Message("", ""), Report(
readOnlyKey, readOnlyKey,
ReportStatus.fatal, ReportStatus.fatal,
"Could not parse message from data $data.", ReportMessages.fatalJSON("Could not parse message from data $data"),
step step
) )
) )
...@@ -88,7 +89,7 @@ class KafkaTopology(private val settings: SettingsLoader) { ...@@ -88,7 +89,7 @@ class KafkaTopology(private val settings: SettingsLoader) {
parsedMessage, Report( parsedMessage, Report(
readOnlyKey, readOnlyKey,
ReportStatus.success, ReportStatus.success,
"", ReportMessages.success(),
step step
) )
) )
...@@ -98,7 +99,7 @@ class KafkaTopology(private val settings: SettingsLoader) { ...@@ -98,7 +99,7 @@ class KafkaTopology(private val settings: SettingsLoader) {
Message("", ""), Report( Message("", ""), Report(
readOnlyKey, readOnlyKey,
ReportStatus.fatal, ReportStatus.fatal,
"JSON Parser Error: ${ex.localizedMessage}.", ReportMessages.fatalJSON(ex.localizedMessage),
step step
) )
) )
......
...@@ -33,6 +33,7 @@ import org.memobase.UtilityFunctions.retrieveCells ...@@ -33,6 +33,7 @@ import org.memobase.UtilityFunctions.retrieveCells
import org.memobase.UtilityFunctions.zip import org.memobase.UtilityFunctions.zip
import org.memobase.models.Formats import org.memobase.models.Formats
import org.memobase.models.Message import org.memobase.models.Message
import org.memobase.models.ReportMessages
import org.memobase.models.ResultMessage import org.memobase.models.ResultMessage
class TableParser(private val step: String, settings: SettingsLoader) { class TableParser(private val step: String, settings: SettingsLoader) {
...@@ -54,7 +55,7 @@ class TableParser(private val step: String, settings: SettingsLoader) { ...@@ -54,7 +55,7 @@ class TableParser(private val step: String, settings: SettingsLoader) {
Report( Report(
key, key,
ReportStatus.fatal, ReportStatus.fatal,
"Invalid CSV Input: ${ex.localizedMessage}.", ReportMessages.fatalCSV(ex.localizedMessage),
step step
) )
) )
...@@ -67,7 +68,7 @@ class TableParser(private val step: String, settings: SettingsLoader) { ...@@ -67,7 +68,7 @@ class TableParser(private val step: String, settings: SettingsLoader) {
Report( Report(
key, key,
ReportStatus.fatal, ReportStatus.fatal,
"Invalid Input: ${ex.localizedMessage}. Could not process any lines.", ReportMessages.fatalInput(ex.localizedMessage),
step step
) )
) )
...@@ -79,7 +80,19 @@ class TableParser(private val step: String, settings: SettingsLoader) { ...@@ -79,7 +80,19 @@ class TableParser(private val step: String, settings: SettingsLoader) {
Report( Report(
key, key,
ReportStatus.fatal, ReportStatus.fatal,
"Invalid Sheet Index provided. The sheet index ${metadata.tableSheetIndex} does not exist.", ReportMessages.fatalSheetIndex(metadata.tableSheetIndex),
step
)
)
)
} catch (ex: Exception) {
listOf(
ResultMessage(
key, null,
Report(
key,
ReportStatus.fatal,
ReportMessages.fatalUnknown(ex::class.java.simpleName, ex.localizedMessage),
step step
) )
) )
...@@ -150,7 +163,7 @@ class TableParser(private val step: String, settings: SettingsLoader) { ...@@ -150,7 +163,7 @@ class TableParser(private val step: String, settings: SettingsLoader) {
Report( Report(
key, key,
ReportStatus.fatal, ReportStatus.fatal,
ex.localizedMessage, ReportMessages.fatalInput(ex.localizedMessage),
step step
) )
) )
...@@ -165,7 +178,7 @@ class TableParser(private val step: String, settings: SettingsLoader) { ...@@ -165,7 +178,7 @@ class TableParser(private val step: String, settings: SettingsLoader) {
val report = Report( val report = Report(
identifier, identifier,
ReportStatus.success, ReportStatus.success,
"", ReportMessages.success(),
step step
) )
resultMessages.add(ResultMessage(identifier, keyValueMap, report)) resultMessages.add(ResultMessage(identifier, keyValueMap, report))
...@@ -239,7 +252,7 @@ class TableParser(private val step: String, settings: SettingsLoader) { ...@@ -239,7 +252,7 @@ class TableParser(private val step: String, settings: SettingsLoader) {
key, null, Report( key, null, Report(
key, key,
ReportStatus.fatal, ReportStatus.fatal,
ex.localizedMessage, ReportMessages.fatalInput(ex.localizedMessage),
step step
) )
) )
...@@ -257,7 +270,7 @@ class TableParser(private val step: String, settings: SettingsLoader) { ...@@ -257,7 +270,7 @@ class TableParser(private val step: String, settings: SettingsLoader) {
rowIdentifier, jsonObject, Report( rowIdentifier, jsonObject, Report(
rowIdentifier, rowIdentifier,
ReportStatus.success, ReportStatus.success,
"", ReportMessages.success(),
step step
) )
) )
......
package org.memobase.models
object ReportMessages {
fun success(): String {
return "Transformed table to map successfully."
}
fun fatalJSON(message: String): String {
return "JSON ERROR: $message."
}
fun fatalCSV(message: String): String {
return "Invalid CSV Input: $message."
}
fun fatalInput(message: String): String {
return "Invalid Input: $message."
}
fun fatalSheetIndex(index: Int): String {
return "Invalid Sheet Index: The loaded workbook does not have a sheet with index $index."
}
fun fatalUnknown(exception: String, message: String): String {
return "Unexpected Exception: $exception with message $message."
}
}
\ No newline at end of file
{ {
"id": "test-id-1", "id": "test-id-1",
"status": "SUCCESS", "status": "SUCCESS",
"message": "", "message": "Transformed table to map successfully.",
"step": "test" "step": "test"
} }
\ No newline at end of file
{ {
"id": "test-id-2", "id": "test-id-2",
"status": "SUCCESS", "status": "SUCCESS",
"message": "", "message": "Transformed table to map successfully.",
"step": "test" "step": "test"
} }
\ No newline at end of file
{ {
"id": "Test-1", "id": "Test-1",
"status": "SUCCESS", "status": "SUCCESS",
"message": "", "message": "Transformed table to map successfully.",
"step": "test" "step": "test"
} }
\ No newline at end of file
{ {
"id": "Test-2", "id": "Test-2",
"status": "SUCCESS", "status": "SUCCESS",
"message": "", "message": "Transformed table to map successfully.",
"step": "test" "step": "test"
} }
\ No newline at end of file
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