diff --git a/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/families/OpFamiliesQueries.java b/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/families/OpFamiliesQueries.java index 8bc54ba65..274333d27 100644 --- a/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/families/OpFamiliesQueries.java +++ b/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/families/OpFamiliesQueries.java @@ -52,23 +52,13 @@ public static String familyQuery(String id, boolean familiesRichTextNextStructur return buildRequest("getFamily.ftlh", params); } - public static String getSeries(String idFamily) { - return "SELECT ?id ?labelLg1 ?labelLg2 \n" - + " FROM <"+config.getOperationsGraph()+"> \n" - + "WHERE { \n" - - + "?family dcterms:hasPart ?uri . \n" - + "?uri skos:prefLabel ?labelLg1 . \n" - + "FILTER (lang(?labelLg1) = '" + config.getLg1() + "') . \n" - + "?uri skos:prefLabel ?labelLg2 . \n" - + "FILTER (lang(?labelLg2) = '" + config.getLg2() + "') . \n" - + "BIND(STRAFTER(STR(?uri),'/operations/serie/') AS ?id) . \n" - - - + "FILTER(STRENDS(STR(?family),'/operations/famille/" + idFamily + "')) . \n" - + "}" - + " ORDER BY ?id" - ; + public static String getSeries(String idFamily) throws RmesException { + HashMap params = new HashMap<>(); + params.put(OPERATIONS_GRAPH, config.getOperationsGraph()); + params.put("LG1", config.getLg1()); + params.put("LG2", config.getLg2()); + params.put("ID", idFamily); + return buildRequest("getSeries.ftlh", params); } public static String getSubjects(String idFamily) { diff --git a/src/main/resources/request/operations/famOpeSer/getSeries.ftlh b/src/main/resources/request/operations/famOpeSer/getSeries.ftlh new file mode 100644 index 000000000..924bc2507 --- /dev/null +++ b/src/main/resources/request/operations/famOpeSer/getSeries.ftlh @@ -0,0 +1,12 @@ +SELECT ?id ?labelLg1 ?labelLg2 +FROM <${OPERATIONS_GRAPH}> +WHERE { + ?family dcterms:hasPart ?uri . + ?uri skos:prefLabel ?labelLg1 . + FILTER (lang(?labelLg1) = '${LG1}') . + ?uri skos:prefLabel ?labelLg2 . + FILTER (lang(?labelLg2) = '${LG2}') . + BIND(STRAFTER(STR(?uri),'/operations/serie/') AS ?id) . + FILTER(STRENDS(STR(?family),'/operations/famille/${ID}')) . +} +ORDER BY ?id \ No newline at end of file diff --git a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/families/OpFamiliesQueriesTest.java b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/families/OpFamiliesQueriesTest.java new file mode 100644 index 000000000..4e90f6e15 --- /dev/null +++ b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/families/OpFamiliesQueriesTest.java @@ -0,0 +1,50 @@ +package fr.insee.rmes.testcontainers.queries.sparql_queries.operations.families; + +import fr.insee.rmes.bauhaus_services.rdf_utils.RepositoryGestion; +import fr.insee.rmes.bauhaus_services.rdf_utils.RepositoryInitiator; +import fr.insee.rmes.bauhaus_services.rdf_utils.RepositoryUtils; +import fr.insee.rmes.config.ConfigStub; +import fr.insee.rmes.persistance.sparql_queries.operations.families.OpFamiliesQueries; +import fr.insee.rmes.persistance.sparql_queries.operations.operations.OperationsQueries; +import fr.insee.rmes.persistance.sparql_queries.operations.series.OpSeriesQueries; +import fr.insee.rmes.testcontainers.queries.WithGraphDBContainer; +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class OpFamiliesQueriesTest extends WithGraphDBContainer { + RepositoryGestion repositoryGestion = new RepositoryGestion(getRdfGestionConnectionDetails(), new RepositoryUtils(null, RepositoryInitiator.Type.DISABLED)); + + @BeforeAll + static void initData(){ + container.withTrigFiles("all-operations-and-indicators.trig"); + } + + @Test + void should_return_all_families() throws Exception { + OpSeriesQueries.setConfig(new ConfigStub()); + JSONArray result = repositoryGestion.getResponseAsArray(OpFamiliesQueries.familiesQuery()); + assertEquals(56, result.length()); + + for (var i = 0; i < result.length(); i++){ + assertNotNull(result.getJSONObject(i).getString("id")); + assertNotNull(result.getJSONObject(i).getString("label")); + } + } + + @Test + void should_return_series() throws Exception { + OpSeriesQueries.setConfig(new ConfigStub()); + JSONArray result = repositoryGestion.getResponseAsArray(OpFamiliesQueries.getSeries("s79")); + assertEquals(3, result.length()); + + assertEquals("s1178", result.getJSONObject(0).getString("id")); + assertEquals("s1266", result.getJSONObject(1).getString("id")); + assertEquals("s1279", result.getJSONObject(2).getString("id")); + } +}