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

Refactor ingester code.

Use RDFDataMgr interface instead of model writer.
Replace constants with variables.
parent b5ca4b43
...@@ -21,6 +21,8 @@ import java.io.File ...@@ -21,6 +21,8 @@ import java.io.File
import java.io.StringWriter import java.io.StringWriter
import java.net.URI import java.net.URI
import org.apache.jena.rdf.model.Model import org.apache.jena.rdf.model.Model
import org.apache.jena.riot.Lang
import org.apache.jena.riot.RDFDataMgr
import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.LogManager
import org.fcrepo.client.FcrepoOperationFailedException import org.fcrepo.client.FcrepoOperationFailedException
import org.memobase.fedora.FedoraClient import org.memobase.fedora.FedoraClient
...@@ -39,14 +41,11 @@ class Ingester( ...@@ -39,14 +41,11 @@ class Ingester(
@Throws(FcrepoOperationFailedException::class) @Throws(FcrepoOperationFailedException::class)
fun ingest(id: String, content: String) { fun ingest(id: String, content: String) {
log.info("Ingest record $id.") log.info("Begin ingest of message with id $id.")
log.info("Content: $content")
val rdfHandler = RdfHandler(content, externalBaseUrl) val rdfHandler = RdfHandler(content, externalBaseUrl)
val recordOutput = StringWriter() val recordOutput = StringWriter()
val recordPair = rdfHandler.getRecord() val recordPair = rdfHandler.getRecord()
recordPair.second.write(recordOutput, "NTRIPLES") RDFDataMgr.write(recordOutput, recordPair.second, Lang.NTRIPLES)
val data = recordOutput.toString() val data = recordOutput.toString()
fedoraClient.startTransaction().use { transaction -> fedoraClient.startTransaction().use { transaction ->
...@@ -64,7 +63,7 @@ class Ingester( ...@@ -64,7 +63,7 @@ class Ingester(
transaction.createOrUpdateRdfResource(URI(recordPair.first), data, RdfContentTypes.NTRIPLES) transaction.createOrUpdateRdfResource(URI(recordPair.first), data, RdfContentTypes.NTRIPLES)
ingestInstantiations(rdfHandler.getInstantiations(), transaction) ingestInstantiations(rdfHandler.getInstantiations(), transaction)
val sftpLocators = rdfHandler.getSftpLocators() val sftpLocators = rdfHandler.getSftpLocators()
if (sftpLocators.size > 0) { if (sftpLocators.isNotEmpty()) {
ingestBinaries(sftpLocators, rdfHandler, transaction) ingestBinaries(sftpLocators, rdfHandler, transaction)
} }
transaction.commit() transaction.commit()
...@@ -75,7 +74,7 @@ class Ingester( ...@@ -75,7 +74,7 @@ class Ingester(
private fun ingestInstantiations(instantiations: List<Pair<String, Model>>, transaction: FedoraTransactionClient) { private fun ingestInstantiations(instantiations: List<Pair<String, Model>>, transaction: FedoraTransactionClient) {
instantiations.forEach { instantiationPair -> instantiations.forEach { instantiationPair ->
val instantiationOutput = StringWriter() val instantiationOutput = StringWriter()
instantiationPair.second.write(instantiationOutput, "NTRIPLES") RDFDataMgr.write(instantiationOutput, instantiationPair.second, Lang.NTRIPLES)
val instantiationData = instantiationOutput.toString() val instantiationData = instantiationOutput.toString()
log.info("Ingesting instantiation ${instantiationPair.first}.") log.info("Ingesting instantiation ${instantiationPair.first}.")
transaction.createOrUpdateRdfResource(URI(instantiationPair.first), instantiationData, RdfContentTypes.NTRIPLES) transaction.createOrUpdateRdfResource(URI(instantiationPair.first), instantiationData, RdfContentTypes.NTRIPLES)
...@@ -91,7 +90,7 @@ class Ingester( ...@@ -91,7 +90,7 @@ class Ingester(
it.second.let { path -> it.second.let { path ->
if (path != null) { if (path != null) {
sftpClient.open(File(path)).use { stream -> sftpClient.open(File(path)).use { stream ->
val binaryUri = "${it.first}/binary" val binaryUri = "${it.first}/${Service.BINARY_FILE_URI_PATH}"
val mimeType = rdfHandler.getMimeType().first { mT -> val mimeType = rdfHandler.getMimeType().first { mT ->
mT.first == digitalInstantiationUrl mT.first == digitalInstantiationUrl
}.second }.second
......
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