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

Fix original identifier source.

The original identifier can now be added to any resource.
parent 2655471f
Pipeline #13536 passed with stages
in 4 minutes and 53 seconds
......@@ -73,7 +73,7 @@ class KafkaTopology(private val settings: SettingsLoader) {
)
val updateDigitalObjects = instantiationBranch[0]
.mapValues { value -> enrichSftpLocator(value) }
.mapValues { readOnlyKey, value -> enrichSftpLocator(readOnlyKey, value) }
.mapValues { value ->
val out = StringWriter()
value.first.write(out, Constant.rdfParserLang)
......@@ -120,7 +120,12 @@ class KafkaTopology(private val settings: SettingsLoader) {
}
private fun getOriginalIdentifiers(res: List<Resource>): List<Resource> {
return res.filterNot { it.hasProperty(RDF.type, RICO.Identifier) && it.hasProperty(RICO.type, Constant.identifierType) }
return res.filter {
it.hasProperty(RDF.type, RICO.Identifier) && it.hasProperty(
RICO.type,
Constant.identifierType
)
}
}
private fun createModel(data: String): Model {
......@@ -129,47 +134,39 @@ class KafkaTopology(private val settings: SettingsLoader) {
return model
}
private fun enrichSftpLocator(data: Pair<Model, List<Resource>>): Pair<Model, Report> {
private fun enrichSftpLocator(key: String, data: Pair<Model, List<Resource>>): Pair<Model, Report> {
var link = ""
val digitalObject =
data.second.first { it.hasProperty(RICO.type, Constant.digitalObject) && !it.hasProperty(EBUCORE.locator) }
val addedStatements = mutableListOf<Statement>()
for (stmt in digitalObject.listProperties(RICO.identifiedBy)) {
if (stmt != null) {
if (stmt.`object`.isResource) {
val resource = stmt.`object`.asResource()
if (resource.hasLiteral(RICO.type, Constant.identifierType)) {
val value = resource.getProperty(RICO.identifier).literal
for (file in files) {
if (file.contains(value.string)) {
link = "${Constant.sftpPathPrefix}$file"
val literal = data.first.createLiteral(link)
addedStatements.add(StatementImpl(digitalObject, EBUCORE.locator, literal))
}
}
}
}
}
// This assumes that there is only one, and always one original identifier present!
val originalIdentifier = try {
getOriginalIdentifiers(data.second)[0]
} catch (ex: IndexOutOfBoundsException) {
return Pair(data.first, Report(key, ReportStatus.failure, ReportMessages.noOriginalIdentifier(key)))
}
if (addedStatements.size > 0) {
data.first.add(addedStatements)
return Pair(
data.first,
Report(
digitalObject.uri,
ReportStatus.success,
ReportMessages.reportSuccess(digitalObject.uri, link)
val value = originalIdentifier.getProperty(RICO.identifier)
for (file in files) {
if (file.contains(value.string)) {
link = "${Constant.sftpPathPrefix}$file"
val literal = data.first.createLiteral(link)
data.first.add(StatementImpl(digitalObject, EBUCORE.locator, literal))
return Pair(
data.first,
Report(
digitalObject.uri,
ReportStatus.success,
ReportMessages.reportSuccess(digitalObject.uri, link)
)
)
)
} else {
return Pair(
data.first,
Report(
digitalObject.id.labelString,
ReportStatus.failure,
ReportMessages.reportFailure(digitalObject.id.labelString)
)
)
}
}
return Pair(
data.first,
Report(
digitalObject.uri,
ReportStatus.failure,
ReportMessages.reportFailure(digitalObject.uri)
)
)
}
}
......@@ -8,4 +8,8 @@ object ReportMessages {
fun reportFailure(id: String): String {
return "Could not enrich sftp locator. Did no find a valid file for resource $id."
}
fun noOriginalIdentifier(key: String): String {
return "The record $key does not contain a identifier with rico:type 'original'!"
}
}
\ No newline at end of file
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