Commit 55a23c4e authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Refactor ReportStatus

Update library dependency
parent 9c66b67a
...@@ -49,7 +49,7 @@ ext { ...@@ -49,7 +49,7 @@ ext {
} }
dependencies { dependencies {
implementation 'org.memobase:memobase-service-utilities:3.0.1' implementation 'org.memobase:memobase-service-utilities:3.0.2'
// Logging Framework // Logging Framework
implementation "org.apache.logging.log4j:log4j-api:${log4jV}" implementation "org.apache.logging.log4j:log4j-api:${log4jV}"
......
...@@ -22,6 +22,7 @@ import ch.memobase.rdf.MB ...@@ -22,6 +22,7 @@ import ch.memobase.rdf.MB
import ch.memobase.rdf.RDF import ch.memobase.rdf.RDF
import ch.memobase.rdf.RICO import ch.memobase.rdf.RICO
import ch.memobase.reporting.Report import ch.memobase.reporting.Report
import ch.memobase.reporting.ReportStatus
import ch.memobase.settings.HeaderExtractionTransformSupplier import ch.memobase.settings.HeaderExtractionTransformSupplier
import ch.memobase.settings.HeaderMetadata import ch.memobase.settings.HeaderMetadata
import ch.memobase.settings.SettingsLoader import ch.memobase.settings.SettingsLoader
...@@ -35,7 +36,6 @@ import org.apache.kafka.streams.kstream.Predicate ...@@ -35,7 +36,6 @@ import org.apache.kafka.streams.kstream.Predicate
import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.LogManager
import org.memobase.model.MemobaseModel import org.memobase.model.MemobaseModel
import org.memobase.model.ProcessResult import org.memobase.model.ProcessResult
import org.memobase.model.ProcessStatus
import org.memobase.model.Transaction import org.memobase.model.Transaction
import java.nio.charset.StandardCharsets import java.nio.charset.StandardCharsets
...@@ -64,12 +64,12 @@ class KafkaTopology( ...@@ -64,12 +64,12 @@ class KafkaTopology(
processOutcome[0] processOutcome[0]
.filter { _, value -> value.status != ProcessStatus.FATAL } .filter { _, value -> value.status != ReportStatus.fatal }
.mapValues { value -> value.data } .mapValues { value -> value.data }
.to(settings.outputTopic + "-records-" + settings.appSettings.getProperty("topicOutPostfix")) .to(settings.outputTopic + "-records-" + settings.appSettings.getProperty("topicOutPostfix"))
processOutcome[0] processOutcome[0]
.filter { _, value -> value.status != ProcessStatus.FATAL } .filter { _, value -> value.status != ReportStatus.fatal }
.mapValues { key, _ -> writeTransaction(key) } .mapValues { key, _ -> writeTransaction(key) }
.to(settings.appSettings.getProperty("topicTransactionsRecords")) .to(settings.appSettings.getProperty("topicTransactionsRecords"))
...@@ -78,7 +78,7 @@ class KafkaTopology( ...@@ -78,7 +78,7 @@ class KafkaTopology(
.to(settings.processReportTopic) .to(settings.processReportTopic)
processOutcome[1] processOutcome[1]
.filter { _, value -> value.status != ProcessStatus.FATAL } .filter { _, value -> value.status != ReportStatus.fatal }
.mapValues { value -> value.data } .mapValues { value -> value.data }
.to(settings.outputTopic + "-record-sets-" + settings.appSettings.getProperty("topicOutPostfix")) .to(settings.outputTopic + "-record-sets-" + settings.appSettings.getProperty("topicOutPostfix"))
...@@ -91,7 +91,7 @@ class KafkaTopology( ...@@ -91,7 +91,7 @@ class KafkaTopology(
.to(settings.processReportTopic) .to(settings.processReportTopic)
processOutcome[2] processOutcome[2]
.filter { _, value -> value.status != ProcessStatus.FATAL } .filter { _, value -> value.status != ReportStatus.fatal }
.mapValues { value -> value.data } .mapValues { value -> value.data }
.to(settings.outputTopic + "-institutions-" + settings.appSettings.getProperty("topicOutPostfix")) .to(settings.outputTopic + "-institutions-" + settings.appSettings.getProperty("topicOutPostfix"))
...@@ -109,7 +109,7 @@ class KafkaTopology( ...@@ -109,7 +109,7 @@ class KafkaTopology(
key, key,
ProcessResult( ProcessResult(
value.data, value.data,
ProcessStatus.FATAL, ReportStatus.fatal,
"Unable to match key type to either records, record sets or institutions." "Unable to match key type to either records, record sets or institutions."
), ),
step step
...@@ -125,7 +125,7 @@ class KafkaTopology( ...@@ -125,7 +125,7 @@ class KafkaTopology(
key, key,
ProcessResult( ProcessResult(
value.data, value.data,
ProcessStatus.FATAL, ReportStatus.fatal,
"Unable to match key type to either records, record sets or institutions." "Unable to match key type to either records, record sets or institutions."
), ),
step step
...@@ -143,13 +143,13 @@ class KafkaTopology( ...@@ -143,13 +143,13 @@ class KafkaTopology(
} catch (ex: RiotException) { } catch (ex: RiotException) {
log.error("Parsing error: ${ex.message}") log.error("Parsing error: ${ex.message}")
log.debug(ex.stackTrace) log.debug(ex.stackTrace)
return ProcessResult(model, ProcessStatus.FATAL, "Parsing of Ntriples failed!") return ProcessResult(model, ReportStatus.fatal, "Parsing of Ntriples failed!")
} }
return ProcessResult(model, ProcessStatus.SUCCESS, "Parsing successful") return ProcessResult(model, ReportStatus.success, "Parsing successful")
} }
private fun writeJsonLd(input: ProcessResult<Model>): ProcessResult<String> { private fun writeJsonLd(input: ProcessResult<Model>): ProcessResult<String> {
return if (input.status != ProcessStatus.SUCCESS) { return if (input.status != ReportStatus.success) {
ProcessResult("", input.status, input.message) ProcessResult("", input.status, input.message)
} else { } else {
ProcessResult(input.data.toString(), input.status, "Transformation successful") ProcessResult(input.data.toString(), input.status, "Transformation successful")
...@@ -172,7 +172,7 @@ class KafkaTopology( ...@@ -172,7 +172,7 @@ class KafkaTopology(
} }
private fun writeReport(id: String, input: ProcessResult<String>, step: String): String { private fun writeReport(id: String, input: ProcessResult<String>, step: String): String {
return Report(id, input.status.toString(), input.message, step).toJson() return Report(id, input.status, input.message, step).toJson()
} }
private fun writeTransaction(id: String): String { private fun writeTransaction(id: String): String {
......
...@@ -18,11 +18,4 @@ ...@@ -18,11 +18,4 @@
package org.memobase.model package org.memobase.model
enum class ProcessStatus { data class ProcessResult<T>(val data: T, val status: String, val message: String)
SUCCESS,
IGNORE,
WARNING,
FATAL
}
data class ProcessResult<T>(val data: T, val status: ProcessStatus, val message: String)
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