From 07187f02bbe116d3f8108a49fdca84dcb8a7c4cf Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Fri, 20 Oct 2023 12:29:53 +0200 Subject: [PATCH] feat: add themes endpoint --- .../bauhaus_services/datasets/DatasetQueries.java | 7 +++++++ .../bauhaus_services/datasets/DatasetService.java | 2 ++ .../datasets/DatasetServiceImpl.java | 7 ++++++- src/main/java/fr/insee/rmes/config/Config.java | 15 +++++++++++++++ .../rmes/webservice/dataset/DatasetResources.java | 13 ++++++++++++- src/main/resources/bauhaus-core.properties | 2 ++ .../resources/request/dataset/getDataset.ftlh | 4 ++-- src/main/resources/request/dataset/getThemes.ftlh | 6 ++++++ 8 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/request/dataset/getThemes.ftlh diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/datasets/DatasetQueries.java b/src/main/java/fr/insee/rmes/bauhaus_services/datasets/DatasetQueries.java index 18bd5fb13..ba1164684 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/datasets/DatasetQueries.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/datasets/DatasetQueries.java @@ -32,4 +32,11 @@ public static String lastDatasetId() throws RmesException { return FreeMarkerUtils.buildRequest(ROOT_DIRECTORY, "getLastDatasetId.ftlh", params); } + + public static String getThemes() throws RmesException { + HashMap params = new HashMap<>(); + params.put("CONCEPTS_GRAPH", config.getBaseGraph() + config.getDatasetsThemeGraph()); + params.put("THEME_TYPE", config.getBaseUriGestion() + config.getDatasetsThemeTypePrefix()); + return FreeMarkerUtils.buildRequest(ROOT_DIRECTORY, "getThemes.ftlh", params); + } } diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/datasets/DatasetService.java b/src/main/java/fr/insee/rmes/bauhaus_services/datasets/DatasetService.java index 3de6b04db..e1daabe29 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/datasets/DatasetService.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/datasets/DatasetService.java @@ -13,4 +13,6 @@ public interface DatasetService { String create(String body) throws RmesException; String getDistributions(String id) throws RmesException; + + String getThemes() throws RmesException; } diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/datasets/DatasetServiceImpl.java b/src/main/java/fr/insee/rmes/bauhaus_services/datasets/DatasetServiceImpl.java index 1d53089a8..913c6c308 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/datasets/DatasetServiceImpl.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/datasets/DatasetServiceImpl.java @@ -90,6 +90,11 @@ public String getDistributions(String id) throws RmesException { return this.repoGestion.getResponseAsArray(DistributionQueries.getDatasetDistributions(id)).toString(); } + @Override + public String getThemes() throws RmesException { + return this.repoGestion.getResponseAsArray(DatasetQueries.getThemes()).toString(); + } + private Dataset deserializeBody(String body) throws RmesException { ObjectMapper mapper = new ObjectMapper(); mapper.configure( @@ -139,7 +144,7 @@ private String persist(Dataset dataset) throws RmesException { RdfUtils.addTripleUri(datasetIri, INSEE.DISSEMINATIONSTATUS, dataset.getDisseminationStatus(), model, graph); RdfUtils.addTripleString(datasetIri, INSEE.VALIDATION_STATE, dataset.getValidationState(), model, graph); RdfUtils.addTripleUri(datasetIri, PROV.WAS_GENERATED_BY, dataset.getIdSerie(), model, graph); - RdfUtils.addTripleString(datasetIri, DCAT.THEME, dataset.getTheme(), model, graph); + RdfUtils.addTripleUri(datasetIri, DCAT.THEME, dataset.getTheme(), model, graph); JSONArray distributions = new JSONArray(this.getDistributions(dataset.getId())); diff --git a/src/main/java/fr/insee/rmes/config/Config.java b/src/main/java/fr/insee/rmes/config/Config.java index 21f6cab6f..17308048c 100644 --- a/src/main/java/fr/insee/rmes/config/Config.java +++ b/src/main/java/fr/insee/rmes/config/Config.java @@ -157,6 +157,12 @@ public class Config { @Value("${fr.insee.rmes.bauhaus.datasets.baseURI}") private String datasetsBaseUri; + @Value("${fr.insee.rmes.bauhaus.theme.graph}") + private String datasetsThemeGraph; + + @Value("${fr.insee.rmes.bauhaus.theme.typePrefix}") + private String datasetsThemeTypePrefix; + /******************************************************/ /** Distributions ***********************************/ @@ -402,6 +408,15 @@ public String getDatasetsGraph() { public String getDatasetsBaseUri() { return datasetsBaseUri; } + + public String getDatasetsThemeGraph() { + return datasetsThemeGraph; + } + + public String getDatasetsThemeTypePrefix() { + return datasetsThemeTypePrefix; + } + public String getDistributionsBaseUri(){ return distributionsBaseUri; } diff --git a/src/main/java/fr/insee/rmes/webservice/dataset/DatasetResources.java b/src/main/java/fr/insee/rmes/webservice/dataset/DatasetResources.java index 6cf1b5834..d250eb3bb 100644 --- a/src/main/java/fr/insee/rmes/webservice/dataset/DatasetResources.java +++ b/src/main/java/fr/insee/rmes/webservice/dataset/DatasetResources.java @@ -36,7 +36,6 @@ public ResponseEntity getDatasets() { } catch (RmesException e) { return ResponseEntity.status(e.getStatus()).body(e.getDetails()); } - } @GetMapping("/{id}") @@ -87,4 +86,16 @@ public ResponseEntity setDataset( return ResponseEntity.status(e.getStatus()).body(e.getDetails()); } } + + @GetMapping("/themes") + @Operation(operationId = "getThemes", summary = "List of themes", + responses = {@ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Dataset.class))))}) + public ResponseEntity getThemes() { + try { + String themes = this.datasetService.getThemes(); + return ResponseEntity.status(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON).body(themes); + } catch (RmesException e) { + return ResponseEntity.status(e.getStatus()).body(e.getDetails()); + } + } } diff --git a/src/main/resources/bauhaus-core.properties b/src/main/resources/bauhaus-core.properties index a9dd2dcd7..81381f80e 100644 --- a/src/main/resources/bauhaus-core.properties +++ b/src/main/resources/bauhaus-core.properties @@ -19,6 +19,8 @@ fr.insee.rmes.bauhaus.sugoi.realm = SSP ############################### fr.insee.rmes.bauhaus.datasets.graph = catalogues fr.insee.rmes.bauhaus.datasets.baseURI = catalogues/jeuDeDonnees +fr.insee.rmes.bauhaus.theme.graph = concepts +fr.insee.rmes.bauhaus.theme.typePrefix = concepts/themes/Theme ############################### diff --git a/src/main/resources/request/dataset/getDataset.ftlh b/src/main/resources/request/dataset/getDataset.ftlh index 62ace0a5b..51b7eb782 100644 --- a/src/main/resources/request/dataset/getDataset.ftlh +++ b/src/main/resources/request/dataset/getDataset.ftlh @@ -23,11 +23,11 @@ WHERE { } OPTIONAL { - ?uri dc:creator ?creator . + ?uri dcterms:creator ?creator . } OPTIONAL { - ?uri dc:contributor ?contributor . + ?uri dcterms:contributor ?contributor . } OPTIONAL { diff --git a/src/main/resources/request/dataset/getThemes.ftlh b/src/main/resources/request/dataset/getThemes.ftlh new file mode 100644 index 000000000..f8e6dcfbf --- /dev/null +++ b/src/main/resources/request/dataset/getThemes.ftlh @@ -0,0 +1,6 @@ +SELECT ?uri ?label +FROM <${CONCEPTS_GRAPH}> +{ + ?uri a <${THEME_TYPE}> . + ?uri skos:prefLabel ?label . +} ORDER BY ASC(?label) \ No newline at end of file