Commit 97b6a20d authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Fix issue with missing roles.

parent ee0908cd
Pipeline #21405 passed with stage
in 2 minutes and 2 seconds
......@@ -130,14 +130,14 @@ class ResourceBuilder(
private fun hasDigitalObject(): Boolean = digitalObject != null
fun writeRecord(): Pair<String, String> {
fun writeRecord(format: RDFFormat): Pair<String, String> {
return StringWriter().use { writer ->
RDFDataMgr.write(writer, record!!.model, RDFFormat.NTRIPLES_UTF8)
RDFDataMgr.write(writer, record!!.model, format)
if (hasPhysicalObject()) {
RDFDataMgr.write(writer, physicalObject!!.model, RDFFormat.NTRIPLES_UTF8)
RDFDataMgr.write(writer, physicalObject!!.model, format)
}
if (hasDigitalObject()) {
RDFDataMgr.write(writer, digitalObject!!.model, RDFFormat.NTRIPLES_UTF8)
RDFDataMgr.write(writer, digitalObject!!.model, format)
}
Pair(record!!.resource.uri, writer.toString().trim())
}
......
......@@ -54,7 +54,7 @@ abstract class TypeFieldMapper : AbstractFieldMapper() {
}
is StringList ->
sourceElement.value.forEachIndexed { index, s ->
if (properties.size == index + 1) {
if (properties.size >= index + 1) {
properties[index].add(Pair(field.key, field.toLiteral(s)))
} else {
properties.add(index, mutableListOf(Pair(field.key, field.toLiteral(s))))
......
......@@ -23,6 +23,7 @@ import ch.memobase.settings.HeaderMetadata
import com.beust.klaxon.Klaxon
import java.io.File
import java.io.FileOutputStream
import org.apache.jena.riot.RDFFormat
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
......@@ -41,6 +42,51 @@ class LocalTestRun {
0, 0, 0, 0
)
@Test
@Disabled
fun `test a single file`() {
val folder = "/home/jonas/memobase/data/snp-001"
val inputPath = "/home/jonas/memobase/data/test/step-2/Fonoteca-18BD1047_A29"
val outputPath = "/home/jonas/memobase/data/test/step-3/snp-001-18BD1047_A29"
val mappingFile = "/config/mapping.yml"
val klaxon = Klaxon()
val configurationParser = MappingConfigurationParser(File(folder + mappingFile).readBytes())
val configuration = configurationParser.get()
val item = klaxon.parse<Map<String, Any>>(File(inputPath)).orEmpty()
val builder = ResourceBuilder(
item,
configuration,
headerMetadata.institutionId,
headerMetadata.recordSetId,
headerMetadata.isPublished
)
val result = builder.extractRecordId()
.extractRecordTypeValue()
.generateRecord()
.generatePhysicalObject()
.generateDigitalObject()
.addDerivedConnection()
val writtenResult = result
.writeRecord(RDFFormat.NTRIPLES_UTF8)
val writtenResultTurtle = result
.writeRecord(RDFFormat.TURTLE_PRETTY)
FileOutputStream(File(outputPath)).use {
it.bufferedWriter().use { writer ->
writer.write(writtenResult.second)
}
}
FileOutputStream(File("output.ttl")).use {
it.bufferedWriter().use { writer ->
writer.write(writtenResultTurtle.second)
}
}
}
@Test
@Disabled
fun `test local folder`() {
......@@ -68,12 +114,12 @@ class LocalTestRun {
headerMetadata.isPublished
)
builder.extractRecordId()
builder.extractRecordTypeValue()
.extractRecordTypeValue()
.generateRecord()
.generatePhysicalObject()
.generateDigitalObject()
.addDerivedConnection()
.writeRecord()
.writeRecord(RDFFormat.NTRIPLES_UTF8)
}
.forEach { result ->
FileOutputStream(File(outputFolder + "/" + result.first.substringAfterLast("/"))).use {
......@@ -84,3 +130,4 @@ class LocalTestRun {
}
}
}
......@@ -5,6 +5,15 @@
@prefix ebucore: <http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
_:b0 a rico:CreationRelation ;
rico:creationRelationHasSource <https://memobase.ch/record/rs1-1> ;
rico:creationRelationHasTarget [ a rico:Person ;
rico:agentIsTargetOfCreationRelation
_:b0 ;
rico:name "Hans Zimmer"
] ;
rico:type "creator" .
<https://memobase.ch/record/rs1-1>
a rico:Record ;
rdau:P60451 <https://memobase.ch/institution/mrv> ;
......@@ -19,12 +28,3 @@
rico:recordResourceOrInstantiationIsSourceOfCreationRelation
_:b0 ;
rico:type "Foto" .
_:b0 a rico:CreationRelation ;
rico:creationRelationHasSource <https://memobase.ch/record/rs1-1> ;
rico:creationRelationHasTarget [ a rico:Person ;
rico:agentIsTargetOfCreationRelation
_:b0 ;
rico:name "Hans Zimmer"
] ;
rico:type "creator" .
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