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
import java.io.StringWriter
import java.net.URI
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.fcrepo.client.FcrepoOperationFailedException
import org.memobase.fedora.FedoraClient
......@@ -39,14 +41,11 @@ class Ingester(
@Throws(FcrepoOperationFailedException::class)
fun ingest(id: String, content: String) {
log.info("Ingest record $id.")
log.info("Content: $content")
log.info("Begin ingest of message with id $id.")
val rdfHandler = RdfHandler(content, externalBaseUrl)
val recordOutput = StringWriter()
val recordPair = rdfHandler.getRecord()
recordPair.second.write(recordOutput, "NTRIPLES")
RDFDataMgr.write(recordOutput, recordPair.second, Lang.NTRIPLES)
val data = recordOutput.toString()
fedoraClient.startTransaction().use { transaction ->
......@@ -64,7 +63,7 @@ class Ingester(
transaction.createOrUpdateRdfResource(URI(recordPair.first), data, RdfContentTypes.NTRIPLES)
ingestInstantiations(rdfHandler.getInstantiations(), transaction)
val sftpLocators = rdfHandler.getSftpLocators()
if (sftpLocators.size > 0) {
if (sftpLocators.isNotEmpty()) {
ingestBinaries(sftpLocators, rdfHandler, transaction)
}
transaction.commit()
......@@ -75,7 +74,7 @@ class Ingester(
private fun ingestInstantiations(instantiations: List<Pair<String, Model>>, transaction: FedoraTransactionClient) {
instantiations.forEach { instantiationPair ->
val instantiationOutput = StringWriter()
instantiationPair.second.write(instantiationOutput, "NTRIPLES")
RDFDataMgr.write(instantiationOutput, instantiationPair.second, Lang.NTRIPLES)
val instantiationData = instantiationOutput.toString()
log.info("Ingesting instantiation ${instantiationPair.first}.")
transaction.createOrUpdateRdfResource(URI(instantiationPair.first), instantiationData, RdfContentTypes.NTRIPLES)
......@@ -91,7 +90,7 @@ class Ingester(
it.second.let { path ->
if (path != null) {
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 ->
mT.first == digitalInstantiationUrl
}.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