From f187a7e4b9184de0c2c2581a2adb008756134f82 Mon Sep 17 00:00:00 2001 From: Alice Lambois Date: Wed, 5 Aug 2020 09:31:41 +0200 Subject: [PATCH 1/9] Initialize v2.1.0 (fix bug with 2.0.0 and add new dev) --- pom.xml | 20 +------------------ .../rmes/config/swagger/SwaggerConfig.java | 2 +- .../rmes/webservice/DocumentsResources.java | 2 ++ .../rmes/webservice/GeographyResources.java | 3 ++- .../rmes/webservice/OperationsResources.java | 3 ++- .../rmes/webservice/StructureResources.java | 2 ++ .../structures/utils/StructureUtilsTest.java | 10 ++++------ 7 files changed, 14 insertions(+), 28 deletions(-) diff --git a/pom.xml b/pom.xml index 9eec591b2..2586d2c4c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ fr.insee.rmes Bauhaus-BO war - 2.0.0 + 2.1.0 Bauhaus-Back-Office Back-office services for Bauhaus https://github.com/InseeFr/Bauhaus-Back-Office @@ -441,24 +441,6 @@ - - - maven-surefire-plugin - 2.22.2 - - - **/*Test.java - - - - - org.junit.platform - junit-platform-surefire-provider - 1.3.2 - - - - org.jacoco diff --git a/src/main/java/fr/insee/rmes/config/swagger/SwaggerConfig.java b/src/main/java/fr/insee/rmes/config/swagger/SwaggerConfig.java index 951c92e01..e6c36ba4c 100644 --- a/src/main/java/fr/insee/rmes/config/swagger/SwaggerConfig.java +++ b/src/main/java/fr/insee/rmes/config/swagger/SwaggerConfig.java @@ -28,7 +28,7 @@ public SwaggerConfig(@Context ServletConfig servletConfig) { super(); OpenAPI openApi = new OpenAPI(); - Info info = new Info().title("Bauhaus API").version("2.0.0").description("Rest Endpoints and services Integration used by Bauhaus"); + Info info = new Info().title("Bauhaus API").version("2.1.0").description("Rest Endpoints and services Integration used by Bauhaus"); openApi.info(info); Server server = new Server(); diff --git a/src/main/java/fr/insee/rmes/webservice/DocumentsResources.java b/src/main/java/fr/insee/rmes/webservice/DocumentsResources.java index d63f693fb..0e6fbc8cd 100644 --- a/src/main/java/fr/insee/rmes/webservice/DocumentsResources.java +++ b/src/main/java/fr/insee/rmes/webservice/DocumentsResources.java @@ -29,6 +29,7 @@ import fr.insee.rmes.config.auth.roles.Roles; import fr.insee.rmes.exceptions.RmesException; import fr.insee.rmes.model.operations.documentations.Document; +import io.swagger.v3.oas.annotations.Hidden; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.ArraySchema; @@ -44,6 +45,7 @@ * * */ +@Hidden @Component @Path("/documents") @Tag(name="Document", description="Document API") diff --git a/src/main/java/fr/insee/rmes/webservice/GeographyResources.java b/src/main/java/fr/insee/rmes/webservice/GeographyResources.java index d5ed21bb0..1698c310c 100644 --- a/src/main/java/fr/insee/rmes/webservice/GeographyResources.java +++ b/src/main/java/fr/insee/rmes/webservice/GeographyResources.java @@ -21,6 +21,7 @@ import fr.insee.rmes.config.auth.roles.Roles; import fr.insee.rmes.exceptions.RmesException; import fr.insee.rmes.model.geography.GeoFeature; +import io.swagger.v3.oas.annotations.Hidden; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; @@ -29,7 +30,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; - +@Hidden @Component @Path("/geo") @Tag(name="Geography", description="Geography API") diff --git a/src/main/java/fr/insee/rmes/webservice/OperationsResources.java b/src/main/java/fr/insee/rmes/webservice/OperationsResources.java index c6bca19c5..716c273c8 100644 --- a/src/main/java/fr/insee/rmes/webservice/OperationsResources.java +++ b/src/main/java/fr/insee/rmes/webservice/OperationsResources.java @@ -38,6 +38,7 @@ import fr.insee.rmes.model.operations.Operation; import fr.insee.rmes.model.operations.Series; import fr.insee.rmes.model.operations.documentations.Documentation; +import io.swagger.v3.oas.annotations.Hidden; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; @@ -47,7 +48,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; - +@Hidden @Component @Path("/operations") @Tag(name="Operations", description="Operation API") diff --git a/src/main/java/fr/insee/rmes/webservice/StructureResources.java b/src/main/java/fr/insee/rmes/webservice/StructureResources.java index c9f180517..bc4a4d908 100644 --- a/src/main/java/fr/insee/rmes/webservice/StructureResources.java +++ b/src/main/java/fr/insee/rmes/webservice/StructureResources.java @@ -21,6 +21,7 @@ import fr.insee.rmes.config.swagger.model.structure.StructureById; import fr.insee.rmes.exceptions.RmesException; import fr.insee.rmes.model.structures.Structure; +import io.swagger.v3.oas.annotations.Hidden; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; @@ -30,6 +31,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; +@Hidden @Component @Path("/structures") @Tag(name = "Data structure definitions", description = "Structure API") diff --git a/src/test/java/fr/insee/rmes/bauhaus_services/structures/utils/StructureUtilsTest.java b/src/test/java/fr/insee/rmes/bauhaus_services/structures/utils/StructureUtilsTest.java index d2be9ef1d..c7a17db77 100644 --- a/src/test/java/fr/insee/rmes/bauhaus_services/structures/utils/StructureUtilsTest.java +++ b/src/test/java/fr/insee/rmes/bauhaus_services/structures/utils/StructureUtilsTest.java @@ -1,7 +1,6 @@ package fr.insee.rmes.bauhaus_services.structures.utils; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; @@ -10,7 +9,6 @@ import java.util.ArrayList; import java.util.List; -import fr.insee.rmes.config.Config; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.model.Resource; @@ -18,15 +16,15 @@ import org.eclipse.rdf4j.model.impl.SimpleValueFactory; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.*; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; import fr.insee.rmes.bauhaus_services.rdf_utils.RepositoryGestion; import fr.insee.rmes.exceptions.RmesException; import fr.insee.rmes.model.structures.ComponentDefinition; import fr.insee.rmes.model.structures.MutualizedComponent; -import fr.insee.rmes.model.structures.Structure; -import fr.insee.rmes.utils.DateUtils; -import org.springframework.core.env.Environment; class StructureUtilsTest { From 74392fcd97796fef6fe412acd6c1d225b1f056d6 Mon Sep 17 00:00:00 2001 From: Alice Lambois Date: Wed, 5 Aug 2020 11:51:17 +0200 Subject: [PATCH 2/9] Fix issue with concept's update --- .../concepts/concepts/ConceptsUtils.java | 14 ++++++++----- .../publication/ConceptsPublication.java | 4 ++-- .../bauhaus_services/notes/NoteManager.java | 21 +++++++++++-------- .../bauhaus_services/notes/NotesUtils.java | 2 ++ 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/concepts/concepts/ConceptsUtils.java b/src/main/java/fr/insee/rmes/bauhaus_services/concepts/concepts/ConceptsUtils.java index fbe508122..3940ad148 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/concepts/concepts/ConceptsUtils.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/concepts/concepts/ConceptsUtils.java @@ -44,18 +44,22 @@ import fr.insee.rmes.utils.JSONUtils; @Component -public class ConceptsUtils extends RdfService { +public class ConceptsUtils extends RdfService { - static final Logger logger = LogManager.getLogger(ConceptsUtils.class); + private static final Logger logger = LogManager.getLogger(ConceptsUtils.class); @Autowired ConceptsPublication conceptsPublication; + + @Autowired + NoteManager noteManager; /** * Concepts + * @throws RmesException */ - public String createID() throws RmesException{ + public String createID() throws RmesException { JSONObject json = repoGestion.getResponseAsObject(ConceptsQueries.lastConceptID()); String notation = json.getString("notation"); int id = Integer.parseInt(notation.substring(1))+1; @@ -85,7 +89,7 @@ public String setConcept(String body) throws RmesException { ObjectMapper mapper = new ObjectMapper(); mapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - Concept concept = null; + Concept concept = new Concept(); try { concept = mapper.readValue(body, Concept.class); } catch (IOException e) { @@ -156,7 +160,7 @@ public void createRdfConcept(Concept concept) throws RmesException { RdfUtils.addTripleDateTime(conceptURI, DCTERMS.MODIFIED, concept.getModified(), model, RdfUtils.conceptGraph()); // Add notes to model, delete some notes and updates some other notes - List> notesToDeleteAndUpdate = new NoteManager().setNotes(concept, model); + List> notesToDeleteAndUpdate = noteManager.setNotes(concept, model); // Add links to model and save member links new LinksUtils().createRdfLinks(conceptURI, concept.getLinks(), model); diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/concepts/publication/ConceptsPublication.java b/src/main/java/fr/insee/rmes/bauhaus_services/concepts/publication/ConceptsPublication.java index 4c8c23e7b..362ee09c9 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/concepts/publication/ConceptsPublication.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/concepts/publication/ConceptsPublication.java @@ -15,7 +15,7 @@ import org.eclipse.rdf4j.repository.RepositoryResult; import org.json.JSONArray; import org.jsoup.Jsoup; -import org.springframework.stereotype.Repository; +import org.springframework.stereotype.Component; import fr.insee.rmes.bauhaus_services.Constants; import fr.insee.rmes.bauhaus_services.rdf_utils.PublicationUtils; @@ -28,7 +28,7 @@ import fr.insee.rmes.persistance.ontologies.XKOS; import fr.insee.rmes.persistance.sparql_queries.concepts.ConceptsQueries; -@Repository +@Component public class ConceptsPublication extends RdfService{ diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/notes/NoteManager.java b/src/main/java/fr/insee/rmes/bauhaus_services/notes/NoteManager.java index 5af7ffb69..6f988b81f 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/notes/NoteManager.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/notes/NoteManager.java @@ -7,6 +7,8 @@ import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Model; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import fr.insee.rmes.bauhaus_services.rdf_utils.RdfUtils; import fr.insee.rmes.exceptions.RmesException; @@ -16,11 +18,13 @@ import fr.insee.rmes.model.notes.concepts.ConceptsDatedNoteTypes; import fr.insee.rmes.model.notes.concepts.ConceptsVersionnedNoteTypes; +@Component public class NoteManager { + + @Autowired + NotesUtils noteUtils; public List> setNotes(Concept concept, Model model) throws RmesException { - - NotesUtils noteUtils = new NotesUtils(); // TODO : see extreme cases to close notes List versionableNotes = concept.getVersionableNotes(); @@ -34,7 +38,7 @@ public List> setNotes(Concept concept, Model model) throws RmesExcepti Set versionableNoteTypesInConcept = new HashSet<>(); - setVersionableNotes(concept, model, noteUtils, versionableNotes, conceptId, conceptVersion, notesToDelete, + setVersionableNotes(concept, model, versionableNotes, conceptId, conceptVersion, notesToDelete, versionableNoteTypesInConcept); Set versionableNoteTypes = new HashSet<>(); @@ -42,9 +46,9 @@ public List> setNotes(Concept concept, Model model) throws RmesExcepti versionableNoteTypes.add(c.toString()); } versionableNoteTypes.removeAll(versionableNoteTypesInConcept); - setVersionableNoteTypes(concept, model, noteUtils, conceptId, conceptVersion, versionableNoteTypes); + setVersionableNoteTypes(concept, model, conceptId, conceptVersion, versionableNoteTypes); - setDatableNotes(concept, model, noteUtils, datableNotes, conceptId, notesToDelete); + setDatableNotes(concept, model, datableNotes, conceptId, notesToDelete); // Keep historical notes noteUtils.keepHistoricalNotes(conceptId, conceptVersion, model); @@ -57,8 +61,7 @@ public List> setNotes(Concept concept, Model model) throws RmesExcepti } - private void setVersionableNotes(Concept concept, Model model, NotesUtils noteUtils, - List versionableNotes, String conceptId, String conceptVersion, List notesToDelete, + private void setVersionableNotes(Concept concept, Model model, List versionableNotes, String conceptId, String conceptVersion, List notesToDelete, Set versionableNoteTypesInConcept) throws RmesException { for (VersionableNote versionableNote : versionableNotes) { versionableNoteTypesInConcept.add(versionableNote.getNoteType()); @@ -85,7 +88,7 @@ private void setVersionableNotes(Concept concept, Model model, NotesUtils noteUt } } - private void setDatableNotes(Concept concept, Model model, NotesUtils noteUtils, List datableNotes, + private void setDatableNotes(Concept concept, Model model, List datableNotes, String conceptId, List notesToDelete) throws RmesException { for (DatableNote datableNote : datableNotes) { for (ConceptsDatedNoteTypes c : ConceptsDatedNoteTypes.values()) { @@ -101,7 +104,7 @@ private void setDatableNotes(Concept concept, Model model, NotesUtils noteUtils, } } - private void setVersionableNoteTypes(Concept concept, Model model, NotesUtils noteUtils, String conceptId, + private void setVersionableNoteTypes(Concept concept, Model model, String conceptId, String conceptVersion, Set versionableNoteTypes) throws RmesException { for (String noteType : versionableNoteTypes) { ConceptsVersionnedNoteTypes versionnedNoteType = ConceptsVersionnedNoteTypes.getByName(noteType); diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/notes/NotesUtils.java b/src/main/java/fr/insee/rmes/bauhaus_services/notes/NotesUtils.java index c9088dedc..7bcac66d4 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/notes/NotesUtils.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/notes/NotesUtils.java @@ -9,6 +9,7 @@ import org.eclipse.rdf4j.model.vocabulary.RDF; import org.json.JSONArray; import org.json.JSONObject; +import org.springframework.stereotype.Component; import fr.insee.rmes.bauhaus_services.rdf_utils.RdfService; import fr.insee.rmes.bauhaus_services.rdf_utils.RdfUtils; @@ -22,6 +23,7 @@ import fr.insee.rmes.persistance.ontologies.XKOS; import fr.insee.rmes.persistance.sparql_queries.notes.NotesQueries; +@Component public class NotesUtils extends RdfService { private static final String ONE = "1"; From 8c9c3d4a2ee03e48e417cbb179736b02b2a8bf88 Mon Sep 17 00:00:00 2001 From: Alice Lambois Date: Wed, 5 Aug 2020 13:23:42 +0200 Subject: [PATCH 3/9] Fix issue with publication --- .../concepts/publication/ConceptsPublication.java | 4 ++-- .../operations/families/FamilyPublication.java | 2 +- .../operations/indicators/IndicatorPublication.java | 2 +- .../operations/operations/OperationPublication.java | 2 +- .../operations/series/SeriesPublication.java | 2 +- .../bauhaus_services/rdf_utils/PublicationUtils.java | 12 ------------ .../rdf_utils/RepositoryGestion.java | 4 ++++ .../bauhaus_services/rdf_utils/RepositoryUtils.java | 1 + 8 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/concepts/publication/ConceptsPublication.java b/src/main/java/fr/insee/rmes/bauhaus_services/concepts/publication/ConceptsPublication.java index 362ee09c9..32d8c841b 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/concepts/publication/ConceptsPublication.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/concepts/publication/ConceptsPublication.java @@ -45,7 +45,7 @@ public void publishConcepts(JSONArray conceptsToPublish) throws RmesException { checkTopConceptOf(conceptId, model); Resource concept = RdfUtils.conceptIRI(conceptId); - RepositoryConnection con =PublicationUtils.getRepositoryConnectionGestion(); + RepositoryConnection con = repoGestion.getConnection(); RepositoryResult statements = repoGestion.getStatements(con, concept); String[] notes = {"scopeNote","definition","editorialNote"} ; @@ -195,7 +195,7 @@ public void publishCollection(JSONArray collectionsToValidate) throws RmesExcept Resource collection = RdfUtils.collectionIRI(collectionId); //TODO uncomment when we can notify... //Boolean creation = !RepositoryPublication.getResponseAsBoolean(CollectionsQueries.isCollectionExist(collectionId)); - RepositoryConnection con = PublicationUtils.getRepositoryConnectionGestion(); + RepositoryConnection con = repoGestion.getConnection(); RepositoryResult statements = repoGestion.getStatements(con, collection); try { diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/operations/families/FamilyPublication.java b/src/main/java/fr/insee/rmes/bauhaus_services/operations/families/FamilyPublication.java index 24362ab7c..ab429e591 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/operations/families/FamilyPublication.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/operations/families/FamilyPublication.java @@ -31,7 +31,7 @@ public void publishFamily(String familyId) throws RmesException { Model model = new LinkedHashModel(); Resource family = RdfUtils.familyIRI(familyId); //TODO notify... - RepositoryConnection con = PublicationUtils.getRepositoryConnectionGestion(); + RepositoryConnection con = repoGestion.getConnection(); RepositoryResult statements = repoGestion.getStatements(con, family); try { diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/operations/indicators/IndicatorPublication.java b/src/main/java/fr/insee/rmes/bauhaus_services/operations/indicators/IndicatorPublication.java index 335e5faf3..0c6c1b2d8 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/operations/indicators/IndicatorPublication.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/operations/indicators/IndicatorPublication.java @@ -33,7 +33,7 @@ public void publishIndicator(String indicatorId) throws RmesException { Resource indicator= RdfUtils.objectIRI(ObjectType.INDICATOR,indicatorId); //TODO notify... - RepositoryConnection con = PublicationUtils.getRepositoryConnectionGestion(); + RepositoryConnection con = repoGestion.getConnection(); RepositoryResult statements = repoGestion.getStatements(con, indicator); try { diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/operations/operations/OperationPublication.java b/src/main/java/fr/insee/rmes/bauhaus_services/operations/operations/OperationPublication.java index 8b0d7536c..95aa3d6cb 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/operations/operations/OperationPublication.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/operations/operations/OperationPublication.java @@ -44,7 +44,7 @@ public void publishOperation(String operationId) throws RmesException { checkSeriesIsPublished(operationId, operationJson); - RepositoryConnection con = PublicationUtils.getRepositoryConnectionGestion(); + RepositoryConnection con = repoGestion.getConnection(); RepositoryResult statements = repoGestion.getStatements(con, operation); try { 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 446c4778b..7896862d1 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 @@ -52,7 +52,7 @@ public void publishSeries(String seriesId) throws RmesException { "Series: "+seriesId+" ; Family: "+familyId); } - RepositoryConnection con = PublicationUtils.getRepositoryConnectionGestion(); + RepositoryConnection con = repoGestion.getConnection(); RepositoryResult statements = repoGestion.getStatements(con, series); RepositoryResult hasPartStatements = repoGestion.getHasPartStatements(con, series); diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/PublicationUtils.java b/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/PublicationUtils.java index 92d208621..dbdeeb548 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/PublicationUtils.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/PublicationUtils.java @@ -3,21 +3,12 @@ import java.util.Arrays; import org.eclipse.rdf4j.model.Resource; -import org.eclipse.rdf4j.repository.RepositoryConnection; -import org.springframework.beans.factory.annotation.Autowired; import fr.insee.rmes.bauhaus_services.Constants; import fr.insee.rmes.config.Config; -import fr.insee.rmes.exceptions.RmesException; import fr.insee.rmes.model.ValidationStatus; public abstract class PublicationUtils { - - @Autowired - static RepositoryUtils repoUtils; - - @Autowired - protected static RepositoryGestion repoGestion; private PublicationUtils() { throw new IllegalStateException("Utility class"); @@ -36,7 +27,4 @@ public static boolean isPublished(String status) { return status.equals(ValidationStatus.UNPUBLISHED.getValue()) || status.equals(Constants.UNDEFINED); } - public static RepositoryConnection getRepositoryConnectionGestion() throws RmesException { - return repoUtils.getConnection(RepositoryGestion.REPOSITORY_GESTION); - } } diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryGestion.java b/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryGestion.java index 4a42ba1c1..7fdb56f73 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryGestion.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryGestion.java @@ -365,4 +365,8 @@ public void loadSimpleObject(IRI geoIRI, Model model) throws RmesException { loadSimpleObject(geoIRI, model, null); } + public RepositoryConnection getConnection() throws RmesException { + return getConnection(RepositoryGestion.REPOSITORY_GESTION); + } + } diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryUtils.java b/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryUtils.java index 3d78bfcb0..eda3ac5de 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryUtils.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryUtils.java @@ -30,6 +30,7 @@ public abstract class RepositoryUtils { private static final String BINDINGS = "bindings"; private static final String RESULTS = "results"; private static final String EXECUTE_QUERY_FAILED = "Execute query failed : "; + static final Logger logger = LogManager.getLogger(RepositoryUtils.class); From 7e9e828aa823e067bf89b24b36d7b3f2e3077077 Mon Sep 17 00:00:00 2001 From: Alice Lambois Date: Wed, 5 Aug 2020 13:39:29 +0200 Subject: [PATCH 4/9] Right query to get notes --- .../sparql_queries/concepts/ConceptsQueries.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/insee/rmes/persistance/sparql_queries/concepts/ConceptsQueries.java b/src/main/java/fr/insee/rmes/persistance/sparql_queries/concepts/ConceptsQueries.java index ea67124b5..1d2f5504c 100644 --- a/src/main/java/fr/insee/rmes/persistance/sparql_queries/concepts/ConceptsQueries.java +++ b/src/main/java/fr/insee/rmes/persistance/sparql_queries/concepts/ConceptsQueries.java @@ -125,8 +125,9 @@ public static String altLabel(String id, String lang) { public static String conceptNotesQuery(String id, int conceptVersion) { return "SELECT ?definitionLg1 ?definitionLg2 ?scopeNoteLg1 ?scopeNoteLg2 " + "?editorialNoteLg1 ?editorialNoteLg2 ?changeNoteLg1 ?changeNoteLg2 \n" - + "WHERE { \n" - + "?concept skos:notation '" + id + "' . \n" + + "WHERE { GRAPH <"+Config.CONCEPTS_GRAPH+"> { \n" + + "?concept skos:prefLabel ?prefLabelLg1 . \n" + + "FILTER(REGEX(STR(?concept),'/concepts/definition/" + id + "')) . \n" + "BIND(STRAFTER(STR(?concept),'/definition/') AS ?id) . \n" // Def Lg1 + "OPTIONAL {?concept skos:definition ?defLg1 . \n" @@ -174,7 +175,7 @@ public static String conceptNotesQuery(String id, int conceptVersion) { + "?noteChangeLg2 dcterms:language '" + Config.LG2 + "'^^xsd:language . \n" + "?noteChangeLg2 evoc:noteLiteral ?changeNoteLg2 . \n" + "?noteChangeLg2 insee:conceptVersion '" + conceptVersion + "'^^xsd:int} . \n" - + "} \n"; + + "}} \n"; } public static String conceptLinks(String id) { From 50433bef967ce4995b37a188cab6cd72eb5d55d9 Mon Sep 17 00:00:00 2001 From: Alice Lambois Date: Fri, 7 Aug 2020 10:53:54 +0200 Subject: [PATCH 5/9] Fix minor issue --- .../persistance/sparql_queries/concepts/ConceptsQueries.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/insee/rmes/persistance/sparql_queries/concepts/ConceptsQueries.java b/src/main/java/fr/insee/rmes/persistance/sparql_queries/concepts/ConceptsQueries.java index 1d2f5504c..624180cbf 100644 --- a/src/main/java/fr/insee/rmes/persistance/sparql_queries/concepts/ConceptsQueries.java +++ b/src/main/java/fr/insee/rmes/persistance/sparql_queries/concepts/ConceptsQueries.java @@ -23,7 +23,7 @@ public static String lastConceptID() { + "?concept skos:notation ?notation .\n" + "BIND(SUBSTR( STR(?notation) , 2 ) AS ?id) . }} \n" + "ORDER BY DESC(xsd:integer(?id)) \n" - + "LIMIT1"; + + "LIMIT 1"; } From 9a210b246d131d5163158eea26e3eca4c8f68b8c Mon Sep 17 00:00:00 2001 From: Alice Lambois Date: Fri, 7 Aug 2020 11:50:55 +0200 Subject: [PATCH 6/9] Fix issue in concept's creation --- .../concepts/concepts/ConceptsUtils.java | 42 ++++++++++--------- .../fr/insee/rmes/model/concepts/Concept.java | 30 ++++++------- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/concepts/concepts/ConceptsUtils.java b/src/main/java/fr/insee/rmes/bauhaus_services/concepts/concepts/ConceptsUtils.java index 3940ad148..9b78ca521 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/concepts/concepts/ConceptsUtils.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/concepts/concepts/ConceptsUtils.java @@ -49,15 +49,11 @@ public class ConceptsUtils extends RdfService { private static final Logger logger = LogManager.getLogger(ConceptsUtils.class); @Autowired - ConceptsPublication conceptsPublication; + private ConceptsPublication conceptsPublication; @Autowired - NoteManager noteManager; + private NoteManager noteManager; - /** - * Concepts - * @throws RmesException - */ public String createID() throws RmesException { JSONObject json = repoGestion.getResponseAsObject(ConceptsQueries.lastConceptID()); @@ -82,39 +78,47 @@ public JSONObject getConceptById(String id) throws RmesException{ return concept; } + /** + * CREATION + * @param body + * @return + * @throws RmesException + */ public String setConcept(String body) throws RmesException { if(!stampsRestrictionsService.canCreateConcept()) { throw new RmesUnauthorizedException(ErrorCodes.CONCEPT_CREATION_RIGHTS_DENIED, "Only an admin or concepts manager can create a new concept."); } - ObjectMapper mapper = new ObjectMapper(); - mapper.configure( - DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - Concept concept = new Concept(); - try { - concept = mapper.readValue(body, Concept.class); - } catch (IOException e) { - throw new RmesException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), "IOException"); - } - createRdfConcept(concept); + Concept concept = setConcept(createID(), true, body); logger.info("Create concept : {} - {}", concept.getId() , concept.getPrefLabelLg1()); return concept.getId(); } + /** + * UPDATE + * @param id + * @param body + * @throws RmesException + */ public void setConcept(String id, String body) throws RmesException { if(!stampsRestrictionsService.canModifyConcept(RdfUtils.conceptIRI(id))) { throw new RmesUnauthorizedException(ErrorCodes.CONCEPT_MODIFICATION_RIGHTS_DENIED, ""); } + Concept concept = setConcept(id, false, body); + logger.info("Update concept : {} - {}" , concept.getId() , concept.getPrefLabelLg1()); + } + + private Concept setConcept(String id, boolean isNewConcept, String body) throws RmesException { ObjectMapper mapper = new ObjectMapper(); mapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - Concept concept = new Concept(id); + Concept concept = new Concept(id, isNewConcept); try { - concept = mapper.readerForUpdating(concept).readValue(body); + concept = mapper.readerForUpdating(concept).readValue(body); } catch (IOException e) { throw new RmesException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), "IOException"); } createRdfConcept(concept); - logger.info("Update concept : {} - {}" , concept.getId() , concept.getPrefLabelLg1()); + return concept; } public void conceptsValidation(String body) throws RmesException { diff --git a/src/main/java/fr/insee/rmes/model/concepts/Concept.java b/src/main/java/fr/insee/rmes/model/concepts/Concept.java index f8e59279b..d8be742b6 100644 --- a/src/main/java/fr/insee/rmes/model/concepts/Concept.java +++ b/src/main/java/fr/insee/rmes/model/concepts/Concept.java @@ -3,8 +3,6 @@ import java.time.LocalDateTime; import java.util.List; -import fr.insee.rmes.bauhaus_services.concepts.concepts.ConceptsUtils; -import fr.insee.rmes.exceptions.RmesException; import fr.insee.rmes.model.links.Link; import fr.insee.rmes.model.notes.DatableNote; import fr.insee.rmes.model.notes.VersionableNote; @@ -31,24 +29,24 @@ public class Concept { private Boolean versioning; - // create empty lists for altLabels and Notes in the constructors ? - - public Concept() throws RmesException { - this.id = new ConceptsUtils().createID(); - this.created = LocalDateTime.now().toString(); - this.modified = LocalDateTime.now().toString(); - this.isValidated = "false"; - this.creation = true; - this.versioning = false; - } - - public Concept(String id) { + public Concept(String id, boolean isNew) { this.id = id; this.modified = LocalDateTime.now().toString(); this.isValidated = "false"; - this.creation = false; + + if (isNew) { + this.created = LocalDateTime.now().toString(); + this.isValidated = "false"; + this.creation = true; + this.versioning = false; + }else { + this.creation = false; + + } } + + public String getCreated() { return created; @@ -125,4 +123,6 @@ public Boolean getCreation() { public Boolean getVersioning() { return versioning; } + + } From 44acbfff70d41aecd3478236eff91e2ed5cbc839 Mon Sep 17 00:00:00 2001 From: Alice Lambois Date: Fri, 7 Aug 2020 14:53:23 +0200 Subject: [PATCH 7/9] Fix issue with links --- .../rmes/bauhaus_services/links/LinksUtils.java | 8 ++++---- .../sparql_queries/concepts/ConceptsQueries.java | 14 +++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/links/LinksUtils.java b/src/main/java/fr/insee/rmes/bauhaus_services/links/LinksUtils.java index 1d0cb8081..71266ff45 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/links/LinksUtils.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/links/LinksUtils.java @@ -22,16 +22,16 @@ public void createRdfLinks(IRI conceptURI, List links, Model model) { if (link.getTypeOfLink().equals("narrower")) { addTripleNarrower(conceptURI, link.getIds(), model); } - if (link.getTypeOfLink().equals("broader")) { + else if (link.getTypeOfLink().equals("broader")) { addTripleBroader(conceptURI, link.getIds(), model); } - if (link.getTypeOfLink().equals("references")) { + else if (link.getTypeOfLink().equals("references")) { addTripleReferences(conceptURI, link.getIds(), model); } - if (link.getTypeOfLink().equals("succeed")) { + else if (link.getTypeOfLink().equals("succeed")) { addTripleSucceed(conceptURI, link.getIds(), model); } - if (link.getTypeOfLink().equals("related")) { + else if (link.getTypeOfLink().equals("related")) { addTripleRelated(conceptURI, link.getIds(), model); } }); diff --git a/src/main/java/fr/insee/rmes/persistance/sparql_queries/concepts/ConceptsQueries.java b/src/main/java/fr/insee/rmes/persistance/sparql_queries/concepts/ConceptsQueries.java index 624180cbf..ead10d8d5 100644 --- a/src/main/java/fr/insee/rmes/persistance/sparql_queries/concepts/ConceptsQueries.java +++ b/src/main/java/fr/insee/rmes/persistance/sparql_queries/concepts/ConceptsQueries.java @@ -180,14 +180,18 @@ public static String conceptNotesQuery(String id, int conceptVersion) { public static String conceptLinks(String id) { return "SELECT ?id ?typeOfLink ?prefLabelLg1 ?prefLabelLg2 \n" - + "WHERE { \n" - + "?concept skos:notation '" + id + "' . \n" + + "WHERE { GRAPH <"+Config.CONCEPTS_GRAPH+"> { \n" + + "?concept rdf:type skos:Concept . \n" + + "FILTER(REGEX(STR(?concept),'/concepts/definition/" + id + "')) . \n" + + //TODO Note for later : why "?concept skos:notation '" + id + "' . \n" doesn't work anymore ??? + + "{?concept skos:narrower ?conceptlinked . \n" - + "BIND('broader' AS ?typeOfLink)} \n" + + "BIND('narrower' AS ?typeOfLink)} \n" + "UNION" + "{?concept skos:broader ?conceptlinked . \n" - + "BIND('narrower' AS ?typeOfLink)} \n" + + "BIND('broader' AS ?typeOfLink)} \n" + "UNION" + "{?concept dcterms:references ?conceptlinked . \n" + "BIND('references' AS ?typeOfLink)} \n" @@ -203,7 +207,7 @@ public static String conceptLinks(String id) { + "OPTIONAL {?conceptlinked skos:prefLabel ?prefLabelLg2 . \n" + "FILTER (lang(?prefLabelLg2) = '" + Config.LG2 + "')} . \n" + "BIND(STRAFTER(STR(?conceptlinked),'/definition/') AS ?id) . \n" - + "} \n" + + "}} \n" + "ORDER BY ?typeOfLink"; } From bc227906f81b38c094d6f375186fa207bc781ef7 Mon Sep 17 00:00:00 2001 From: Alice Lambois Date: Fri, 7 Aug 2020 15:11:44 +0200 Subject: [PATCH 8/9] Fix issue with concept publication Concept has both is_validated=true and is_validated=false --- .../rmes/bauhaus_services/rdf_utils/RepositoryGestion.java | 2 ++ .../persistance/sparql_queries/concepts/ConceptsQueries.java | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryGestion.java b/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryGestion.java index 7fdb56f73..2331935ce 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryGestion.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryGestion.java @@ -237,6 +237,7 @@ public void objectsValidation(List collectionsToValidateList, Model model) RepositoryConnection conn = RepositoryGestion.REPOSITORY_GESTION.getConnection(); for (IRI item : collectionsToValidateList) { conn.remove(item, INSEE.VALIDATION_STATE, null); + conn.remove(item, INSEE.IS_VALIDATED, null); } conn.add(model); conn.close(); @@ -249,6 +250,7 @@ public void objectValidation(IRI ressourceURI, Model model) throws RmesException try { RepositoryConnection conn = RepositoryGestion.REPOSITORY_GESTION.getConnection(); conn.remove(ressourceURI, INSEE.VALIDATION_STATE, null); + conn.remove(ressourceURI, INSEE.IS_VALIDATED, null); conn.add(model); conn.close(); } catch (RepositoryException e) { diff --git a/src/main/java/fr/insee/rmes/persistance/sparql_queries/concepts/ConceptsQueries.java b/src/main/java/fr/insee/rmes/persistance/sparql_queries/concepts/ConceptsQueries.java index ead10d8d5..815c6d999 100644 --- a/src/main/java/fr/insee/rmes/persistance/sparql_queries/concepts/ConceptsQueries.java +++ b/src/main/java/fr/insee/rmes/persistance/sparql_queries/concepts/ConceptsQueries.java @@ -76,14 +76,14 @@ public static String conceptsSearchQuery() { public static String conceptsToValidateQuery() { return "SELECT DISTINCT ?id ?label ?creator ?valid \n" - + "WHERE { \n" + + "WHERE { GRAPH <"+Config.CONCEPTS_GRAPH+"> { \n" + "?concept rdf:type skos:Concept . \n" + "BIND(STRAFTER(STR(?concept),'/concepts/definition/') AS ?id) . \n" + "?concept skos:prefLabel ?label . \n" + "?concept dc:creator ?creator . \n" + "?concept insee:isValidated 'false'^^xsd:boolean . \n" + "OPTIONAL {?concept dcterms:valid ?valid .} \n" - + "FILTER (lang(?label) = '" + Config.LG1 + "') } \n" + + "FILTER (lang(?label) = '" + Config.LG1 + "') }} \n" + "ORDER BY ?label"; } From 31832bd802c42616ea29a7518df54b213227917c Mon Sep 17 00:00:00 2001 From: Alice Lambois Date: Mon, 10 Aug 2020 11:13:28 +0200 Subject: [PATCH 9/9] Update to match new release's rules --- bauhaus-back-changeLog.txt | 1 + src/main/java/fr/insee/rmes/config/ApplicationContext.java | 2 +- .../java/fr/insee/rmes/config/Log4j2ServletContextListener.java | 1 + .../auth/security/conditions/NoOpenIDConnectAuthCondition.java | 1 + .../auth/security/conditions/OpenIDConnectAuthCondition.java | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 bauhaus-back-changeLog.txt diff --git a/bauhaus-back-changeLog.txt b/bauhaus-back-changeLog.txt new file mode 100644 index 000000000..9192e11f2 --- /dev/null +++ b/bauhaus-back-changeLog.txt @@ -0,0 +1 @@ +2.1.0 : Ajout de la publication vers l'interne et changement d'ergonomie de l'application \ No newline at end of file diff --git a/src/main/java/fr/insee/rmes/config/ApplicationContext.java b/src/main/java/fr/insee/rmes/config/ApplicationContext.java index 3926f0f17..285554c5e 100644 --- a/src/main/java/fr/insee/rmes/config/ApplicationContext.java +++ b/src/main/java/fr/insee/rmes/config/ApplicationContext.java @@ -25,7 +25,7 @@ @Configuration("AppContext") @PropertySource(value = { "classpath:bauhaus-core.properties", "classpath:bauhaus-dev.properties", - "file:${catalina.base}/webapps/bauhaus-dev.properties", "file:${catalina.base}/webapps/bauhaus-qf.properties", + "file:${catalina.base}/webapps/bauhaus-dev.properties", "file:${catalina.base}/webapps/bauhaus-qf.properties","file:${catalina.base}/webapps/bauhaus-production.properties", "file:${catalina.base}/webapps/production.properties", }, ignoreResourceNotFound = true) public class ApplicationContext { diff --git a/src/main/java/fr/insee/rmes/config/Log4j2ServletContextListener.java b/src/main/java/fr/insee/rmes/config/Log4j2ServletContextListener.java index bc4b8a338..71e25c013 100644 --- a/src/main/java/fr/insee/rmes/config/Log4j2ServletContextListener.java +++ b/src/main/java/fr/insee/rmes/config/Log4j2ServletContextListener.java @@ -57,6 +57,7 @@ private Properties getProperties() throws IOException { props.load(getClass().getClassLoader().getResourceAsStream("bauhaus-dev.properties")); loadPropertiesIfExist(props, "bauhaus-dev.properties"); loadPropertiesIfExist(props, "bauhaus-qf.properties"); + loadPropertiesIfExist(props, "bauhaus-production.properties"); loadPropertiesIfExist(props, "production.properties"); return props; } diff --git a/src/main/java/fr/insee/rmes/config/auth/security/conditions/NoOpenIDConnectAuthCondition.java b/src/main/java/fr/insee/rmes/config/auth/security/conditions/NoOpenIDConnectAuthCondition.java index 2550e6462..556524a4a 100644 --- a/src/main/java/fr/insee/rmes/config/auth/security/conditions/NoOpenIDConnectAuthCondition.java +++ b/src/main/java/fr/insee/rmes/config/auth/security/conditions/NoOpenIDConnectAuthCondition.java @@ -35,6 +35,7 @@ private String getEnv() throws IOException { props.load(getClass().getClassLoader().getResourceAsStream("bauhaus-dev.properties")); loadPropertiesIfExist(props, "bauhaus-dev.properties"); loadPropertiesIfExist(props, "bauhaus-qf.properties"); + loadPropertiesIfExist(props, "bauhaus-production.properties"); loadPropertiesIfExist(props, "production.properties"); return props.getProperty("fr.insee.rmes.bauhaus.env"); } diff --git a/src/main/java/fr/insee/rmes/config/auth/security/conditions/OpenIDConnectAuthCondition.java b/src/main/java/fr/insee/rmes/config/auth/security/conditions/OpenIDConnectAuthCondition.java index 592ef877a..bf4f0a521 100644 --- a/src/main/java/fr/insee/rmes/config/auth/security/conditions/OpenIDConnectAuthCondition.java +++ b/src/main/java/fr/insee/rmes/config/auth/security/conditions/OpenIDConnectAuthCondition.java @@ -38,6 +38,7 @@ private String getEnv() throws IOException { .getResourceAsStream("bauhaus-dev.properties")); loadPropertiesIfExist(props, "bauhaus-dev.properties"); loadPropertiesIfExist(props, "bauhaus-qf.properties"); + loadPropertiesIfExist(props, "bauhaus-production.properties"); loadPropertiesIfExist(props, "production.properties"); return props.getProperty("fr.insee.rmes.bauhaus.env"); }