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

Rename JSON to JsonUtility

parent 812e958d
...@@ -31,7 +31,7 @@ import org.apache.kafka.streams.kstream.KStream ...@@ -31,7 +31,7 @@ import org.apache.kafka.streams.kstream.KStream
import org.apache.kafka.streams.kstream.Predicate import org.apache.kafka.streams.kstream.Predicate
import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.LogManager
import org.memobase.helpers.ElasticSearchWrapper import org.memobase.helpers.ElasticSearchWrapper
import org.memobase.helpers.JSON import org.memobase.helpers.JsonUtility
import org.memobase.helpers.Constants.SettingsProps import org.memobase.helpers.Constants.SettingsProps
import org.memobase.helpers.TranslationMappers import org.memobase.helpers.TranslationMappers
import org.memobase.helpers.UpdateQueryBuilder import org.memobase.helpers.UpdateQueryBuilder
...@@ -67,14 +67,14 @@ class KafkaTopology( ...@@ -67,14 +67,14 @@ class KafkaTopology(
val builder = StreamsBuilder() val builder = StreamsBuilder()
val stream = builder.stream<String, String>(settings.inputTopic) val stream = builder.stream<String, String>(settings.inputTopic)
val branchedStream = stream val branchedStream = stream
.mapValues { value -> JSON.parse(value) } .mapValues { value -> JsonUtility.parse(value) }
.filter { _, value -> value.isNotEmpty() } .filter { _, value -> value.isNotEmpty() }
.mapValues { value -> JSON.unpack(value) } .mapValues { value -> JsonUtility.unpack(value) }
.map { key, value -> KeyValue(key.substringAfterLast("/"), value) } .map { key, value -> KeyValue(key.substringAfterLast("/"), value) }
.branch( .branch(
Predicate { _, value -> value.containsKey(JSON.recordTag) }, Predicate { _, value -> value.containsKey(JsonUtility.recordTag) },
Predicate { _, value -> value.containsKey(JSON.institutionTag) }, Predicate { _, value -> value.containsKey(JsonUtility.institutionTag) },
Predicate { _, value -> value.containsKey(JSON.recordSetTag) }, Predicate { _, value -> value.containsKey(JsonUtility.recordSetTag) },
Predicate { _, _ -> true } Predicate { _, _ -> true }
) )
...@@ -181,7 +181,7 @@ class KafkaTopology( ...@@ -181,7 +181,7 @@ class KafkaTopology(
} }
} }
.filter { _, value -> value != null } .filter { _, value -> value != null }
.mapValues { value -> JSON.queryToJson(value!!) } .mapValues { value -> JsonUtility.queryToJson(value!!) }
.to(updateTopic) .to(updateTopic)
...@@ -202,7 +202,7 @@ class KafkaTopology( ...@@ -202,7 +202,7 @@ class KafkaTopology(
} }
} }
.filter { _, value -> value != null } .filter { _, value -> value != null }
.mapValues { value -> JSON.queryToJson(value!!) } .mapValues { value -> JsonUtility.queryToJson(value!!) }
.to(updateTopic) .to(updateTopic)
} }
......
...@@ -30,7 +30,7 @@ import org.apache.logging.log4j.LogManager ...@@ -30,7 +30,7 @@ import org.apache.logging.log4j.LogManager
import org.memobase.helpers.Date import org.memobase.helpers.Date
import org.memobase.helpers.ElasticSearchWrapper import org.memobase.helpers.ElasticSearchWrapper
import org.memobase.helpers.Extract import org.memobase.helpers.Extract
import org.memobase.helpers.JSON import org.memobase.helpers.JsonUtility
import org.memobase.helpers.Constants import org.memobase.helpers.Constants
import org.memobase.model.FacetContainer import org.memobase.model.FacetContainer
import org.memobase.model.IntegerRange import org.memobase.model.IntegerRange
...@@ -44,7 +44,7 @@ class RecordSetSearchDocBuilder(private val elasticSearchWrapper: ElasticSearchW ...@@ -44,7 +44,7 @@ class RecordSetSearchDocBuilder(private val elasticSearchWrapper: ElasticSearchW
fun transform(key: String, input: Map<String, JsonObject>): Schema { fun transform(key: String, input: Map<String, JsonObject>): Schema {
val recordSet = val recordSet =
input[JSON.recordSetTag] ?: throw InvalidInputException("No record set entity found in message $key.") input[JsonUtility.recordSetTag] ?: throw InvalidInputException("No record set entity found in message $key.")
val relatedRecordSetIds = val relatedRecordSetIds =
Extract.identifiers(recordSet[RICO.isRecordResourceAssociatedWithRecordResource.localName]) Extract.identifiers(recordSet[RICO.isRecordResourceAssociatedWithRecordResource.localName])
val metadataLanguages = mutableListOf<JsonObject>() val metadataLanguages = mutableListOf<JsonObject>()
......
...@@ -27,7 +27,7 @@ import java.io.StringReader ...@@ -27,7 +27,7 @@ import java.io.StringReader
import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.LogManager
import org.memobase.model.UpdateQuery import org.memobase.model.UpdateQuery
object JSON { object JsonUtility {
private val log = LogManager.getLogger("JsonParser") private val log = LogManager.getLogger("JsonParser")
......
...@@ -8,11 +8,9 @@ import org.assertj.core.api.Assertions.assertThat ...@@ -8,11 +8,9 @@ import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance import org.junit.jupiter.api.TestInstance
import org.memobase.helpers.ElasticSearchWrapper import org.memobase.helpers.ElasticSearchWrapper
import org.memobase.helpers.JSON import org.memobase.helpers.JsonUtility
import org.memobase.model.DocumentsSearchDoc import org.memobase.model.DocumentsSearchDoc
import org.memobase.model.FacetContainer
import org.memobase.model.LanguageContainer import org.memobase.model.LanguageContainer
import org.memobase.model.LanguageContainer.Companion
@TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestDocumentsSearchDoc { class TestDocumentsSearchDoc {
...@@ -41,8 +39,8 @@ class TestDocumentsSearchDoc { ...@@ -41,8 +39,8 @@ class TestDocumentsSearchDoc {
@Test @Test
fun `test minimal record required`() { fun `test minimal record required`() {
val input = JSON.parse(readFile("minimal_record_required.json")) val input = JsonUtility.parse(readFile("minimal_record_required.json"))
val mappedInput = JSON.unpack(input) val mappedInput = JsonUtility.unpack(input)
val output = transformer.transform( val output = transformer.transform(
"TestIdentifier", "TestIdentifier",
mappedInput mappedInput
......
...@@ -18,7 +18,7 @@ import org.junit.jupiter.api.Test ...@@ -18,7 +18,7 @@ import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.assertAll import org.junit.jupiter.api.assertAll
import org.memobase.helpers.ElasticSearchWrapper import org.memobase.helpers.ElasticSearchWrapper
import org.memobase.helpers.JSON import org.memobase.helpers.JsonUtility
import org.memobase.helpers.Constants.SettingsProps import org.memobase.helpers.Constants.SettingsProps
import org.memobase.model.FacetContainer import org.memobase.model.FacetContainer
import org.memobase.model.InstitutionSearchDoc import org.memobase.model.InstitutionSearchDoc
...@@ -46,7 +46,7 @@ class TestInstitutionSearchDoc { ...@@ -46,7 +46,7 @@ class TestInstitutionSearchDoc {
props.appSettings.getProperty(SettingsProps.recordSetIndex) props.appSettings.getProperty(SettingsProps.recordSetIndex)
) )
val input = JSON.unpack(JSON.parse(readFile("completeExample.json"))) val input = JsonUtility.unpack(JsonUtility.parse(readFile("completeExample.json")))
val builder = InstitutionSearchDocBuilder(TestUtilities.translationMappers, elastic) val builder = InstitutionSearchDocBuilder(TestUtilities.translationMappers, elastic)
val output = builder.transform("aag", input) as InstitutionSearchDoc val output = builder.transform("aag", input) as InstitutionSearchDoc
......
...@@ -18,7 +18,7 @@ import org.junit.jupiter.api.Test ...@@ -18,7 +18,7 @@ import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.assertAll import org.junit.jupiter.api.assertAll
import org.memobase.helpers.ElasticSearchWrapper import org.memobase.helpers.ElasticSearchWrapper
import org.memobase.helpers.JSON import org.memobase.helpers.JsonUtility
import org.memobase.model.FacetContainer import org.memobase.model.FacetContainer
import org.memobase.model.LanguageContainer import org.memobase.model.LanguageContainer
import org.memobase.model.RecordSetSearchDoc import org.memobase.model.RecordSetSearchDoc
...@@ -79,7 +79,7 @@ class TestRecordSetSearchDoc { ...@@ -79,7 +79,7 @@ class TestRecordSetSearchDoc {
listOf("Complete Record Set (FR)"), listOf("Complete Record Set (FR)"),
listOf("Complete Record Set (IT)") listOf("Complete Record Set (IT)")
) )
val input = JSON.unpack(JSON.parse(data)) val input = JsonUtility.unpack(JsonUtility.parse(data))
val searchDocBuilder = RecordSetSearchDocBuilder(wrapper) val searchDocBuilder = RecordSetSearchDocBuilder(wrapper)
val result = searchDocBuilder.transform("https://memobase.ch/recordSet/completeExample", input) val result = searchDocBuilder.transform("https://memobase.ch/recordSet/completeExample", input)
......
...@@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test ...@@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.assertThrows import org.junit.jupiter.api.assertThrows
import org.memobase.helpers.ElasticSearchWrapper import org.memobase.helpers.ElasticSearchWrapper
import org.memobase.helpers.JSON import org.memobase.helpers.JsonUtility
import org.memobase.model.LanguageContainer import org.memobase.model.LanguageContainer
@TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestInstance(TestInstance.Lifecycle.PER_CLASS)
...@@ -36,8 +36,8 @@ class TestTransform { ...@@ -36,8 +36,8 @@ class TestTransform {
@Test @Test
fun `test enriched digital metadata record`() { fun `test enriched digital metadata record`() {
val input = JSON.unpack( val input = JsonUtility.unpack(
JSON.parse( JsonUtility.parse(
FileInputStream(File("$dataPath/enrich_digital_metadata_record.json")).bufferedReader().readLines() FileInputStream(File("$dataPath/enrich_digital_metadata_record.json")).bufferedReader().readLines()
.reduce { acc, s -> acc + "\n" + s }) .reduce { acc, s -> acc + "\n" + s })
) )
......
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