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
import org.apache.kafka.streams.kstream.Predicate
import org.memobase.models.Formats
import org.memobase.models.Message
import org.memobase.models.ReportMessages
class KafkaTopology(private val settings: SettingsLoader) {
private val step = settings.appSettings.getProperty(Service.reportingStepNamePropName)
......@@ -79,7 +80,7 @@ class KafkaTopology(private val settings: SettingsLoader) {
Message("", ""), Report(
readOnlyKey,
ReportStatus.fatal,
"Could not parse message from data $data.",
ReportMessages.fatalJSON("Could not parse message from data $data"),
step
)
)
......@@ -88,7 +89,7 @@ class KafkaTopology(private val settings: SettingsLoader) {
parsedMessage, Report(
readOnlyKey,
ReportStatus.success,
"",
ReportMessages.success(),
step
)
)
......@@ -98,7 +99,7 @@ class KafkaTopology(private val settings: SettingsLoader) {
Message("", ""), Report(
readOnlyKey,
ReportStatus.fatal,
"JSON Parser Error: ${ex.localizedMessage}.",
ReportMessages.fatalJSON(ex.localizedMessage),
step
)
)
......
......@@ -33,6 +33,7 @@ import org.memobase.UtilityFunctions.retrieveCells
import org.memobase.UtilityFunctions.zip
import org.memobase.models.Formats
import org.memobase.models.Message
import org.memobase.models.ReportMessages
import org.memobase.models.ResultMessage
class TableParser(private val step: String, settings: SettingsLoader) {
......@@ -54,7 +55,7 @@ class TableParser(private val step: String, settings: SettingsLoader) {
Report(
key,
ReportStatus.fatal,
"Invalid CSV Input: ${ex.localizedMessage}.",
ReportMessages.fatalCSV(ex.localizedMessage),
step
)
)
......@@ -67,7 +68,7 @@ class TableParser(private val step: String, settings: SettingsLoader) {
Report(
key,
ReportStatus.fatal,
"Invalid Input: ${ex.localizedMessage}. Could not process any lines.",
ReportMessages.fatalInput(ex.localizedMessage),
step
)
)
......@@ -79,7 +80,19 @@ class TableParser(private val step: String, settings: SettingsLoader) {
Report(
key,
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
)
)
......@@ -150,7 +163,7 @@ class TableParser(private val step: String, settings: SettingsLoader) {
Report(
key,
ReportStatus.fatal,
ex.localizedMessage,
ReportMessages.fatalInput(ex.localizedMessage),
step
)
)
......@@ -165,7 +178,7 @@ class TableParser(private val step: String, settings: SettingsLoader) {
val report = Report(
identifier,
ReportStatus.success,
"",
ReportMessages.success(),
step
)
resultMessages.add(ResultMessage(identifier, keyValueMap, report))
......@@ -239,7 +252,7 @@ class TableParser(private val step: String, settings: SettingsLoader) {
key, null, Report(
key,
ReportStatus.fatal,
ex.localizedMessage,
ReportMessages.fatalInput(ex.localizedMessage),
step
)
)
......@@ -257,7 +270,7 @@ class TableParser(private val step: String, settings: SettingsLoader) {
rowIdentifier, jsonObject, Report(
rowIdentifier,
ReportStatus.success,
"",
ReportMessages.success(),
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",
"status": "SUCCESS",
"message": "",
"message": "Transformed table to map successfully.",
"step": "test"
}
\ No newline at end of file
{
"id": "test-id-2",
"status": "SUCCESS",
"message": "",
"message": "Transformed table to map successfully.",
"step": "test"
}
\ No newline at end of file
{
"id": "Test-1",
"status": "SUCCESS",
"message": "",
"message": "Transformed table to map successfully.",
"step": "test"
}
\ No newline at end of file
{
"id": "Test-2",
"status": "SUCCESS",
"message": "",
"message": "Transformed table to map successfully.",
"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