Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
memoriav
Memobase 2020
services
Import Process
Fedora Ingest Service
Commits
4443288e
Commit
4443288e
authored
Jul 17, 2020
by
Jonas Waeber
Browse files
Implement locator replacement in rdf handler
parent
ab768e50
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/main/kotlin/Ingester.kt
View file @
4443288e
...
...
@@ -64,7 +64,8 @@ class Ingester(private val producer: Producer, private val sftpClient: SftpClien
val
instantiationOutput
=
StringWriter
()
instantiationPair
.
second
.
write
(
instantiationOutput
)
try
{
fedoraClient
.
createOrUpdateRdfResource
(
URI
(
instantiationPair
.
first
),
instantiationOutput
.
toString
(),
RdfContentTypes
.
NTRIPLES
)
val
data
=
instantiationOutput
.
toString
()
fedoraClient
.
createOrUpdateRdfResource
(
URI
(
instantiationPair
.
first
),
data
,
RdfContentTypes
.
NTRIPLES
)
log
.
info
(
"Ingested instantiation ${instantiationPair.first}."
)
producer
.
sendReport
(
Report
(
instantiationPair
.
first
,
ReportStatus
.
success
,
"Ingested an instantiation in fedora."
))
...
...
src/main/kotlin/RdfHandler.kt
View file @
4443288e
...
...
@@ -2,13 +2,17 @@ package org.memobase
import
org.apache.jena.rdf.model.Model
import
org.apache.jena.rdf.model.ModelFactory
import
org.apache.jena.rdf.model.Statement
import
org.apache.jena.rdf.model.impl.SelectorImpl
import
org.apache.jena.rdf.model.impl.StatementImpl
import
org.apache.log4j.LogManager
import
org.memobase.rdf.EBUCORE
import
org.memobase.rdf.RDF
import
org.memobase.rdf.RICO
import
java.io.ByteArrayInputStream
class
RdfHandler
(
data
:
String
)
{
private
val
log
=
LogManager
.
getLogger
(
"RdfHandler"
)
private
val
model
=
ModelFactory
.
createDefaultModel
()
init
{
...
...
@@ -50,10 +54,32 @@ class RdfHandler(data: String) {
}
model
.
add
(
statement
)
}
if
(
resource
.
hasProperty
(
EBUCORE
.
locator
))
{
replaceSftpLocator
(
resource
.
uri
,
model
)
}
Pair
(
resource
.
uri
,
model
)
}.
toList
()
}
private
fun
replaceSftpLocator
(
uri
:
String
,
model
:
Model
)
{
var
newStatement
:
Statement
?
=
null
val
string
:
String
?
=
null
val
removedStatement
=
model
.
listStatements
(
SelectorImpl
(
null
,
EBUCORE
.
locator
,
string
)).
mapWith
{
if
(
it
.
`object`
.
asLiteral
().
string
.
startsWith
(
"sftp:"
))
{
newStatement
=
StatementImpl
(
it
.
subject
,
it
.
predicate
,
model
.
createLiteral
(
"$uri/binary"
))
}
it
}.
nextOptional
()
removedStatement
.
let
{
if
(
it
.
isPresent
&&
newStatement
!=
null
)
{
model
.
remove
(
it
.
get
())
model
.
add
(
newStatement
)
}
}
log
.
error
(
"Removed statement $removedStatement."
)
log
.
error
(
"Added statement $newStatement."
)
}
fun
getSftpLocators
():
List
<
Pair
<
String
,
String
?
>>
{
return
model
.
listSubjectsWithProperty
(
RICO
.
type
,
"digitalObject"
).
filterKeep
{
it
.
hasProperty
(
EBUCORE
.
locator
)
...
...
src/test/kotlin/TestRdfHandler.kt
View file @
4443288e
...
...
@@ -95,4 +95,28 @@ class TestRdfHandler {
Pair
(
"https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-2"
,
"/path/to/file/filename.jpg"
)
)
@Test
fun
`test
replace
sftp
locators`
()
{
val
rdfHandler
=
RdfHandler
(
readFile
(
"inputSftp.nt"
))
val
list
=
rdfHandler
.
getInstantiations
()
list
.
forEachIndexed
{
index
,
pair
->
val
out
=
StringWriter
()
RDFDataMgr
.
write
(
out
,
pair
.
second
,
Lang
.
NTRIPLES
)
val
sortedOut
=
sort
(
out
.
toString
().
split
(
"\n"
)).
trim
()
assertThat
(
sortedOut
)
.
isEqualTo
(
sort
(
readFile
(
"replaceSftpLocatorOutput$index.nt"
).
split
(
"\n"
)).
trim
())
assertThat
(
pair
.
first
)
.
isEqualTo
(
uris2
[
index
])
}
}
private
val
uris2
=
listOf
(
"https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-1"
,
"https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-2"
)
}
\ No newline at end of file
src/test/resources/log4j2.xml
View file @
4443288e
...
...
@@ -24,7 +24,7 @@
</Console>
</Appenders>
<Loggers>
<Root
level=
"
info
"
>
<Root
level=
"
error
"
>
<AppenderRef
ref=
"STDOUT"
/>
</Root>
</Loggers>
...
...
src/test/resources/rdf/replaceSftpLocatorOutput0.nt
0 → 100644
View file @
4443288e
<https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Instantiation> .
<https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-1> <https://www.ica.org/standards/RiC/ontology#type> "digitalObject" .
<https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-1> <http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#locator> "http://digitalisate.afz.ethz.ch/?&guid=0a9aef73bc2845eabc3c20db7c141bea" .
\ No newline at end of file
src/test/resources/rdf/replaceSftpLocatorOutput1.nt
0 → 100644
View file @
4443288e
<https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Instantiation> .
<https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-2> <https://www.ica.org/standards/RiC/ontology#type> "digitalObject" .
<https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-2> <http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#locator> "https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-2/binary" .
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment