From c9f62f4177d7ecd9433db6407fab82b13cab34b8 Mon Sep 17 00:00:00 2001 From: Alice Lambois Date: Wed, 28 Apr 2021 16:34:57 +0200 Subject: [PATCH 1/5] Improve healthcheck --- .../rdf_utils/RepositoryPublication.java | 11 ++++++++ .../insee/rmes/webservice/HealthcheckApi.java | 26 ++++++++++++------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryPublication.java b/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryPublication.java index ddbf30e76..b18a70dff 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryPublication.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryPublication.java @@ -57,6 +57,17 @@ public class RepositoryPublication extends RepositoryUtils{ public static String getResponse(String query) throws RmesException { return getResponse(query, REPOSITORY_PUBLICATION); } + + /** + * Method which aims to produce response from a sparql query for internal Repository + * + * @param query + * @return String + * @throws RmesException + */ + public static String getResponseInternalPublication(String query) throws RmesException { + return getResponse(query, REPOSITORY_PUBLICATION_INTERNE); + } /** * Method which aims to produce response from a sparql query diff --git a/src/main/java/fr/insee/rmes/webservice/HealthcheckApi.java b/src/main/java/fr/insee/rmes/webservice/HealthcheckApi.java index 4a3b314c2..6ef16ef43 100644 --- a/src/main/java/fr/insee/rmes/webservice/HealthcheckApi.java +++ b/src/main/java/fr/insee/rmes/webservice/HealthcheckApi.java @@ -61,7 +61,7 @@ public Response getHealthcheck() { //Test database connexion stateResult.add("Database connexion \n"); - stateResult = testDatabaseConnexions(errorMessage, stateResult); + checkDatabaseConnexions(errorMessage, stateResult); //Test access to storage stateResult = stateResult.add("Document storage \n"); @@ -98,25 +98,33 @@ public Response getHealthcheck() { } } - public StringJoiner testDatabaseConnexions(StringJoiner errorMessage, StringJoiner stateResult) { + public void checkDatabaseConnexions(StringJoiner errorMessage, StringJoiner stateResult) { try { if (StringUtils.isEmpty(RepositoryPublication.getResponse(sparlQuery))){ errorMessage.add("- Repository publication doesn't return statement \n"); - stateResult = stateResult.add(" - Connexion publication").add(KO_STATE); + stateResult.add(" - Connexion publication Z").add(KO_STATE); }else { - stateResult = stateResult.add(" - Connexion publication").add(OK_STATE); + stateResult.add(" - Connexion publication Z").add(OK_STATE); } - if (StringUtils.isEmpty( repoGestion.getResponse(sparlQuery))) { + if (StringUtils.isEmpty(RepositoryPublication.getResponseInternalPublication(sparlQuery))){ + errorMessage.add("- Repository publication interne doesn't return statement \n"); + stateResult.add(" - Connexion publication I").add(KO_STATE); + }else { + stateResult.add(" - Connexion publication I").add(OK_STATE); + } + if (StringUtils.isEmpty( repoGestion.getResponse(sparlQuery))) { errorMessage.add("- Repository gestion doesn't return statement \n"); - stateResult = stateResult.add(" - Connexion gestion").add(KO_STATE); + stateResult.add(" - Connexion gestion").add(KO_STATE); }else { - stateResult = stateResult.add(" - Connexion gestion").add(OK_STATE); + stateResult.add(" - Connexion gestion").add(OK_STATE); } } catch (RmesException e) { errorMessage.add("- "+e.getMessage()+ " \n"); - stateResult = stateResult.add(" - Connexion database").add(KO_STATE); + stateResult.add(" - Connexion database").add(KO_STATE); + } catch (Exception e) { + errorMessage.add("- "+e.getClass().getSimpleName() +e.getMessage()+ " \n"); + stateResult.add(" - Connexion database").add(KO_STATE); } - return stateResult; } private void checkDocumentStorage(String pathToStorage, String storageType, StringJoiner stateResult, StringJoiner errorMessage) { From 321665d8286e127f5a749f1e5c7531fd3fa34aa9 Mon Sep 17 00:00:00 2001 From: Emmanuel DEMEY Date: Thu, 29 Apr 2021 20:43:53 +0200 Subject: [PATCH 2/5] fix: delete component specification when publishing --- .../rdf_utils/RepositoryPublication.java | 41 ++++++++++++++++++- .../utils/StructurePublication.java | 8 ++-- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryPublication.java b/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryPublication.java index ddbf30e76..c1e69d40c 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryPublication.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryPublication.java @@ -1,5 +1,6 @@ package fr.insee.rmes.bauhaus_services.rdf_utils; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -7,6 +8,7 @@ import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status.Family; +import fr.insee.rmes.persistance.ontologies.QB; import org.apache.http.HttpStatus; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -20,6 +22,7 @@ import org.eclipse.rdf4j.repository.RepositoryConnection; import org.eclipse.rdf4j.repository.RepositoryException; import org.eclipse.rdf4j.repository.RepositoryResult; +import org.eclipse.rdf4j.repository.util.Repositories; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -182,8 +185,42 @@ private static void publishContext(Resource context, Model model, String type, R throw new RmesException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), CONNECTION_TO + repo + FAILED); } } - - + + public static void clearStructureAndComponentForAllRepositories(Resource structure) { + clearStructureAndComponents(structure, REPOSITORY_PUBLICATION); + clearStructureAndComponents(structure, REPOSITORY_PUBLICATION_INTERNE); + } + + public static void clearStructureAndComponents(Resource structure, Repository repository) { + List toRemove = new ArrayList<>(); + try { + RepositoryConnection conn = repository.getConnection(); + RepositoryResult nodes = null; + RepositoryResult specifications = null; + nodes = conn.getStatements(structure, QB.COMPONENT, null, false); + while (nodes.hasNext()) { + Resource node = (Resource) nodes.next().getObject(); + toRemove.add(node); + specifications = conn.getStatements(node, QB.COMPONENT, null, false); + while (specifications.hasNext()) { + toRemove.add((Resource) specifications.next().getObject()); + } + specifications.close(); + + } + nodes.close(); + toRemove.forEach(res -> { + try { + RepositoryResult statements = conn.getStatements(res, null, null, false); + conn.remove(statements); + } catch (RepositoryException e) { + logger.error("RepositoryGestion Error {}", e.getMessage()); + } + }); + } catch (RepositoryException e) { + new RmesException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), "Failure deletion : " + structure); + } + } private static void clearConceptLinks(Resource concept, RepositoryConnection conn) throws RmesException { List typeOfLink = Arrays.asList(SKOS.BROADER, SKOS.NARROWER, SKOS.MEMBER, DCTERMS.REFERENCES, DCTERMS.REPLACES, SKOS.RELATED); diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/structures/utils/StructurePublication.java b/src/main/java/fr/insee/rmes/bauhaus_services/structures/utils/StructurePublication.java index 6764e066b..b29084902 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/structures/utils/StructurePublication.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/structures/utils/StructurePublication.java @@ -70,9 +70,11 @@ public void publish(Resource structure) throws RmesException { RepositoryConnection con = repoGestion.getConnection(); this.copyTriplet(structure, model, con, new String[]{"validationState", Constants.CREATOR, Constants.CONTRIBUTOR}); - Resource componentToPublishRessource = PublicationUtils.tranformBaseURIToPublish(structure); - RepositoryPublication.publishResource(componentToPublishRessource, model, "Structure"); - + Resource structureToPublish = PublicationUtils.tranformBaseURIToPublish(structure); + + RepositoryPublication.clearStructureAndComponentForAllRepositories(structureToPublish); + RepositoryPublication.publishResource(structureToPublish, model, "Structure"); + } } From 6488ec9e58017fee344be489ed296929a574f40a Mon Sep 17 00:00:00 2001 From: Alice Lambois Date: Fri, 30 Apr 2021 16:13:16 +0200 Subject: [PATCH 3/5] Add method to publish document with uri in C:// --- .../documents/DocumentsPublication.java | 63 +++++++++++++++++-- 1 file changed, 58 insertions(+), 5 deletions(-) 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 df7cdfb68..3d2171052 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 @@ -98,9 +98,11 @@ private Model getModelToPublish(String documentId, String filename) throws RmesE Resource document = RdfUtils.documentIRI(documentId); RepositoryConnection con = repoGestion.getConnection(); - RepositoryResult documentStatements = repoGestion.getStatements(con, document); + RepositoryResult documentStatements = null ; try { + documentStatements = repoGestion.getStatements(con, document); + if (!documentStatements.hasNext()) { throw new RmesNotFoundException(ErrorCodes.DOCUMENT_UNKNOWN_ID, "Document not found", documentId); } @@ -119,17 +121,68 @@ private Model getModelToPublish(String documentId, String filename) throws RmesE renameAndAddTripleToModel(model, st, subject); } } - } catch (RepositoryException e) { - throw new RmesException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), - Constants.REPOSITORY_EXCEPTION); + } catch (RepositoryException |RmesException e) { + model = getModelWithErrorToPublish(documentId, filename); } finally { - repoGestion.closeStatements(documentStatements); + if (documentStatements != null) { + repoGestion.closeStatements(documentStatements); + } } return model; } + private Model getModelWithErrorToPublish(String documentId, String filename) throws RmesException { + logger.error("PUBLISHING A DOCUMENT WITH RDF ERROR (URL)"); + Model model = new LinkedHashModel(); + Resource document = RdfUtils.documentIRI(documentId); + + try { + JSONArray tuples = repoGestion.getResponseAsArray("" + + "select ?predicat ?obj FROM <"+RdfUtils.documentsGraph()+"> " + + "WHERE {" + + "?document ?predicat ?obj . " + + "FILTER (?document = <"+document+">) " + + "}"); + + + if (tuples.length()==0) { + throw new RmesNotFoundException(ErrorCodes.DOCUMENT_UNKNOWN_ID, "Document not found", documentId); + } + + Resource newSubject = PublicationUtils.tranformBaseURIToPublish(document); + Value object ; + + for (int i = 0; i < tuples.length(); i++) { + JSONObject tuple = (JSONObject) tuples.get(i); + String predicatString = tuple.getString("predicat"); + IRI predicate = (SimpleIRI) PublicationUtils.tranformBaseURIToPublish(RdfUtils.toURI(predicatString)); + if (predicatString.endsWith("url")) { + String newUrl = Config.DOCUMENTS_BASEURL + "/"+ filename; + logger.info("Publishing document : {}",newUrl); + object = RdfUtils.toURI(newUrl); + } else { + String objectString = tuple.getString("obj"); + try { + object = RdfUtils.toURI(objectString); + object = PublicationUtils.tranformBaseURIToPublish((Resource) object); + + }catch(IllegalArgumentException iAe) { + object = RdfUtils.setLiteralString(objectString); + } + } + model.add(newSubject, predicate, object, RdfUtils.documentsGraph()); + } + } catch (RepositoryException e) { + logger.error(e.getMessage()); + throw new RmesException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), + Constants.REPOSITORY_EXCEPTION); + } + return model; + + } + private Model getLinkModelToPublish(String linkId) throws RmesException { Model model = new LinkedHashModel(); Resource link = RdfUtils.linkIRI(linkId); From 50f4531707b0c37bbbe9a754b17707a9d856803c Mon Sep 17 00:00:00 2001 From: Alice Lambois Date: Mon, 10 May 2021 12:07:58 +0200 Subject: [PATCH 4/5] fix issue with space in url after a document's publication --- .../documentations/documents/DocumentsPublication.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 3d2171052..81e7fd1e2 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 @@ -112,7 +112,7 @@ private Model getModelToPublish(String documentId, String filename) throws RmesE Resource subject = PublicationUtils.tranformBaseURIToPublish(st.getSubject()); IRI predicate = RdfUtils .createIRI(PublicationUtils.tranformBaseURIToPublish(st.getPredicate()).stringValue()); - String newUrl = Config.DOCUMENTS_BASEURL + "/"+ filename; + String newUrl = Config.DOCUMENTS_BASEURL.trim() + "/"+ filename; logger.info("Publishing document : {}",newUrl); Value object = RdfUtils.toURI(newUrl); model.add(subject, predicate, object, st.getContext()); @@ -159,7 +159,7 @@ private Model getModelWithErrorToPublish(String documentId, String filename) thr String predicatString = tuple.getString("predicat"); IRI predicate = (SimpleIRI) PublicationUtils.tranformBaseURIToPublish(RdfUtils.toURI(predicatString)); if (predicatString.endsWith("url")) { - String newUrl = Config.DOCUMENTS_BASEURL + "/"+ filename; + String newUrl = Config.DOCUMENTS_BASEURL.trim() + "/"+ filename; logger.info("Publishing document : {}",newUrl); object = RdfUtils.toURI(newUrl); } else { From 67b7115246b109f09ccae9c484c1bf1f84ec267c Mon Sep 17 00:00:00 2001 From: Alice Lambois Date: Tue, 11 May 2021 09:23:41 +0200 Subject: [PATCH 5/5] Version 3.0.2 --- bauhaus-back-changeLog.txt | 1 + pom.xml | 2 +- .../operations/documentations/DocumentationExport.java | 2 +- .../rmes/bauhaus_services/rdf_utils/RepositoryPublication.java | 3 +-- src/main/java/fr/insee/rmes/config/swagger/SwaggerConfig.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bauhaus-back-changeLog.txt b/bauhaus-back-changeLog.txt index 6a4216412..050c993f0 100644 --- a/bauhaus-back-changeLog.txt +++ b/bauhaus-back-changeLog.txt @@ -1,3 +1,4 @@ +3.0.2 : Corrections de l'url des documents à la publication 3.0.1 : Rétablissement du swagger et des droits d'accès 3.0.0 : Module Opérations 2.1.2 : - Correction du bug à la publication des concepts (la modification supprimait les anciennes versions de notes) diff --git a/pom.xml b/pom.xml index 6e39d16da..1b7f74aed 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ fr.insee.rmes Bauhaus-BO war - 3.0.1 + 3.0.2 Bauhaus-Back-Office Back-office services for Bauhaus https://github.com/InseeFr/Bauhaus-Back-Office diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/operations/documentations/DocumentationExport.java b/src/main/java/fr/insee/rmes/bauhaus_services/operations/documentations/DocumentationExport.java index 455a67559..9f56f3cb0 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/operations/documentations/DocumentationExport.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/operations/documentations/DocumentationExport.java @@ -140,7 +140,7 @@ public Response export(String simsXML,String operationXML,String indicatorXML,St private String buildParams(Boolean lg1, Boolean lg2, Boolean includeEmptyMas, String targetType) { - String includeEmptyMasString=( includeEmptyMas ? "true" : "false"); + String includeEmptyMasString=( Boolean.TRUE.equals(includeEmptyMas) ? "true" : "false"); String parametersXML=""; parametersXML=parametersXML.concat(Constants.XML_OPEN_PARAMETERS_TAG); diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryPublication.java b/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryPublication.java index 4fe8530d2..6ccca53e7 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryPublication.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RepositoryPublication.java @@ -8,7 +8,6 @@ import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status.Family; -import fr.insee.rmes.persistance.ontologies.QB; import org.apache.http.HttpStatus; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -22,7 +21,6 @@ import org.eclipse.rdf4j.repository.RepositoryConnection; import org.eclipse.rdf4j.repository.RepositoryException; import org.eclipse.rdf4j.repository.RepositoryResult; -import org.eclipse.rdf4j.repository.util.Repositories; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -30,6 +28,7 @@ import fr.insee.rmes.bauhaus_services.Constants; import fr.insee.rmes.config.Config; import fr.insee.rmes.exceptions.RmesException; +import fr.insee.rmes.persistance.ontologies.QB; /** * Getters only get on publication base 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 131b862aa..3676bfd58 100644 --- a/src/main/java/fr/insee/rmes/config/swagger/SwaggerConfig.java +++ b/src/main/java/fr/insee/rmes/config/swagger/SwaggerConfig.java @@ -30,7 +30,7 @@ public SwaggerConfig(@Context ServletConfig servletConfig) { super(); OpenAPI openApi = new OpenAPI(); - Info info = new Info().title("Bauhaus API").version("3.0.1").description("Rest Endpoints and services Integration used by Bauhaus"); + Info info = new Info().title("Bauhaus API").version("3.0.2").description("Rest Endpoints and services Integration used by Bauhaus"); openApi.info(info); Server server = new Server();