Commit 2f3e6e88 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Update resource builder with new config.

parent 39a54af5
Pipeline #15773 passed with stage
in 2 minutes and 2 seconds
...@@ -20,7 +20,7 @@ plugins { ...@@ -20,7 +20,7 @@ plugins {
id 'java-library' id 'java-library'
id 'org.jetbrains.kotlin.jvm' version '1.3.71' id 'org.jetbrains.kotlin.jvm' version '1.3.71'
id 'org.jetbrains.dokka' version '0.10.1' id 'org.jetbrains.dokka' version '0.10.1'
id "com.gitlab.morality.grit" version "2.0.2" id 'com.gitlab.morality.grit' version '2.0.2'
id 'org.jlleitschuh.gradle.ktlint' version '9.2.1' id 'org.jlleitschuh.gradle.ktlint' version '9.2.1'
id 'com.jfrog.bintray' version '1.8.5' id 'com.jfrog.bintray' version '1.8.5'
} }
......
...@@ -21,19 +21,13 @@ package ch.memobase.builder ...@@ -21,19 +21,13 @@ package ch.memobase.builder
import ch.memobase.mapping.KEYS import ch.memobase.mapping.KEYS
import ch.memobase.mapping.fields.ConstantField import ch.memobase.mapping.fields.ConstantField
import ch.memobase.mapping.fields.MappedAnnotationField import ch.memobase.mapping.fields.MappedAnnotationField
import ch.memobase.mapping.fields.SimpleAnnotationField import mapping.MapperConfiguration
import ch.memobase.mapping.mappers.IFieldMapper
class ResourceBuilder( class ResourceBuilder(
private val recordIdField: String,
private val recordType: SimpleAnnotationField,
private val recordFieldMappers: List<IFieldMapper>,
private val physicalObjectFieldMappers: List<IFieldMapper>,
private val digitalObjectFieldMappers: List<IFieldMapper>,
private val source: Map<String, String>, private val source: Map<String, String>,
private val config: MapperConfiguration,
private val institutionId: String, private val institutionId: String,
private val recordSetId: String, private val recordSetId: String,
private val isSponsoredByMemoriav: Boolean,
private val isPublished: Boolean private val isPublished: Boolean
) { ) {
private var record: Record? = null private var record: Record? = null
...@@ -44,10 +38,10 @@ class ResourceBuilder( ...@@ -44,10 +38,10 @@ class ResourceBuilder(
private var errorMessage = "" private var errorMessage = ""
fun extractRecordId(): ResourceBuilder { fun extractRecordId(): ResourceBuilder {
if (source.containsKey(recordIdField)) { if (source.containsKey(config.uri)) {
recordId = source[recordIdField] as String recordId = source[config.uri] as String
} else { } else {
errorMessage = "No id for record found in field '$recordIdField' for source $source." errorMessage = "No id for record found in field '${config.uri}' for source $source."
} }
return this return this
} }
...@@ -57,7 +51,7 @@ class ResourceBuilder( ...@@ -57,7 +51,7 @@ class ResourceBuilder(
} }
fun extractRecordTypeValue(): ResourceBuilder { fun extractRecordTypeValue(): ResourceBuilder {
recordTypeValue = when (recordType) { recordTypeValue = when (val recordType = config.recordType) {
is MappedAnnotationField -> source[recordType.field].let { is MappedAnnotationField -> source[recordType.field].let {
if (it.isNullOrEmpty()) { if (it.isNullOrEmpty()) {
errorMessage = "No type for record in field '${recordType.field} for source $source." errorMessage = "No type for record in field '${recordType.field} for source $source."
...@@ -82,8 +76,8 @@ class ResourceBuilder( ...@@ -82,8 +76,8 @@ class ResourceBuilder(
} }
fun generateRecord(): ResourceBuilder { fun generateRecord(): ResourceBuilder {
record = Record(recordId, recordTypeValue, recordSetId, institutionId, isSponsoredByMemoriav, isPublished) record = Record(recordId, recordTypeValue, recordSetId, institutionId, config.sponsoredByMemoriav, isPublished)
for (recordFieldMapper in recordFieldMappers) { for (recordFieldMapper in config.recordFieldMappers) {
recordFieldMapper.apply(source, record!!) recordFieldMapper.apply(source, record!!)
} }
return this return this
...@@ -91,9 +85,9 @@ class ResourceBuilder( ...@@ -91,9 +85,9 @@ class ResourceBuilder(
fun generatePhysicalObject(): ResourceBuilder { fun generatePhysicalObject(): ResourceBuilder {
physicalObject = physicalObject =
if (physicalObjectFieldMappers.isNotEmpty()) { if (config.physicalFieldMappers.isNotEmpty()) {
val physicalObject = PhysicalObject(recordId, recordSetId, institutionId, 1) val physicalObject = PhysicalObject(recordId, recordSetId, institutionId, 1)
physicalObjectFieldMappers.forEach { config.physicalFieldMappers.forEach {
it.apply(source, physicalObject) it.apply(source, physicalObject)
} }
record?.addInstantiation(physicalObject) record?.addInstantiation(physicalObject)
...@@ -107,9 +101,9 @@ class ResourceBuilder( ...@@ -107,9 +101,9 @@ class ResourceBuilder(
fun generateDigitalObject(): ResourceBuilder { fun generateDigitalObject(): ResourceBuilder {
digitalObject = digitalObject =
if (digitalObjectFieldMappers.isNotEmpty()) { if (config.digitalFieldMappers.isNotEmpty()) {
val digitalObject = DigitalObject(recordId, recordSetId, institutionId, 1) val digitalObject = DigitalObject(recordId, recordSetId, institutionId, 1)
digitalObjectFieldMappers.forEach { config.digitalFieldMappers.forEach {
it.apply(source, digitalObject) it.apply(source, digitalObject)
} }
digitalObject.addRecord(record!!) digitalObject.addRecord(record!!)
......
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