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

Fix rico:Concept mapper

Duplicate keys are not allowed.
Need to use lists if sections
are needed twice or more.
parent 4665dc7f
...@@ -176,21 +176,32 @@ class MappingConfig(directory: String) { ...@@ -176,21 +176,32 @@ class MappingConfig(directory: String) {
private fun buildRicoConceptMappers(key: String, value: Any?): List<IFieldMapper> { private fun buildRicoConceptMappers(key: String, value: Any?): List<IFieldMapper> {
return when (value) { return when (value) {
is Map<*, *> -> { is Map<*, *> -> {
value.entries.map { extractRicoConceptFields(key, value as Map<String, Any>)
KEYS.ricoConceptCategoryToTypesMap[key].let { typeList -> }
if (typeList != null) is List<*> -> {
parseFieldWithKeyValidation(key, it as Map.Entry<String, Any>, typeList) value.flatMap {
else if (it is Map<*, *>) {
throw InvalidMappingException("Could not find a types configuration for field $key.") extractRicoConceptFields(key, it as Map<String, Any>)
} else {
throw InvalidMappingException("Expected a key-value map in section $key.")
} }
}.map {
RicoConceptMapper(key, it)
} }
} }
else -> throw InvalidMappingException("Expected a key-value map in section $key.") else -> throw InvalidMappingException("Expected a key-value map in section $key.")
} }
}
private fun extractRicoConceptFields(key: String, map: Map<String, Any>): List<IFieldMapper> {
return map.entries.map { entry ->
KEYS.ricoConceptCategoryToTypesMap[key].let { typeList ->
if (typeList != null)
parseFieldWithKeyValidation(key, entry, typeList)
else
throw InvalidMappingException("Could not find a types configuration for field $key.")
}
}.map { field ->
RicoConceptMapper(key, field)
}
} }
private fun buildAgentMapper(key: String, value: Any?): List<IFieldMapper> { private fun buildAgentMapper(key: String, value: Any?): List<IFieldMapper> {
......
...@@ -23,6 +23,7 @@ import org.memobase.settings.CustomEnvConfig ...@@ -23,6 +23,7 @@ import org.memobase.settings.CustomEnvConfig
import org.memobase.settings.MissingSettingException import org.memobase.settings.MissingSettingException
import org.snakeyaml.engine.v2.api.Load import org.snakeyaml.engine.v2.api.Load
import org.snakeyaml.engine.v2.api.LoadSettings import org.snakeyaml.engine.v2.api.LoadSettings
import org.snakeyaml.engine.v2.exceptions.DuplicateKeyException
import org.snakeyaml.engine.v2.exceptions.MissingEnvironmentVariableException import org.snakeyaml.engine.v2.exceptions.MissingEnvironmentVariableException
import java.nio.charset.Charset import java.nio.charset.Charset
import java.nio.file.Files import java.nio.file.Files
...@@ -37,7 +38,7 @@ class YamlLoader(private val directory: String) { ...@@ -37,7 +38,7 @@ class YamlLoader(private val directory: String) {
fun load(): Iterable<Any> { fun load(): Iterable<Any> {
val settings = val settings =
LoadSettings.builder().setAllowDuplicateKeys(true).setEnvConfig(Optional.of(CustomEnvConfig())).build() LoadSettings.builder().setEnvConfig(Optional.of(CustomEnvConfig())).build()
val load = Load(settings) val load = Load(settings)
return try { return try {
val data = readFiles() val data = readFiles()
...@@ -49,6 +50,9 @@ class YamlLoader(private val directory: String) { ...@@ -49,6 +50,9 @@ class YamlLoader(private val directory: String) {
throw MissingSettingException("env", ex.localizedMessage) throw MissingSettingException("env", ex.localizedMessage)
} catch (ex: ClassCastException) { } catch (ex: ClassCastException) {
throw InvalidMappingException("Top level structure of the mapping file must be a map!") throw InvalidMappingException("Top level structure of the mapping file must be a map!")
} catch (ex: DuplicateKeyException) {
// TODO: Figure out why this exception is not properly caught...
throw InvalidMappingException("Duplicate Key Detected: ${ex.localizedMessage}.")
} }
} }
} }
\ No newline at end of file
...@@ -223,6 +223,20 @@ class Tests { ...@@ -223,6 +223,20 @@ class Tests {
"Successfully created a record from source." "Successfully created a record from source."
) )
) )
),
KafkaTestParams(
6,
"ID_1",
listOf(
"https://memobase.ch/record/TEST-ID_1"
),
listOf(
Report(
"https://memobase.ch/record/TEST-ID_1",
"SUCCESS",
"Successfully created a record from source."
)
)
) )
) )
......
app:
institutionId: "TEST"
recordSetId: "TEST_RECORD_SET"
configs: src/test/resources/kafkaTests/6/config
kafka:
streams:
bootstrap.servers: localhost:12345
application.id: test-clinet-1234
topic:
in: test-topic-in
out: test-topic-out
process: test-topic-process
\ No newline at end of file
record:
uri: id
type:
const: Foto
languages: # blank node rico:Language with type content or caption and relation rico:hasLanguage
- content:
fr:
- content1
- content:
fr:
- content2
- caption:
fr:
- caption1
{
"id": "ID_1",
"content1": "franz",
"content2": "deutsch",
"caption1": "english"
}
\ No newline at end of file
<https://memobase.ch/record/TEST-ID_1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Record> .
<https://memobase.ch/record/TEST-ID_1> <https://www.ica.org/standards/RiC/ontology#hasLanguage> _:B .
<https://memobase.ch/record/TEST-ID_1> <https://www.ica.org/standards/RiC/ontology#hasLanguage> _:B .
<https://memobase.ch/record/TEST-ID_1> <https://www.ica.org/standards/RiC/ontology#hasLanguage> _:B .
<https://memobase.ch/record/TEST-ID_1> <https://www.ica.org/standards/RiC/ontology#heldBy> <https://memobase.ch/institution/TEST> .
<https://memobase.ch/record/TEST-ID_1> <https://www.ica.org/standards/RiC/ontology#identifiedBy> _:B .
<https://memobase.ch/record/TEST-ID_1> <https://www.ica.org/standards/RiC/ontology#isPartOf> <https://memobase.ch/recordSet/TEST_RECORD_SET> .
<https://memobase.ch/record/TEST-ID_1> <https://www.ica.org/standards/RiC/ontology#type> "Foto" .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Identifier> .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Language> .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Language> .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Language> .
_:B <https://www.ica.org/standards/RiC/ontology#identifier> "https://memobase.ch/record/TEST-ID_1" .
_:B <https://www.ica.org/standards/RiC/ontology#name> "deutsch"@fr .
_:B <https://www.ica.org/standards/RiC/ontology#name> "english"@fr .
_:B <https://www.ica.org/standards/RiC/ontology#name> "franz"@fr .
_:B <https://www.ica.org/standards/RiC/ontology#type> "caption" .
_:B <https://www.ica.org/standards/RiC/ontology#type> "content" .
_:B <https://www.ica.org/standards/RiC/ontology#type> "content" .
_:B <https://www.ica.org/standards/RiC/ontology#type> "main" .
\ No newline at end of file
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