Skip to content

Commit

Permalink
fix: correct RDF serialization of sources
Browse files Browse the repository at this point in the history
  • Loading branch information
NilsOveTen committed Sep 4, 2024
1 parent 6918211 commit 4c32e76
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,17 @@ class SkosApNoModelService(
if (!it.kilde.isNullOrEmpty()) {
it.kilde.forEach { sourceEntry ->
if (sourceEntry.uri.isValidURI()) {
addProperty(DCTerms.source, model.safeCreateResource(sourceEntry.uri))
} else if (!sourceEntry.tekst.isNullOrBlank()) {
addProperty(DCTerms.source, sourceEntry.tekst, NB)
val source = model.safeCreateResource(sourceEntry.uri)
source.addProperty(RDF.type, RDFS.Resource)
if (!sourceEntry.tekst.isNullOrBlank()) {
source.addProperty(RDFS.label, sourceEntry.tekst, NB)
}
addProperty(DCTerms.source, source)
} else if (!sourceEntry.tekst.isNullOrBlank()){
val source = model.createResource()
source.addProperty(RDF.type, RDFS.Resource)
source.addProperty(RDFS.label, sourceEntry.tekst, NB)
addProperty(DCTerms.source, source)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/kotlin/no/fdk/concept_catalog/service/SkosApNo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ class SkosApNo {
.thenReturn(BEGREP_6.copy(definisjon = BEGREP_6.definisjon?.copy(kildebeskrivelse = Kildebeskrivelse(forholdTilKilde = ForholdTilKildeEnum.SITATFRAKILDE, kilde = listOf(URITekst(uri = "https://an invalid uri", tekst = "Testdirektoratet"))))))
val modelInvalidURI = assertDoesNotThrow { skosApNo.buildModelForConcept(BEGREP_6.ansvarligVirksomhet.id, BEGREP_6.id!!) }

val sourceNullURI = modelInvalidURI.listObjectsOfProperty(EUVOC.xlDefinition).toList().first().asResource().getProperty(DCTerms.source)
assertTrue { sourceNullURI.`object`.isLiteral }
assertEquals("Testdirektoratet", sourceNullURI.literal.string)
val sourceNullURI = modelInvalidURI.listObjectsOfProperty(EUVOC.xlDefinition).toList().first().asResource().getProperty(DCTerms.source).`object`
assertTrue { sourceNullURI.isAnon }
assertEquals("Testdirektoratet", sourceNullURI.asResource().listProperties(RDFS.label).toList().first().string)
}
}
7 changes: 7 additions & 0 deletions src/test/resources/all_collections.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@
] ;
skosno:valueRange <https://test.no> .

<https://festdirektoratet.no>
a rdfs:Resource ;
rdfs:label "Festdirektoratet"@nb .

<https://testdirektoratet.no>
a rdfs:Resource ;
rdfs:label "Testdirektoratet"@nb .

<https://concept-catalog.fellesdatakatalog.digdir.no/collections/111222333>
rdf:type skos:Collection ;
Expand Down
8 changes: 8 additions & 0 deletions src/test/resources/collection_1.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@

skosno:valueRange <https://test.no> .

<https://festdirektoratet.no>
a rdfs:Resource ;
rdfs:label "Festdirektoratet"@nb .

<https://testdirektoratet.no>
a rdfs:Resource ;
rdfs:label "Testdirektoratet"@nb .

<https://concept-catalog.fellesdatakatalog.digdir.no/collections/111222333>
rdf:type skos:Collection ;
dct:title "Concept collection belonging to 111222333" ;
Expand Down

0 comments on commit 4c32e76

Please sign in to comment.