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 {
sealed class ComplexAnnotationField : AnnotationField() {
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 {
when (it) {
is MappedAnnotationField ->
source[it.field].let { value ->
FieldParsers.unpackSource(it.field, source).let { value ->
if (value != null) {
it.toLiteral(value)
} else {
......@@ -86,12 +86,12 @@ sealed class ConfigField {
data class LanguageField(val key: String, val fields: List<Pair<String, List<SimpleAnnotationField>>>) :
ComplexAnnotationField() {
fun toLangLiterals(source: Map<String, String>): List<Literal> {
fun toLangLiterals(source: Map<String, Any>): List<Literal> {
return fields.flatMap { pairs ->
pairs.second.mapNotNull {
when (it) {
is MappedAnnotationField ->
source[it.field].let { value ->
FieldParsers.unpackSource(it.field, source).let { value ->
if (value != null) {
it.toLangLiteral(value, pairs.first)
} else {
......
......@@ -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
class AgentFieldMapper : TypeFieldMapper() {
var sourceKey: String = ""
override fun apply(source: Map<String, String>, subject: IResource) {
translateProperties(source, subject)
override fun apply(source: Map<String, Any>, subject: IResource) {
translateProperties(source)
if (properties.size > 0) {
val relationNameField = properties.filter { it.first == KEYS.relationName }
val otherFields = properties.filterNot { it.first == KEYS.relationName }
......
......@@ -21,15 +21,16 @@ package org.memobase.mapping.mappers
import org.memobase.builder.IResource
import org.memobase.mapping.fields.AnnotationField
import org.memobase.mapping.fields.ConstantField
import org.memobase.mapping.fields.FieldParsers
import org.memobase.mapping.fields.LanguageField
import org.memobase.mapping.fields.ListField
import org.memobase.mapping.fields.MappedAnnotationField
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) {
is MappedAnnotationField ->
source[field.field].let {
FieldParsers.unpackSource(field.field, source).let {
if (it != null) {
subject.addRicoCarrierType(listOf(field.toLiteral(it)))
}
......
......@@ -22,7 +22,7 @@ import org.memobase.builder.IResource
import org.memobase.mapping.fields.ConstantField
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())
}
}
\ No newline at end of file
......@@ -20,10 +20,11 @@ package org.memobase.mapping.mappers
import org.memobase.builder.IResource
import org.memobase.mapping.fields.DirectMapField
import org.memobase.mapping.fields.FieldParsers
class DateFieldMapper(private val directMapField: DirectMapField) : IFieldMapper {
override fun apply(source: Map<String, String>, subject: IResource) {
source[directMapField.field].let {
override fun apply(source: Map<String, Any>, subject: IResource) {
FieldParsers.unpackSource(directMapField.field, source).let {
if (it != null) {
subject.addDate(directMapField.key, it)
}
......
......@@ -20,10 +20,11 @@ package org.memobase.mapping.mappers
import org.memobase.builder.IResource
import org.memobase.mapping.fields.DirectMapField
import org.memobase.mapping.fields.FieldParsers
class DirectFieldMapper(private val directMapField: DirectMapField) : IFieldMapper {
override fun apply(source: Map<String, String>, subject: IResource) {
source[directMapField.field].let {
override fun apply(source: Map<String, Any>, subject: IResource) {
FieldParsers.unpackSource(directMapField.field, source).let {
if (it != null) {
subject.addLiteral(directMapField.key, directMapField.toLiteral(it))
}
......
......@@ -21,17 +21,18 @@ package org.memobase.mapping.mappers
import org.memobase.builder.IResource
import org.memobase.mapping.fields.ConfigField
import org.memobase.mapping.fields.ConstantField
import org.memobase.mapping.fields.FieldParsers
import org.memobase.mapping.fields.LanguageField
import org.memobase.mapping.fields.ListField
import org.memobase.mapping.fields.MappedAnnotationField
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 ->
when (field) {
is MappedAnnotationField ->
source[field.field].let {
FieldParsers.unpackSource(field.field, source).let {
if (it != null) {
Pair(field.key, listOf(field.toLiteral(it)))
} else {
......
......@@ -21,5 +21,5 @@ package org.memobase.mapping.mappers
import org.memobase.builder.IResource
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
import org.memobase.mapping.fields.LanguageField
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 {
subject.addLiteral(languageField.key, it)
}
......
......@@ -23,7 +23,7 @@ import org.memobase.mapping.fields.ListField
class ListFieldMapper(private val listField: ListField) :
IFieldMapper {
override fun apply(source: Map<String, String>, subject: IResource) {
override fun apply(source: Map<String, Any>, subject: IResource) {
listField.toLiterals(source).forEach {
subject.addLiteral(listField.key, it)
}
......
......@@ -21,8 +21,8 @@ package org.memobase.mapping.mappers
import org.memobase.builder.IResource
class PlaceFieldMapper : TypeFieldMapper() {
override fun apply(source: Map<String, String>, subject: IResource) {
translateProperties(source, subject)
override fun apply(source: Map<String, Any>, subject: IResource) {
translateProperties(source)
if (properties.size > 0) {
subject.addPlace(agentClassType, properties)
}
......
......@@ -19,11 +19,12 @@
package org.memobase.mapping.mappers
import org.memobase.builder.IResource
import org.memobase.mapping.fields.FieldParsers
import org.memobase.mapping.fields.PrefixField
class PrefixFieldMapper(private val prefixField: PrefixField) : IFieldMapper {
override fun apply(source: Map<String, String>, subject: IResource) {
source[prefixField.field].let {
override fun apply(source: Map<String, Any>, subject: IResource) {
FieldParsers.unpackSource(prefixField.field, source).let {
if (it != null) {
subject.addLiteral(prefixField.key, prefixField.toLiteral(it))
}
......
......@@ -21,15 +21,16 @@ package org.memobase.mapping.mappers
import org.memobase.builder.IResource
import org.memobase.mapping.fields.AnnotationField
import org.memobase.mapping.fields.ConstantField
import org.memobase.mapping.fields.FieldParsers
import org.memobase.mapping.fields.LanguageField
import org.memobase.mapping.fields.ListField
import org.memobase.mapping.fields.MappedAnnotationField
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) {
is MappedAnnotationField ->
source[field.field].let {
FieldParsers.unpackSource(field.field, source).let {
if (it != null) {
subject.addRicoConcept(rdfType, field.key, listOf(field.toLiteral(it)))
}
......
......@@ -22,16 +22,17 @@ import org.memobase.builder.IResource
import org.memobase.mapping.KEYS
import org.memobase.mapping.fields.ConfigField
import org.memobase.mapping.fields.ConstantField
import org.memobase.mapping.fields.FieldParsers
import org.memobase.mapping.fields.LanguageField
import org.memobase.mapping.fields.ListField
import org.memobase.mapping.fields.MappedAnnotationField
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) {
is MappedAnnotationField ->
source[configField.field].let {
FieldParsers.unpackSource(configField.field, source).let {
if (it != null) {
subject.addRule(configField.key, listOf(Pair(KEYS.name, listOf(configField.toLiteral(it)))))
}
......
......@@ -22,8 +22,8 @@ import org.memobase.builder.IResource
import org.memobase.rdf.SKOS
class SkosConceptFieldMapper : TypeFieldMapper() {
override fun apply(source: Map<String, String>, subject: IResource) {
translateProperties(source, subject)
override fun apply(source: Map<String, Any>, subject: IResource) {
translateProperties(source)
if (properties.any { value -> SKOS.labelProperties.contains(value.first) }) {
subject.addSkosConcept(agentClassType, properties)
}
......
......@@ -22,6 +22,7 @@ import org.apache.jena.rdf.model.Literal
import org.memobase.builder.IResource
import org.memobase.mapping.fields.ConfigField
import org.memobase.mapping.fields.ConstantField
import org.memobase.mapping.fields.FieldParsers
import org.memobase.mapping.fields.LanguageField
import org.memobase.mapping.fields.ListField
import org.memobase.mapping.fields.MappedAnnotationField
......@@ -36,8 +37,8 @@ abstract class TypeFieldMapper : IFieldMapper {
this.fields.addAll(fields)
}
private fun addMappedField(field: MappedAnnotationField, source: Map<String, String>) {
source[field.field].let {
private fun addMappedField(field: MappedAnnotationField, source: Map<String, Any>) {
FieldParsers.unpackSource(field.field, source).let {
if (it != null) {
properties.add(Pair(field.key, field.toLiteral(it)))
}
......@@ -49,7 +50,7 @@ abstract class TypeFieldMapper : IFieldMapper {
}
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()
for (field in fields) {
when (field) {
......
......@@ -265,6 +265,20 @@ class Tests {
"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