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

Replace constant strings with const val for the most part.

parent a2ab0ccc
......@@ -32,7 +32,7 @@ ext {
}
dependencies {
implementation 'org.memobase:memobase-service-utilities:2.0.9'
implementation 'org.memobase:memobase-service-utilities:2.0.12'
// Logging Framework
implementation "org.apache.logging.log4j:log4j-api:${log4jV}"
......
......@@ -14,7 +14,7 @@ object JSON {
return try {
val int = klaxon.parse<Input>(StringReader(data))
return if (int == null) {
log.error("No input parsed for message: $key.")
log.error("Could not parse input in message with key: $key.")
emptyList()
}
else listOf(int)
......
......@@ -24,6 +24,7 @@ import ch.memobase.rdf.NS
import ch.memobase.rdf.RDA
import ch.memobase.rdf.RDF
import ch.memobase.rdf.RICO
import ch.memobase.rdf.RICO.Types
import ch.memobase.rdf.SCHEMA
import ch.memobase.rdf.WD
import ch.memobase.rdf.XSD
......@@ -53,12 +54,13 @@ class RdfTransformer(properties: Properties) {
val resource = model.createResource(NS.mbcb + input.field_memobase_id)
resource.addProperty(RDF.type, RICO.CorporateBody)
resource.addProperty(RICO.type, "memobaseInstitution")
resource.addProperty(RICO.type, Types.CorporateBody.memobaseInstitution)
resource.addLiteral(MB.isPublished, input.status)
resource.addProperty(RICO.identifiedBy, addIdentifier(model, "main", input.field_memobase_id))
resource.addProperty(RICO.identifiedBy, addIdentifier(model, Types.Identifier.main, input.field_memobase_id))
if (input.field_old_memobase_id != null)
resource.addProperty(RICO.identifiedBy, addIdentifier(model, "oldMemobase", input.field_old_memobase_id))
resource.addProperty(RICO.identifiedBy, addIdentifier(model, Types.Identifier.oldMemobase, input.field_old_memobase_id))
input.recordset_ids.forEach {
resource.addProperty(RICO.isHolderOf, NS.mbrs + it)
......@@ -100,6 +102,7 @@ class RdfTransformer(properties: Properties) {
}
if (input.computed_teaser_image_url != null)
resource.addLiteral(WD.image, input.computed_teaser_image_url)
log.info("Transformed institution ${resource.uri}.")
return Pair(resource.uri, model)
}
......@@ -120,7 +123,7 @@ class RdfTransformer(properties: Properties) {
*/
// 0.1 Titel (Memobase)
addTitle(resource, model, "main", listOf(input.title_de, input.title_fr, input.title_it))
addTitle(resource, model, Types.Title.main, listOf(input.title_de, input.title_fr, input.title_it))
// + convenience label on the resource directly.
resource.addProperty(RICO.title, langLiteral(input.title_de, "de"))
resource.addProperty(RICO.title, langLiteral(input.title_fr, "fr"))
......@@ -171,7 +174,7 @@ class RdfTransformer(properties: Properties) {
addTitle(
resource,
model,
"original",
Types.Title.original,
listOf(input.field_original_title_de, input.field_original_title_fr, input.field_original_title_it)
)
// 3.2 Umfang -> recordResourceExtent
......@@ -213,13 +216,13 @@ class RdfTransformer(properties: Properties) {
// 3.7 Original ID
input.field_original_id.let {
if (it != null) {
resource.addProperty(RICO.identifiedBy, addIdentifier(model, "original", it))
resource.addProperty(RICO.identifiedBy, addIdentifier(model, Types.Identifier.original, it))
}
}
// 3.8 Original Signatur
input.field_original_shelf_mark.let {
if (it != null) {
resource.addProperty(RICO.identifiedBy, addIdentifier(model, "callNumber", it))
resource.addProperty(RICO.identifiedBy, addIdentifier(model, Types.Identifier.callNumber, it))
}
}
// 3.9 Original Beschreibung (Text)
......@@ -241,11 +244,11 @@ class RdfTransformer(properties: Properties) {
RICO.conditionsOfAccess
)
// 4.2 Zuständige Institution (Original)
addRelatedInstitution(model, resource, "original", input.field_resp_institution_original)
addRelatedInstitution(model, resource, Types.CorporateBody.original, input.field_resp_institution_original)
// 4.3 Zuständige Institution (Master)
addRelatedInstitution(model, resource, "master", input.field_resp_institution_master)
addRelatedInstitution(model, resource, Types.CorporateBody.master, input.field_resp_institution_master)
// 4.4 Zuständige Institution (Access)
addRelatedInstitution(model, resource, "access", input.field_resp_institution_access)
addRelatedInstitution(model, resource, Types.CorporateBody.access, input.field_resp_institution_access)
// Currently each project link is added as a separate entity.
// 5.1 Projekt (Titel)
......@@ -275,25 +278,25 @@ class RdfTransformer(properties: Properties) {
// 5.5 Publikationen (Titel)
// 5.6 Publikationen (Link)
input.field_publications_de.forEach { link ->
addRelatedRecord(resource, model, link, "de", RICO.isSubjectOf)
addRelatedRecord(resource, model, link, "de", RICO.isSubjectOf, Types.Record.publication)
}
input.field_publications_fr.forEach { link ->
addRelatedRecord(resource, model, link, "fr", RICO.isSubjectOf)
addRelatedRecord(resource, model, link, "fr", RICO.isSubjectOf, Types.Record.publication)
}
input.field_publications_it.forEach { link ->
addRelatedRecord(resource, model, link, "it", RICO.isSubjectOf)
addRelatedRecord(resource, model, link, "it", RICO.isSubjectOf, Types.Record.publication)
}
// Currently each record link is added as a separate entity.
// 5.7 Dokumente (Titel)
// 5.8 Dokumente (Link)
input.field_documents_de.forEach { link ->
addRelatedRecord(resource, model, link, "de", RICO.isRecordResourceAssociatedWithRecordResource)
addRelatedRecord(resource, model, link, "de", RICO.isRecordResourceAssociatedWithRecordResource, Types.Record.related)
}
input.field_documents_fr.forEach { link ->
addRelatedRecord(resource, model, link, "fr", RICO.isRecordResourceAssociatedWithRecordResource)
addRelatedRecord(resource, model, link, "fr", RICO.isRecordResourceAssociatedWithRecordResource, Types.Record.related)
}
input.field_documents_it.forEach { link ->
addRelatedRecord(resource, model, link, "it", RICO.isRecordResourceAssociatedWithRecordResource)
addRelatedRecord(resource, model, link, "it", RICO.isRecordResourceAssociatedWithRecordResource, Types.Record.related)
}
// 6.1 Datenübernahme
addRichTextLiteralIfNotNull(
......@@ -313,17 +316,18 @@ class RdfTransformer(properties: Properties) {
val literal = model.createTypedLiteral(Util.now, XSD.dateTime)
resource.addLiteral(RICO.modificationDate, literal)
// 6.4 Memobase ID
resource.addProperty(RICO.identifiedBy, addIdentifier(model, "main", input.field_memobase_id))
resource.addProperty(RICO.identifiedBy, addIdentifier(model, Types.Identifier.main, input.field_memobase_id))
// 8.1 Unterstützt durch Memoriav
resource.addProperty(RDA.hasSponsoringAgentOfResource, model.createResource(Util.memoriavUri))
resource.addProperty(RDA.hasSponsoringAgentOfResource, model.createResource(MB.memoriavInstitutionURI))
// 8.2 Institution
input.field_institution.forEach {
resource.addProperty(RICO.heldBy, NS.mbcb + it)
}
// 9.3 Alte Memobase ID
if (input.field_old_memobase_id != null)
resource.addProperty(RICO.identifiedBy, addIdentifier(model, "oldMemobase", input.field_old_memobase_id))
resource.addProperty(RICO.identifiedBy, addIdentifier(model, Types.Identifier.oldMemobase, input.field_old_memobase_id))
log.info("Transformed record set ${resource.uri}.")
return Pair(resource.uri, model)
}
......@@ -338,7 +342,7 @@ class RdfTransformer(properties: Properties) {
private fun addLanguage(model: Model, value: String): Resource {
val language = model.createResource()
language.addProperty(RDF.type, RICO.Language)
language.addProperty(RICO.type, literal("metadata"))
language.addProperty(RICO.type, literal(Types.Language.metadata))
languages[value].let {
if (it == null) {
language.addProperty(RICO.name, literal(value))
......@@ -368,7 +372,7 @@ class RdfTransformer(properties: Properties) {
private fun addMemoriavProject(resource: Resource, model: Model, link: Link, language: String) {
val node = model.createResource()
node.addProperty(RDF.type, RICO.CorporateBody)
node.addProperty(RICO.type, Util.memoriavProject)
node.addProperty(RICO.type, Types.CorporateBody.memoriavProject)
link.title.let {
if (it != null && it.isNotEmpty())
node.addProperty(RICO.title, langLiteral(it, language))
......@@ -383,16 +387,18 @@ class RdfTransformer(properties: Properties) {
if (it != null && it.isNotEmpty())
node.addProperty(RICO.title, langLiteral(it, language))
}
node.addProperty(RICO.type, literal(Types.RecordSet.related))
node.addProperty(SCHEMA.sameAs, literal(link.uri))
resource.addProperty(RICO.isRecordResourceAssociatedWithRecordResource, node)
}
private fun addRelatedRecord(resource: Resource, model: Model, link: Link, language: String, property: Property) {
private fun addRelatedRecord(resource: Resource, model: Model, link: Link, language: String, property: Property, type: String) {
val node = model.createResource()
node.addProperty(RDF.type, RICO.Record)
link.title.let {
if (it != null && it.isNotEmpty())
node.addProperty(RICO.title, langLiteral(it, language))
}
node.addProperty(RICO.type, literal(type))
node.addProperty(SCHEMA.sameAs, literal(link.uri))
resource.addProperty(property, node)
}
......
......@@ -37,9 +37,9 @@ object Util {
const val pathCantons = "path.cantons"
const val pathMunicipalities = "path.municipalities"
const val memoriavProject = "memoriavProject"
const val drupalInstitutionTypeIdentifier = "node--institution"
const val drupalRecordSetTypeIdentifier = "node--record_set"
const val memoriavUri = NS.mbcb + "mrv"
val now: String = LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME)
private val log = LogManager.getLogger(this::class.java)
......
......@@ -20,13 +20,14 @@ package org.memobase.model
import com.beust.klaxon.TypeAdapter
import kotlin.reflect.KClass
import org.apache.logging.log4j.LogManager
import org.memobase.Util
class InputTypeAdapter : TypeAdapter<Input> {
private val log = LogManager.getLogger("InputTypeAdapter")
private val log = LogManager.getLogger(this::class.java)
override fun classFor(type: Any): KClass<out Input> = when(type as String) {
"node--institution" -> Institution::class
"node--record_set" -> RecordSet::class
Util.drupalInstitutionTypeIdentifier -> Institution::class
Util.drupalRecordSetTypeIdentifier -> RecordSet::class
else -> {
log.error("Unknown input type: $type. Could not parse this input.")
Input::class
......
......@@ -17,6 +17,8 @@
*/
package org.memobase.model
import org.memobase.Util
data class Institution(
val status: Boolean,
......@@ -43,4 +45,4 @@ data class Institution(
val field_institution_types: List<String>,
val field_wikidata_id: String,
val computed_teaser_image_url: String?
) : Input("Institution")
\ No newline at end of file
) : Input(Util.drupalInstitutionTypeIdentifier)
\ No newline at end of file
......@@ -17,6 +17,8 @@
*/
package org.memobase.model
import org.memobase.Util
data class RecordSet(
/* Publikations Status */
val status: Boolean,
......@@ -123,4 +125,4 @@ data class RecordSet(
val field_institution: List<String>,
/* 9.3 Memobase ID (Alt)*/
val field_old_memobase_id: String?
) : Input("RecordSet")
\ No newline at end of file
) : Input(Util.drupalRecordSetTypeIdentifier)
\ No newline at end of file
......@@ -49,14 +49,14 @@ mbcb:completeExampleTest
wdt:P669 "Street" ;
wdt:P670 "Address"
] ;
rico:identifiedBy [ a rico:Identifier ;
rico:identifier "completeExampleTest" ;
rico:type "main"
] ;
rico:identifiedBy [ a rico:Identifier ;
rico:identifier "OLD_MEMOBASE_ID" ;
rico:type "oldMemobase"
] ;
rico:identifiedBy [ a rico:Identifier ;
rico:identifier "completeExampleTest" ;
rico:type "main"
] ;
rico:isHolderOf "https://memobase.ch/recordSet/testComplete" ;
rico:name "Complete Example"@de , "Complete Example"@fr , "Complete Example"@it ;
rico:type "memobaseInstitution" .
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