diff --git a/compose.yaml b/compose.yaml index e1e9ce0e5..a429272c9 100644 --- a/compose.yaml +++ b/compose.yaml @@ -4,10 +4,12 @@ services: build: . ports: - "8080:8080" + environment: + - fr.insee.rmes.bauhaus.sesame.gestion.sesameServer=http://graphdb:7200 links: - - graphdb:localhost + - graphdb graphdb: - image: ontotext/graphdb:latest + image: ontotext/graphdb:10.6.4 restart: always ports: - "7200:7200" 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/bauhaus_services/operations/series/SeriesPublication.java b/src/main/java/fr/insee/rmes/bauhaus_services/operations/series/SeriesPublication.java index e7e79bbfb..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 @@ -5,110 +5,139 @@ 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 org.apache.http.HttpStatus; +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 fr.insee.rmes.utils.JSONUtils; 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; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; @Repository public class SeriesPublication extends RdfService { - - @Autowired - 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); - 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); - } - - 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); - - try { - try { - if (!statements.hasNext()) { - throw new RmesNotFoundException(ErrorCodes.SERIES_UNKNOWN_ID,"Series not found", seriesId); - } - 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); - - } - } 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(series); - 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; + } + + 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); + + 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); + + checkIfSeriesExist(id, statements); + + RepositoryResult hasPartStatements = repoGestion.getHasPartStatements(con, resource); + RepositoryResult replacesStatements = repoGestion.getReplacesStatements(con, resource); + RepositoryResult isReplacedByStatements = repoGestion.getIsReplacedByStatements(con, resource); + + try { + 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 + */ + addOperationsWhoHavePartWithToModel(resource, model); + + + } finally { + repoGestion.closeStatements(statements); + repoGestion.closeStatements(hasPartStatements); + con.close(); + } + Resource seriesToPublishRessource = publicationUtils.tranformBaseURIToPublish(resource); + repositoryPublication.publishResource(seriesToPublishRessource, model, "serie"); + + } + + + 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(); + 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/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); + } } 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; } - } 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 4fe423fcb..d6f8b5362 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; @@ -27,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") 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/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) { 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/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..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 @@ -4,24 +4,131 @@ 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 fr.insee.rmes.utils.JSONUtils; import org.json.JSONArray; 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.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +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 static void initData(){ container.withTrigFiles("all-operations-and-indicators.trig"); + container.withTrigFiles("sims-all.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_series() throws Exception { + OpSeriesQueries.setConfig(new ConfigStub()); + JSONObject result = repositoryGestion.getResponseAsObject(OpSeriesQueries.oneSeriesQuery("s1226", false)); + 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 + 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_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_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_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 @@ -29,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 @@ -48,4 +152,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/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) diff --git a/src/test/resources/testcontainers/all-operations-and-indicators.trig b/src/test/resources/testcontainers/all-operations-and-indicators.trig index 23f2d09fc..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 ; @@ -5035,7 +5037,7 @@ "2011" ; - "Validated" ; + "Unpublished" ; "EnDD 2011"@en , "EnDD 2011"@fr ;