Skip to content

Commit

Permalink
feat: add themes endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelDemey committed Oct 20, 2023
1 parent e340e55 commit 07187f0
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface DatasetService {
String create(String body) throws RmesException;

String getDistributions(String id) throws RmesException;

String getThemes() throws RmesException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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()));

Expand Down
15 changes: 15 additions & 0 deletions src/main/java/fr/insee/rmes/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 ***********************************/
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public ResponseEntity<Object> getDatasets() {
} catch (RmesException e) {
return ResponseEntity.status(e.getStatus()).body(e.getDetails());
}

}

@GetMapping("/{id}")
Expand Down Expand Up @@ -87,4 +86,16 @@ public ResponseEntity<Object> 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<Object> 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());
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/bauhaus-core.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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


###############################
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/request/dataset/getDataset.ftlh
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ WHERE {
}

OPTIONAL {
?uri dc:creator ?creator .
?uri dcterms:creator ?creator .
}

OPTIONAL {
?uri dc:contributor ?contributor .
?uri dcterms:contributor ?contributor .
}

OPTIONAL {
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/request/dataset/getThemes.ftlh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT ?uri ?label
FROM <${CONCEPTS_GRAPH}>
{
?uri a <${THEME_TYPE}> .
?uri skos:prefLabel ?label .
} ORDER BY ASC(?label)

0 comments on commit 07187f0

Please sign in to comment.