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/operations/documentations/documents/DocumentsPublication.java b/src/main/java/fr/insee/rmes/bauhaus_services/operations/documentations/documents/DocumentsPublication.java
index df7cdfb68..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
@@ -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);
}
@@ -110,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());
@@ -119,15 +121,66 @@ 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.trim() + "/"+ 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 {
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..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
@@ -1,5 +1,6 @@
package fr.insee.rmes.bauhaus_services.rdf_utils;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -27,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
@@ -57,6 +59,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
@@ -182,8 +195,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");
+
}
}
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();
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) {