From f565006095a61fcca135420a45de436214e76da2 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Tue, 5 Nov 2024 14:36:27 +0000 Subject: [PATCH 01/19] fix: remove unused Exception --- .../fr/insee/rmes/webservice/operations/SeriesResources.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/insee/rmes/webservice/operations/SeriesResources.java b/src/main/java/fr/insee/rmes/webservice/operations/SeriesResources.java index cb87a4dbf..abc76b359 100644 --- a/src/main/java/fr/insee/rmes/webservice/operations/SeriesResources.java +++ b/src/main/java/fr/insee/rmes/webservice/operations/SeriesResources.java @@ -173,7 +173,7 @@ public ResponseEntity createSeries( consumes = MediaType.APPLICATION_JSON_VALUE) @io.swagger.v3.oas.annotations.Operation(operationId = "setSeriesValidation", summary = "Series validation") public ResponseEntity setSeriesValidation( - @PathVariable(Constants.ID) String id) throws RmesException { + @PathVariable(Constants.ID) String id) { try { operationsService.setSeriesValidation(id); } catch (RmesException e) { From 25e71b25bcf990e525826207c7887fc464805769 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Tue, 5 Nov 2024 14:36:43 +0000 Subject: [PATCH 02/19] fix: remove unused empty line --- src/main/java/fr/insee/rmes/utils/StringUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/fr/insee/rmes/utils/StringUtils.java b/src/main/java/fr/insee/rmes/utils/StringUtils.java index 9289ff380..409515cf9 100644 --- a/src/main/java/fr/insee/rmes/utils/StringUtils.java +++ b/src/main/java/fr/insee/rmes/utils/StringUtils.java @@ -43,5 +43,4 @@ public static String convertHtmlStringToRaw(String html) { } return raw; } - } From b241bbc75c824ba8a6542228611ab2eaac29f61a Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Tue, 5 Nov 2024 15:05:37 +0000 Subject: [PATCH 03/19] feat: publish operations hasPart for series --- .../operations/series/SeriesPublication.java | 63 +++++++++++++------ 1 file changed, 44 insertions(+), 19 deletions(-) diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/operations/series/SeriesPublication.java b/src/main/java/fr/insee/rmes/bauhaus_services/operations/series/SeriesPublication.java index e7e79bbfb..e385eb6d2 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/operations/series/SeriesPublication.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/operations/series/SeriesPublication.java @@ -5,7 +5,12 @@ import fr.insee.rmes.bauhaus_services.rdf_utils.PublicationUtils; import fr.insee.rmes.bauhaus_services.rdf_utils.RdfService; import fr.insee.rmes.bauhaus_services.rdf_utils.RdfUtils; -import fr.insee.rmes.exceptions.*; +import fr.insee.rmes.exceptions.ErrorCodes; +import fr.insee.rmes.exceptions.RmesBadRequestException; +import fr.insee.rmes.exceptions.RmesException; +import fr.insee.rmes.exceptions.RmesNotFoundException; +import fr.insee.rmes.persistance.ontologies.DCTERMS; +import fr.insee.rmes.persistance.sparql_queries.operations.series.OpSeriesQueries; import org.apache.http.HttpStatus; import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.model.Resource; @@ -14,40 +19,45 @@ import org.eclipse.rdf4j.repository.RepositoryConnection; import org.eclipse.rdf4j.repository.RepositoryException; import org.eclipse.rdf4j.repository.RepositoryResult; +import org.json.JSONArray; import org.json.JSONObject; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; @Repository public class SeriesPublication extends RdfService { - @Autowired + final ParentUtils ownersUtils; - - public void publishSeries(String seriesId, JSONObject serieJson) throws RmesException { - Model model = new LinkedHashModel(); - Resource series = RdfUtils.seriesIRI(seriesId); - String familyId = serieJson.getJSONObject(Constants.FAMILY).getString(Constants.ID); + + public SeriesPublication(ParentUtils ownersUtils) { + this.ownersUtils = ownersUtils; + } + + public void publishSeries(String id, JSONObject series) throws RmesException { + String familyId = series.getJSONObject(Constants.FAMILY).getString(Constants.ID); String status= ownersUtils.getValidationStatus(familyId); if(PublicationUtils.isPublished(status)) { throw new RmesBadRequestException( ErrorCodes.SERIES_VALIDATION_UNPUBLISHED_FAMILY, "This Series cannot be published before its family is published", - "Series: "+seriesId+" ; Family: "+familyId); + "Series: "+id+" ; Family: "+familyId); } - + + Model model = new LinkedHashModel(); + Resource resource = RdfUtils.seriesIRI(id); + RepositoryConnection con = repoGestion.getConnection(); - RepositoryResult statements = repoGestion.getStatements(con, series); - - RepositoryResult hasPartStatements = repoGestion.getHasPartStatements(con, series); - RepositoryResult replacesStatements = repoGestion.getReplacesStatements(con, series); - RepositoryResult isReplacedByStatements = repoGestion.getIsReplacedByStatements(con, series); + RepositoryResult statements = repoGestion.getStatements(con, resource); + RepositoryResult hasPartStatements = repoGestion.getHasPartStatements(con, resource); + RepositoryResult replacesStatements = repoGestion.getReplacesStatements(con, resource); + RepositoryResult isReplacedByStatements = repoGestion.getIsReplacedByStatements(con, resource); + try { try { if (!statements.hasNext()) { - throw new RmesNotFoundException(ErrorCodes.SERIES_UNKNOWN_ID,"Series not found", seriesId); + throw new RmesNotFoundException(ErrorCodes.SERIES_UNKNOWN_ID, "Series not found", id); } while (statements.hasNext()) { Statement st = statements.next(); @@ -75,13 +85,28 @@ public void publishSeries(String seriesId, JSONObject serieJson) throws RmesExce st.getPredicate(), st.getObject(), st.getContext() - ); + ); } addStatementsToModel(model, hasPartStatements); addStatementsToModel(model, replacesStatements); addStatementsToModel(model, isReplacedByStatements); - } + + /** + * We have to query all published operations linked to this series and publish all of them + */ + JSONArray operations = repoGestion.getResponseAsArray(OpSeriesQueries.getPublishedOperationsForSeries(resource.toString())); + for(var i = 0; i < operations.length(); i++){ + JSONObject operation = operations.getJSONObject(i); + String iri = operation.getString("operation"); + model.add( + publicationUtils.tranformBaseURIToPublish(resource), + DCTERMS.HAS_PART, + publicationUtils.tranformBaseURIToPublish(RdfUtils.createIRI(iri)), + RdfUtils.operationsGraph() + ); + } + } catch (RepositoryException e) { throw new RmesException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), Constants.REPOSITORY_EXCEPTION); } @@ -91,7 +116,7 @@ public void publishSeries(String seriesId, JSONObject serieJson) throws RmesExce repoGestion.closeStatements(hasPartStatements); con.close(); } - Resource seriesToPublishRessource = publicationUtils.tranformBaseURIToPublish(series); + Resource seriesToPublishRessource = publicationUtils.tranformBaseURIToPublish(resource); repositoryPublication.publishResource(seriesToPublishRessource, model, "serie"); } From 9697c8856b3c0083945f47913ca946b38e18076b Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Tue, 5 Nov 2024 15:06:03 +0000 Subject: [PATCH 04/19] fix: add missing query --- .../sparql_queries/operations/series/OpSeriesQueries.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/series/OpSeriesQueries.java b/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/series/OpSeriesQueries.java index 166a6b365..2b5c33c75 100644 --- a/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/series/OpSeriesQueries.java +++ b/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/series/OpSeriesQueries.java @@ -196,4 +196,10 @@ public static String checkIfSeriesExists(List iris) throws RmesException params.put(URI_SERIES, iris); return buildSeriesRequest("checkIfSeriesExists.ftlh", params); } + + public static String getPublishedOperationsForSeries(String iri) throws RmesException { + Map params = initParams(); + params.put("SERIES_IRI", iri); + return buildSeriesRequest("getPublishedOperationsForSeries.ftlh", params); + } } From 10117decc0ba60f45f01c15297be8b6515c81cb1 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Tue, 5 Nov 2024 15:06:36 +0000 Subject: [PATCH 05/19] feat: add testcontainer test --- .../operations/series/OpSeriesQueriesTest.java | 8 +++++++- .../testcontainers/all-operations-and-indicators.trig | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java index 3c8037924..5a6658f7a 100644 --- a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java +++ b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java @@ -7,7 +7,6 @@ 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; @@ -48,4 +47,11 @@ void should_return_filter_missing_objects() throws Exception { JSONArray result = repositoryGestion.getResponseAsArray(OpSeriesQueries.checkIfSeriesExists(List.of("http://bauhaus/operations/serie/unknown", "http://bauhaus/operations/operation/s1489"))); assertEquals(1, result.length()); } + + @Test + void should_return_published_operations_for_series() throws Exception { + OpSeriesQueries.setConfig(new ConfigStub()); + JSONArray result = repositoryGestion.getResponseAsArray(OpSeriesQueries.getPublishedOperationsForSeries("http://bauhaus/operations/serie/s1227")); + assertEquals(1, result.length()); + } } diff --git a/src/test/resources/testcontainers/all-operations-and-indicators.trig b/src/test/resources/testcontainers/all-operations-and-indicators.trig index 23f2d09fc..8da03705d 100644 --- a/src/test/resources/testcontainers/all-operations-and-indicators.trig +++ b/src/test/resources/testcontainers/all-operations-and-indicators.trig @@ -5035,7 +5035,7 @@ "2011" ; - "Validated" ; + "Unpublished" ; "EnDD 2011"@en , "EnDD 2011"@fr ; From 9798ca085d95bfa50807661fb273d67fa453f29e Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Tue, 5 Nov 2024 15:08:00 +0000 Subject: [PATCH 06/19] fix: remove unused import --- .../insee/rmes/bauhaus_services/FilesOperations.java | 4 ---- .../rmes/bauhaus_services/OperationsService.java | 5 ----- .../documents/DocumentsPublication.java | 1 - .../fr/insee/rmes/webservice/ConceptsResources.java | 1 - .../distribution/DistributionResources.java | 1 - .../webservice/operations/OperationsResources.java | 1 - .../series/getPublishedOperationsForSeries.ftlh | 7 +++++++ .../distribution/DistributionServiceImplTest.java | 3 ++- .../operations/OperationsDocumentationsImplTest.java | 5 ----- .../operations/indicators/IndicatorsUtilsTest.java | 2 -- ...TestIndicatorsResourcesAuthorizationsEnvProd.java | 1 - ...MetadataReportResourcesAuthorizationsEnvProd.java | 12 +++--------- .../fr/insee/rmes/stubs/RepositoryGestionStub.java | 2 -- .../java/fr/insee/rmes/utils/ExportUtilsTest.java | 7 ------- .../rmes/webservice/CodeListsResourcesTest.java | 3 +-- .../insee/rmes/webservice/DatasetResourcesTest.java | 1 - 16 files changed, 13 insertions(+), 43 deletions(-) create mode 100644 src/main/resources/request/operations/series/getPublishedOperationsForSeries.ftlh delete mode 100644 src/test/java/fr/insee/rmes/utils/ExportUtilsTest.java diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/FilesOperations.java b/src/main/java/fr/insee/rmes/bauhaus_services/FilesOperations.java index 6445056c2..7f7f6453f 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/FilesOperations.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/FilesOperations.java @@ -1,10 +1,6 @@ package fr.insee.rmes.bauhaus_services; -import fr.insee.rmes.exceptions.RmesException; - -import java.io.IOException; import java.io.InputStream; -import java.net.URI; import java.nio.file.Path; public interface FilesOperations { diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/OperationsService.java b/src/main/java/fr/insee/rmes/bauhaus_services/OperationsService.java index 1ff3f65f0..7504fbd91 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/OperationsService.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/OperationsService.java @@ -4,11 +4,6 @@ import fr.insee.rmes.model.operations.Indicator; import fr.insee.rmes.model.operations.Operation; import fr.insee.rmes.model.operations.Series; -import org.springframework.core.io.Resource; -import org.springframework.http.ResponseEntity; -import org.springframework.web.multipart.MultipartFile; - -import java.io.File; public interface OperationsService { diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/operations/documentations/documents/DocumentsPublication.java b/src/main/java/fr/insee/rmes/bauhaus_services/operations/documentations/documents/DocumentsPublication.java index 3c64df1de..51b6a327d 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/operations/documentations/documents/DocumentsPublication.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/operations/documentations/documents/DocumentsPublication.java @@ -7,7 +7,6 @@ import fr.insee.rmes.bauhaus_services.rdf_utils.RdfUtils; import fr.insee.rmes.exceptions.ErrorCodes; import fr.insee.rmes.exceptions.RmesException; -import fr.insee.rmes.exceptions.RmesFileException; import fr.insee.rmes.exceptions.RmesNotFoundException; import org.apache.http.HttpStatus; import org.eclipse.rdf4j.model.*; diff --git a/src/main/java/fr/insee/rmes/webservice/ConceptsResources.java b/src/main/java/fr/insee/rmes/webservice/ConceptsResources.java index 4fe423fcb..e443cff29 100644 --- a/src/main/java/fr/insee/rmes/webservice/ConceptsResources.java +++ b/src/main/java/fr/insee/rmes/webservice/ConceptsResources.java @@ -19,7 +19,6 @@ import jakarta.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; diff --git a/src/main/java/fr/insee/rmes/webservice/distribution/DistributionResources.java b/src/main/java/fr/insee/rmes/webservice/distribution/DistributionResources.java index 51c0779a9..29ec1c917 100644 --- a/src/main/java/fr/insee/rmes/webservice/distribution/DistributionResources.java +++ b/src/main/java/fr/insee/rmes/webservice/distribution/DistributionResources.java @@ -20,7 +20,6 @@ import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; 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.security.core.annotation.AuthenticationPrincipal; diff --git a/src/main/java/fr/insee/rmes/webservice/operations/OperationsResources.java b/src/main/java/fr/insee/rmes/webservice/operations/OperationsResources.java index 0a6ed7516..b02969437 100644 --- a/src/main/java/fr/insee/rmes/webservice/operations/OperationsResources.java +++ b/src/main/java/fr/insee/rmes/webservice/operations/OperationsResources.java @@ -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.XMLUtils; import fr.insee.rmes.webservice.OperationsCommonResources; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Content; diff --git a/src/main/resources/request/operations/series/getPublishedOperationsForSeries.ftlh b/src/main/resources/request/operations/series/getPublishedOperationsForSeries.ftlh new file mode 100644 index 000000000..417a6d116 --- /dev/null +++ b/src/main/resources/request/operations/series/getPublishedOperationsForSeries.ftlh @@ -0,0 +1,7 @@ +SELECT ?operation +FROM <${OPERATIONS_GRAPH}> +WHERE { + <${SERIES_IRI}> dcterms:hasPart ?operation . + ?operation insee:validationState ?value + FILTER(?value != 'Unpublished') . +} \ No newline at end of file diff --git a/src/test/java/fr/insee/rmes/bauhaus_services/distribution/DistributionServiceImplTest.java b/src/test/java/fr/insee/rmes/bauhaus_services/distribution/DistributionServiceImplTest.java index f87cc30f6..a095364f6 100644 --- a/src/test/java/fr/insee/rmes/bauhaus_services/distribution/DistributionServiceImplTest.java +++ b/src/test/java/fr/insee/rmes/bauhaus_services/distribution/DistributionServiceImplTest.java @@ -20,14 +20,15 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; -import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; + import java.time.LocalDateTime; import java.util.Set; + import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; diff --git a/src/test/java/fr/insee/rmes/bauhaus_services/operations/OperationsDocumentationsImplTest.java b/src/test/java/fr/insee/rmes/bauhaus_services/operations/OperationsDocumentationsImplTest.java index 463edc227..c48cb7d68 100644 --- a/src/test/java/fr/insee/rmes/bauhaus_services/operations/OperationsDocumentationsImplTest.java +++ b/src/test/java/fr/insee/rmes/bauhaus_services/operations/OperationsDocumentationsImplTest.java @@ -1,7 +1,6 @@ package fr.insee.rmes.bauhaus_services.operations; import fr.insee.rmes.bauhaus_services.Constants; -import fr.insee.rmes.bauhaus_services.OperationsDocumentationsService; import fr.insee.rmes.bauhaus_services.operations.documentations.DocumentationExport; import fr.insee.rmes.exceptions.ErrorCodes; import fr.insee.rmes.exceptions.RmesException; @@ -12,16 +11,12 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.Resource; import org.springframework.http.ResponseEntity; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) diff --git a/src/test/java/fr/insee/rmes/bauhaus_services/operations/indicators/IndicatorsUtilsTest.java b/src/test/java/fr/insee/rmes/bauhaus_services/operations/indicators/IndicatorsUtilsTest.java index bad1ee08e..1772fed85 100644 --- a/src/test/java/fr/insee/rmes/bauhaus_services/operations/indicators/IndicatorsUtilsTest.java +++ b/src/test/java/fr/insee/rmes/bauhaus_services/operations/indicators/IndicatorsUtilsTest.java @@ -4,7 +4,6 @@ import fr.insee.rmes.bauhaus_services.rdf_utils.RepositoryGestion; import fr.insee.rmes.exceptions.RmesException; import fr.insee.rmes.model.links.OperationsLink; -import fr.insee.rmes.model.operations.Family; import fr.insee.rmes.model.operations.Indicator; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Model; @@ -19,7 +18,6 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import java.util.ArrayList; import java.util.List; diff --git a/src/test/java/fr/insee/rmes/integration/authorizations/TestIndicatorsResourcesAuthorizationsEnvProd.java b/src/test/java/fr/insee/rmes/integration/authorizations/TestIndicatorsResourcesAuthorizationsEnvProd.java index 76768ef59..0adf29937 100644 --- a/src/test/java/fr/insee/rmes/integration/authorizations/TestIndicatorsResourcesAuthorizationsEnvProd.java +++ b/src/test/java/fr/insee/rmes/integration/authorizations/TestIndicatorsResourcesAuthorizationsEnvProd.java @@ -9,7 +9,6 @@ import fr.insee.rmes.config.auth.security.CommonSecurityConfiguration; import fr.insee.rmes.config.auth.security.DefaultSecurityContext; import fr.insee.rmes.config.auth.security.OpenIDConnectSecurityContext; -import fr.insee.rmes.config.auth.security.SecurityExpressionRootForBauhaus; import fr.insee.rmes.webservice.operations.IndicatorsResources; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/test/java/fr/insee/rmes/integration/authorizations/TestMetadataReportResourcesAuthorizationsEnvProd.java b/src/test/java/fr/insee/rmes/integration/authorizations/TestMetadataReportResourcesAuthorizationsEnvProd.java index 9401fe892..09f460f35 100644 --- a/src/test/java/fr/insee/rmes/integration/authorizations/TestMetadataReportResourcesAuthorizationsEnvProd.java +++ b/src/test/java/fr/insee/rmes/integration/authorizations/TestMetadataReportResourcesAuthorizationsEnvProd.java @@ -3,8 +3,6 @@ import fr.insee.rmes.bauhaus_services.OperationsDocumentationsService; import fr.insee.rmes.bauhaus_services.OperationsService; import fr.insee.rmes.bauhaus_services.StampAuthorizationChecker; -import fr.insee.rmes.bauhaus_services.datasets.DatasetQueries; -import fr.insee.rmes.bauhaus_services.rdf_utils.FreeMarkerUtils; import fr.insee.rmes.config.Config; import fr.insee.rmes.config.auth.UserProviderFromSecurityContext; import fr.insee.rmes.config.auth.security.CommonSecurityConfiguration; @@ -13,8 +11,8 @@ import fr.insee.rmes.exceptions.RmesException; import fr.insee.rmes.model.operations.documentations.Documentation; import fr.insee.rmes.model.operations.documentations.MSD; +import fr.insee.rmes.utils.XMLUtils; import fr.insee.rmes.webservice.operations.MetadataReportResources; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; import org.mockito.Mockito; @@ -30,19 +28,15 @@ import org.springframework.security.oauth2.jwt.JwtDecoder; import org.springframework.test.web.servlet.MockMvc; -import java.util.HashMap; import java.util.List; -import java.util.Map; import static fr.insee.rmes.integration.authorizations.TokenForTestsConfiguration.*; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import fr.insee.rmes.utils.XMLUtils; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @WebMvcTest(controllers = MetadataReportResources.class, properties = {"fr.insee.rmes.bauhaus.env=PROD", diff --git a/src/test/java/fr/insee/rmes/stubs/RepositoryGestionStub.java b/src/test/java/fr/insee/rmes/stubs/RepositoryGestionStub.java index 558d547f5..e111ef64c 100644 --- a/src/test/java/fr/insee/rmes/stubs/RepositoryGestionStub.java +++ b/src/test/java/fr/insee/rmes/stubs/RepositoryGestionStub.java @@ -1,8 +1,6 @@ package fr.insee.rmes.stubs; import fr.insee.rmes.bauhaus_services.rdf_utils.RepositoryGestion; -import fr.insee.rmes.bauhaus_services.rdf_utils.RepositoryUtils; -import fr.insee.rmes.config.Config; import fr.insee.rmes.exceptions.RmesException; public class RepositoryGestionStub extends RepositoryGestion { diff --git a/src/test/java/fr/insee/rmes/utils/ExportUtilsTest.java b/src/test/java/fr/insee/rmes/utils/ExportUtilsTest.java deleted file mode 100644 index 10bce820a..000000000 --- a/src/test/java/fr/insee/rmes/utils/ExportUtilsTest.java +++ /dev/null @@ -1,7 +0,0 @@ -package fr.insee.rmes.utils; - -import static org.junit.jupiter.api.Assertions.*; - -class ExportUtilsTest { - -} \ No newline at end of file diff --git a/src/test/java/fr/insee/rmes/webservice/CodeListsResourcesTest.java b/src/test/java/fr/insee/rmes/webservice/CodeListsResourcesTest.java index a6bc8a413..6daa2a725 100644 --- a/src/test/java/fr/insee/rmes/webservice/CodeListsResourcesTest.java +++ b/src/test/java/fr/insee/rmes/webservice/CodeListsResourcesTest.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import fr.insee.rmes.bauhaus_services.CodeListService; -import fr.insee.rmes.bauhaus_services.code_list.DetailedCodeList; import fr.insee.rmes.bauhaus_services.code_list.CodeListItem; import fr.insee.rmes.config.swagger.model.code_list.CodeList; import fr.insee.rmes.config.swagger.model.code_list.Page; @@ -20,9 +19,9 @@ import java.util.ArrayList; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.when; -import static org.junit.jupiter.api.Assertions.assertEquals; @ExtendWith(MockitoExtension.class) class CodeListsResourcesTest { diff --git a/src/test/java/fr/insee/rmes/webservice/DatasetResourcesTest.java b/src/test/java/fr/insee/rmes/webservice/DatasetResourcesTest.java index 13ecf4598..2b71596cb 100644 --- a/src/test/java/fr/insee/rmes/webservice/DatasetResourcesTest.java +++ b/src/test/java/fr/insee/rmes/webservice/DatasetResourcesTest.java @@ -12,7 +12,6 @@ import org.mockito.junit.jupiter.MockitoExtension; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) From d5d5be4b6360dea83e8b70661af32dc82970d714 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Wed, 6 Nov 2024 10:31:14 +0000 Subject: [PATCH 07/19] feat: remove useless comment --- .../rmes/webservice/ClassificationsResources.java | 8 -------- .../fr/insee/rmes/webservice/ConceptsResources.java | 7 ------- .../fr/insee/rmes/webservice/LoaderResources.java | 11 +---------- .../fr/insee/rmes/webservice/PublicResources.java | 8 -------- 4 files changed, 1 insertion(+), 33 deletions(-) diff --git a/src/main/java/fr/insee/rmes/webservice/ClassificationsResources.java b/src/main/java/fr/insee/rmes/webservice/ClassificationsResources.java index 1b46c049c..6c8882874 100644 --- a/src/main/java/fr/insee/rmes/webservice/ClassificationsResources.java +++ b/src/main/java/fr/insee/rmes/webservice/ClassificationsResources.java @@ -31,14 +31,6 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -/** - * WebService class for resources of Classifications - * - * - * @author N. Laval - * - */ - @RestController @RequestMapping("/classifications") @Tag(name ="Classifications",description = "Classification API") diff --git a/src/main/java/fr/insee/rmes/webservice/ConceptsResources.java b/src/main/java/fr/insee/rmes/webservice/ConceptsResources.java index e443cff29..d6f8b5362 100644 --- a/src/main/java/fr/insee/rmes/webservice/ConceptsResources.java +++ b/src/main/java/fr/insee/rmes/webservice/ConceptsResources.java @@ -26,13 +26,6 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; -/** - * WebService class for resources of Concepts - * - * - * @author N. Laval - * - */ @RestController @RequestMapping("/concepts") @SecurityRequirement(name = "bearerAuth") diff --git a/src/main/java/fr/insee/rmes/webservice/LoaderResources.java b/src/main/java/fr/insee/rmes/webservice/LoaderResources.java index 82bf43919..86d7769e4 100644 --- a/src/main/java/fr/insee/rmes/webservice/LoaderResources.java +++ b/src/main/java/fr/insee/rmes/webservice/LoaderResources.java @@ -30,16 +30,7 @@ import java.io.IOException; import java.io.InputStream; -/** - * WebService class to download/upload resources in databases - * - * schemes: - http - * - * consumes: - application/json - * - * produces: - application/json - * - */ + @RestController @RequestMapping("/loader") @SecurityRequirement(name = "bearerAuth") diff --git a/src/main/java/fr/insee/rmes/webservice/PublicResources.java b/src/main/java/fr/insee/rmes/webservice/PublicResources.java index 54a71ebf1..e44cd223e 100644 --- a/src/main/java/fr/insee/rmes/webservice/PublicResources.java +++ b/src/main/java/fr/insee/rmes/webservice/PublicResources.java @@ -30,14 +30,6 @@ import java.util.List; import java.util.TreeSet; -/** - * WebService class for resources - * schemes: - http - *

- * consumes: - application/json - *

- * produces: - application/json - */ @RestController @RequestMapping("/") @Tag(name = "Application", description = "Application API") From 37238ed9c0319934c532745990d82a486eadabff Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Wed, 6 Nov 2024 10:31:29 +0000 Subject: [PATCH 08/19] feat: add unit test for series query --- .../operations/series/OpSeriesQueriesTest.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java index 5a6658f7a..3caf2666b 100644 --- a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java +++ b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java @@ -12,8 +12,7 @@ import java.util.List; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.*; public class OpSeriesQueriesTest extends WithGraphDBContainer { RepositoryGestion repositoryGestion = new RepositoryGestion(getRdfGestionConnectionDetails(), new RepositoryUtils(null, RepositoryInitiator.Type.DISABLED)); @@ -23,6 +22,20 @@ static void initData(){ container.withTrigFiles("all-operations-and-indicators.trig"); } + @Test + void should_return_true_if_series_if_label_exist() throws Exception { + OpSeriesQueries.setConfig(new ConfigStub()); + boolean result = repositoryGestion.getResponseAsBoolean(OpSeriesQueries.checkPrefLabelUnicity("1", "Enquête Loyers et charges", "fr")); + assertTrue(result); + } + + @Test + void should_return_false_series_if_label_does_not_exist() throws Exception { + OpSeriesQueries.setConfig(new ConfigStub()); + boolean result = repositoryGestion.getResponseAsBoolean(OpSeriesQueries.checkPrefLabelUnicity("1", "label", "fr")); + assertFalse(result); + } + @Test void should_return_all_series() throws Exception { OpSeriesQueries.setConfig(new ConfigStub()); From 2d4f6c12066734d9ec04ca3de5a999d821704a1f Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Wed, 6 Nov 2024 20:51:06 +0000 Subject: [PATCH 09/19] feat: update graphdb image version --- compose.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compose.yaml b/compose.yaml index e1e9ce0e5..58711c7a0 100644 --- a/compose.yaml +++ b/compose.yaml @@ -7,7 +7,7 @@ services: links: - graphdb:localhost graphdb: - image: ontotext/graphdb:latest + image: ontotext/graphdb:10.6.4 restart: always ports: - "7200:7200" From 8801ae629316b7876d1702a0f8e686756e34520a Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Thu, 7 Nov 2024 16:21:22 +0000 Subject: [PATCH 10/19] fix: configure graphdb on docker compose --- compose.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compose.yaml b/compose.yaml index 58711c7a0..a429272c9 100644 --- a/compose.yaml +++ b/compose.yaml @@ -4,8 +4,10 @@ services: build: . ports: - "8080:8080" + environment: + - fr.insee.rmes.bauhaus.sesame.gestion.sesameServer=http://graphdb:7200 links: - - graphdb:localhost + - graphdb graphdb: image: ontotext/graphdb:10.6.4 restart: always From c216665187bf858c2b2f4d7143a39b6a32cb7d6c Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Fri, 8 Nov 2024 11:35:32 +0000 Subject: [PATCH 11/19] feat: add a testcontainer test --- .../operations/series/OpSeriesQueriesTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java index 3caf2666b..829797284 100644 --- a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java +++ b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java @@ -7,6 +7,7 @@ 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; @@ -36,6 +37,23 @@ void should_return_false_series_if_label_does_not_exist() throws Exception { assertFalse(result); } + @Test + void should_return_series() throws Exception { + OpSeriesQueries.setConfig(new ConfigStub()); + JSONObject result = repositoryGestion.getResponseAsObject(OpSeriesQueries.oneSeriesQuery("s1226", false)); + assertEquals(result.getString("validationState"), "Validated"); + assertEquals(result.getString("altLabelLg1"), "EVA"); + assertEquals(result.getString("altLabelLg2"), "EVA"); + assertEquals(result.getString("id"), "s1226"); + assertEquals(result.getString("prefLabelLg1"), "Enquête sur l'entrée dans la vie adulte"); + assertEquals(result.getString("prefLabelLg2"), "Survey on entry into adult life"); + assertEquals(result.getString("abstractLg1"), "

L’objectif du dispositif sur l’entrée dans la vie adulte (EVA ) est d’observer l’entrée dans la vie adulte et l’insertion professionnelle des jeunes, au regard de leurs études.

Il permet de mettre en regard les informations sur les débuts de carrière et l’insertion professionnelle avec les cursus scolaires et universitaires détaillés et les projets formés pendant l’adolescence ou la jeunesse.

"); + assertEquals(result.getString("abstractLg2"), "

The purpose of the EVA system is to observe the entry of young people into adult life and their professional integration in the light of their studies. The EVA system allows to link and compare informations about professional career beginning and professional integration to data related to detailed school and university pathways and plans made for the future during youth ages.

"); + assertEquals(result.getString("historyNoteLg1"), "

Une première série d’enquêtes EVA avait été menée par l’Insee de 2005 à 2012 auprès des jeunes du panel de la Depp d’élèves du second degré entrés en 6e en 1995.
Ce dispositif se décomposait en deux volets :
- le parcours scolaire des jeunes dans le secondaire ainsi que leurs études supérieures sont suivis par la Direction de l'évaluation, de la prospective et de la performance (Depp - Ministère en charge de l’éducation) ;
- et les sortants du système scolaire sont interrogés dans le cadre de l’enquête EVA de l’Insee.

La nouvelle série d’enquêtes EVA s’appuie sur l’édition suivante du panel de la Depp, celle des entrants en 6e en 2007.
Après deux enquêtes légères en 2013 et 2014 réalisées par l’Insee, les jeunes sont suivis chaque année via une enquête dite de tronc commun.
Ce dispositif se décompose en trois volets :
 - le parcours scolaire des jeunes dans le secondaire est suivi par la  Direction de l'évaluation, de la prospective et de la performance (Depp - Ministère en charge de l’éducation) ;
- la période des études supérieures est suivie par le Système d'information et d'études statistiques (Sies - Ministère en charge de l’enseignement supérieur) ;
- les sortants du système scolaire sont interrogés dans le cadre de l’enquête EVA de l’Insee.

"); + assertEquals(result.getString("historyNoteLg2"), "

A first sequence of EVA surveys had been carried out by Insee from 2005 to 2012 and collected from the young people of the Depp education panel who had entered the first year of secondary education in 1995.
This program was consisting of two parts :
- the schooling path of young people in secondary education and their higher education studies are observed by the Ministry for Education (Depp) ;
- and the data collection on young people who have left the education system is conducted by Insee, by the mean of the EVA survey.

This new sequence of EVA surveys relies on the following edition of the Depp panel, of young people who entered the first year of secondary education in 2007.
After two short surveys in 2013 and 2014 conducted by Insee, the situation of these young persons is observed each year by a survey named « de tronc commun ».
This program consists of three parts :
- the schooling path of young people in secondary education is observed by the Ministry for Education (Depp) ;
- the  higher education studies period is observed by the Ministry in charge of Higher Education (Sies) ;
- and the data collection on young people who have left the education system is conducted by Insee, by the mean of the EVA survey.

"); + } + + @Test void should_return_all_series() throws Exception { OpSeriesQueries.setConfig(new ConfigStub()); From e2870e30fe6c12bf05015b4a2ebe0e2d09b2c397 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Sat, 9 Nov 2024 14:17:35 +0000 Subject: [PATCH 12/19] feat: add testcontainer test --- .../series/OpSeriesQueriesTest.java | 20 +++++++++++++++++++ .../all-operations-and-indicators.trig | 2 ++ 2 files changed, 22 insertions(+) diff --git a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java index 829797284..f8b7264cd 100644 --- a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java +++ b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java @@ -4,6 +4,7 @@ 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.exceptions.RmesException; import fr.insee.rmes.persistance.sparql_queries.operations.series.OpSeriesQueries; import fr.insee.rmes.testcontainers.queries.WithGraphDBContainer; import org.json.JSONArray; @@ -53,7 +54,26 @@ void should_return_series() throws Exception { assertEquals(result.getString("historyNoteLg2"), "

A first sequence of EVA surveys had been carried out by Insee from 2005 to 2012 and collected from the young people of the Depp education panel who had entered the first year of secondary education in 1995.
This program was consisting of two parts :
- the schooling path of young people in secondary education and their higher education studies are observed by the Ministry for Education (Depp) ;
- and the data collection on young people who have left the education system is conducted by Insee, by the mean of the EVA survey.

This new sequence of EVA surveys relies on the following edition of the Depp panel, of young people who entered the first year of secondary education in 2007.
After two short surveys in 2013 and 2014 conducted by Insee, the situation of these young persons is observed each year by a survey named « de tronc commun ».
This program consists of three parts :
- the schooling path of young people in secondary education is observed by the Ministry for Education (Depp) ;
- the  higher education studies period is observed by the Ministry in charge of Higher Education (Sies) ;
- and the data collection on young people who have left the education system is conducted by Insee, by the mean of the EVA survey.

"); } + @Test + void should_return_no_series_for_search_if_unknown_stamp() throws RmesException { + OpSeriesQueries.setConfig(new ConfigStub()); + JSONArray result = repositoryGestion.getResponseAsArray(OpSeriesQueries.getSeriesForSearch("unknow_stamp")); + assertEquals(0, result.length()); + } + + @Test + void should_return_one_series_for_search() throws RmesException { + OpSeriesQueries.setConfig(new ConfigStub()); + JSONArray result = repositoryGestion.getResponseAsArray(OpSeriesQueries.getSeriesForSearch("stamp")); + assertEquals(1, result.length()); + } + @Test + void should_return_all_series_for_search_if_not_defined_stamp() throws RmesException { + OpSeriesQueries.setConfig(new ConfigStub()); + JSONArray result = repositoryGestion.getResponseAsArray(OpSeriesQueries.getSeriesForSearch("")); + assertEquals(174, result.length()); + } @Test void should_return_all_series() throws Exception { OpSeriesQueries.setConfig(new ConfigStub()); diff --git a/src/test/resources/testcontainers/all-operations-and-indicators.trig b/src/test/resources/testcontainers/all-operations-and-indicators.trig index 8da03705d..ae0ced2b1 100644 --- a/src/test/resources/testcontainers/all-operations-and-indicators.trig +++ b/src/test/resources/testcontainers/all-operations-and-indicators.trig @@ -2807,6 +2807,8 @@ a ; , , ; + + "stamp" ; "

This survey allows to draw up a regular balance sheet on the visits of the tourists on the territory of the Guadeloupe Island and to have a quantitative and qualitative information about this tourists.

It is also a question of knowing better the main characteristics of the tourists (passagers and Guadeloupe residents), and quantifying their expenses to measure the economic effects.

"@en , "

Cette enquête permet de dresser un bilan annuel régulier sur les visites des touristes sur le territoire guadeloupéen et de disposer ainsi d'informations quantitatives et qualitatives sur ces derniers.

Il s'agit aussi de mieux connaître les principales caractéristiques des voyageurs (touristes et résidents de Guadeloupe) et de quantifier leurs dépenses pour en mesurer les retombées économiques.

"@fr ; From 342a17e4fbbed44ae2e59e8aa4b6b1257b8c04b6 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Sun, 10 Nov 2024 20:40:09 +0000 Subject: [PATCH 13/19] feat: add unit test --- .../operations/series/OpSeriesQueriesTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java index f8b7264cd..c5950766c 100644 --- a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java +++ b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java @@ -74,6 +74,15 @@ void should_return_all_series_for_search_if_not_defined_stamp() throws RmesExcep JSONArray result = repositoryGestion.getResponseAsArray(OpSeriesQueries.getSeriesForSearch("")); assertEquals(174, result.length()); } + + @Test + void should_return_series_family() throws RmesException { + OpSeriesQueries.setConfig(new ConfigStub()); + JSONObject family = repositoryGestion.getResponseAsObject(OpSeriesQueries.getFamily("s1028")); + assertEquals("Housing", family.getString("labelLg2")); + assertEquals("Logement", family.getString("labelLg1")); + assertEquals("s60", family.getString("id")); + } @Test void should_return_all_series() throws Exception { OpSeriesQueries.setConfig(new ConfigStub()); From 3f67f7d0ae6642d92e8d530d8f3e1d22ed6a52f9 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Mon, 11 Nov 2024 08:37:32 +0000 Subject: [PATCH 14/19] feat: add testcontainer test --- .../operations/series/OpSeriesQueriesTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java index c5950766c..bc5f7b9c9 100644 --- a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java +++ b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java @@ -83,6 +83,14 @@ void should_return_series_family() throws RmesException { assertEquals("Logement", family.getString("labelLg1")); assertEquals("s60", family.getString("id")); } + + @Test + void should_return_series_crators() throws RmesException { + OpSeriesQueries.setConfig(new ConfigStub()); + JSONArray creators = repositoryGestion.getResponseAsArray(OpSeriesQueries.getCreatorsBySeriesUri("")); + assertEquals("stamp", creators.getJSONObject(0).getString("creators")); + assertEquals(1, creators.length()); + } @Test void should_return_all_series() throws Exception { OpSeriesQueries.setConfig(new ConfigStub()); From 0e0786e8097f7dc1df2097e020dfaef2b791b7a7 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Wed, 13 Nov 2024 14:51:57 +0000 Subject: [PATCH 15/19] feat: add testcontainer test --- .../series/OpSeriesQueriesTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java index bc5f7b9c9..f04d289ee 100644 --- a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java +++ b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java @@ -22,6 +22,7 @@ public class OpSeriesQueriesTest extends WithGraphDBContainer { @BeforeAll static void initData(){ container.withTrigFiles("all-operations-and-indicators.trig"); + container.withTrigFiles("sims-all.trig"); } @Test @@ -91,6 +92,35 @@ void should_return_series_crators() throws RmesException { assertEquals("stamp", creators.getJSONObject(0).getString("creators")); assertEquals(1, creators.length()); } + + @Test + void should_return_true_if_series_has_sims() throws RmesException { + OpSeriesQueries.setConfig(new ConfigStub()); + boolean hasSims = repositoryGestion.getResponseAsBoolean(OpSeriesQueries.checkIfSeriesHasSims("http://bauhaus/operations/serie/s1236")); + assertTrue(hasSims); + } + + @Test + void should_return_false_if_series_does_not_have_sims() throws RmesException { + OpSeriesQueries.setConfig(new ConfigStub()); + boolean hasSims = repositoryGestion.getResponseAsBoolean(OpSeriesQueries.checkIfSeriesHasSims("http://bauhaus/operations/serie/s12361")); + assertFalse(hasSims); + } + + @Test + void should_return_true_if_series_has_operation() throws RmesException { + OpSeriesQueries.setConfig(new ConfigStub()); + boolean hasSims = repositoryGestion.getResponseAsBoolean(OpSeriesQueries.checkIfSeriesHasOperation("http://bauhaus/operations/serie/s1228")); + assertTrue(hasSims); + } + + @Test + void should_return_false_if_series_does_not_have_operation() throws RmesException { + OpSeriesQueries.setConfig(new ConfigStub()); + boolean hasSims = repositoryGestion.getResponseAsBoolean(OpSeriesQueries.checkIfSeriesHasOperation("http://bauhaus/operations/serie/s1236")); + assertFalse(hasSims); + } + @Test void should_return_all_series() throws Exception { OpSeriesQueries.setConfig(new ConfigStub()); From 30a143173a686957ddd037c8e4df6abfa314d50b Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Thu, 14 Nov 2024 13:56:57 +0000 Subject: [PATCH 16/19] feat: add test container test --- .../operations/series/OpSeriesQueriesTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java index f04d289ee..3aca76aa2 100644 --- a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java +++ b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java @@ -121,6 +121,14 @@ void should_return_false_if_series_does_not_have_operation() throws RmesExceptio assertFalse(hasSims); } + @Test + void should_creators() throws RmesException { + OpSeriesQueries.setConfig(new ConfigStub()); + JSONArray creators = repositoryGestion.getResponseAsArray(OpSeriesQueries.getCreatorsById("s1236")); + assertEquals(1, creators.length()); + assertEquals("stamp", creators.getJSONObject(0).getString("creators")); + } + @Test void should_return_all_series() throws Exception { OpSeriesQueries.setConfig(new ConfigStub()); From 60c54a067b3af521a14d20985b053de0f1c5ea76 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Fri, 15 Nov 2024 09:34:51 +0000 Subject: [PATCH 17/19] feat: add testcontainer test --- .../operations/series/OpSeriesQueriesTest.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java index 3aca76aa2..a98fd1d1c 100644 --- a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java +++ b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java @@ -122,13 +122,20 @@ void should_return_false_if_series_does_not_have_operation() throws RmesExceptio } @Test - void should_creators() throws RmesException { + void should_get_creators() throws RmesException { OpSeriesQueries.setConfig(new ConfigStub()); JSONArray creators = repositoryGestion.getResponseAsArray(OpSeriesQueries.getCreatorsById("s1236")); assertEquals(1, creators.length()); assertEquals("stamp", creators.getJSONObject(0).getString("creators")); } + @Test + void should_get_operations() throws RmesException { + OpSeriesQueries.setConfig(new ConfigStub()); + JSONArray operations = repositoryGestion.getResponseAsArray(OpSeriesQueries.getOperations("s1207")); + assertEquals(13, operations.length()); + } + @Test void should_return_all_series() throws Exception { OpSeriesQueries.setConfig(new ConfigStub()); From b93a7ec10669e5c0371124e61ed196cb8f8c54e9 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Tue, 19 Nov 2024 13:43:52 +0000 Subject: [PATCH 18/19] fix: review --- .../operations/series/SeriesPublication.java | 216 +++++++++--------- .../series/OpSeriesQueriesTest.java | 58 +++-- 2 files changed, 131 insertions(+), 143 deletions(-) diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/operations/series/SeriesPublication.java b/src/main/java/fr/insee/rmes/bauhaus_services/operations/series/SeriesPublication.java index e385eb6d2..86ad9d657 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/operations/series/SeriesPublication.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/operations/series/SeriesPublication.java @@ -11,13 +11,11 @@ import fr.insee.rmes.exceptions.RmesNotFoundException; import fr.insee.rmes.persistance.ontologies.DCTERMS; import fr.insee.rmes.persistance.sparql_queries.operations.series.OpSeriesQueries; -import org.apache.http.HttpStatus; import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.model.Resource; import org.eclipse.rdf4j.model.Statement; import org.eclipse.rdf4j.model.impl.LinkedHashModel; import org.eclipse.rdf4j.repository.RepositoryConnection; -import org.eclipse.rdf4j.repository.RepositoryException; import org.eclipse.rdf4j.repository.RepositoryResult; import org.json.JSONArray; import org.json.JSONObject; @@ -25,115 +23,111 @@ @Repository public class SeriesPublication extends RdfService { - - final - ParentUtils ownersUtils; - - public SeriesPublication(ParentUtils ownersUtils) { - this.ownersUtils = ownersUtils; - } - - public void publishSeries(String id, JSONObject series) throws RmesException { - String familyId = series.getJSONObject(Constants.FAMILY).getString(Constants.ID); - String status= ownersUtils.getValidationStatus(familyId); - - if(PublicationUtils.isPublished(status)) { - throw new RmesBadRequestException( - ErrorCodes.SERIES_VALIDATION_UNPUBLISHED_FAMILY, - "This Series cannot be published before its family is published", - "Series: "+id+" ; Family: "+familyId); - } - - Model model = new LinkedHashModel(); - Resource resource = RdfUtils.seriesIRI(id); - - RepositoryConnection con = repoGestion.getConnection(); - RepositoryResult statements = repoGestion.getStatements(con, resource); - - RepositoryResult hasPartStatements = repoGestion.getHasPartStatements(con, resource); - RepositoryResult replacesStatements = repoGestion.getReplacesStatements(con, resource); - RepositoryResult isReplacedByStatements = repoGestion.getIsReplacedByStatements(con, resource); - - try { - try { - if (!statements.hasNext()) { - throw new RmesNotFoundException(ErrorCodes.SERIES_UNKNOWN_ID, "Series not found", id); - } - while (statements.hasNext()) { - Statement st = statements.next(); - String pred = RdfUtils.toString(st.getPredicate()); - - // Other URI to transform - if (pred.endsWith("isPartOf") || - pred.endsWith(Constants.SEEALSO) || - pred.endsWith(Constants.REPLACES) || - pred.endsWith(Constants.ISREPLACEDBY)|| - pred.endsWith(Constants.DATA_COLLECTOR) || - pred.endsWith(Constants.CONTRIBUTOR) || - pred.endsWith(Constants.PUBLISHER) || - pred.endsWith("accrualPeriodicity")|| - pred.endsWith("type") ) { - transformSubjectAndObject(model, st); - } else if (pred.endsWith("isValidated") - || pred.endsWith("validationState") - || pred.endsWith("hasPart")) { - // nothing, wouldn't copy this attr - } - // Literals - else { - model.add(publicationUtils.tranformBaseURIToPublish(st.getSubject()), - st.getPredicate(), - st.getObject(), - st.getContext() - ); - } - addStatementsToModel(model, hasPartStatements); - addStatementsToModel(model, replacesStatements); - addStatementsToModel(model, isReplacedByStatements); - } - - /** - * We have to query all published operations linked to this series and publish all of them - */ - JSONArray operations = repoGestion.getResponseAsArray(OpSeriesQueries.getPublishedOperationsForSeries(resource.toString())); - for(var i = 0; i < operations.length(); i++){ - JSONObject operation = operations.getJSONObject(i); - String iri = operation.getString("operation"); - model.add( - publicationUtils.tranformBaseURIToPublish(resource), - DCTERMS.HAS_PART, - publicationUtils.tranformBaseURIToPublish(RdfUtils.createIRI(iri)), - RdfUtils.operationsGraph() - ); - } - - } catch (RepositoryException e) { - throw new RmesException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), Constants.REPOSITORY_EXCEPTION); - } - - } finally { - repoGestion.closeStatements(statements); - repoGestion.closeStatements(hasPartStatements); - con.close(); - } - Resource seriesToPublishRessource = publicationUtils.tranformBaseURIToPublish(resource); - repositoryPublication.publishResource(seriesToPublishRessource, model, "serie"); - - } - - public void addStatementsToModel(Model model, RepositoryResult statements) { - while (statements.hasNext()) { - Statement statement = statements.next(); - transformSubjectAndObject(model, statement); - } - } - - public void transformSubjectAndObject(Model model, Statement statement) { - model.add(publicationUtils.tranformBaseURIToPublish(statement.getSubject()), - statement.getPredicate(), - publicationUtils.tranformBaseURIToPublish((Resource) statement.getObject()), - statement.getContext()); - } + + final + ParentUtils ownersUtils; + + public SeriesPublication(ParentUtils ownersUtils) { + this.ownersUtils = ownersUtils; + } + + public void publishSeries(String id, JSONObject series) throws RmesException { + String familyId = series.getJSONObject(Constants.FAMILY).getString(Constants.ID); + String status = ownersUtils.getValidationStatus(familyId); + + if (PublicationUtils.isPublished(status)) { + throw new RmesBadRequestException( + ErrorCodes.SERIES_VALIDATION_UNPUBLISHED_FAMILY, + "This Series cannot be published before its family is published", + "Series: " + id + " ; Family: " + familyId); + } + + Model model = new LinkedHashModel(); + Resource resource = RdfUtils.seriesIRI(id); + + RepositoryConnection con = repoGestion.getConnection(); + RepositoryResult statements = repoGestion.getStatements(con, resource); + + RepositoryResult hasPartStatements = repoGestion.getHasPartStatements(con, resource); + RepositoryResult replacesStatements = repoGestion.getReplacesStatements(con, resource); + RepositoryResult isReplacedByStatements = repoGestion.getIsReplacedByStatements(con, resource); + + try { + if (!statements.hasNext()) { + throw new RmesNotFoundException(ErrorCodes.SERIES_UNKNOWN_ID, "Series not found", id); + } + while (statements.hasNext()) { + Statement st = statements.next(); + String pred = RdfUtils.toString(st.getPredicate()); + + // Other URI to transform + if (pred.endsWith("isPartOf") || + pred.endsWith(Constants.SEEALSO) || + pred.endsWith(Constants.REPLACES) || + pred.endsWith(Constants.ISREPLACEDBY) || + pred.endsWith(Constants.DATA_COLLECTOR) || + pred.endsWith(Constants.CONTRIBUTOR) || + pred.endsWith(Constants.PUBLISHER) || + pred.endsWith("accrualPeriodicity") || + pred.endsWith("type")) { + transformSubjectAndObject(model, st); + } else if (pred.endsWith("isValidated") + || pred.endsWith("validationState") + || pred.endsWith("hasPart")) { + // nothing, wouldn't copy this attr + } + // Literals + else { + model.add(publicationUtils.tranformBaseURIToPublish(st.getSubject()), + st.getPredicate(), + st.getObject(), + st.getContext() + ); + } + addStatementsToModel(model, hasPartStatements); + addStatementsToModel(model, replacesStatements); + addStatementsToModel(model, isReplacedByStatements); + } + + /** + * We have to query all published operations linked to this series and publish all of them + */ + JSONArray operations = repoGestion.getResponseAsArray(OpSeriesQueries.getPublishedOperationsForSeries(resource.toString())); + for (var i = 0; i < operations.length(); i++) { + JSONObject operation = operations.getJSONObject(i); + String iri = operation.getString("operation"); + model.add( + publicationUtils.tranformBaseURIToPublish(resource), + DCTERMS.HAS_PART, + publicationUtils.tranformBaseURIToPublish(RdfUtils.createIRI(iri)), + RdfUtils.operationsGraph() + ); + } + + + } finally { + repoGestion.closeStatements(statements); + repoGestion.closeStatements(hasPartStatements); + con.close(); + } + Resource seriesToPublishRessource = publicationUtils.tranformBaseURIToPublish(resource); + repositoryPublication.publishResource(seriesToPublishRessource, model, "serie"); + + } + + public void addStatementsToModel(Model model, RepositoryResult statements) { + while (statements.hasNext()) { + Statement statement = statements.next(); + transformSubjectAndObject(model, statement); + } + } + + public void transformSubjectAndObject(Model model, Statement statement) { + model.add(publicationUtils.tranformBaseURIToPublish(statement.getSubject()), + statement.getPredicate(), + publicationUtils.tranformBaseURIToPublish((Resource) statement.getObject()), + statement.getContext()); + } } diff --git a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java index a98fd1d1c..9cf4033f9 100644 --- a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java +++ b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java @@ -11,12 +11,15 @@ import org.json.JSONObject; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import java.util.List; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.junit.jupiter.api.Assertions.*; -public class OpSeriesQueriesTest extends WithGraphDBContainer { +class OpSeriesQueriesTest extends WithGraphDBContainer { RepositoryGestion repositoryGestion = new RepositoryGestion(getRdfGestionConnectionDetails(), new RepositoryUtils(null, RepositoryInitiator.Type.DISABLED)); @BeforeAll @@ -43,37 +46,28 @@ void should_return_false_series_if_label_does_not_exist() throws Exception { void should_return_series() throws Exception { OpSeriesQueries.setConfig(new ConfigStub()); JSONObject result = repositoryGestion.getResponseAsObject(OpSeriesQueries.oneSeriesQuery("s1226", false)); - assertEquals(result.getString("validationState"), "Validated"); - assertEquals(result.getString("altLabelLg1"), "EVA"); - assertEquals(result.getString("altLabelLg2"), "EVA"); - assertEquals(result.getString("id"), "s1226"); - assertEquals(result.getString("prefLabelLg1"), "Enquête sur l'entrée dans la vie adulte"); - assertEquals(result.getString("prefLabelLg2"), "Survey on entry into adult life"); - assertEquals(result.getString("abstractLg1"), "

L’objectif du dispositif sur l’entrée dans la vie adulte (EVA ) est d’observer l’entrée dans la vie adulte et l’insertion professionnelle des jeunes, au regard de leurs études.

Il permet de mettre en regard les informations sur les débuts de carrière et l’insertion professionnelle avec les cursus scolaires et universitaires détaillés et les projets formés pendant l’adolescence ou la jeunesse.

"); - assertEquals(result.getString("abstractLg2"), "

The purpose of the EVA system is to observe the entry of young people into adult life and their professional integration in the light of their studies. The EVA system allows to link and compare informations about professional career beginning and professional integration to data related to detailed school and university pathways and plans made for the future during youth ages.

"); - assertEquals(result.getString("historyNoteLg1"), "

Une première série d’enquêtes EVA avait été menée par l’Insee de 2005 à 2012 auprès des jeunes du panel de la Depp d’élèves du second degré entrés en 6e en 1995.
Ce dispositif se décomposait en deux volets :
- le parcours scolaire des jeunes dans le secondaire ainsi que leurs études supérieures sont suivis par la Direction de l'évaluation, de la prospective et de la performance (Depp - Ministère en charge de l’éducation) ;
- et les sortants du système scolaire sont interrogés dans le cadre de l’enquête EVA de l’Insee.

La nouvelle série d’enquêtes EVA s’appuie sur l’édition suivante du panel de la Depp, celle des entrants en 6e en 2007.
Après deux enquêtes légères en 2013 et 2014 réalisées par l’Insee, les jeunes sont suivis chaque année via une enquête dite de tronc commun.
Ce dispositif se décompose en trois volets :
 - le parcours scolaire des jeunes dans le secondaire est suivi par la  Direction de l'évaluation, de la prospective et de la performance (Depp - Ministère en charge de l’éducation) ;
- la période des études supérieures est suivie par le Système d'information et d'études statistiques (Sies - Ministère en charge de l’enseignement supérieur) ;
- les sortants du système scolaire sont interrogés dans le cadre de l’enquête EVA de l’Insee.

"); - assertEquals(result.getString("historyNoteLg2"), "

A first sequence of EVA surveys had been carried out by Insee from 2005 to 2012 and collected from the young people of the Depp education panel who had entered the first year of secondary education in 1995.
This program was consisting of two parts :
- the schooling path of young people in secondary education and their higher education studies are observed by the Ministry for Education (Depp) ;
- and the data collection on young people who have left the education system is conducted by Insee, by the mean of the EVA survey.

This new sequence of EVA surveys relies on the following edition of the Depp panel, of young people who entered the first year of secondary education in 2007.
After two short surveys in 2013 and 2014 conducted by Insee, the situation of these young persons is observed each year by a survey named « de tronc commun ».
This program consists of three parts :
- the schooling path of young people in secondary education is observed by the Ministry for Education (Depp) ;
- the  higher education studies period is observed by the Ministry in charge of Higher Education (Sies) ;
- and the data collection on young people who have left the education system is conducted by Insee, by the mean of the EVA survey.

"); - } - - @Test - void should_return_no_series_for_search_if_unknown_stamp() throws RmesException { - OpSeriesQueries.setConfig(new ConfigStub()); - JSONArray result = repositoryGestion.getResponseAsArray(OpSeriesQueries.getSeriesForSearch("unknow_stamp")); - assertEquals(0, result.length()); - } - - @Test - void should_return_one_series_for_search() throws RmesException { - OpSeriesQueries.setConfig(new ConfigStub()); - JSONArray result = repositoryGestion.getResponseAsArray(OpSeriesQueries.getSeriesForSearch("stamp")); - assertEquals(1, result.length()); - } - - @Test - void should_return_all_series_for_search_if_not_defined_stamp() throws RmesException { - OpSeriesQueries.setConfig(new ConfigStub()); - JSONArray result = repositoryGestion.getResponseAsArray(OpSeriesQueries.getSeriesForSearch("")); - assertEquals(174, result.length()); + assertThat(result.getString("validationState")).hasToString("Validated"); + assertThat(result.getString("altLabelLg1")).hasToString("EVA"); + assertThat(result.getString("altLabelLg2")).hasToString("EVA"); + assertThat(result.getString("id")).hasToString("s1226"); + assertThat(result.getString("prefLabelLg1")).hasToString("Enquête sur l'entrée dans la vie adulte"); + assertThat(result.getString("prefLabelLg2")).hasToString("Survey on entry into adult life"); + assertThat(result.getString("abstractLg1")).hasToString("

L’objectif du dispositif sur l’entrée dans la vie adulte (EVA ) est d’observer l’entrée dans la vie adulte et l’insertion professionnelle des jeunes, au regard de leurs études.

Il permet de mettre en regard les informations sur les débuts de carrière et l’insertion professionnelle avec les cursus scolaires et universitaires détaillés et les projets formés pendant l’adolescence ou la jeunesse.

"); + assertThat(result.getString("abstractLg2")).hasToString("

The purpose of the EVA system is to observe the entry of young people into adult life and their professional integration in the light of their studies. The EVA system allows to link and compare informations about professional career beginning and professional integration to data related to detailed school and university pathways and plans made for the future during youth ages.

"); + assertThat(result.getString("historyNoteLg1")).hasToString("

Une première série d’enquêtes EVA avait été menée par l’Insee de 2005 à 2012 auprès des jeunes du panel de la Depp d’élèves du second degré entrés en 6e en 1995.
Ce dispositif se décomposait en deux volets :
- le parcours scolaire des jeunes dans le secondaire ainsi que leurs études supérieures sont suivis par la Direction de l'évaluation, de la prospective et de la performance (Depp - Ministère en charge de l’éducation) ;
- et les sortants du système scolaire sont interrogés dans le cadre de l’enquête EVA de l’Insee.

La nouvelle série d’enquêtes EVA s’appuie sur l’édition suivante du panel de la Depp, celle des entrants en 6e en 2007.
Après deux enquêtes légères en 2013 et 2014 réalisées par l’Insee, les jeunes sont suivis chaque année via une enquête dite de tronc commun.
Ce dispositif se décompose en trois volets :
 - le parcours scolaire des jeunes dans le secondaire est suivi par la  Direction de l'évaluation, de la prospective et de la performance (Depp - Ministère en charge de l’éducation) ;
- la période des études supérieures est suivie par le Système d'information et d'études statistiques (Sies - Ministère en charge de l’enseignement supérieur) ;
- les sortants du système scolaire sont interrogés dans le cadre de l’enquête EVA de l’Insee.

"); + assertThat(result.getString("historyNoteLg2")).hasToString("

A first sequence of EVA surveys had been carried out by Insee from 2005 to 2012 and collected from the young people of the Depp education panel who had entered the first year of secondary education in 1995.
This program was consisting of two parts :
- the schooling path of young people in secondary education and their higher education studies are observed by the Ministry for Education (Depp) ;
- and the data collection on young people who have left the education system is conducted by Insee, by the mean of the EVA survey.

This new sequence of EVA surveys relies on the following edition of the Depp panel, of young people who entered the first year of secondary education in 2007.
After two short surveys in 2013 and 2014 conducted by Insee, the situation of these young persons is observed each year by a survey named « de tronc commun ».
This program consists of three parts :
- the schooling path of young people in secondary education is observed by the Ministry for Education (Depp) ;
- the  higher education studies period is observed by the Ministry in charge of Higher Education (Sies) ;
- and the data collection on young people who have left the education system is conducted by Insee, by the mean of the EVA survey.

"); + } + + @CsvSource({ + "'unknow_stamp', 0", + "'stamp', 1", + "'', 174" + }) + @ParameterizedTest + void should_series_for_search_based_on_stamp(String stamp, int expectedLength) throws RmesException { + OpSeriesQueries.setConfig(new ConfigStub()); + JSONArray result = repositoryGestion.getResponseAsArray(OpSeriesQueries.getSeriesForSearch(stamp)); + assertEquals(expectedLength, result.length()); } @Test From 1417616107bf2822e5d39616f5b70b5f896de735 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Tue, 19 Nov 2024 13:58:29 +0000 Subject: [PATCH 19/19] feat: review --- .../operations/series/SeriesPublication.java | 38 ++++++++++++------- .../series/OpSeriesQueriesTest.java | 6 +-- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/operations/series/SeriesPublication.java b/src/main/java/fr/insee/rmes/bauhaus_services/operations/series/SeriesPublication.java index 86ad9d657..6092bc01c 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/operations/series/SeriesPublication.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/operations/series/SeriesPublication.java @@ -11,6 +11,7 @@ import fr.insee.rmes.exceptions.RmesNotFoundException; import fr.insee.rmes.persistance.ontologies.DCTERMS; import fr.insee.rmes.persistance.sparql_queries.operations.series.OpSeriesQueries; +import fr.insee.rmes.utils.JSONUtils; import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.model.Resource; import org.eclipse.rdf4j.model.Statement; @@ -31,6 +32,11 @@ public SeriesPublication(ParentUtils ownersUtils) { this.ownersUtils = ownersUtils; } + private static void checkIfSeriesExist(String id, RepositoryResult statements) throws RmesNotFoundException { + if (!statements.hasNext()) { + throw new RmesNotFoundException(ErrorCodes.SERIES_UNKNOWN_ID, "Series not found", id); + } + } public void publishSeries(String id, JSONObject series) throws RmesException { String familyId = series.getJSONObject(Constants.FAMILY).getString(Constants.ID); String status = ownersUtils.getValidationStatus(familyId); @@ -48,14 +54,13 @@ public void publishSeries(String id, JSONObject series) throws RmesException { RepositoryConnection con = repoGestion.getConnection(); RepositoryResult statements = repoGestion.getStatements(con, resource); + checkIfSeriesExist(id, statements); + RepositoryResult hasPartStatements = repoGestion.getHasPartStatements(con, resource); RepositoryResult replacesStatements = repoGestion.getReplacesStatements(con, resource); RepositoryResult isReplacedByStatements = repoGestion.getIsReplacedByStatements(con, resource); try { - if (!statements.hasNext()) { - throw new RmesNotFoundException(ErrorCodes.SERIES_UNKNOWN_ID, "Series not found", id); - } while (statements.hasNext()) { Statement st = statements.next(); String pred = RdfUtils.toString(st.getPredicate()); @@ -92,17 +97,7 @@ public void publishSeries(String id, JSONObject series) throws RmesException { /** * We have to query all published operations linked to this series and publish all of them */ - JSONArray operations = repoGestion.getResponseAsArray(OpSeriesQueries.getPublishedOperationsForSeries(resource.toString())); - for (var i = 0; i < operations.length(); i++) { - JSONObject operation = operations.getJSONObject(i); - String iri = operation.getString("operation"); - model.add( - publicationUtils.tranformBaseURIToPublish(resource), - DCTERMS.HAS_PART, - publicationUtils.tranformBaseURIToPublish(RdfUtils.createIRI(iri)), - RdfUtils.operationsGraph() - ); - } + addOperationsWhoHavePartWithToModel(resource, model); } finally { @@ -115,6 +110,21 @@ public void publishSeries(String id, JSONObject series) throws RmesException { } + + private void addOperationsWhoHavePartWithToModel(Resource resource, Model model) throws RmesException { + JSONArray operations = repoGestion.getResponseAsArray(OpSeriesQueries.getPublishedOperationsForSeries(resource.toString())); + JSONUtils.stream(operations) + .map(operation -> operation.getString("operation")) + .forEach(iri -> { + model.add( + publicationUtils.tranformBaseURIToPublish(resource), + DCTERMS.HAS_PART, + publicationUtils.tranformBaseURIToPublish(RdfUtils.createIRI(iri)), + RdfUtils.operationsGraph() + ); + }); + } + public void addStatementsToModel(Model model, RepositoryResult statements) { while (statements.hasNext()) { Statement statement = statements.next(); diff --git a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java index 9cf4033f9..d468e67d1 100644 --- a/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java +++ b/src/test/java/fr/insee/rmes/testcontainers/queries/sparql_queries/operations/series/OpSeriesQueriesTest.java @@ -7,6 +7,7 @@ import fr.insee.rmes.exceptions.RmesException; import fr.insee.rmes.persistance.sparql_queries.operations.series.OpSeriesQueries; import fr.insee.rmes.testcontainers.queries.WithGraphDBContainer; +import fr.insee.rmes.utils.JSONUtils; import org.json.JSONArray; import org.json.JSONObject; import org.junit.jupiter.api.BeforeAll; @@ -135,10 +136,7 @@ void should_return_all_series() throws Exception { OpSeriesQueries.setConfig(new ConfigStub()); JSONArray result = repositoryGestion.getResponseAsArray(OpSeriesQueries.seriesWithSimsQuery()); assertEquals(174, result.length()); - - for (var i = 0; i < result.length(); i++){ - assertNotNull(result.getJSONObject(i).getString("iri")); - } + JSONUtils.stream(result).forEach(object -> assertNotNull(object.getString("iri"))); } @Test