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
c09b783f
Verified
Commit
c09b783f
authored
Jul 24, 2020
by
Sebastian Schüpbach
Browse files
fetch mime type dynamically from input data
Signed-off-by:
Sebastian Schüpbach
<
sebastian.schuepbach@unibas.ch
>
parent
5f3e0310
Pipeline
#11983
failed with stages
in 1 minute and 51 seconds
Changes
7
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
c09b783f
...
...
@@ -2,5 +2,6 @@
!.idea/copyright
build
out/
.gradle
\ No newline at end of file
.gradle
build.gradle
View file @
c09b783f
...
...
@@ -46,7 +46,7 @@ dependencies {
implementation
'org.apache.jena:apache-jena:3.14.0'
implementation
'org.memobase:memobase-service-utilities:1.
6
.0'
implementation
'org.memobase:memobase-service-utilities:1.
10
.0'
implementation
'org.memobase:fedora-client:0.4.1'
// KOTLIN IMPORTS
...
...
src/main/kotlin/Ingester.kt
View file @
c09b783f
...
...
@@ -29,7 +29,11 @@ import java.io.File
import
java.io.StringWriter
import
java.net.URI
class
Ingester
(
private
val
producer
:
Producer
,
private
val
sftpClient
:
SftpClient
,
private
val
fedoraClient
:
FedoraClient
)
:
Closeable
{
class
Ingester
(
private
val
producer
:
Producer
,
private
val
sftpClient
:
SftpClient
,
private
val
fedoraClient
:
FedoraClient
)
:
Closeable
{
private
val
log
=
LogManager
.
getLogger
(
"FedoraIngester"
)
...
...
@@ -54,11 +58,13 @@ class Ingester(private val producer: Producer, private val sftpClient: SftpClien
fedoraClient
.
createOrUpdateRdfResource
(
URI
(
recordPair
.
first
),
data
,
RdfContentTypes
.
NTRIPLES
)
log
.
info
(
"Ingested record ${recordPair.first}."
)
producer
.
sendReport
(
Report
(
recordPair
.
first
,
ReportStatus
.
success
,
"Ingested record in fedora."
))
Report
(
recordPair
.
first
,
ReportStatus
.
success
,
"Ingested record in fedora."
)
)
}
catch
(
ex
:
FcrepoOperationFailedException
)
{
log
.
error
(
"Ingestion of record ${recordPair.first} failed: ${ex.localizedMessage}."
)
producer
.
sendReport
(
Report
(
recordPair
.
first
,
ReportStatus
.
failure
,
ex
.
localizedMessage
))
Report
(
recordPair
.
first
,
ReportStatus
.
failure
,
ex
.
localizedMessage
)
)
}
rdfHandler
.
getInstantiations
().
forEach
{
instantiationPair
->
...
...
@@ -69,11 +75,13 @@ class Ingester(private val producer: Producer, private val sftpClient: SftpClien
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."
))
Report
(
instantiationPair
.
first
,
ReportStatus
.
success
,
"Ingested an instantiation in fedora."
)
)
}
catch
(
ex
:
FcrepoOperationFailedException
)
{
log
.
error
(
"Ingestion of instantiation ${instantiationPair.first} failed: ${ex.localizedMessage}."
)
producer
.
sendReport
(
Report
(
instantiationPair
.
first
,
ReportStatus
.
failure
,
ex
.
localizedMessage
))
Report
(
instantiationPair
.
first
,
ReportStatus
.
failure
,
ex
.
localizedMessage
)
)
}
}
...
...
@@ -81,16 +89,22 @@ class Ingester(private val producer: Producer, private val sftpClient: SftpClien
it
.
second
.
let
{
path
->
if
(
path
!=
null
)
{
sftpClient
.
open
(
File
(
path
)).
use
{
stream
->
val
binaryUri
=
"${it.first}/binary"
val
digitalInstantationUri
=
it
.
first
val
binaryUri
=
"$digitalInstantationUri/binary"
try
{
fedoraClient
.
createOrUpdateBinaryResource
(
URI
(
binaryUri
),
stream
,
"image/jpeg"
)
val
mimeType
=
rdfHandler
.
getMimeType
().
first
{
mT
->
mT
.
first
==
digitalInstantationUri
}.
second
fedoraClient
.
createOrUpdateBinaryResource
(
URI
(
binaryUri
),
stream
,
mimeType
)
log
.
info
(
"Ingested binary $binaryUri."
)
producer
.
sendReport
(
Report
(
binaryUri
,
ReportStatus
.
success
,
"Ingested a binary in fedora."
))
Report
(
binaryUri
,
ReportStatus
.
success
,
"Ingested a binary in fedora."
)
)
}
catch
(
ex
:
FcrepoOperationFailedException
)
{
log
.
error
(
"Ingestion of binary $binaryUri failed: ${ex.localizedMessage}."
)
producer
.
sendReport
(
Report
(
binaryUri
,
ReportStatus
.
failure
,
ex
.
localizedMessage
))
Report
(
binaryUri
,
ReportStatus
.
failure
,
ex
.
localizedMessage
)
)
}
}
}
...
...
@@ -110,15 +124,15 @@ class Ingester(private val producer: Producer, private val sftpClient: SftpClien
return
try
{
ingest
(
record
.
key
(),
record
.
value
())
Report
(
id
=
record
.
key
(),
status
=
ReportStatus
.
success
,
message
=
ReportMessages
.
ingestedRecord
(
record
.
key
())
id
=
record
.
key
(),
status
=
ReportStatus
.
success
,
message
=
ReportMessages
.
ingestedRecord
(
record
.
key
())
)
}
catch
(
e
:
FcrepoOperationFailedException
)
{
Report
(
id
=
record
.
key
(),
status
=
ReportStatus
.
failure
,
message
=
ReportMessages
.
ingestFailed
(
record
.
key
())
id
=
record
.
key
(),
status
=
ReportStatus
.
failure
,
message
=
ReportMessages
.
ingestFailed
(
record
.
key
())
)
}
}
...
...
src/main/kotlin/RdfHandler.kt
View file @
c09b783f
...
...
@@ -92,4 +92,12 @@ class RdfHandler(data: String) {
}
}.
toList
()
}
fun
getMimeType
():
List
<
Pair
<
String
,
String
?
>>
{
return
model
.
listSubjectsWithProperty
(
RICO
.
type
,
"digitalObject"
).
filterKeep
{
it
.
hasProperty
(
EBUCORE
.
hasMimeType
)
}.
mapWith
{
Pair
(
it
.
uri
,
it
.
getProperty
(
EBUCORE
.
hasMimeType
).
`object`
.
asLiteral
().
string
)
}.
toList
()
}
}
\ No newline at end of file
src/test/kotlin/TestRdfHandler.kt
View file @
c09b783f
package
org.memobase
import
org.apache.jena.rdf.model.Model
import
org.apache.jena.rdf.model.ModelFactory
import
org.apache.jena.rdf.model.impl.SelectorImpl
import
org.apache.jena.riot.Lang
import
org.apache.jena.riot.RDFDataMgr
import
org.assertj.core.api.Assertions.`in`
import
org.assertj.core.api.Assertions.assertThat
import
org.assertj.core.api.Condition
import
org.junit.jupiter.api.Test
import
org.junit.jupiter.api.TestInstance
import
java.io.File
import
java.io.FileInputStream
import
java.io.StringWriter
import
java.nio.charset.Charset
import
java.util.function.Predicate
@TestInstance
(
TestInstance
.
Lifecycle
.
PER_CLASS
)
...
...
@@ -113,6 +106,12 @@ class TestRdfHandler {
}
}
@Test
fun
`test
mime
type
extraction
for
binaries`
()
{
val
rdfHandler
=
RdfHandler
(
readFile
(
"input.nt"
))
assertThat
(
rdfHandler
.
getMimeType
().
first
().
second
).
isEqualTo
(
"video/mpeg"
)
}
private
val
uris2
=
listOf
(
"https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-1"
,
...
...
src/test/resources/rdf/input.nt
View file @
c09b783f
...
...
@@ -107,6 +107,7 @@ _:Bcb5da6d9X2Dfec6X2D4dd8X2D9b01X2D1c158a0464c7 <http://www.w3.org/1999/02/22-rd
<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> <https://www.ica.org/standards/RiC/ontology#identifiedBy> _:Bdd8afd91375dbb381b51dad3dd9af500 .
<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" .
<https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-1> <http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#hasMimeType> "video/mpeg" .
<https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-1> <https://www.ica.org/standards/RiC/ontology#regulatedBy> _:Bc3f1507debc5b4ef586c9d1adc9a4e45 .
<https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-1> <https://www.ica.org/standards/RiC/ontology#regulatedBy> _:B9e9ebd9742b512fd44e26136d2fef230 .
<https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-1> <https://www.ica.org/standards/RiC/ontology#instantiates> <https://memobase.ch/record/AFZ-IB_Becker_Audiovisuals_63> .
...
...
src/test/resources/rdf/inputSftp.nt
View file @
c09b783f
<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" .
<https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-1> <http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#hasMimeType> "video/mpeg" .
<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> "sftp:/path/to/file/filename.jpg" .
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