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

Add resource writer to resource builder

parent 09c57a88
Pipeline #15794 passed with stage
in 3 minutes and 6 seconds
......@@ -21,7 +21,10 @@ package ch.memobase.builder
import ch.memobase.mapping.KEYS
import ch.memobase.mapping.fields.ConstantField
import ch.memobase.mapping.fields.MappedAnnotationField
import mapping.MapperConfiguration
import org.apache.jena.riot.RDFDataMgr
import org.apache.jena.riot.RDFFormat
class ResourceBuilder(
private val source: Map<String, Any>,
......@@ -126,4 +129,17 @@ class ResourceBuilder(
private fun hasPhysicalObject(): Boolean = physicalObject != null
private fun hasDigitalObject(): Boolean = digitalObject != null
fun writeRecord(builder: ResourceBuilder): Pair<String, String> {
return StringWriter().use { writer ->
RDFDataMgr.write(writer, builder.record!!.model, RDFFormat.NTRIPLES_UTF8)
if (builder.hasPhysicalObject()) {
RDFDataMgr.write(writer, physicalObject!!.model, RDFFormat.NTRIPLES_UTF8)
if (hasDigitalObject()) {
RDFDataMgr.write(writer, digitalObject!!.model, RDFFormat.NTRIPLES_UTF8)
Pair(record!!.resource.uri, writer.toString().trim())
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