diff --git a/bauhaus-back-changeLog.txt b/bauhaus-back-changeLog.txt
index 015c41e89..619fb39f3 100644
--- a/bauhaus-back-changeLog.txt
+++ b/bauhaus-back-changeLog.txt
@@ -1,3 +1,5 @@
+3.0.13 : - Tentatives pour supprimer les erreurs trop de fichiers ouverts
+ - Quelques mises à jour de dépendances
3.0.9 : - Amélioration de la consultation: Ajout des parents/enfants
- Fin des développements pour "Géographie"
- Correction d'un bug lors de l'exportation des indicateurs en odt
diff --git a/pom.xml b/pom.xml
index 4a6c82b1f..3b9ff65c8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
fr.insee.rmes
Bauhaus-BO
war
- 3.0.12
+ 3.0.13
Bauhaus-Back-Office
Back-office services for Bauhaus
https://github.com/InseeFr/Bauhaus-Back-Office
@@ -33,17 +33,19 @@
+
+
bauhaus
- 2.19
- 2.10.1
- 3.5.0
- 2.0.9
- 5.2.16.RELEASE
- 5.3.10.RELEASE
+ 2.32
+ 2.13.1
+ 3.7.3
+ 2.1.12
+ 5.3.14
+ 5.6.1
2.17.1
- 5.7.0
+ 5.8.2
UTF-8
2.22.2
@@ -76,6 +78,8 @@
https://repository.jboss.org/nexus/content/groups/public
+
+
@@ -121,12 +125,12 @@
jakarta.xml.bind
jakarta.xml.bind-api
- 2.3.3
+ 4.0.0-RC2
jakarta.servlet
jakarta.servlet-api
- 4.0.3
+ 5.0.0
provided
@@ -138,7 +142,7 @@
org.glassfish.jersey.ext
- jersey-spring3
+ jersey-spring5
${jersey.version}
@@ -161,6 +165,10 @@
org.springframework
spring-context
+
+ org.springframework
+ spring-aop
+
@@ -225,10 +233,6 @@
com.fasterxml.jackson.core
jackson-core
-
- com.fasterxml.jackson.core
- jackson-databind
-
com.fasterxml.jackson.core
jackson-annotations
@@ -395,7 +399,7 @@
xerces
xercesImpl
- 2.12.0
+ 2.12.2
com.itextpdf
@@ -438,6 +442,11 @@
commons-text
1.9
+
+ commons-io
+ commons-io
+ 2.11.0
+
diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/ConceptsService.java b/src/main/java/fr/insee/rmes/bauhaus_services/ConceptsService.java
index 77620ed7b..f00edc7b7 100644
--- a/src/main/java/fr/insee/rmes/bauhaus_services/ConceptsService.java
+++ b/src/main/java/fr/insee/rmes/bauhaus_services/ConceptsService.java
@@ -44,7 +44,7 @@ public interface ConceptsService {
public void setConceptsValidation(String body) throws RmesException ;
- public Response getConceptExport(String id, String acceptHeader) throws RmesException;
+ public Response exportConcept(String id, String acceptHeader) throws RmesException;
public boolean setConceptSend(String id, String body) throws RmesException ;
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 ead78a011..30d70bb27 100644
--- a/src/main/java/fr/insee/rmes/bauhaus_services/OperationsService.java
+++ b/src/main/java/fr/insee/rmes/bauhaus_services/OperationsService.java
@@ -32,6 +32,8 @@ public interface OperationsService {
String createFamily(String body) throws RmesException;
+ String getSeriesWithReport(String id) throws RmesException;
+
/******************************************************************************************
* SERIES
* *******************************************************************************************/
diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/code_list/CodeListServiceImpl.java b/src/main/java/fr/insee/rmes/bauhaus_services/code_list/CodeListServiceImpl.java
index e0ca749c2..a86f3d327 100644
--- a/src/main/java/fr/insee/rmes/bauhaus_services/code_list/CodeListServiceImpl.java
+++ b/src/main/java/fr/insee/rmes/bauhaus_services/code_list/CodeListServiceImpl.java
@@ -2,6 +2,8 @@
import javax.ws.rs.BadRequestException;
+import fr.insee.rmes.exceptions.ErrorCodes;
+import fr.insee.rmes.exceptions.RmesUnauthorizedException;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -39,6 +41,10 @@
@Service
public class CodeListServiceImpl extends RdfService implements CodeListService {
+ private static final String CODE = "code";
+
+ private static final String POSITION = "position";
+
private static final String CODES = "codes";
private static final String LAST_LIST_URI_SEGMENT = "lastListUriSegment";
@@ -100,7 +106,7 @@ private void formatCodesForFullList(String notation, JSONObject codeList, JSONAr
JSONObject formattedCodes = new JSONObject();
codes.forEach(c -> {
JSONObject tempCode = (JSONObject) c;
- String code = tempCode.getString("code");
+ String code = tempCode.getString(CODE);
if(tempCode.has(Constants.PARENTS)){
String parentCode = tempCode.getString(Constants.PARENTS);
if(!parents.containsKey(parentCode)){
@@ -119,68 +125,68 @@ private void formatCodesForFullList(String notation, JSONObject codeList, JSONAr
int rootPosition = 1;
if(seq.length() > 0){
- int startPosition = 0;
- for(int i = 0; i < seq.length(); i++){
- JSONObject codeAndPosition = seq.getJSONObject(i);
- String code = codeAndPosition.getString("code");
-
-
- if(parents.containsKey(code)){
- for(int j = startPosition; j < i; j++){
- String childCode = seq.getJSONObject(j).getString("code");
+ formatCodeListBySeq(parents, formattedCodes, seq, rootPosition);
+ } else {
+ formatCodeListWithoutSeq(parents, formattedCodes);
+ }
+ codeList.put(CODES, formattedCodes);
+ }
+ }
- JSONObject child = formattedCodes.getJSONObject(childCode);
+ private void formatCodeListWithoutSeq(Map> parents, JSONObject formattedCodes) {
+ // If we do not have a Seq, we have to sort alphabetically.
+ parents.keySet().forEach(key -> {
+ List children = parents.get(key);
+ children.sort((o1, o2) -> o1.compareTo(o2));
+
+ for(int i = 0; i < children.size(); i++){
+ String child = children.get(i);
+ JSONObject codeObject = formattedCodes.getJSONObject(child);
+ addOrUpdateParents(i + 1, key, codeObject);
+ formattedCodes.put(child, codeObject);
+ }
+ });
+ // Here will order all root codes. Codes without parents
+ orderRootCodes(formattedCodes);
+ }
- if(!child.has(Constants.PARENTS)){
- child.put(Constants.PARENTS, new JSONArray());
- }
- child.getJSONArray(Constants.PARENTS).put(new JSONObject().put("code", code).put("position", j - startPosition + 1));
- formattedCodes.put(childCode, child);
- }
- startPosition = i + 1;
+ private void formatCodeListBySeq(Map> parents, JSONObject formattedCodes, JSONArray seq,
+ int rootPosition) {
+ int startPosition = 0;
+ for(int i = 0; i < seq.length(); i++){
+ JSONObject codeAndPosition = seq.getJSONObject(i);
+ String code = codeAndPosition.getString(CODE);
- rootPosition = setPositonForRootNode(formattedCodes, startPosition, code);
- } else if(isRootNodeWithoutChildren(code, parents)){
- rootPosition = setPositonForRootNode(formattedCodes, rootPosition, code);
- startPosition = i + 1;
+ if(parents.containsKey(code)){
+ for(int j = startPosition; j < i; j++){
+ String childCode = seq.getJSONObject(j).getString(CODE);
+ JSONObject child = formattedCodes.getJSONObject(childCode);
+ addOrUpdateParents(j - startPosition + 1, code, child);
+ formattedCodes.put(childCode, child);
}
+ startPosition = i + 1;
+ rootPosition = setPositonForRootNode(formattedCodes, startPosition, code);
-
- }
- } else {
- // If we do not have a Seq, we have to sort alphabetically.
- parents.keySet().forEach(key -> {
- List children = parents.get(key);
- children.sort((o1, o2) -> o1.compareTo(o2));
-
- for(int i = 0; i < children.size(); i++){
- String child = children.get(i);
- JSONObject codeObject = formattedCodes.getJSONObject(child);
- if(!codeObject.has(Constants.PARENTS)){
- codeObject.put(Constants.PARENTS, new JSONArray());
- }
- codeObject.getJSONArray(Constants.PARENTS).put(new JSONObject().put("code", key).put("position", i + 1));
- formattedCodes.put(child, codeObject);
- }
- });
- // Here will order all root codes. Codes without parents
- orderRootCodes(formattedCodes);
+ } else if(isRootNodeWithoutChildren(code, parents)){
+ rootPosition = setPositonForRootNode(formattedCodes, rootPosition, code);
+ startPosition = i + 1;
}
-
- codeList.put(CODES, formattedCodes);
}
}
- private int setPositonForRootNode(JSONObject formattedCodes, int rootPosition, String code) {
- JSONObject child = formattedCodes.getJSONObject(code);
-
+ private void addOrUpdateParents(int position, String code, JSONObject child) {
if(!child.has(Constants.PARENTS)){
child.put(Constants.PARENTS, new JSONArray());
}
- child.getJSONArray(Constants.PARENTS).put(new JSONObject().put("code", "").put("position", rootPosition));
+ child.getJSONArray(Constants.PARENTS).put(new JSONObject().put(CODE, code).put(POSITION, position));
+ }
+
+ private int setPositonForRootNode(JSONObject formattedCodes, int rootPosition, String code) {
+ JSONObject child = formattedCodes.getJSONObject(code);
+ addOrUpdateParents(rootPosition,"",child);
formattedCodes.put(code, child);
rootPosition = rootPosition + 1;
return rootPosition;
@@ -195,8 +201,8 @@ private int setPositonForRootNode(JSONObject formattedCodes, int rootPosition, S
private boolean isRootNodeWithoutChildren(String code, Map> parents) {
return parents.keySet().stream().filter((parentCode) -> {
List codes = parents.get(parentCode);
- return codes.stream().filter((c) -> c.equalsIgnoreCase(code)).collect(Collectors.toList()).size() > 0;
- }).collect(Collectors.toList()).size() == 0;
+ return codes.stream().filter((c) -> !c.equalsIgnoreCase(code)).collect(Collectors.toList()).isEmpty();
+ }).collect(Collectors.toList()).isEmpty();
}
/**
@@ -210,7 +216,7 @@ private void formatCodesForPartialList(JSONObject codeList, JSONArray codes) {
JSONObject formattedCodes = new JSONObject();
codes.forEach(c -> {
JSONObject tempCode = (JSONObject) c;
- String code = tempCode.getString("code");
+ String code = tempCode.getString(CODE);
if (tempCode.has(Constants.PARENTS)) {
tempCode.remove(Constants.PARENTS);
}
@@ -220,12 +226,14 @@ private void formatCodesForPartialList(JSONObject codeList, JSONArray codes) {
}
private void orderRootCodes(JSONObject formattedCodes) {
- List rootCodes = formattedCodes.keySet().stream().filter(key -> {
- return !formattedCodes.getJSONObject(key).has(Constants.PARENTS);
- }).sorted(Comparator.comparing(code -> code)).collect(Collectors.toList());
- if(rootCodes.size() > 0) {
+ List rootCodes = formattedCodes.keySet().stream().filter(key ->
+ !formattedCodes.getJSONObject(key).has(Constants.PARENTS))
+ .sorted(Comparator.comparing(code -> code))
+ .collect(Collectors.toList()
+ );
+ if(!rootCodes.isEmpty()) {
for(int i = 0; i < rootCodes.size(); i++) {
- JSONObject parent = new JSONObject().put("code", "").put("position", i + 1);
+ JSONObject parent = new JSONObject().put(CODE, "").put(POSITION, i + 1);
formattedCodes.getJSONObject(rootCodes.get(i)).put(Constants.PARENTS, new JSONArray().put(parent));
}
}
@@ -257,10 +265,28 @@ public void validateCodeList(JSONObject codeList, boolean partial){
if (!partial && !codeList.has("lastClassUriSegment")) {
throw new BadRequestException("The lastClassUriSegment of the list should be defined");
}
- if (!codeList.has(LAST_LIST_URI_SEGMENT)) {
+ if (!partial && !codeList.has(LAST_LIST_URI_SEGMENT)) {
throw new BadRequestException("The lastListUriSegment of the list should be defined");
}
}
+
+ private IRI generateIri(JSONObject codesList, boolean partial) {
+ if(partial){
+ return RdfUtils.codeListIRI(codesList.getString(Constants.ID));
+ } else {
+ return RdfUtils.codeListIRI(codesList.getString(LAST_LIST_URI_SEGMENT));
+ }
+ }
+
+ private boolean checkCodeListUnicity(boolean partial, JSONObject codeList, String iri) throws RmesException {
+ String id = codeList.getString(Constants.ID);
+ if(!partial) {
+ IRI seeAlso = RdfUtils.codeListIRI("concept/" + codeList.getString("lastClassUriSegment"));
+ return repoGestion.getResponseAsBoolean(CodeListQueries.checkCodeListUnicity(id, iri, seeAlso.toString(), partial));
+ }
+ return repoGestion.getResponseAsBoolean(CodeListQueries.checkCodeListUnicity(id, iri, "", partial));
+ }
+
@Override
public String setCodesList(String body, boolean partial) throws RmesException {
ObjectMapper mapper = new ObjectMapper();
@@ -270,7 +296,13 @@ public String setCodesList(String body, boolean partial) throws RmesException {
this.validateCodeList(codesList, partial);
- IRI codeListIri = RdfUtils.codeListIRI(codesList.getString(LAST_LIST_URI_SEGMENT));
+ IRI codeListIri = this.generateIri(codesList, partial);
+
+ if(this.checkCodeListUnicity(partial, codesList, codeListIri.toString())){
+ throw new RmesUnauthorizedException(ErrorCodes.CODE_LIST_UNICITY,
+ "The identifier, IRI and OWL class should be unique", "");
+ }
+
repoGestion.clearStructureNodeAndComponents(codeListIri);
Model model = new LinkedHashModel();
Resource graph = RdfUtils.codesListGraph();
@@ -288,7 +320,7 @@ public String setCodesList(String id, String body, boolean partial) throws RmesE
this.validateCodeList(codesList, partial);
- IRI codeListIri = RdfUtils.codeListIRI(codesList.getString(LAST_LIST_URI_SEGMENT));
+ IRI codeListIri = this.generateIri(codesList, partial);
repoGestion.clearStructureNodeAndComponents(codeListIri);
Model model = new LinkedHashModel();
Resource graph = RdfUtils.codesListGraph();
@@ -305,20 +337,10 @@ private String createOrUpdateCodeList(Model model, Resource graph, JSONObject co
model.add(codeListIri, INSEE.VALIDATION_STATE, RdfUtils.setLiteralString(ValidationStatus.UNPUBLISHED), graph);
- if(partial){
- RdfUtils.addTripleUri(codeListIri, RDF.TYPE, SKOS.COLLECTION, model, graph);
- } else {
- RdfUtils.addTripleUri(codeListIri, RDF.TYPE, SKOS.CONCEPT_SCHEME, model, graph);
- }
+ IRI type = partial ? SKOS.COLLECTION : SKOS.CONCEPT_SCHEME ;
+ RdfUtils.addTripleUri(codeListIri, RDF.TYPE, type, model, graph);
model.add(codeListIri, SKOS.NOTATION, RdfUtils.setLiteralString(codeListId), graph);
- if(!partial){
- IRI owlClassUri = RdfUtils.codeListIRI("concept/" + codesList.getString("lastClassUriSegment"));
- RdfUtils.addTripleUri(codeListIri, RDFS.SEEALSO, owlClassUri, model, graph);
- RdfUtils.addTripleUri(owlClassUri, RDF.TYPE, OWL.CLASS, model, graph);
- RdfUtils.addTripleUri(owlClassUri, RDFS.SEEALSO, codeListIri, model, graph);
- }
-
if(codesList.has("disseminationStatus")){
RdfUtils.addTripleUri(codeListIri, INSEE.DISSEMINATIONSTATUS, codesList.getString("disseminationStatus"), model, graph);
@@ -353,6 +375,11 @@ private String createOrUpdateCodeList(Model model, Resource graph, JSONObject co
RdfUtils.addTripleUri(codeListIri, PROV.WAS_DERIVED_FROM, codesList.getString("iriParent"), model, graph);
}
} else {
+ IRI owlClassUri = RdfUtils.codeListIRI("concept/" + codesList.getString("lastClassUriSegment"));
+ RdfUtils.addTripleUri(codeListIri, RDFS.SEEALSO, owlClassUri, model, graph);
+ RdfUtils.addTripleUri(owlClassUri, RDF.TYPE, OWL.CLASS, model, graph);
+ RdfUtils.addTripleUri(owlClassUri, RDFS.SEEALSO, codeListIri, model, graph);
+
CodeList original = getCodeList(codeListId);
if(original.getCodes() != null) {
original.getCodes().forEach(code -> {
@@ -366,8 +393,6 @@ private String createOrUpdateCodeList(Model model, Resource graph, JSONObject co
}
createCodeTriplet(graph, codesList, codeListIri, model);
}
-
-
repoGestion.loadSimpleObject(codeListIri, model, null);
return codeListId;
}
@@ -382,29 +407,29 @@ private void createCodeTriplet(Resource graph, JSONObject codesList, IRI codeLis
JSONObject code = codes.getJSONObject(key);
Model codeModel = new LinkedHashModel();
- IRI codeIri = RdfUtils.codeListIRI(codesList.getString(LAST_LIST_URI_SEGMENT) + "/" + code.get("code"));
+ IRI codeIri = RdfUtils.codeListIRI(codesList.getString(LAST_LIST_URI_SEGMENT) + "/" + code.get(CODE));
createMainCodeTriplet(graph, codeListIri, code, codeModel, codeIri);
- if (code.has("parents")) {
+ if (code.has(Constants.PARENTS)) {
JSONArray parentsWithPosition = code.getJSONArray(Constants.PARENTS);
parentsWithPosition.forEach(parentWithPosition -> {
- String parentCode = ((JSONObject) parentWithPosition).getString("code");
+ String parentCode = ((JSONObject) parentWithPosition).getString(CODE);
if(!parentCode.equalsIgnoreCase("")){
IRI parentIRI = RdfUtils.codeListIRI(codesList.getString(LAST_LIST_URI_SEGMENT) + "/" + parentCode);
RdfUtils.addTripleUri(codeIri, SKOS.BROADER, parentIRI, codeModel, graph);
if (parentsModel.has(parentCode)) {
- parentsModel.getJSONArray(parentCode).put(code.get("code"));
+ parentsModel.getJSONArray(parentCode).put(code.get(CODE));
} else {
- parentsModel.put(parentCode, new JSONArray().put(code.get("code")));
+ parentsModel.put(parentCode, new JSONArray().put(code.get(CODE)));
}
}
else {
if (parentsModel.has("")) {
- parentsModel.getJSONArray("").put(code.get("code"));
+ parentsModel.getJSONArray("").put(code.get(CODE));
} else {
- parentsModel.put("", new JSONArray().put(code.get("code")));
+ parentsModel.put("", new JSONArray().put(code.get(CODE)));
}
}
});
@@ -433,24 +458,24 @@ private void createCodesSeq(Resource graph, IRI codeListIri, JSONObject parentsM
//IRI codeIri = RdfUtils.codeListIRI(codesList.getString(LAST_LIST_URI_SEGMENT) + "/" + code.get("code"));
RdfUtils.addTripleUri(codeListIri, RDF.TYPE, RDF.SEQ, codeListModel, graph);
- JSONObject codes = codesList.getJSONObject("codes");
+ JSONObject codes = codesList.getJSONObject(CODES);
AtomicInteger i = new AtomicInteger();
List