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
libraries
Mapper Service Configuration
Commits
7a09a8e8
Commit
7a09a8e8
authored
Mar 09, 2022
by
Jonas Waeber
Browse files
Remove digital object if there are no properties added.
Add tests for this.
parent
bab6e012
Pipeline
#44199
passed with stage
in 2 minutes and 44 seconds
Changes
6
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/main/kotlin/builder/ResourceBuilder.kt
View file @
7a09a8e8
...
...
@@ -145,6 +145,10 @@ class ResourceBuilder(
digitalObject
=
if
(
config
.
digitalFieldMappers
.
isNotEmpty
())
{
val
digitalObject
=
DigitalObject
(
recordId
,
recordSetId
,
institutionId
,
1
,
config
.
hasProxyType
)
var
count
=
0
digitalObject
.
resource
.
listProperties
().
forEach
{
_
->
count
+=
1
}
config
.
digitalFieldMappers
.
forEach
{
try
{
it
.
apply
(
source
,
digitalObject
)
...
...
@@ -155,9 +159,20 @@ class ResourceBuilder(
isFatal
=
true
}
}
digitalObject
.
addRecord
(
record
!!
)
record
?.
addInstantiation
(
digitalObject
)
digitalObject
var
countExpanded
=
0
digitalObject
.
resource
.
listProperties
().
forEach
{
_
->
countExpanded
+=
1
}
if
(
count
==
countExpanded
)
{
val
message
=
"Removed digital object from resource as there are no properties extracted from the data."
log
.
warn
(
message
)
errorMessages
.
add
(
message
)
null
}
else
{
digitalObject
.
addRecord
(
record
!!
)
record
?.
addInstantiation
(
digitalObject
)
digitalObject
}
}
else
{
null
}
...
...
src/test/kotlin/ch/memobase/test/TestResourceBuilder.kt
0 → 100644
View file @
7a09a8e8
/*
* mapper-service
* Copyright (C) 2020 Memoriav
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package
ch.memobase.test
import
ch.memobase.builder.ResourceBuilder
import
ch.memobase.mapping.MappingConfigurationParser
import
org.assertj.core.api.Assertions.assertThat
import
org.junit.jupiter.api.Test
import
org.junit.jupiter.api.TestInstance
import
java.io.File
import
java.io.FileInputStream
@TestInstance
(
TestInstance
.
Lifecycle
.
PER_CLASS
)
class
TestResourceBuilder
{
private
val
path
=
"src/test/resources/resource-builder"
@Test
fun
`test
exclude
digital
object
without input`() {
val config =
MappingConfigurationParser
((
FileInputStream
(
File
(
"$path/mapping1.yml"
)).
readBytes
())).
get
()
val
resourceBuilder
=
ResourceBuilder
(
mapOf
(
),
config
,
"tst"
,
"tst-001"
,
false
)
resourceBuilder
.
generateDigitalObject
()
assertThat
(
resourceBuilder
.
errorMessages
)
.
isEqualTo
(
listOf
(
"Removed digital object from resource as there are no properties extracted from the data."
))
}
@Test
fun
`test
include
digital
object
with input`() {
val config =
MappingConfigurationParser
((
FileInputStream
(
File
(
"$path/mapping1.yml"
)).
readBytes
())).
get
()
val
resourceBuilder
=
ResourceBuilder
(
mapOf
(
Pair
(
"id"
,
"tst-001-202"
),
Pair
(
"locator"
,
"https://www.example.org/image.jpg"
)
),
config
,
"tst"
,
"tst-001"
,
false
)
resourceBuilder
.
generateRecord
()
resourceBuilder
.
generateDigitalObject
()
assertThat
(
resourceBuilder
.
errorMessages
)
.
isEqualTo
(
emptyList
<
String
>())
}
}
src/test/resources/resource-builder/mapping1.yml
0 → 100644
View file @
7a09a8e8
record
:
uri
:
identifier
type
:
type
digital
:
locator
:
locator
\ No newline at end of file
src/test/resources/turtleOutput/agent-mapper-with-multiple-authors.ttl
View file @
7a09a8e8
...
...
@@ -5,6 +5,16 @@
@prefix
ebucore:
<http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#>
.
@prefix
skos:
<http://www.w3.org/2004/02/skos/core#>
.
_:
b0
a
rico:
CreationRelation
;
rico:
creationRelationHasSource
<https://memobase.ch/record/rs1-1>
;
rico:
creationRelationHasTarget
[
a
rico:
Person
;
rico:
agentIsTargetOfCreationRelation
_:
b0
;
rico:
name
"PERSON 1"
]
;
rico:
name
"RELATION 1"
;
rico:
type
"creator"
.
<https://memobase.ch/record/rs1-1>
a
rico:
Record
;
rdau:
P60451
<https://memobase.ch/institution/mav>
;
...
...
@@ -17,7 +27,7 @@
]
;
rico:
isPartOf
<https://memobase.ch/recordSet/rs1>
;
rico:
recordResourceOrInstantiationIsSourceOfCreationRelation
_:
b
0
,
_:
b
1
;
_:
b
1
,
_:
b
0
;
rico:
type
"Foto"
.
_:
b1
a
rico:
CreationRelation
;
...
...
@@ -25,16 +35,6 @@ _:b1 a rico:CreationRelation ;
rico:
creationRelationHasTarget
[
a
rico:
Person
;
rico:
agentIsTargetOfCreationRelation
_:
b1
;
rico:
name
"PERSON 1"
]
;
rico:
name
"RELATION 1"
;
rico:
type
"creator"
.
_:
b0
a
rico:
CreationRelation
;
rico:
creationRelationHasSource
<https://memobase.ch/record/rs1-1>
;
rico:
creationRelationHasTarget
[
a
rico:
Person
;
rico:
agentIsTargetOfCreationRelation
_:
b0
;
rico:
name
"PERSON 2"
]
;
rico:
name
"RELATION 2"
;
...
...
src/test/resources/turtleOutput/agent-mapper-with-name-only.ttl
View file @
7a09a8e8
...
...
@@ -5,6 +5,15 @@
@prefix
ebucore:
<http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#>
.
@prefix
skos:
<http://www.w3.org/2004/02/skos/core#>
.
_:
b0
a
rico:
CreationRelation
;
rico:
creationRelationHasSource
<https://memobase.ch/record/rs1-1>
;
rico:
creationRelationHasTarget
[
a
rico:
Person
;
rico:
agentIsTargetOfCreationRelation
_:
b0
;
rico:
name
"Hans Zimmer"
]
;
rico:
type
"creator"
.
<https://memobase.ch/record/rs1-1>
a
rico:
Record
;
rdau:
P60451
<https://memobase.ch/institution/mav>
;
...
...
@@ -19,12 +28,3 @@
rico:
recordResourceOrInstantiationIsSourceOfCreationRelation
_:
b0
;
rico:
type
"Foto"
.
_:
b0
a
rico:
CreationRelation
;
rico:
creationRelationHasSource
<https://memobase.ch/record/rs1-1>
;
rico:
creationRelationHasTarget
[
a
rico:
Person
;
rico:
agentIsTargetOfCreationRelation
_:
b0
;
rico:
name
"Hans Zimmer"
]
;
rico:
type
"creator"
.
src/test/resources/turtleOutput/missing-relation-name-value-in-list.ttl
View file @
7a09a8e8
...
...
@@ -20,31 +20,31 @@
_:
b0
,
_:
b1
,
_:
b2
;
rico:
type
"Foto"
.
_:
b
2
a
rico:
CreationRelation
;
_:
b
0
a
rico:
CreationRelation
;
rico:
creationRelationHasSource
<https://memobase.ch/record/rs1-1>
;
rico:
creationRelationHasTarget
[
a
rico:
Person
;
rico:
agentIsTargetOfCreationRelation
_:
b
2
;
_:
b
0
;
rico:
name
"Second Person"
]
;
rico:
type
"creator"
.
_:
b
0
a
rico:
CreationRelation
;
_:
b
1
a
rico:
CreationRelation
;
rico:
creationRelationHasSource
<https://memobase.ch/record/rs1-1>
;
rico:
creationRelationHasTarget
[
a
rico:
Person
;
rico:
agentIsTargetOfCreationRelation
_:
b
0
;
rico:
name
"
Third
Person"
_:
b
1
;
rico:
name
"
First
Person"
]
;
rico:
name
"Relation
3
"
;
rico:
name
"Relation
1
"
;
rico:
type
"creator"
.
_:
b
1
a
rico:
CreationRelation
;
_:
b
2
a
rico:
CreationRelation
;
rico:
creationRelationHasSource
<https://memobase.ch/record/rs1-1>
;
rico:
creationRelationHasTarget
[
a
rico:
Person
;
rico:
agentIsTargetOfCreationRelation
_:
b
1
;
rico:
name
"
First
Person"
_:
b
2
;
rico:
name
"
Third
Person"
]
;
rico:
name
"Relation
1
"
;
rico:
name
"Relation
3
"
;
rico:
type
"creator"
.
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