Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

715 migrer toutes les requetes sparql vers des fichiers freemarker 2nd part #744

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,47 +45,14 @@ public static String indicatorsQuery() throws RmesException {
return buildIndicatorRequest("getIndicators.ftlh", params);
}

public static String indicatorsQueryForSearch() {
return "SELECT ?id ?prefLabelLg1 ?prefLabelLg2 (group_concat(?altLabelLang1;separator=' || ') as ?altLabelLg1) ?altLabelLg2 ?abstractLg1 ?abstractLg2 "
+ "?historyNoteLg1 ?historyNoteLg2 ?accrualPeriodicityCode ?accrualPeriodicityList ?publishers ?idSims ?validationState "
+ "WHERE { \r\n"
+ "?indic a insee:StatisticalIndicator ."
+ "BIND(STRAFTER(STR(?indic),'/"+config.getProductsBaseUri()+"/') AS ?id) . "
+ "?indic skos:prefLabel ?prefLabelLg1 \r\n"
+ "FILTER (lang(?prefLabelLg1) = 'fr') \r\n"
+ " OPTIONAL{?indic skos:prefLabel ?prefLabelLg2 \r\n"
+ "FILTER (lang(?prefLabelLg2) = 'en') } \r\n"
+ " OPTIONAL{?indic skos:altLabel ?altLabelLang1 \r\n"
+ "FILTER (lang(?altLabelLang1) = 'fr') } \r\n"
+ " OPTIONAL{?indic skos:altLabel ?altLabelLg2 \r\n"
+ "FILTER (lang(?altLabelLg2) = 'en') } \r\n"
+ " OPTIONAL{?indic dcterms:abstract ?abstractLg1 \r\n"
+ "FILTER (lang(?abstractLg1) = 'fr') } \r\n"
+ " OPTIONAL{?indic dcterms:abstract ?abstractLg2 \r\n"
+ "FILTER (lang(?abstractLg2) = 'en') } \r\n"
+ " OPTIONAL{?indic skos:historyNote ?historyNoteLg1 \r\n"
+ "FILTER (lang(?historyNoteLg1) = 'fr') } \r\n"
+ " OPTIONAL{?indic skos:historyNote ?historyNoteLg2 \r\n"
+ "FILTER (lang(?historyNoteLg2) = 'en') } \r\n"
+ " OPTIONAL {?indic dcterms:accrualPeriodicity ?accrualPeriodicity . \r\n"
+ "?accrualPeriodicity skos:notation ?accrualPeriodicityCode . \r\n"
+ "?accrualPeriodicity skos:inScheme ?accrualPeriodicityCodeList . \r\n"
+ "?accrualPeriodicityCodeList skos:notation ?accrualPeriodicityList . \r\n"
+ "} \r\n"
+ "OPTIONAL {?indic dcterms:publisher ?uriPublisher . \r\n"
+ "?uriPublisher dcterms:identifier ?publishers . \r\n"
+ "} \r\n"
+ "OPTIONAL{ ?report rdf:type sdmx-mm:MetadataReport . ?report sdmx-mm:target ?indic BIND(STRAFTER(STR(?report),'/rapport/') AS ?idSims) . \r\n"
+ "} \r\n"
+ "OPTIONAL {?indic insee:validationState ?validationState . \r\n"
+ "} \r\n"
+ "} \r\n"
+ "GROUP BY ?id ?prefLabelLg1 ?prefLabelLg2 ?altLabelLang1 ?altLabelLg2 ?abstractLg1 ?abstractLg2 ?historyNoteLg1 ?historyNoteLg2 "
+ "?accrualPeriodicityCode ?accrualPeriodicityList ?publishers ?idSims ?validationState \n";

public static String indicatorsQueryForSearch() throws RmesException {
HashMap<String, Object> params = new HashMap<>();
params.put("PRODUCT_BASE_URI",config.getProductsBaseUri());
params.put("LG1", config.getLg1());
params.put("LG2", config.getLg2());
return buildIndicatorRequest("getIndicatorsQueryForSearch.ftlh", params);
}


public static String indicatorQuery(String id, boolean indicatorsRichTextNexStructure) throws RmesException {
return indicatorFullObjectQuery(id, true, indicatorsRichTextNexStructure);
}
Expand All @@ -100,57 +67,44 @@ private static String indicatorFullObjectQuery(String id, boolean withLimit, boo
return buildIndicatorRequest("getIndicator.ftlh", params);
}

public static String getCreatorsById(String id) {
return "SELECT ?creators\n"
+ "WHERE { GRAPH <"+config.getProductsGraph()+"> { \n"
+ "?indic a insee:StatisticalIndicator . \n"
+" FILTER(STRENDS(STR(?indic),'/"+config.getProductsBaseUri()+"/" + id+ "')) . \n"
+"?indic dc:creator ?creators . \n"
+ "} }"
;

public static String getCreatorsById(String id) throws RmesException {
HashMap<String, Object> params = new HashMap<>();
params.put("PRODUCT_BASE_URI",config.getProductsBaseUri());
params.put("OPERATIONS_GRAPH", config.getProductsGraph());
params.put("ID", id);
return buildIndicatorRequest("getCreatorsById.ftlh", params);
}

public static String getPublishersById(String id) {
return "SELECT ?publishers\n"
+ "WHERE { GRAPH <"+config.getProductsGraph()+"> { \n"
+ "?indic a insee:StatisticalIndicator . \n"
+" FILTER(STRENDS(STR(?indic),'/"+config.getProductsBaseUri()+"/" + id+ "')) . \n"
+"?indic dcterms:publisher ?publishers . \n"
+ "} }"
;
}

public static String indicatorLinks(String id, IRI linkPredicate) {
return "SELECT ?id ?typeOfObject ?labelLg1 ?labelLg2 \n"
+ "WHERE { \n"
+ "?indic <"+linkPredicate+"> ?uriLinked . \n"
+ "?uriLinked skos:prefLabel ?labelLg1 . \n"
+ "FILTER (lang(?labelLg1) = '" + config.getLg1() + "') . \n"
+ "OPTIONAL {?uriLinked skos:prefLabel ?labelLg2 . \n"
+ "FILTER (lang(?labelLg2) = '" + config.getLg2() + "')} . \n"
+ "?uriLinked rdf:type ?typeOfObject . \n"
+ "BIND(REPLACE( STR(?uriLinked) , '(.*/)(\\\\w+$)', '$2' ) AS ?id) . \n"

+ "FILTER(STRENDS(STR(?indic),'/"+config.getProductsBaseUri()+"/" + id + "')) . \n"
public static String getPublishersById(String id) throws RmesException {
HashMap<String, Object> params = new HashMap<>();
params.put("PRODUCT_BASE_URI",config.getProductsBaseUri());
params.put("OPERATIONS_GRAPH", config.getProductsGraph());
params.put("ID", id);
return buildIndicatorRequest("getPublishersById.ftlh", params);
}


+ "} \n"
+ "ORDER BY ?labelLg1";
public static String indicatorLinks(String id, IRI linkPredicate) throws RmesException {
HashMap<String, Object> params = new HashMap<>();
params.put("PRODUCT_BASE_URI",config.getProductsBaseUri());
params.put("LG1", config.getLg1());
params.put("LG2", config.getLg2());
params.put("ID", id);
params.put("LINKPREDICATE", linkPredicate);
return buildIndicatorRequest("getIndicatorLinks.ftlh", params);
}

public static String getMultipleOrganizations(String idIndicator, IRI linkPredicate) {
return "SELECT ?id ?labelLg1 ?labelLg2\n"
+ "WHERE { \n"
+"?indicator <"+linkPredicate+"> ?uri . \n"
+ "?uri dcterms:identifier ?id . \n"
+ "?uri skos:prefLabel ?labelLg1 . \n"
+ "FILTER (lang(?labelLg1) = '" + config.getLg1() + "') . \n"
+ "OPTIONAL {?uri skos:prefLabel ?labelLg2 . \n"
+ "FILTER (lang(?labelLg2) = '" + config.getLg2() + "')} . \n"

+ "FILTER(STRENDS(STR(?indicator),'/"+config.getProductsBaseUri()+"/" + idIndicator + "')) . \n"

+ "} \n"
+ "ORDER BY ?id";

public static String getMultipleOrganizations(String idIndicator, IRI linkPredicate) throws RmesException {
HashMap<String, Object> params = new HashMap<>();
params.put("PRODUCT_BASE_URI",config.getProductsBaseUri());
params.put("LG1", config.getLg1());
params.put("LG2", config.getLg2());
params.put("ID", idIndicator);
params.put("LINKPREDICATE", linkPredicate);
return buildIndicatorRequest("getMultipleOrganizations.ftlh", params);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
import java.util.Map;

public class OperationsQueries extends GenericQueries {
public static final String OPERATIONS_GRAPH = "OPERATIONS_GRAPH";
static Map<String,Object> params ;

private static void initParams() {
params = new HashMap<>();
params.put("OPERATIONS_GRAPH", config.getOperationsGraph());
params.put(OPERATIONS_GRAPH, config.getOperationsGraph());
params.put("LG1", config.getLg1());
params.put("LG2", config.getLg2());
}
Expand All @@ -24,7 +25,7 @@ private static String buildIndicatorRequest(String fileName, Map<String, Object>

public static String checkPrefLabelUnicity(String id, String label, String lang) throws RmesException {
HashMap<String, Object> params = new HashMap<>();
params.put("OPERATIONS_GRAPH", config.getOperationsGraph());
params.put(OPERATIONS_GRAPH, config.getOperationsGraph());
params.put("LANG", lang);
params.put("ID", id);
params.put("LABEL", label);
Expand All @@ -34,100 +35,36 @@ public static String checkPrefLabelUnicity(String id, String label, String lang)
}

public static String operationsQuery() throws RmesException {
HashMap<String, Object> params = new HashMap<>();
params.put("OPERATIONS_GRAPH", config.getOperationsGraph());
params.put("LG1", config.getLg1());
params.put("LG2", config.getLg2());
initParams();
return FreeMarkerUtils.buildRequest("operations/", "getOperations.ftlh", params);
}

public static String operationQuery(String id){
return "SELECT ?id ?prefLabelLg1 ?prefLabelLg2 ?altLabelLg1 ?altLabelLg2 ?idSims ?validationState ?created ?modified \n"
+ "WHERE { "
+ "GRAPH <"+config.getOperationsGraph()+"> { \n"
+ "?operation skos:prefLabel ?prefLabelLg1 . \n"
+ "FILTER(STRENDS(STR(?operation),'/operations/operation/" + id+ "')) . \n"
+ "BIND(STRAFTER(STR(?operation),'/operation/') AS ?id) . \n"

+ "FILTER (lang(?prefLabelLg1) = '" + config.getLg1() + "') . \n"
+ "OPTIONAL {?operation skos:prefLabel ?prefLabelLg2 . \n"
+ "FILTER (lang(?prefLabelLg2) = '" + config.getLg2() + "') } . \n"

+ "OPTIONAL {?operation skos:altLabel ?altLabelLg1 . \n"
+ "FILTER (lang(?altLabelLg1) = '" + config.getLg1() + "') } . \n"
+ "OPTIONAL {?operation skos:altLabel ?altLabelLg2 . \n"
+ "FILTER (lang(?altLabelLg2) = '" + config.getLg2() + "') } . \n"
+ "}"
+ "OPTIONAL { ?operation dcterms:created ?created } . \n"
+ "OPTIONAL { ?operation dcterms:modified ?modified } . \n"
+ "OPTIONAL{ ?report rdf:type sdmx-mm:MetadataReport ."
+ " ?report sdmx-mm:target ?operation "
+ " BIND(STRAFTER(STR(?report),'/rapport/') AS ?idSims) . \n"
+ "} \n"

+ "OPTIONAL {?operation insee:validationState ?validationState . \n"
+ "} \n"
+ "} \n"
+ "LIMIT 1";

public static String operationQuery(String id) throws RmesException {
initParams();
params.put("ID", id);
return FreeMarkerUtils.buildRequest("operations/", "getOperation.ftlh", params);
}

public static String seriesQuery(String idOperation) {
return "SELECT ?id ?labelLg1 ?labelLg2 \n"
+ "WHERE { GRAPH <"+config.getOperationsGraph()+"> { \n"
+ "FILTER(STRENDS(STR(?operation),'/operations/operation/" + idOperation+ "')) . \n"

+ "?seriesUri dcterms:hasPart ?operation . \n"
+ "?seriesUri skos:prefLabel ?labelLg1 . \n"
+ "FILTER (lang(?labelLg1) = '" + config.getLg1() + "') . \n"
+ "?seriesUri skos:prefLabel ?labelLg2 . \n"
+ "FILTER (lang(?labelLg2) = '" + config.getLg2() + "') . \n"
+ "BIND(STRAFTER(STR(?seriesUri),'/serie/') AS ?id) . \n"
public static String seriesQuery(String idOperation) throws RmesException {
initParams();
params.put("ID", idOperation);
return FreeMarkerUtils.buildRequest("operations/series/", "getSeries.ftlh", params);
}


+ "}} \n"
+ "LIMIT 1";
public static String operationsWithoutSimsQuery(String idSeries) throws RmesException {
initParams();
params.put("ID", idSeries);
return FreeMarkerUtils.buildRequest("operations/series/", "getOperationsWithoutSimsQuery.ftlh", params);
}

public static String operationsWithoutSimsQuery(String idSeries) {
return "SELECT DISTINCT ?id ?labelLg1 ?labelLg2 \n"
+ "WHERE { \n"
+ "?operation a insee:StatisticalOperation . \n"
+ "?series dcterms:hasPart ?operation \n "
+ "FILTER(STRENDS(STR(?series),'/operations/serie/" + idSeries+ "')) . \n"

+ "?operation skos:prefLabel ?labelLg1 . \n"
+ "FILTER (lang(?labelLg1) = '" + config.getLg1() + "') \n"
+ "?operation skos:prefLabel ?labelLg2 . \n"
+ "FILTER (lang(?labelLg2) = '" + config.getLg2() + "') \n"

+ "BIND(STRAFTER(STR(?operation),'/operations/operation/') AS ?id) . \n"
+ "FILTER NOT EXISTS { ?documentation sdmx-mm:target ?operation }"

+ "} \n"
+ "GROUP BY ?id ?labelLg1 ?labelLg2 \n"
+ "ORDER BY ?labelLg1 ";
}

public static String operationsWithSimsQuery(String idSeries) {
return "SELECT DISTINCT ?id ?labelLg1 ?labelLg2 ?idSims \n"
+ "WHERE { \n"
+ "?operation a insee:StatisticalOperation . \n"
+ "?series dcterms:hasPart ?operation \n "
+ "FILTER(STRENDS(STR(?series),'/operations/serie/" + idSeries+ "')) . \n"

+ "?operation skos:prefLabel ?labelLg1 . \n"
+ "FILTER (lang(?labelLg1) = '" + config.getLg1() + "') \n"
+ "?operation skos:prefLabel ?labelLg2 . \n"
+ "FILTER (lang(?labelLg2) = '" + config.getLg2() + "') \n"

+ "BIND(STRAFTER(STR(?operation),'/operations/operation/') AS ?id) . \n"
+ "?report rdf:type sdmx-mm:MetadataReport ."
+ " ?report sdmx-mm:target ?operation "
+ " BIND(STRAFTER(STR(?report),'/rapport/') AS ?idSims) . \n"
+ "} \n"
+ "GROUP BY ?id ?labelLg1 ?labelLg2 ?idSims \n"
+ "ORDER BY ?labelLg1 ";
}
public static String operationsWithSimsQuery(String idSeries) throws RmesException {
initParams();
params.put("ID", idSeries);
return FreeMarkerUtils.buildRequest("operations/series/", "getOperationsWithSimsQuery.ftlh", params);
}

private OperationsQueries() {
throw new IllegalStateException("Utility class");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import fr.insee.rmes.exceptions.RmesException;
import fr.insee.rmes.model.operations.documentations.Documentation;
import fr.insee.rmes.model.operations.documentations.MAS;
import fr.insee.rmes.model.operations.documentations.MSD;
import fr.insee.rmes.utils.XMLUtils;
import fr.insee.rmes.webservice.OperationsCommonResources;
import io.swagger.v3.oas.annotations.Operation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import fr.insee.rmes.config.swagger.model.IdLabelAltLabel;
import fr.insee.rmes.exceptions.RmesException;
import fr.insee.rmes.model.operations.Operation;
import fr.insee.rmes.utils.FilesUtils;
import fr.insee.rmes.utils.XMLUtils;
import fr.insee.rmes.webservice.OperationsCommonResources;
import io.swagger.v3.oas.annotations.Parameter;
Expand All @@ -14,19 +13,11 @@
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

@Qualifier("Operation")
@RestController
Expand Down
20 changes: 20 additions & 0 deletions src/main/resources/request/operations/getOperation.ftlh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
SELECT ?id ?prefLabelLg1 ?prefLabelLg2 ?altLabelLg1 ?altLabelLg2 ?idSims ?validationState ?created ?modified
WHERE { GRAPH <${OPERATIONS_GRAPH}> {
?operation skos:prefLabel ?prefLabelLg1 .
FILTER(STRENDS(STR(?operation),'/operations/operation/${ID}')) .
BIND(STRAFTER(STR(?operation),'/operation/') AS ?id) .
FILTER (lang(?prefLabelLg1) = '${LG1}') .
OPTIONAL {?operation skos:prefLabel ?prefLabelLg2 .
FILTER (lang(?prefLabelLg2) = '${LG2}') } .
OPTIONAL {?operation skos:altLabel ?altLabelLg1 .
FILTER (lang(?altLabelLg1) = '${LG1}') } .
OPTIONAL {?operation skos:altLabel ?altLabelLg2 .
FILTER (lang(?altLabelLg2) = '${LG2}') } .
}OPTIONAL { ?operation dcterms:created ?created } .
OPTIONAL { ?operation dcterms:modified ?modified } .
OPTIONAL{ ?report rdf:type sdmx-mm:MetadataReport . ?report sdmx-mm:target ?operation BIND(STRAFTER(STR(?report),'/rapport/') AS ?idSims) .
}
OPTIONAL {?operation insee:validationState ?validationState .
}
}
LIMIT 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT ?creators
WHERE { GRAPH <${OPERATIONS_GRAPH}> {
?indic a insee:StatisticalIndicator .
FILTER(STRENDS(STR(?indic),'/${PRODUCT_BASE_URI}/${ID}')) .
?indic dc:creator ?creators .
} }
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SELECT ?id ?typeOfObject ?labelLg1 ?labelLg2
WHERE {
?indic <${LINKPREDICATE}> ?uriLinked .
?uriLinked skos:prefLabel ?labelLg1 .
FILTER (lang(?labelLg1) = '${LG1}') .
OPTIONAL {?uriLinked skos:prefLabel ?labelLg2 .
FILTER (lang(?labelLg2) = '${LG2}')} .
?uriLinked rdf:type ?typeOfObject .
BIND(REPLACE(STR(?uriLinked), '^.*/([^/]+)$', '$1') AS ?id) .

FILTER(STRENDS(STR(?indic),'/${PRODUCT_BASE_URI}/${ID}')) .

}
ORDER BY ?labelLg1
Loading