Skip to content

Commit

Permalink
feat: add distribution dcat:mediaType attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreiffers committed Jun 26, 2023
1 parent 3a2006d commit c381635
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/main/kotlin/no/fdk/dataset_catalog/model/Dataset.kt
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ data class Distribution(
val conformsTo: List<SkosConcept>? = null,
val page: List<SkosConcept>? = null,
val format: List<String>? = null,
val mediaType: List<String>? = null,
val accessService: List<DataDistributionService>? = null,
)

Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/no/fdk/dataset_catalog/rdf/RDFUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ fun Resource.addDistribution(property: Property, distributions: Collection<Distr
.addConformsTo(it.conformsTo)
.safeAddURLs(FOAF.page, it.page?.map { page -> page.uri })
.safeAddURLs(DCTerms.format, it.format)
.safeAddURLs(DCAT.mediaType, it.mediaType)
.addDataDistributionServices(it.accessService)
)
}
Expand All @@ -190,10 +191,11 @@ private fun Distribution.hasNonNullOrEmptyProperty(): Boolean =

format?.all { entry -> entry.isNullOrEmpty() } == false ||

mediaType?.all { entry -> entry.isNullOrEmpty() } == false ||

!accessService.isNullOrEmpty()

// TODO: add dcat:endpointURLs and make sure front-end sends necessary data (https://doc.difi.no/review/dcat-ap-no/#_obligatoriske_egenskaper_for_datatjeneste)
// TODO: add a list of dct:MediaTypes (https://doc.difi.no/review/dcat-ap-no/#distribusjon-medietype)

fun Resource.addDataDistributionServices(dataDistributionServices: Collection<DataDistributionService>?): Resource {
dataDistributionServices?.forEach {
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/specification/specification.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,11 @@ components:
items:
type: string
description: Associated formats
mediaType:
type: array
items:
type: string
description: Associated media types
accessService:
type: array
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ val DISTRIBUTION_EX = Distribution(
conformsTo = listOf(SKOSCONCEPT_EX("dct:conformsTo")),
page = listOf(SKOSCONCEPT_EX("foaf:page")),
format = listOf("Formats"),
mediaType = listOf("MediaTypes"),
accessService = listOf(DATADISTRIBUTIONSERVICE_EX),
)

Expand Down
6 changes: 4 additions & 2 deletions src/test/kotlin/no/fdk/dataset_catalog/utils/TestDataset_1.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,16 @@ val DISTRIBUTION = Distribution(
conformsTo= listOf(CONFORMS_TO),
license=SkosConcept("https://data.norge.no/nlod/no/2.0", mapOf(Pair("nb", "NODL")), extraType = DCTerms.LicenseDocument.uri),
page= listOf(SkosConcept("http://lenke/til/mer/info", mapOf(Pair("nb", "Dokumentasjon av distribusjonen")), extraType = FOAF.Document.uri)),
format=listOf("https://www.iana.org/assignments/media-types/application/json"),
format=listOf("http://publications.europa.eu/resource/authority/file-type/JSON"),
mediaType=listOf("https://www.iana.org/assignments/media-types/application/json"),
accessService=listOf(SAMPLE_DESCRIPTION)
)

val SAMPLE = Distribution(
uri = "$DATASET_URI/samples/d2",
description = mapOf(Pair("nb", "Dette er beskrivelsen av eksempeldataene. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.")),
format = listOf("https://www.iana.org/assignments/media-types/application/rdf+xml"),
format = listOf("http://publications.europa.eu/resource/authority/file-type/RDF"),
mediaType = listOf("https://www.iana.org/assignments/media-types/application/rdf+xml"),
accessURL = listOf("http://www.detteerenlenke.no/til-nedlasting", "www.dette.kan.også/hende")
)

Expand Down
8 changes: 5 additions & 3 deletions src/test/resources/catalog_2.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
<http://localhost:5000/catalogs/987654321/datasets/72a54592-692c-4cfa-a938-cd1a56a2ed8d/samples/d2>
a dcat:Distribution ;
dct:description "Dette er beskrivelsen av eksempeldataene. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor."@nb ;
dct:format <https://www.iana.org/assignments/media-types/application/rdf+xml> ;
dcat:accessURL <http://www.detteerenlenke.no/til-nedlasting> .
dct:format <http://publications.europa.eu/resource/authority/file-type/RDF> ;
dcat:mediaType <https://www.iana.org/assignments/media-types/application/rdf+xml> ;
dcat:accessURL <http://www.detteerenlenke.no/til-nedlasting> .

<http://localhost:5000/catalogs/987654321>
a dcat:Catalog ;
Expand Down Expand Up @@ -63,7 +64,8 @@
dct:title "SOSI"@nb
] ;
dct:description "Dette er beskrivelsen av distribusjonen. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Vestibulum id ligula porta felis euismod semper con desbit arum. Se dokumentasjon for denne distribusjonen."@nb ;
dct:format <https://www.iana.org/assignments/media-types/application/json> ;
dct:format <http://publications.europa.eu/resource/authority/file-type/JSON> ;
dcat:mediaType <https://www.iana.org/assignments/media-types/application/json> ;
dct:license <https://data.norge.no/nlod/no/2.0> ;
dcat:accessURL <http://www.detteerentredjelenke.no/til-en-tredje-nedlasting> , <http://www.detteerenannenlenke.no/til-en-annen-nedlasting> , <http://www.detteerenlenke.no/til-nedlasting> ;
foaf:page <http://lenke/til/mer/info> .
Expand Down

0 comments on commit c381635

Please sign in to comment.