Commit 76b29c7f authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Add rules to digital and physical

parent 4c6e5853
......@@ -107,23 +107,7 @@ class MappingConfig(directory: String) {
KEYS.abstract, KEYS.source, KEYS.hasSponsoringAgent, KEYS.hasFindingAid ->
recordFieldMappers.add(buildSimpleMappers(entry))
KEYS.rights ->
when (val value = entry.value) {
is Map<*, *> -> {
for (rightsEntry in value.entries) {
val configField =
parseFieldWithKeyValidation(
KEYS.rights,
rightsEntry as Map.Entry<String, Any>, ruleTypes
)
recordFieldMappers.add(
RuleFieldMapper(
configField
)
)
}
}
else -> throw InvalidMappingException("Expected key value map under rights label.")
}
recordFieldMappers.addAll(buildRuleMappers(entry.value))
KEYS.titles ->
when (val value = entry.value) {
is Map<*, *> -> {
......@@ -145,7 +129,8 @@ class MappingConfig(directory: String) {
}
else -> throw InvalidMappingException("Expected key value map under title label.")
}
KEYS.identifiers -> recordFieldMappers.addAll(buildIdentifierMapper(entry.value))
KEYS.identifiers ->
recordFieldMappers.addAll(buildIdentifierMapper(entry.value))
KEYS.languages ->
when (val value = entry.value) {
is Map<*, *> -> {
......@@ -184,7 +169,6 @@ class MappingConfig(directory: String) {
}
KEYS.placeOfCapture, KEYS.relatedPlaces ->
recordFieldMappers.addAll(buildPlaceMapper(key, entry.value))
KEYS.creationDate, KEYS.issuedDate, KEYS.temporal ->
when (val value = parseField(entry)) {
is SimpleField -> recordFieldMappers.add(
......@@ -192,7 +176,6 @@ class MappingConfig(directory: String) {
)
else -> throw InvalidMappingException("Dates only allow simple field assignment. Invalid mapping ${entry.key}.")
}
KEYS.creators ->
recordFieldMappers.addAll(buildCreatorMapper(entry.value))
else -> throw InvalidMappingException("Unknown top level key $key in mapping.")
......@@ -207,10 +190,10 @@ class MappingConfig(directory: String) {
KEYS.colour, KEYS.duration, KEYS.displayAspectRatio, KEYS.audioTrackConfiguration,
KEYS.playbackSpeed, KEYS.hasStandard ->
physicalObjectFieldMappers.add(buildSimpleMappers(entry))
KEYS.identifiers ->
physicalObjectFieldMappers.addAll(buildIdentifierMapper(entry.value))
KEYS.rights ->
physicalObjectFieldMappers.addAll(buildRuleMappers(entry.value))
else -> throw InvalidMappingException("Unknown top level key $key in mapping.")
}
}
......@@ -221,6 +204,8 @@ class MappingConfig(directory: String) {
when (val key = entry.key) {
KEYS.locator ->
digitalObjectFieldMappers.add(buildSimpleMappers(entry))
KEYS.rights ->
digitalObjectFieldMappers.addAll(buildRuleMappers(entry.value))
else -> throw InvalidMappingException("Unknown top level key $key in mapping.")
}
}
......@@ -265,6 +250,21 @@ class MappingConfig(directory: String) {
}
}
private fun buildRuleMappers(value: Any?): List<IFieldMapper> {
when (value) {
is Map<*, *> -> {
return value.entries.map {
val configField = parseFieldWithKeyValidation(
KEYS.rights,
it as Map.Entry<String, Any>,
ruleTypes)
RuleFieldMapper(configField)
}
}
else -> throw InvalidMappingException("Expected key value map under rights label.")
}
}
private fun extractAgentTypeMapper(value: Map<String, Any>): IFieldMapper {
val mapper = when {
value.containsKey(KEYS.agent) -> {
......
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