Commit 7a09a8e8 authored by Jonas Waeber's avatar 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
......@@ -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
}
......
/*
* 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>())
}
}
record:
uri: identifier
type: type
digital:
locator: locator
\ No newline at end of file
......@@ -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
_:b0 , _:b1 ;
_:b1 , _:b0 ;
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" ;
......
......@@ -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" .
......@@ -20,31 +20,31 @@
_:b0 , _:b1 , _:b2 ;
rico:type "Foto" .
_:b2 a rico:CreationRelation ;
_:b0 a rico:CreationRelation ;
rico:creationRelationHasSource <https://memobase.ch/record/rs1-1> ;
rico:creationRelationHasTarget [ a rico:Person ;
rico:agentIsTargetOfCreationRelation
_:b2 ;
_:b0 ;
rico:name "Second Person"
] ;
rico:type "creator" .
_:b0 a rico:CreationRelation ;
_:b1 a rico:CreationRelation ;
rico:creationRelationHasSource <https://memobase.ch/record/rs1-1> ;
rico:creationRelationHasTarget [ a rico:Person ;
rico:agentIsTargetOfCreationRelation
_:b0 ;
rico:name "Third Person"
_:b1 ;
rico:name "First Person"
] ;
rico:name "Relation 3" ;
rico:name "Relation 1" ;
rico:type "creator" .
_:b1 a rico:CreationRelation ;
_:b2 a rico:CreationRelation ;
rico:creationRelationHasSource <https://memobase.ch/record/rs1-1> ;
rico:creationRelationHasTarget [ a rico:Person ;
rico:agentIsTargetOfCreationRelation
_:b1 ;
rico:name "First Person"
_:b2 ;
rico:name "Third Person"
] ;
rico:name "Relation 1" ;
rico:name "Relation 3" ;
rico:type "creator" .
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment