Commit 4a04581c authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Remove serialization support code in mappers. This was a failed attempt...

Remove serialization support code in mappers. This was a failed attempt deserialization is now just done after merging in Kafka.
parent 7782d796
package ch.memobase.mapping.mappers package ch.memobase.mapping.mappers
import com.beust.klaxon.TypeFor
@TypeFor(field = "type", adapter = MapperAdapter::class) abstract class AbstractFieldMapper() : IFieldMapper
abstract class AbstractFieldMapper(val type: String) : IFieldMapper
...@@ -21,7 +21,7 @@ package ch.memobase.mapping.mappers ...@@ -21,7 +21,7 @@ package ch.memobase.mapping.mappers
import ch.memobase.builder.IResource import ch.memobase.builder.IResource
import ch.memobase.mapping.KEYS import ch.memobase.mapping.KEYS
class AgentFieldMapper : TypeFieldMapper(MapperTypes.agent) { class AgentFieldMapper : TypeFieldMapper() {
var sourceKey: String = "" var sourceKey: String = ""
override fun apply(source: Map<String, Any>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
translateProperties(source) translateProperties(source)
...@@ -38,16 +38,4 @@ class AgentFieldMapper : TypeFieldMapper(MapperTypes.agent) { ...@@ -38,16 +38,4 @@ class AgentFieldMapper : TypeFieldMapper(MapperTypes.agent) {
} }
} }
} }
override fun equals(other: Any?): Boolean {
if (this === other) return true
return when (other) {
null -> false
!is AgentFieldMapper -> false
else ->
this.sourceKey == other.sourceKey && super.equals(other)
// this.agentClassType == other.agentClassType
// && this.fields == other.fields && this.properties == this.properties
}
}
} }
...@@ -26,7 +26,7 @@ import ch.memobase.mapping.fields.LanguageField ...@@ -26,7 +26,7 @@ import ch.memobase.mapping.fields.LanguageField
import ch.memobase.mapping.fields.ListField import ch.memobase.mapping.fields.ListField
import ch.memobase.mapping.fields.MappedAnnotationField import ch.memobase.mapping.fields.MappedAnnotationField
class CarrierTypeMapper(val field: AnnotationField) : AbstractFieldMapper(MapperTypes.carrierType) { class CarrierTypeMapper(val field: AnnotationField) : AbstractFieldMapper() {
override fun apply(source: Map<String, Any>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
when (field) { when (field) {
is MappedAnnotationField -> is MappedAnnotationField ->
...@@ -51,17 +51,4 @@ class CarrierTypeMapper(val field: AnnotationField) : AbstractFieldMapper(Mapper ...@@ -51,17 +51,4 @@ class CarrierTypeMapper(val field: AnnotationField) : AbstractFieldMapper(Mapper
} }
} }
} }
override fun equals(other: Any?): Boolean {
if (this === other) return true
return when (other) {
null -> false
!is CarrierTypeMapper -> false
else -> field == other.field
}
}
override fun hashCode(): Int {
return field.hashCode()
}
} }
...@@ -21,21 +21,8 @@ package ch.memobase.mapping.mappers ...@@ -21,21 +21,8 @@ package ch.memobase.mapping.mappers
import ch.memobase.builder.IResource import ch.memobase.builder.IResource
import ch.memobase.mapping.fields.ConstantField import ch.memobase.mapping.fields.ConstantField
class ConstantFieldMapper(val constantField: ConstantField) : AbstractFieldMapper(MapperTypes.constant) { class ConstantFieldMapper(val constantField: ConstantField) : AbstractFieldMapper() {
override fun apply(source: Map<String, Any>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
subject.addLiteral(constantField.key, constantField.toLiteral()) subject.addLiteral(constantField.key, constantField.toLiteral())
} }
override fun equals(other: Any?): Boolean {
if (this === other) return true
return when (other) {
null -> false
!is ConstantFieldMapper -> false
else -> constantField == other.constantField
}
}
override fun hashCode(): Int {
return constantField.hashCode()
}
} }
...@@ -22,7 +22,7 @@ import ch.memobase.builder.IResource ...@@ -22,7 +22,7 @@ import ch.memobase.builder.IResource
import ch.memobase.mapping.fields.DirectMapField import ch.memobase.mapping.fields.DirectMapField
import ch.memobase.mapping.fields.FieldParsers import ch.memobase.mapping.fields.FieldParsers
class DateFieldMapper(val directMapField: DirectMapField) : AbstractFieldMapper(MapperTypes.date) { class DateFieldMapper(val directMapField: DirectMapField) : AbstractFieldMapper() {
override fun apply(source: Map<String, Any>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
FieldParsers.unpackSource(directMapField.field, source).let { FieldParsers.unpackSource(directMapField.field, source).let {
if (it != null) { if (it != null) {
...@@ -30,17 +30,4 @@ class DateFieldMapper(val directMapField: DirectMapField) : AbstractFieldMapper( ...@@ -30,17 +30,4 @@ class DateFieldMapper(val directMapField: DirectMapField) : AbstractFieldMapper(
} }
} }
} }
override fun equals(other: Any?): Boolean {
if (this === other) return true
return when (other) {
null -> false
!is DateFieldMapper -> false
else -> directMapField == other.directMapField
}
}
override fun hashCode(): Int {
return directMapField.hashCode()
}
} }
...@@ -22,7 +22,7 @@ import ch.memobase.builder.IResource ...@@ -22,7 +22,7 @@ import ch.memobase.builder.IResource
import ch.memobase.mapping.fields.DirectMapField import ch.memobase.mapping.fields.DirectMapField
import ch.memobase.mapping.fields.FieldParsers import ch.memobase.mapping.fields.FieldParsers
class DirectFieldMapper(val directMapField: DirectMapField) : AbstractFieldMapper(MapperTypes.direct) { class DirectFieldMapper(val directMapField: DirectMapField) : AbstractFieldMapper() {
override fun apply(source: Map<String, Any>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
FieldParsers.unpackSource(directMapField.field, source).let { FieldParsers.unpackSource(directMapField.field, source).let {
if (it != null) { if (it != null) {
...@@ -30,17 +30,4 @@ class DirectFieldMapper(val directMapField: DirectMapField) : AbstractFieldMappe ...@@ -30,17 +30,4 @@ class DirectFieldMapper(val directMapField: DirectMapField) : AbstractFieldMappe
} }
} }
} }
override fun equals(other: Any?): Boolean {
if (this === other) return true
return when (other) {
null -> false
!is DirectFieldMapper -> false
else -> directMapField == other.directMapField
}
}
override fun hashCode(): Int {
return directMapField.hashCode()
}
} }
...@@ -29,9 +29,7 @@ import ch.memobase.mapping.fields.MappedAnnotationField ...@@ -29,9 +29,7 @@ import ch.memobase.mapping.fields.MappedAnnotationField
class ExpandedRuleFieldMapper( class ExpandedRuleFieldMapper(
val ricoType: String, val ricoType: String,
val configField: List<ConfigField> val configField: List<ConfigField>
) : AbstractFieldMapper( ) : AbstractFieldMapper() {
MapperTypes.expandedRule
) {
override fun apply(source: Map<String, Any>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
val properties = configField.mapNotNull { field -> val properties = configField.mapNotNull { field ->
...@@ -68,19 +66,4 @@ class ExpandedRuleFieldMapper( ...@@ -68,19 +66,4 @@ class ExpandedRuleFieldMapper(
subject.addRule(ricoType, properties) subject.addRule(ricoType, properties)
} }
} }
override fun equals(other: Any?): Boolean {
if (this === other) return true
return when (other) {
null -> false
!is ExpandedRuleFieldMapper -> false
else -> hashCode() == other.hashCode()
}
}
override fun hashCode(): Int {
var result = ricoType.hashCode()
result = 31 * result + configField.hashCode()
return result
}
} }
...@@ -21,19 +21,10 @@ package ch.memobase.mapping.mappers ...@@ -21,19 +21,10 @@ package ch.memobase.mapping.mappers
import ch.memobase.builder.IResource import ch.memobase.builder.IResource
import ch.memobase.mapping.fields.LanguageField import ch.memobase.mapping.fields.LanguageField
class LanguageFieldMapper(val languageField: LanguageField) : AbstractFieldMapper(MapperTypes.language) { class LanguageFieldMapper(val languageField: LanguageField) : AbstractFieldMapper() {
override fun apply(source: Map<String, Any>, 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)
} }
} }
override fun equals(other: Any?): Boolean {
if (this === other) return true
return when (other) {
null -> false
!is LanguageFieldMapper -> false
else -> languageField == other.languageField
}
}
} }
...@@ -22,23 +22,10 @@ import ch.memobase.builder.IResource ...@@ -22,23 +22,10 @@ import ch.memobase.builder.IResource
import ch.memobase.mapping.fields.ListField import ch.memobase.mapping.fields.ListField
class ListFieldMapper(val listField: ListField) : class ListFieldMapper(val listField: ListField) :
AbstractFieldMapper(MapperTypes.list) { AbstractFieldMapper() {
override fun apply(source: Map<String, Any>, 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)
} }
} }
override fun equals(other: Any?): Boolean {
if (this === other) return true
return when (other) {
null -> false
!is ListFieldMapper -> false
else -> hashCode() == other.hashCode()
}
}
override fun hashCode(): Int {
return listField.hashCode()
}
} }
package ch.memobase.mapping.mappers
import com.beust.klaxon.TypeAdapter
import kotlin.reflect.KClass
class MapperAdapter : TypeAdapter<AbstractFieldMapper> {
override fun classFor(type: Any): KClass<out AbstractFieldMapper> {
return when (type) {
MapperTypes.agent -> AgentFieldMapper::class
MapperTypes.carrierType -> CarrierTypeMapper::class
MapperTypes.constant -> ConstantFieldMapper::class
MapperTypes.date -> DateFieldMapper::class
MapperTypes.direct -> DirectFieldMapper::class
MapperTypes.expandedRule -> ExpandedRuleFieldMapper::class
MapperTypes.language -> LanguageFieldMapper::class
MapperTypes.list -> ListFieldMapper::class
MapperTypes.place -> PlaceFieldMapper::class
MapperTypes.prefix -> PrefixFieldMapper::class
MapperTypes.ricoConcept -> RicoConceptMapper::class
MapperTypes.rule -> RuleFieldMapper::class
MapperTypes.skosConcept -> SkosConceptFieldMapper::class
else -> throw Exception("Could not parse mapper instance with type $type.")
}
}
}
package ch.memobase.mapping.mappers
object MapperTypes {
const val agent = "agent"
const val carrierType = "carrier-type"
const val constant = "constant"
const val date = "date"
const val direct = "direct"
const val expandedRule = "expanded-rule"
const val language = "language"
const val list = "list"
const val place = "place"
const val prefix = "prefix"
const val ricoConcept = "rico-concept"
const val rule = "rule"
const val skosConcept = "skos-concept"
}
...@@ -20,20 +20,11 @@ package ch.memobase.mapping.mappers ...@@ -20,20 +20,11 @@ package ch.memobase.mapping.mappers
import ch.memobase.builder.IResource import ch.memobase.builder.IResource
@Suppress("EqualsOrHashCode") class PlaceFieldMapper : TypeFieldMapper() {
class PlaceFieldMapper : TypeFieldMapper(MapperTypes.place) {
override fun apply(source: Map<String, Any>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
translateProperties(source) translateProperties(source)
if (properties.size > 0) { if (properties.size > 0) {
subject.addPlace(agentClassType, properties) subject.addPlace(agentClassType, properties)
} }
} }
override fun equals(other: Any?): Boolean {
return when (other) {
null -> false
!is PlaceFieldMapper -> false
else -> this.hashCode() == other.hashCode()
}
}
} }
...@@ -22,7 +22,7 @@ import ch.memobase.builder.IResource ...@@ -22,7 +22,7 @@ import ch.memobase.builder.IResource
import ch.memobase.mapping.fields.FieldParsers import ch.memobase.mapping.fields.FieldParsers
import ch.memobase.mapping.fields.PrefixField import ch.memobase.mapping.fields.PrefixField
class PrefixFieldMapper(val prefixField: PrefixField) : AbstractFieldMapper(MapperTypes.prefix) { class PrefixFieldMapper(val prefixField: PrefixField) : AbstractFieldMapper() {
override fun apply(source: Map<String, Any>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
FieldParsers.unpackSource(prefixField.field, source).let { FieldParsers.unpackSource(prefixField.field, source).let {
if (it != null) { if (it != null) {
...@@ -30,17 +30,4 @@ class PrefixFieldMapper(val prefixField: PrefixField) : AbstractFieldMapper(Mapp ...@@ -30,17 +30,4 @@ class PrefixFieldMapper(val prefixField: PrefixField) : AbstractFieldMapper(Mapp
} }
} }
} }
override fun equals(other: Any?): Boolean {
if (this === other) return true
return when (other) {
null -> false
!is PrefixFieldMapper -> false
else -> hashCode() == other.hashCode()
}
}
override fun hashCode(): Int {
return prefixField.hashCode()
}
} }
...@@ -26,9 +26,8 @@ import ch.memobase.mapping.fields.LanguageField ...@@ -26,9 +26,8 @@ import ch.memobase.mapping.fields.LanguageField
import ch.memobase.mapping.fields.ListField import ch.memobase.mapping.fields.ListField
import ch.memobase.mapping.fields.MappedAnnotationField import ch.memobase.mapping.fields.MappedAnnotationField
class RicoConceptMapper(val rdfType: String, val field: AnnotationField) : AbstractFieldMapper( class RicoConceptMapper(val rdfType: String, val field: AnnotationField) :
MapperTypes.ricoConcept AbstractFieldMapper() {
) {
override fun apply(source: Map<String, Any>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
when (field) { when (field) {
is MappedAnnotationField -> is MappedAnnotationField ->
...@@ -53,19 +52,4 @@ class RicoConceptMapper(val rdfType: String, val field: AnnotationField) : Abstr ...@@ -53,19 +52,4 @@ class RicoConceptMapper(val rdfType: String, val field: AnnotationField) : Abstr
} }
} }
} }
override fun equals(other: Any?): Boolean {
if (this === other) return true
return when (other) {
null -> false
!is RicoConceptMapper -> false
else -> hashCode() == other.hashCode()
}
}
override fun hashCode(): Int {
var result = rdfType.hashCode()
result = 31 * result + field.hashCode()
return result
}
} }
...@@ -27,7 +27,7 @@ import ch.memobase.mapping.fields.LanguageField ...@@ -27,7 +27,7 @@ import ch.memobase.mapping.fields.LanguageField
import ch.memobase.mapping.fields.ListField import ch.memobase.mapping.fields.ListField
import ch.memobase.mapping.fields.MappedAnnotationField import ch.memobase.mapping.fields.MappedAnnotationField
class RuleFieldMapper(val configField: ConfigField) : AbstractFieldMapper(MapperTypes.rule) { class RuleFieldMapper(val configField: ConfigField) : AbstractFieldMapper() {
override fun apply(source: Map<String, Any>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
when (configField) { when (configField) {
...@@ -53,17 +53,4 @@ class RuleFieldMapper(val configField: ConfigField) : AbstractFieldMapper(Mapper ...@@ -53,17 +53,4 @@ class RuleFieldMapper(val configField: ConfigField) : AbstractFieldMapper(Mapper
} }
} }
} }
override fun equals(other: Any?): Boolean {
if (this === other) return true
return when (other) {
null -> false
!is RuleFieldMapper -> false
else -> hashCode() == other.hashCode()
}
}
override fun hashCode(): Int {
return configField.hashCode()
}
} }
...@@ -21,20 +21,11 @@ package ch.memobase.mapping.mappers ...@@ -21,20 +21,11 @@ package ch.memobase.mapping.mappers
import ch.memobase.builder.IResource import ch.memobase.builder.IResource
import ch.memobase.rdf.SKOS import ch.memobase.rdf.SKOS
@Suppress("EqualsOrHashCode") class SkosConceptFieldMapper : TypeFieldMapper() {
class SkosConceptFieldMapper : TypeFieldMapper(MapperTypes.skosConcept) {
override fun apply(source: Map<String, Any>, subject: IResource) { override fun apply(source: Map<String, Any>, subject: IResource) {
translateProperties(source) 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)
} }
} }
override fun equals(other: Any?): Boolean {
return when (other) {
null -> false
!is SkosConceptFieldMapper -> false
else -> this.hashCode() == other.hashCode()
}
}
} }
...@@ -26,7 +26,7 @@ import ch.memobase.mapping.fields.ListField ...@@ -26,7 +26,7 @@ import ch.memobase.mapping.fields.ListField
import ch.memobase.mapping.fields.MappedAnnotationField import ch.memobase.mapping.fields.MappedAnnotationField
import org.apache.jena.rdf.model.Literal import org.apache.jena.rdf.model.Literal
abstract class TypeFieldMapper(type: String) : AbstractFieldMapper(type) { abstract class TypeFieldMapper : AbstractFieldMapper() {
var agentClassType = "" var agentClassType = ""
val fields = mutableListOf<ConfigField>() val fields = mutableListOf<ConfigField>()
...@@ -66,24 +66,4 @@ abstract class TypeFieldMapper(type: String) : AbstractFieldMapper(type) { ...@@ -66,24 +66,4 @@ abstract class TypeFieldMapper(type: String) : AbstractFieldMapper(type) {
} }
} }
} }
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as TypeFieldMapper
if (agentClassType != other.agentClassType) return false
if (fields != other.fields) return false
if (properties != other.properties) return false
return true
}
override fun hashCode(): Int {
var result = agentClassType.hashCode()
result = 31 * result + fields.hashCode()
result = 31 * result + properties.hashCode()
return result
}
} }
...@@ -29,7 +29,6 @@ class TestMapperParseHelpers { ...@@ -29,7 +29,6 @@ class TestMapperParseHelpers {
val mapperReqs: Consumer<AgentFieldMapper> = Consumer { agentFieldMapper: AgentFieldMapper -> val mapperReqs: Consumer<AgentFieldMapper> = Consumer { agentFieldMapper: AgentFieldMapper ->
assertThat(agentFieldMapper.sourceKey).isEqualTo("creators") assertThat(agentFieldMapper.sourceKey).isEqualTo("creators")
assertThat(agentFieldMapper.agentClassType).isEqualTo("person") assertThat(agentFieldMapper.agentClassType).isEqualTo("person")
assertThat(agentFieldMapper.type).isEqualTo("agent")
} }
val mapper = mappers[0] as AgentFieldMapper val mapper = mappers[0] as AgentFieldMapper
assertThat(mapper) assertThat(mapper)
...@@ -54,7 +53,6 @@ class TestMapperParseHelpers { ...@@ -54,7 +53,6 @@ class TestMapperParseHelpers {
val mapperReqs: Consumer<AgentFieldMapper> = Consumer { agentFieldMapper: AgentFieldMapper -> val mapperReqs: Consumer<AgentFieldMapper> = Consumer { agentFieldMapper: AgentFieldMapper ->
assertThat(agentFieldMapper.sourceKey).isEqualTo("creators") assertThat(agentFieldMapper.sourceKey).isEqualTo("creators")
assertThat(agentFieldMapper.agentClassType).isEqualTo("person") assertThat(agentFieldMapper.agentClassType).isEqualTo("person")
assertThat(agentFieldMapper.type).isEqualTo("agent")
} }
val mapper = mappers[0] as AgentFieldMapper val mapper = mappers[0] as AgentFieldMapper
assertThat(mapper) assertThat(mapper)
...@@ -77,7 +75,6 @@ class TestMapperParseHelpers { ...@@ -77,7 +75,6 @@ class TestMapperParseHelpers {
val mapperReqs: Consumer<AgentFieldMapper> = Consumer { agentFieldMapper: AgentFieldMapper -> val mapperReqs: Consumer<AgentFieldMapper> = Consumer { agentFieldMapper: AgentFieldMapper ->
assertThat(agentFieldMapper.sourceKey).isEqualTo("creators") assertThat(agentFieldMapper.sourceKey).isEqualTo("creators")
assertThat(agentFieldMapper.agentClassType).isEqualTo("person") assertThat(agentFieldMapper.agentClassType).isEqualTo("person")
assertThat(agentFieldMapper.type).isEqualTo("agent")
} }
val mapper = mappers[0] as AgentFieldMapper val mapper = mappers[0] as AgentFieldMapper
assertThat(mapper) assertThat(mapper)
...@@ -103,7 +100,6 @@ class TestMapperParseHelpers { ...@@ -103,7 +100,6 @@ class TestMapperParseHelpers {