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