Commit aaaf42ba authored by Thomas Bernhart's avatar Thomas Bernhart
Browse files

WIP: MEMO-713: Send message to resource topic for every created resource

parent f2ce9c34
Pipeline #13806 passed with stages
in 5 minutes and 5 seconds
......@@ -22,13 +22,13 @@ import com.beust.klaxon.Klaxon
import java.time.LocalDateTime
data class FedoraResource(
val id: String,
val url: String,
val createdAt: String = LocalDateTime.now().toString(),
val rdfType: String,
val ricoType: String,
val institution: String,
val recordSet: String
val id: String,
val url: String,
val createdAt: String = LocalDateTime.now().toString(),
val rdfType: String,
val ricoType: String,
val institution: String,
val recordSet: String
) {
fun toJson(): String {
return Klaxon().toJsonString(this)
......
......@@ -29,6 +29,7 @@ import org.fcrepo.client.FcrepoOperationFailedException
import org.memobase.fedora.FedoraClient
import org.memobase.fedora.FedoraTransactionClient
import org.memobase.fedora.RdfContentTypes
import org.memobase.rdf.RICO
import org.memobase.sftp.SftpClient
class Ingester(
......@@ -72,10 +73,24 @@ class Ingester(
// ingest record, instantiations and binaries:
transaction.createOrUpdateRdfResource(URI(recordPair.first), data, RdfContentTypes.NTRIPLES)
ingestInstantiations(rdfHandler.getInstantiations(), transaction)
val ingestedInstantiations = ingestInstantiations(rdfHandler.getInstantiations(), transaction)
ingestBinaries(rdfHandler.getSftpLocators(), rdfHandler, transaction)
transaction.commit()
log.info("Ingested record ${recordPair.first}.")
producer.sendFedoraResourceDetails(
FedoraResource(
id = id,
rdfType = RICO.Record.toString(),
url = recordPair.first,
ricoType = "",
institution = "TODO",
recordSet = "TODO"
)
)
ingestedInstantiations.forEach { resource ->
producer.sendFedoraResourceDetails(resource)
}
}
}
......@@ -105,7 +120,8 @@ class Ingester(
}
}
private fun ingestInstantiations(instantiations: List<Pair<String, Model>>, transaction: FedoraTransactionClient) {
private fun ingestInstantiations(instantiations: List<Pair<String, Model>>, transaction: FedoraTransactionClient): MutableList<FedoraResource> {
val ingestedResources = mutableListOf<FedoraResource>()
instantiations.forEach { instantiationPair ->
val instantiationOutput = StringWriter()
instantiationPair.second.write(instantiationOutput, "NTRIPLES")
......@@ -113,12 +129,23 @@ class Ingester(
val instantiationData = instantiationOutput.toString()
log.info("Ingesting instantiation ${instantiationPair.first}.")
transaction.createOrUpdateRdfResource(URI(instantiationPair.first), instantiationData, RdfContentTypes.NTRIPLES)
ingestedResources.add(
FedoraResource(
id = "TODO",
url = instantiationPair.first,
rdfType = RICO.Instantiation.toString(),
ricoType = "TODO",
institution = "TODO",
recordSet = "TODO"
)
)
log.info("Ingested instantiation ${instantiationPair.first}.")
} catch (ex: FcrepoOperationFailedException) {
log.error("Ingestion of instantiation ${instantiationPair.first} failed: ${ex.localizedMessage}.")
throw ex
}
}
return ingestedResources
}
private fun ingestBinaries(sftpLocators: List<Pair<String, String?>>, rdfHandler: RdfHandler, transaction: FedoraTransactionClient) {
......
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