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

Add json objects dot notation.

parent f52ac32e
Pipeline #11885 passed with stages
in 5 minutes and 26 seconds
...@@ -67,11 +67,11 @@ sealed class ConfigField { ...@@ -67,11 +67,11 @@ sealed class ConfigField {
sealed class ComplexAnnotationField : AnnotationField() { sealed class ComplexAnnotationField : AnnotationField() {
data class ListField(val key: String, val fields: List<SimpleAnnotationField>) : ComplexAnnotationField() { data class ListField(val key: String, val fields: List<SimpleAnnotationField>) : ComplexAnnotationField() {
fun toLiterals(source: Map<String, String>): List<Literal> { fun toLiterals(source: Map<String, Any>): List<Literal> {
return fields.mapNotNull { return fields.mapNotNull {
when (it) { when (it) {
is MappedAnnotationField -> is MappedAnnotationField ->
source[it.field].let { value -> FieldParsers.unpackSource(it.field, source).let { value ->
if (value != null) { if (value != null) {
it.toLiteral(value) it.toLiteral(value)
} else { } else {
...@@ -86,12 +86,12 @@ sealed class ConfigField { ...@@ -86,12 +86,12 @@ sealed class ConfigField {
data class LanguageField(val key: String, val fields: List<Pair<String, List<SimpleAnnotationField>>>) : data class LanguageField(val key: String, val fields: List<Pair<String, List<SimpleAnnotationField>>>) :
ComplexAnnotationField() { ComplexAnnotationField() {
fun toLangLiterals(source: Map<String, String>): List<Literal> { fun toLangLiterals(source: Map<String, Any>): List<Literal> {
return fields.flatMap { pairs -> return fields.flatMap { pairs ->
pairs.second.mapNotNull { pairs.second.mapNotNull {
when (it) { when (it) {
is MappedAnnotationField -> is MappedAnnotationField ->
source[it.field].let { value -> FieldParsers.unpackSource(it.field, source).let { value ->
if (value != null) { if (value != null) {
it.toLangLiteral(value, pairs.first) it.toLangLiteral(value, pairs.first)
} else { } else {
......
...@@ -138,4 +138,19 @@ object FieldParsers { ...@@ -138,4 +138,19 @@ object FieldParsers {
} }
} }
} }
fun unpackSource(field: String, source: Map<String, Any>): String? {
return if (field.contains('.')) {
val fields = field.split('.')
source[fields[0]].let {
if (it is Map<*, *>) {
it[fields[1]] as String?
} else {
null
}
}
} else {
source[field] as String?
}
}
} }
\ No newline at end of file
...@@ -23,8 +23,8 @@ import org.memobase.mapping.KEYS ...@@ -23,8 +23,8 @@ import org.memobase.mapping.KEYS
class AgentFieldMapper : TypeFieldMapper() { class AgentFieldMapper : TypeFieldMapper() {
var sourceKey: String = "" var sourceKey: String = ""
override fun apply(source: Map<String, String>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
translateProperties(source, subject) translateProperties(source)
if (properties.size > 0) { if (properties.size > 0) {
val relationNameField = properties.filter { it.first == KEYS.relationName } val relationNameField = properties.filter { it.first == KEYS.relationName }
val otherFields = properties.filterNot { it.first == KEYS.relationName } val otherFields = properties.filterNot { it.first == KEYS.relationName }
......
...@@ -21,15 +21,16 @@ package org.memobase.mapping.mappers ...@@ -21,15 +21,16 @@ package org.memobase.mapping.mappers
import org.memobase.builder.IResource import org.memobase.builder.IResource
import org.memobase.mapping.fields.AnnotationField import org.memobase.mapping.fields.AnnotationField
import org.memobase.mapping.fields.ConstantField import org.memobase.mapping.fields.ConstantField
import org.memobase.mapping.fields.FieldParsers
import org.memobase.mapping.fields.LanguageField import org.memobase.mapping.fields.LanguageField
import org.memobase.mapping.fields.ListField import org.memobase.mapping.fields.ListField
import org.memobase.mapping.fields.MappedAnnotationField import org.memobase.mapping.fields.MappedAnnotationField
class CarrierTypeMapper(private val field: AnnotationField) : IFieldMapper { class CarrierTypeMapper(private val field: AnnotationField) : IFieldMapper {
override fun apply(source: Map<String, String>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
when (field) { when (field) {
is MappedAnnotationField -> is MappedAnnotationField ->
source[field.field].let { FieldParsers.unpackSource(field.field, source).let {
if (it != null) { if (it != null) {
subject.addRicoCarrierType(listOf(field.toLiteral(it))) subject.addRicoCarrierType(listOf(field.toLiteral(it)))
} }
......
...@@ -22,7 +22,7 @@ import org.memobase.builder.IResource ...@@ -22,7 +22,7 @@ import org.memobase.builder.IResource
import org.memobase.mapping.fields.ConstantField import org.memobase.mapping.fields.ConstantField
class ConstantFieldMapper(private val constantField: ConstantField) : IFieldMapper { class ConstantFieldMapper(private val constantField: ConstantField) : IFieldMapper {
override fun apply(source: Map<String, String>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
subject.addLiteral(constantField.key, constantField.toLiteral()) subject.addLiteral(constantField.key, constantField.toLiteral())
} }
} }
\ No newline at end of file
...@@ -20,10 +20,11 @@ package org.memobase.mapping.mappers ...@@ -20,10 +20,11 @@ package org.memobase.mapping.mappers
import org.memobase.builder.IResource import org.memobase.builder.IResource
import org.memobase.mapping.fields.DirectMapField import org.memobase.mapping.fields.DirectMapField
import org.memobase.mapping.fields.FieldParsers
class DateFieldMapper(private val directMapField: DirectMapField) : IFieldMapper { class DateFieldMapper(private val directMapField: DirectMapField) : IFieldMapper {
override fun apply(source: Map<String, String>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
source[directMapField.field].let { FieldParsers.unpackSource(directMapField.field, source).let {
if (it != null) { if (it != null) {
subject.addDate(directMapField.key, it) subject.addDate(directMapField.key, it)
} }
......
...@@ -20,10 +20,11 @@ package org.memobase.mapping.mappers ...@@ -20,10 +20,11 @@ package org.memobase.mapping.mappers
import org.memobase.builder.IResource import org.memobase.builder.IResource
import org.memobase.mapping.fields.DirectMapField import org.memobase.mapping.fields.DirectMapField
import org.memobase.mapping.fields.FieldParsers
class DirectFieldMapper(private val directMapField: DirectMapField) : IFieldMapper { class DirectFieldMapper(private val directMapField: DirectMapField) : IFieldMapper {
override fun apply(source: Map<String, String>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
source[directMapField.field].let { FieldParsers.unpackSource(directMapField.field, source).let {
if (it != null) { if (it != null) {
subject.addLiteral(directMapField.key, directMapField.toLiteral(it)) subject.addLiteral(directMapField.key, directMapField.toLiteral(it))
} }
......
...@@ -21,17 +21,18 @@ package org.memobase.mapping.mappers ...@@ -21,17 +21,18 @@ package org.memobase.mapping.mappers
import org.memobase.builder.IResource import org.memobase.builder.IResource
import org.memobase.mapping.fields.ConfigField import org.memobase.mapping.fields.ConfigField
import org.memobase.mapping.fields.ConstantField import org.memobase.mapping.fields.ConstantField
import org.memobase.mapping.fields.FieldParsers
import org.memobase.mapping.fields.LanguageField import org.memobase.mapping.fields.LanguageField
import org.memobase.mapping.fields.ListField import org.memobase.mapping.fields.ListField
import org.memobase.mapping.fields.MappedAnnotationField import org.memobase.mapping.fields.MappedAnnotationField
class ExpandedRuleFieldMapper(private val type: String, private val configField: List<ConfigField>) : IFieldMapper { class ExpandedRuleFieldMapper(private val type: String, private val configField: List<ConfigField>) : IFieldMapper {
override fun apply(source: Map<String, String>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
val properties = configField.mapNotNull { field -> val properties = configField.mapNotNull { field ->
when (field) { when (field) {
is MappedAnnotationField -> is MappedAnnotationField ->
source[field.field].let { FieldParsers.unpackSource(field.field, source).let {
if (it != null) { if (it != null) {
Pair(field.key, listOf(field.toLiteral(it))) Pair(field.key, listOf(field.toLiteral(it)))
} else { } else {
......
...@@ -21,5 +21,5 @@ package org.memobase.mapping.mappers ...@@ -21,5 +21,5 @@ package org.memobase.mapping.mappers
import org.memobase.builder.IResource import org.memobase.builder.IResource
interface IFieldMapper { interface IFieldMapper {
fun apply(source: Map<String, String>, subject: IResource) fun apply(source: Map<String, Any>, subject: IResource)
} }
\ No newline at end of file
...@@ -22,7 +22,7 @@ import org.memobase.builder.IResource ...@@ -22,7 +22,7 @@ import org.memobase.builder.IResource
import org.memobase.mapping.fields.LanguageField import org.memobase.mapping.fields.LanguageField
class LanguageFieldMapper(private val languageField: LanguageField) : IFieldMapper { class LanguageFieldMapper(private val languageField: LanguageField) : IFieldMapper {
override fun apply(source: Map<String, String>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
languageField.toLangLiterals(source).forEach { languageField.toLangLiterals(source).forEach {
subject.addLiteral(languageField.key, it) subject.addLiteral(languageField.key, it)
} }
......
...@@ -23,7 +23,7 @@ import org.memobase.mapping.fields.ListField ...@@ -23,7 +23,7 @@ import org.memobase.mapping.fields.ListField
class ListFieldMapper(private val listField: ListField) : class ListFieldMapper(private val listField: ListField) :
IFieldMapper { IFieldMapper {
override fun apply(source: Map<String, String>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
listField.toLiterals(source).forEach { listField.toLiterals(source).forEach {
subject.addLiteral(listField.key, it) subject.addLiteral(listField.key, it)
} }
......
...@@ -21,8 +21,8 @@ package org.memobase.mapping.mappers ...@@ -21,8 +21,8 @@ package org.memobase.mapping.mappers
import org.memobase.builder.IResource import org.memobase.builder.IResource
class PlaceFieldMapper : TypeFieldMapper() { class PlaceFieldMapper : TypeFieldMapper() {
override fun apply(source: Map<String, String>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
translateProperties(source, subject) translateProperties(source)
if (properties.size > 0) { if (properties.size > 0) {
subject.addPlace(agentClassType, properties) subject.addPlace(agentClassType, properties)
} }
......
...@@ -19,11 +19,12 @@ ...@@ -19,11 +19,12 @@
package org.memobase.mapping.mappers package org.memobase.mapping.mappers
import org.memobase.builder.IResource import org.memobase.builder.IResource
import org.memobase.mapping.fields.FieldParsers
import org.memobase.mapping.fields.PrefixField import org.memobase.mapping.fields.PrefixField
class PrefixFieldMapper(private val prefixField: PrefixField) : IFieldMapper { class PrefixFieldMapper(private val prefixField: PrefixField) : IFieldMapper {
override fun apply(source: Map<String, String>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
source[prefixField.field].let { FieldParsers.unpackSource(prefixField.field, source).let {
if (it != null) { if (it != null) {
subject.addLiteral(prefixField.key, prefixField.toLiteral(it)) subject.addLiteral(prefixField.key, prefixField.toLiteral(it))
} }
......
...@@ -21,15 +21,16 @@ package org.memobase.mapping.mappers ...@@ -21,15 +21,16 @@ package org.memobase.mapping.mappers
import org.memobase.builder.IResource import org.memobase.builder.IResource
import org.memobase.mapping.fields.AnnotationField import org.memobase.mapping.fields.AnnotationField
import org.memobase.mapping.fields.ConstantField import org.memobase.mapping.fields.ConstantField
import org.memobase.mapping.fields.FieldParsers
import org.memobase.mapping.fields.LanguageField import org.memobase.mapping.fields.LanguageField
import org.memobase.mapping.fields.ListField import org.memobase.mapping.fields.ListField
import org.memobase.mapping.fields.MappedAnnotationField import org.memobase.mapping.fields.MappedAnnotationField
class RicoConceptMapper(private val rdfType: String, private val field: AnnotationField) : IFieldMapper { class RicoConceptMapper(private val rdfType: String, private val field: AnnotationField) : IFieldMapper {
override fun apply(source: Map<String, String>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
when (field) { when (field) {
is MappedAnnotationField -> is MappedAnnotationField ->
source[field.field].let { FieldParsers.unpackSource(field.field, source).let {
if (it != null) { if (it != null) {
subject.addRicoConcept(rdfType, field.key, listOf(field.toLiteral(it))) subject.addRicoConcept(rdfType, field.key, listOf(field.toLiteral(it)))
} }
......
...@@ -22,16 +22,17 @@ import org.memobase.builder.IResource ...@@ -22,16 +22,17 @@ import org.memobase.builder.IResource
import org.memobase.mapping.KEYS import org.memobase.mapping.KEYS
import org.memobase.mapping.fields.ConfigField import org.memobase.mapping.fields.ConfigField
import org.memobase.mapping.fields.ConstantField import org.memobase.mapping.fields.ConstantField
import org.memobase.mapping.fields.FieldParsers
import org.memobase.mapping.fields.LanguageField import org.memobase.mapping.fields.LanguageField
import org.memobase.mapping.fields.ListField import org.memobase.mapping.fields.ListField
import org.memobase.mapping.fields.MappedAnnotationField import org.memobase.mapping.fields.MappedAnnotationField
class RuleFieldMapper(private val configField: ConfigField) : IFieldMapper { class RuleFieldMapper(private val configField: ConfigField) : IFieldMapper {
override fun apply(source: Map<String, String>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
when (configField) { when (configField) {
is MappedAnnotationField -> is MappedAnnotationField ->
source[configField.field].let { FieldParsers.unpackSource(configField.field, source).let {
if (it != null) { if (it != null) {
subject.addRule(configField.key, listOf(Pair(KEYS.name, listOf(configField.toLiteral(it))))) subject.addRule(configField.key, listOf(Pair(KEYS.name, listOf(configField.toLiteral(it)))))
} }
......
...@@ -22,8 +22,8 @@ import org.memobase.builder.IResource ...@@ -22,8 +22,8 @@ import org.memobase.builder.IResource
import org.memobase.rdf.SKOS import org.memobase.rdf.SKOS
class SkosConceptFieldMapper : TypeFieldMapper() { class SkosConceptFieldMapper : TypeFieldMapper() {
override fun apply(source: Map<String, String>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
translateProperties(source, subject) translateProperties(source)
if (properties.any { value -> SKOS.labelProperties.contains(value.first) }) { if (properties.any { value -> SKOS.labelProperties.contains(value.first) }) {
subject.addSkosConcept(agentClassType, properties) subject.addSkosConcept(agentClassType, properties)
} }
......
...@@ -22,6 +22,7 @@ import org.apache.jena.rdf.model.Literal ...@@ -22,6 +22,7 @@ import org.apache.jena.rdf.model.Literal
import org.memobase.builder.IResource import org.memobase.builder.IResource
import org.memobase.mapping.fields.ConfigField import org.memobase.mapping.fields.ConfigField
import org.memobase.mapping.fields.ConstantField import org.memobase.mapping.fields.ConstantField
import org.memobase.mapping.fields.FieldParsers
import org.memobase.mapping.fields.LanguageField import org.memobase.mapping.fields.LanguageField
import org.memobase.mapping.fields.ListField import org.memobase.mapping.fields.ListField
import org.memobase.mapping.fields.MappedAnnotationField import org.memobase.mapping.fields.MappedAnnotationField
...@@ -36,8 +37,8 @@ abstract class TypeFieldMapper : IFieldMapper { ...@@ -36,8 +37,8 @@ abstract class TypeFieldMapper : IFieldMapper {
this.fields.addAll(fields) this.fields.addAll(fields)
} }
private fun addMappedField(field: MappedAnnotationField, source: Map<String, String>) { private fun addMappedField(field: MappedAnnotationField, source: Map<String, Any>) {
source[field.field].let { FieldParsers.unpackSource(field.field, source).let {
if (it != null) { if (it != null) {
properties.add(Pair(field.key, field.toLiteral(it))) properties.add(Pair(field.key, field.toLiteral(it)))
} }
...@@ -49,7 +50,7 @@ abstract class TypeFieldMapper : IFieldMapper { ...@@ -49,7 +50,7 @@ abstract class TypeFieldMapper : IFieldMapper {
} }
protected val properties = mutableListOf<Pair<String, Literal>>() protected val properties = mutableListOf<Pair<String, Literal>>()
protected fun translateProperties(source: Map<String, String>, subject: IResource) { protected fun translateProperties(source: Map<String, Any>) {
properties.clear() properties.clear()
for (field in fields) { for (field in fields) {
when (field) { when (field) {
......
...@@ -265,6 +265,20 @@ class Tests { ...@@ -265,6 +265,20 @@ class Tests {
"Successfully created a record from source." "Successfully created a record from source."
) )
) )
),
KafkaTestParams(
9,
"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/9/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
creators:
- person:
name: person.name
relationName: person.role
- corporateBody:
name:
de: person.name
relationName:
de: person.role
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