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
postprocessing
Media Converter
Commits
c916f79c
Verified
Commit
c916f79c
authored
Oct 22, 2021
by
Sebastian Schüpbach
Browse files
use file name as binary object identifier
parent
65fdc8e9
Pipeline
#35331
passed with stages
in 8 minutes and 18 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/scala/ch/memobase/models/BinaryResourceMetadata.scala
View file @
c916f79c
...
...
@@ -55,19 +55,14 @@ object BinaryResourceMetadata extends RecordUtils {
extractBinaryResourceMetadata
(
jsonldGraph
,
externalBaseUrl
,
distributorHost
)
}
private
def
buildDistributorUrl
(
longId
:
String
,
baseUrl
:
String
,
distributorHost
:
String
,
resourceType
:
MemobaseResource
)
:
String
=
{
val
pattern
=
raw
"""${baseUrl.stripSuffix("/")}/digital/([^/]+)-1"""
.
r
pattern
.
findFirstMatchIn
(
longId
)
match
{
case
Some
(
m
)
=>
resourceType
match
{
case
DigitalObject
=>
s
"${distributorHost.stripSuffix("
/
")}/media/${m.group(1)}"
case
Thumbnail
=>
s
"${distributorHost.stripSuffix("
/
")}/thumbnail/${m.group(1)}"
case
_
=>
""
}
case
None
=>
""
private
def
buildDistributorUrl
(
fileName
:
String
,
distributorHost
:
String
,
resourceType
:
MemobaseResource
)
:
String
=
{
resourceType
match
{
case
DigitalObject
=>
s
"${distributorHost.stripSuffix("
/
")}/media/$fileName"
case
Thumbnail
=>
s
"${distributorHost.stripSuffix("
/
")}/thumbnail/$fileName"
case
_
=>
""
}
}
...
...
@@ -77,25 +72,27 @@ object BinaryResourceMetadata extends RecordUtils {
.
withFilter
{
v
=>
isDigitalObject
(
v
.
obj
)
||
isPreviewImage
(
v
.
obj
)
}
.
map
{
v
=>
{
val
id
=
v
.
obj
.
getOrElse
(
"@id"
,
Value
(
"<unknown id>"
)).
str
Try
(
v
.
obj
match
{
case
v
if
isLocalRecord
(
v
)
&&
isProcessableMimeType
(
v
)
=>
val
instantiation
=
MemobaseResource
(
v
(
"type"
).
str
)
BinaryResourceMetadata
(
v
(
"@id"
).
str
.
substring
(
s
"$baseUrl/digital/"
.
length
-
1
),
buildDistributorUrl
(
v
(
"@id"
).
str
,
baseUrl
,
distributorHost
,
instantiation
),
Conversions
.
getMediaFileType
(
v
(
"hasMimeType"
).
str
).
get
,
instantiation
)
case
v
if
isLocalRecord
(
v
)
=>
val
resource
=
MemobaseResource
(
v
(
"type"
).
str
)
throw
new
UnmanageableMediaFileType
(
s
"Media file type for $id unknown"
,
resource
)
case
v
=>
val
resource
=
MemobaseResource
(
v
(
"type"
).
str
)
throw
new
NoLocalBinary
(
id
,
resource
)
}
)
}
.
map
{
v
=>
{
val
resourceId
=
v
.
obj
.
getOrElse
(
"@id"
,
Value
(
"<unknown id>"
)).
str
Try
(
v
.
obj
match
{
case
v
if
isLocalRecord
(
v
)
&&
isProcessableMimeType
(
v
)
=>
val
instantiation
=
MemobaseResource
(
v
(
"type"
).
str
)
val
locator
=
v
(
"locator"
).
str
.
split
(
"/"
).
last
.
replaceAll
(
" "
,
"_"
)
BinaryResourceMetadata
(
v
(
"@id"
).
str
.
substring
(
s
"$baseUrl/digital/"
.
length
-
1
),
buildDistributorUrl
(
locator
,
distributorHost
,
instantiation
),
Conversions
.
getMediaFileType
(
v
(
"hasMimeType"
).
str
).
get
,
instantiation
)
case
v
if
isLocalRecord
(
v
)
=>
val
resource
=
MemobaseResource
(
v
(
"type"
).
str
)
throw
new
UnmanageableMediaFileType
(
s
"Media file type for $resourceId unknown"
,
resource
)
case
v
=>
val
resource
=
MemobaseResource
(
v
(
"type"
).
str
)
throw
new
NoLocalBinary
(
resourceId
,
resource
)
}
)
}
}.
toList
}
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