Commit 90c60ac0 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Add digital object to record builder

parent 2820bb18
......@@ -61,6 +61,7 @@ class KafkaTopology(private val settings: SettingsLoader
config.recordType,
config.recordFieldMappers,
config.physicalObjectFieldMappers,
config.digitalObjectFieldMappers,
value,
settings.appSettings.getProperty("institutionId"),
settings.appSettings.getProperty("recordSetId")
......
......@@ -29,34 +29,47 @@ class ResourceBuilder(
recordType: String,
recordFieldMappers: List<IFieldMapper>,
physicalObjectFieldMappers: List<IFieldMapper>,
digitalObjectFieldMappers: List<IFieldMapper>,
source: Map<String, String>,
institutionId: String, recordSetId: String) {
private val record: Record
private val physicalObject: PhysicalObject
private val resources: List<RecordResource>
private val resources: MutableList<RecordResource> = mutableListOf()
private var count = 0
init {
val recordId = if (source.containsKey(recordIdField)) {
source[recordIdField] as String
} else {
throw InvalidMappingException("No id for record found in field '$recordIdField'.")
}
record =
val record =
Record(recordId, recordType, recordSetId, institutionId)
for (recordFieldMapper in recordFieldMappers) {
recordFieldMapper.apply(source, record)
}
physicalObject =
PhysicalObject(recordId, institutionId, 0)
resources.add(record)
physicalObjectFieldMappers.forEach {
it.apply(source, physicalObject)
if (physicalObjectFieldMappers.isNotEmpty()) {
val physicalObject = PhysicalObject(recordId, institutionId, count)
count += 1
physicalObjectFieldMappers.forEach {
it.apply(source, physicalObject)
}
record.addInstantiation(physicalObject)
physicalObject.addRecord(record)
resources.add(physicalObject)
}
physicalObject.addRecord(record)
record.addInstantiation(physicalObject)
resources = listOf(record, physicalObject)
if (digitalObjectFieldMappers.isNotEmpty()) {
val digitalObject = DigitalObject(recordId, institutionId, count)
count += 1
digitalObjectFieldMappers.forEach {
it.apply(source, digitalObject)
}
digitalObject.addRecord(record)
record.addInstantiation(digitalObject)
resources.add(digitalObject)
}
}
fun write(): List<Pair<String, String>> {
......
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