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
c7e4d27c
Commit
c7e4d27c
authored
Oct 23, 2020
by
Jonas Waeber
Browse files
Refactor ingester code.
Use RDFDataMgr interface instead of model writer. Replace constants with variables.
parent
b5ca4b43
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/kotlin/Ingester.kt
View file @
c7e4d27c
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
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