Skip to content

Commit

Permalink
feat: add dekningsområde to public service (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
hegeaal authored Mar 12, 2024
1 parent 224b152 commit 36e6b7e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ data class PublicService (
val produces: List<Output>?,
val contactPoints: List<ContactPoint>?,
val homepage: String?,
val status: String?
val status: String?,
val spatial: List<String>?
)

@JsonIgnoreProperties(ignoreUnknown = true)
Expand All @@ -32,5 +33,6 @@ data class PublicServiceToBeCreated(
val produces: List<Output>?,
val contactPoints: List<ContactPoint>?,
val homepage: String?,
val status: String?
val status: String?,
val spatial: List<String>?
)
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class PublicServiceService(private val publicServiceRepository: PublicServiceRep
produces = publicServiceToBeCreated.produces,
contactPoints = publicServiceToBeCreated.contactPoints,
homepage = publicServiceToBeCreated.homepage,
status = publicServiceToBeCreated.status
status = publicServiceToBeCreated.status,
spatial = publicServiceToBeCreated.spatial
).let { publicServiceRepository.insert(it) }
} catch (ex: Exception) {
logger.error("Failed to create public service for $catalogId", ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import no.digdir.servicecatalog.model.hasData
import no.digdir.servicecatalog.rdf.*
import org.apache.jena.rdf.model.Model
import org.apache.jena.rdf.model.ModelFactory
import org.apache.jena.rdf.model.RDFNode
import org.apache.jena.rdf.model.Resource
import org.apache.jena.riot.Lang
import org.apache.jena.sparql.vocabulary.FOAF
Expand Down Expand Up @@ -99,6 +100,13 @@ class RDFService(
return this
}

private fun Resource.addSpatial(resources: List<String>?): Resource {
resources?.forEach {
addAsResourceIfValid(DCTerms.spatial, it)
}
return this
}

private fun Output.isValid(): Boolean =
title != null && title.hasData()

Expand Down Expand Up @@ -147,6 +155,7 @@ class RDFService(
.addContactPoints(publicService.contactPoints)
.addPropertyIfExists(FOAF.homepage, publicService.homepage)
.addAsResourceIfValid(ADMS.status, publicService.status)
.addSpatial(publicService.spatial)

publicServiceResource.addProperty(DCTerms.identifier, publicServiceResource)
return publicServiceResource
Expand Down
18 changes: 12 additions & 6 deletions src/test/kotlin/no/digdir/servicecatalog/utils/TestData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ val SERVICE_0 = Service("00", "910244132",
telephone = "+4712345678",
contactPage = "digdir.no",
language = listOf("http://publications.europa.eu/resource/authority/language/ENG")
)), homepage = "digdir.no", status = "http://purl.org/adms/status/Completed"
)),
homepage = "digdir.no", status = "http://purl.org/adms/status/Completed"
)
val SERVICE_1 = Service("01", "910244132",
title = LocalizedStrings("NB Tittel 0", "NN Tittel 0", "EN Tittel 0"),
Expand Down Expand Up @@ -61,25 +62,30 @@ val PUBLIC_SERVICE_0 =
telephone = "+4712345678",
contactPage = "digdir.no",
language = listOf("http://publications.europa.eu/resource/authority/language/ENG")
)), homepage = "data.norge.no", status = "http://purl.org/adms/status/UnderDevelopment"
)),
homepage = "data.norge.no", status = "http://purl.org/adms/status/UnderDevelopment",
spatial = listOf("https://data.geonorge.no/administrativeEnheter/nasjon/id/173163")
)
val PUBLIC_SERVICE_1 =
PublicService("1", "910244132",
title = LocalizedStrings("NB Tittel 1", "NN Tittel 1", "EN Tittel 1"),
description = LocalizedStrings("Beskrivelse 1", "Beskriving 1", "Description 1"),
published = false, produces = null, contactPoints = null, homepage = null, status = null)
published = false, produces = null, contactPoints = null, homepage = null, status = null,
spatial = listOf("https://data.geonorge.no/administrativeEnheter/nasjon/id/173163"))
val PUBLIC_SERVICE_2 =
PublicService("2", "910244132",
title = LocalizedStrings("NB Tittel 2", "NN Tittel 2", "EN Tittel 2"),
description = null,
published = true, produces = null, contactPoints = null, homepage = null, status = null)
published = true, produces = null, contactPoints = null, homepage = null, status = null,
spatial = listOf("https://data.geonorge.no/administrativeEnheter/nasjon/id/173163"))
val PUBLIC_SERVICE_DIFFERENT_CATALOG =
PublicService("123", "123456789",
title = LocalizedStrings("NB Tittel 0", "NN Tittel 0", "EN Tittel 0"),
description = null,
published = true, produces = null, contactPoints = null, homepage = null, status = null)
published = true, produces = null, contactPoints = null, homepage = null, status = null, spatial = listOf("https://data.geonorge.no/administrativeEnheter/nasjon/id/173163"))

val PUBLIC_SERVICE_TO_BE_CREATED = PublicServiceToBeCreated(title = LocalizedStrings("NB Tittel 2", "NN Tittel 2", "EN Tittel 2"), null, null, null, null, null)
val PUBLIC_SERVICE_TO_BE_CREATED = PublicServiceToBeCreated(title = LocalizedStrings("NB Tittel 2", "NN Tittel 2", "EN Tittel 2"),
null, null, null, null, null, null)

val PUBLIC_SERVICES = listOf(PUBLIC_SERVICE_0, PUBLIC_SERVICE_1, PUBLIC_SERVICE_2)

Expand Down
3 changes: 2 additions & 1 deletion src/test/resources/public_service.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
vcard:language <http://publications.europa.eu/resource/authority/language/ENG>
];
foaf:homepage "data.norge.no";
cpsv:produces <http://localhost:5050/rdf/catalogs/910244132/public-services/0/output/123> .
cpsv:produces <http://localhost:5050/rdf/catalogs/910244132/public-services/0/output/123> ;
dct:spatial <https://data.geonorge.no/administrativeEnheter/nasjon/id/173163> .

<http://localhost:5050/rdf/catalogs/910244132/public-services/0/output/123>
a cv:Output;
Expand Down
6 changes: 4 additions & 2 deletions src/test/resources/service_catalog.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
vcard:language <http://publications.europa.eu/resource/authority/language/ENG>
];
foaf:homepage "data.norge.no";
cpsv:produces <http://localhost:5050/rdf/catalogs/910244132/public-services/0/output/123> .
cpsv:produces <http://localhost:5050/rdf/catalogs/910244132/public-services/0/output/123>;
dct:spatial <https://data.geonorge.no/administrativeEnheter/nasjon/id/173163> .

<http://localhost:5050/rdf/catalogs/910244132/public-services/0/output/123>
a cv:Output;
Expand All @@ -43,7 +44,8 @@
a cpsv:PublicService;
cv:hasCompetentAuthority <https://data.brreg.no/enhetsregisteret/api/enheter/910244132>;
dct:identifier <http://localhost:5050/rdf/catalogs/910244132/public-services/2>;
dct:title "EN Tittel 2"@en , "NN Tittel 2"@nn , "NB Tittel 2"@nb .
dct:title "EN Tittel 2"@en , "NN Tittel 2"@nn , "NB Tittel 2"@nb ;
dct:spatial <https://data.geonorge.no/administrativeEnheter/nasjon/id/173163> .

<http://localhost:5050/rdf/catalogs/910244132/services/00>
a cpsvno:Service;
Expand Down

0 comments on commit 36e6b7e

Please sign in to comment.