Commit b0c2f4d1 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Add proxy type property to record.

parent 76f72ecd
......@@ -46,7 +46,7 @@ dependencies {
//compile group: 'org.elasticsearch.client', name: 'elasticsearch-rest-high-level-client', version: '7.1.0'
implementation "org.apache.logging.log4j:log4j-api:${log4jV}"
implementation 'org.memobase:memobase-service-utilities:3.0.1'
implementation 'org.memobase:memobase-service-utilities:3.0.3'
// YAML Parser
implementation 'org.snakeyaml:snakeyaml-engine:2.1'
......
......@@ -32,7 +32,8 @@ class Record(
recordSetId: String,
institutionId: String,
hasSponsoringAgent: Boolean,
isPublished: Boolean
isPublished: Boolean,
hasProxyType: Boolean
) :
RecordResource(institutionId) {
......@@ -49,11 +50,19 @@ class Record(
resource.addProperty(RDA.hasSponsoringAgentOfResource, model.createResource(KEYS.memoriavUri))
}
resource.addProperty(MB.isPublished, model.createTypedLiteral(isPublished))
// no supplied proxy type present.
if (!hasProxyType) {
addDefaultProxyType()
}
}
fun addInstantiation(instantiation: Instantiation) {
resource.addProperty(RICO.hasInstantiation, instantiation.resource)
}
private fun addDefaultProxyType() {
resource.addProperty(MB.proxyType, KEYS.defaultProxyType)
}
private fun recordSetUri(id: String): Resource = model.createResource(uri(NS.mbrs, id))
}
......@@ -24,10 +24,10 @@ import ch.memobase.mapping.MapperConfiguration
import ch.memobase.mapping.fields.ConstantField
import ch.memobase.mapping.fields.MappedAnnotationField
import com.beust.klaxon.JsonArray
import java.io.StringWriter
import org.apache.jena.riot.RDFDataMgr
import org.apache.jena.riot.RDFFormat
import org.apache.logging.log4j.LogManager
import java.io.StringWriter
class ResourceBuilder(
private val source: Map<String, Any>,
......@@ -50,11 +50,13 @@ class ResourceBuilder(
when (val id = source[config.uri]) {
is String -> recordId = id
is Int -> recordId = id.toString()
is JsonArray<*> -> errorMessages.add("Found multiple values in the field '${config.uri}' for identifiers: ${
id.joinToString(
", "
)
}.")
is JsonArray<*> -> errorMessages.add(
"Found multiple values in the field '${config.uri}' for identifiers: ${
id.joinToString(
", "
)
}."
)
null -> errorMessages.add("The value for id is 'null' in field '${config.uri}'.")
else -> errorMessages.add("Invalid value '$id' for id in field '${config.uri}'.")
}
......@@ -94,7 +96,15 @@ class ResourceBuilder(
}
fun generateRecord(): ResourceBuilder {
record = Record(recordId, recordTypeValue, recordSetId, institutionId, config.sponsoredByMemoriav, isPublished)
record = Record(
recordId,
recordTypeValue,
recordSetId,
institutionId,
config.sponsoredByMemoriav,
isPublished,
config.hasProxyType
)
for (recordFieldMapper in config.recordFieldMappers) {
try {
recordFieldMapper.apply(source, record!!)
......@@ -105,6 +115,7 @@ class ResourceBuilder(
isFatal = true
}
}
return this
}
......
......@@ -18,12 +18,7 @@
package ch.memobase.mapping
import ch.memobase.rdf.DC
import ch.memobase.rdf.EBUCORE
import ch.memobase.rdf.NS
import ch.memobase.rdf.RDA
import ch.memobase.rdf.RICO
import ch.memobase.rdf.SCHEMA
import ch.memobase.rdf.*
object KEYS {
......@@ -34,7 +29,7 @@ object KEYS {
const val uri = "uri"
const val type = "type"
// Literal Mappings
// Literal Mappings on Record (mostly)
const val name = "name"
const val descriptiveNote = "descriptiveNote"
......@@ -48,6 +43,8 @@ object KEYS {
const val relation = "relation"
const val conditionsOfUse = "conditionsOfUse"
const val conditionsOfAccess = "conditionsOfAccess"
const val proxyType = "proxy"
const val defaultProxyType = "proxydirect"
// Rules
......@@ -154,6 +151,7 @@ object KEYS {
val keysToPropertyMap = mapOf(
Pair(abstract, DC.abstract),
Pair(proxyType, MB.proxyType),
Pair(relatedPlaces, DC.spatial),
Pair(name, RICO.name),
Pair(title, RICO.title),
......
......@@ -6,6 +6,7 @@ import ch.memobase.mapping.mappers.AbstractFieldMapper
data class MapperConfiguration(
val uri: String,
val sponsoredByMemoriav: Boolean,
val hasProxyType: Boolean,
val recordType: SimpleAnnotationField,
val recordFieldMappers: List<AbstractFieldMapper>,
val physicalFieldMappers: List<AbstractFieldMapper>,
......
......@@ -30,6 +30,7 @@ import org.apache.logging.log4j.LogManager
class MappingConfigurationParser(data: ByteArray) {
private var uriField: String = ""
private var localRecordType: SimpleAnnotationField? = null
private var hasProxyType: Boolean = false
private val recordType: SimpleAnnotationField
private val recordFieldMappers = mutableListOf<AbstractFieldMapper>()
private val physicalObjectFieldMappers = mutableListOf<AbstractFieldMapper>()
......@@ -74,6 +75,7 @@ class MappingConfigurationParser(data: ByteArray) {
fun get() = MapperConfiguration(
uriField,
sponsoredByMemoriav,
hasProxyType,
recordType,
recordFieldMappers,
physicalObjectFieldMappers,
......@@ -90,6 +92,12 @@ class MappingConfigurationParser(data: ByteArray) {
KEYS.isSponsoredByMemoriav -> {
sponsoredByMemoriav = entry.value as Boolean
}
// checks of the proxy type is defined locally.
KEYS.proxyType -> {
val field = FieldParsers.parseSimpleAnnotationField(key, entry.value)
recordFieldMappers.add(MapperParsers.buildAnnotationMappers(field))
hasProxyType = true
}
// literal properties
KEYS.name, KEYS.title, KEYS.descriptiveNote, KEYS.scopeAndContent, KEYS.sameAs,
KEYS.abstract, KEYS.source, KEYS.hasFindingAid, KEYS.relation,
......
......@@ -109,7 +109,8 @@ class TestAgentMapper {
"rs1",
"ins1",
hasSponsoringAgent = true,
isPublished = false
isPublished = false,
hasProxyType = false
)
mapper.apply(source, record)
RDFDataMgr.write(FileOutputStream("$resourcePath/agent-mapper-with-name-only.ttl"), record.model, Lang.TURTLE)
......@@ -130,7 +131,8 @@ class TestAgentMapper {
"rs1",
"ins1",
hasSponsoringAgent = true,
isPublished = false
isPublished = false,
hasProxyType = false
)
mapper.apply(source, record)
RDFDataMgr.write(
......@@ -159,7 +161,8 @@ class TestAgentMapper {
"rs1",
"ins1",
hasSponsoringAgent = true,
isPublished = false
isPublished = false,
hasProxyType = false
)
mapper.apply(source, record)
......
......@@ -28,6 +28,7 @@ class TestMappingParser {
MapperConfiguration(
"TestField",
false,
false,
FieldParsers.parseSimpleAnnotationField("type", mapOf(Pair("const", "Foto"))),
emptyList(),
emptyList(),
......@@ -44,6 +45,7 @@ class TestMappingParser {
MapperConfiguration(
"TestField",
true,
false,
FieldParsers.parseSimpleAnnotationField("type", mapOf(Pair("const", "Foto"))),
emptyList(),
emptyList(),
......
......@@ -48,7 +48,8 @@ class TestSkosConceptMapper {
"rs1",
"ins1",
hasSponsoringAgent = true,
isPublished = false
isPublished = false,
hasProxyType = false
)
skosConceptFieldMapper.apply(source, record)
......
<https://memobase.ch/record/test-001-identifier> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Record> .
<https://memobase.ch/record/test-001-identifier> <https://memobase.ch/internal/isPublished> "false"^^<http://www.w3.org/2001/XMLSchema#boolean> .
<https://memobase.ch/record/test-001-identifier> <https://memobase.ch/internal/proxyType> "proxydirect" .
<https://memobase.ch/record/test-001-identifier> <https://www.ica.org/standards/RiC/ontology#heldBy> <https://memobase.ch/institution/test> .
<https://memobase.ch/record/test-001-identifier> <https://www.ica.org/standards/RiC/ontology#identifiedBy> _:B .
<https://memobase.ch/record/test-001-identifier> <https://www.ica.org/standards/RiC/ontology#isPartOf> <https://memobase.ch/recordSet/test-001> .
......
{"digitalFieldMappers" : [{"field" : {"directField" : "MainID", "directKey" : "main", "field" : "MainID", "key" : "main"}}], "physicalFieldMappers" : [{"field" : {"directField" : "MainID", "directKey" : "main", "field" : "MainID", "key" : "main"}}], "recordFieldMappers" : [{"field" : {"directField" : "MainID", "directKey" : "main", "field" : "MainID", "key" : "main"}}], "recordType" : {"constant" : "Foto", "key" : "type"}, "sponsoredByMemoriav" : true, "uri" : "TestField"}
\ No newline at end of file
{"digitalFieldMappers" : [{"field" : {"directField" : "MainID", "directKey" : "main", "field" : "MainID", "key" : "main"}}], "hasProxyType" : false, "physicalFieldMappers" : [{"field" : {"directField" : "MainID", "directKey" : "main", "field" : "MainID", "key" : "main"}}], "recordFieldMappers" : [{"field" : {"directField" : "MainID", "directKey" : "main", "field" : "MainID", "key" : "main"}}], "recordType" : {"constant" : "Foto", "key" : "type"}, "sponsoredByMemoriav" : true, "uri" : "TestField"}
\ No newline at end of file
{"digitalFieldMappers" : [], "physicalFieldMappers" : [], "recordFieldMappers" : [{"agentClassType" : "subject", "fields" : [{"fields" : [{"sources" : [{"directField" : "Schlagworte", "directKey" : "prefLabel", "field" : "Schlagworte", "key" : "prefLabel"}], "tag" : "fr"}], "key" : "prefLabel"}, {"constant" : "Ursprungsfeld: Mots clés", "key" : "editorialNote"}]}, {"agentClassType" : "genre", "fields" : [{"fields" : [{"sources" : [{"directField" : "Genre", "directKey" : "prefLabel", "field" : "Genre", "key" : "prefLabel"}], "tag" : "fr"}], "key" : "prefLabel"}, {"constant" : "Ursprungsfeld: Genre", "key" : "editorialNote"}]}], "recordType" : {"constant" : "Foto", "key" : "type"}, "sponsoredByMemoriav" : false, "uri" : "id"}
\ No newline at end of file
{"digitalFieldMappers" : [], "hasProxyType" : false, "physicalFieldMappers" : [], "recordFieldMappers" : [{"agentClassType" : "subject", "fields" : [{"fields" : [{"sources" : [{"directField" : "Schlagworte", "directKey" : "prefLabel", "field" : "Schlagworte", "key" : "prefLabel"}], "tag" : "fr"}], "key" : "prefLabel"}, {"constant" : "Ursprungsfeld: Mots clés", "key" : "editorialNote"}]}, {"agentClassType" : "genre", "fields" : [{"fields" : [{"sources" : [{"directField" : "Genre", "directKey" : "prefLabel", "field" : "Genre", "key" : "prefLabel"}], "tag" : "fr"}], "key" : "prefLabel"}, {"constant" : "Ursprungsfeld: Genre", "key" : "editorialNote"}]}], "recordType" : {"constant" : "Foto", "key" : "type"}, "sponsoredByMemoriav" : false, "uri" : "id"}
\ No newline at end of file
......@@ -20,6 +20,8 @@ _:b0 a rico:CreationRelation ;
rdau:P60451 <https://memobase.ch/institution/mrv> ;
<https://memobase.ch/internal/isPublished>
false ;
<https://memobase.ch/internal/proxyType>
"proxydirect" ;
rico:heldBy <https://memobase.ch/institution/ins1> ;
rico:identifiedBy [ a rico:Identifier ;
rico:identifier "rs1-1" ;
......
......@@ -19,6 +19,8 @@ _:b0 a rico:CreationRelation ;
rdau:P60451 <https://memobase.ch/institution/mrv> ;
<https://memobase.ch/internal/isPublished>
false ;
<https://memobase.ch/internal/proxyType>
"proxydirect" ;
rico:heldBy <https://memobase.ch/institution/ins1> ;
rico:identifiedBy [ a rico:Identifier ;
rico:identifier "rs1-1" ;
......
......@@ -10,6 +10,8 @@
rdau:P60451 <https://memobase.ch/institution/mrv> ;
<https://memobase.ch/internal/isPublished>
false ;
<https://memobase.ch/internal/proxyType>
"proxydirect" ;
rico:heldBy <https://memobase.ch/institution/ins1> ;
rico:identifiedBy [ a rico:Identifier ;
rico:identifier "rs1-1" ;
......@@ -20,20 +22,20 @@
_:b0 , _:b1 , _:b2 ;
rico:type "Foto" .
_:b2 a rico:CreationRelation ;
_:b1 a rico:CreationRelation ;
rico:creationRelationHasSource <https://memobase.ch/record/rs1-1> ;
rico:creationRelationHasTarget [ a rico:Person ;
rico:agentIsTargetOfCreationRelation
_:b2 ;
_:b1 ;
rico:name "Second Person"
] ;
rico:type "creator" .
_:b1 a rico:CreationRelation ;
_:b2 a rico:CreationRelation ;
rico:creationRelationHasSource <https://memobase.ch/record/rs1-1> ;
rico:creationRelationHasTarget [ a rico:Person ;
rico:agentIsTargetOfCreationRelation
_:b1 ;
_:b2 ;
rico:name "Third Person"
] ;
rico:name "Relation 3" ;
......
......@@ -9,6 +9,8 @@
a rico:Record ;
<https://memobase.ch/internal/isPublished>
false ;
<https://memobase.ch/internal/proxyType>
"proxydirect" ;
rico:heldBy <https://memobase.ch/institution/test> ;
rico:identifiedBy [ a rico:Identifier ;
rico:identifier "test-001-identifier" ;
......
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