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 rootNodes = parentsModel.getJSONArray("").toList(); rootNodes.sort((key1, key2) -> { - JSONObject parent1 = findParentPositionForCode(key1, "", codes, codeListIri); - JSONObject parent2 = findParentPositionForCode(key2, "", codes, codeListIri) ; ; - return parent1.getInt("position") - parent2.getInt("position"); + JSONObject parent1 = findParentPositionForCode(key1, "", codes); + JSONObject parent2 = findParentPositionForCode(key2, "", codes) ; + return parent1.getInt(POSITION) - parent2.getInt(POSITION); }); rootNodes.forEach(rootNode -> { String rootNodeCode = (String) rootNode; if (parentsModel.has(rootNodeCode)) { List children = parentsModel.getJSONArray(rootNodeCode).toList(); children.sort((child1, child2) -> { - JSONObject parent1 = findParentPositionForCode(child1, rootNodeCode, codes, codeListIri); - JSONObject parent2 = findParentPositionForCode(child2, rootNodeCode, codes, codeListIri) ; ; - return parent1.getInt("position") - parent2.getInt("position"); + JSONObject parent1 = findParentPositionForCode(child1, rootNodeCode, codes); + JSONObject parent2 = findParentPositionForCode(child2, rootNodeCode, codes) ; + return parent1.getInt(POSITION) - parent2.getInt(POSITION); }); children.forEach(child -> { @@ -465,13 +490,13 @@ private void createCodesSeq(Resource graph, IRI codeListIri, JSONObject parentsM }); } - private JSONObject findParentPositionForCode(Object childCode, String parentCode, JSONObject codes, IRI codeListIri) { + private JSONObject findParentPositionForCode(Object childCode, String parentCode, JSONObject codes) { JSONArray parents = codes .getJSONObject(((String) childCode)) .getJSONArray(Constants.PARENTS); JSONObject parentWithPosition = new JSONObject(); for (int i = 0; i < parents.length(); i++){ - if(parents.getJSONObject(i).getString("code").equalsIgnoreCase(parentCode)){ + if(parents.getJSONObject(i).getString(CODE).equalsIgnoreCase(parentCode)){ parentWithPosition = parents.getJSONObject(i); break; } @@ -486,7 +511,7 @@ private void createParentChildRelationForCodes(Resource graph, JSONObject codesL JSONArray children = parentsModel.getJSONArray(key); children.forEach(child -> { IRI childIri = RdfUtils.codeListIRI(codesList.getString(LAST_LIST_URI_SEGMENT) + "/" + child); - RdfUtils.addTripleUri(parentIRI, SKOS.NARROWER, childIri.toString(), parentModel, graph); + RdfUtils.addTripleUri(parentIRI, SKOS.NARROWER, RdfUtils.toString(childIri), parentModel, graph); }); try { repoGestion.getConnection().add(parentModel); @@ -498,8 +523,8 @@ private void createParentChildRelationForCodes(Resource graph, JSONObject codesL private void createMainCodeTriplet(Resource graph, IRI codeListIri, JSONObject code, Model codeListModel, IRI codeIri) { RdfUtils.addTripleUri(codeIri, SKOS.IN_SCHEME, codeListIri, codeListModel, graph); - if(code.has("code")){ - RdfUtils.addTripleString(codeIri, SKOS.NOTATION, code.getString("code"), codeListModel, graph); + if(code.has(CODE)){ + RdfUtils.addTripleString(codeIri, SKOS.NOTATION, code.getString(CODE), codeListModel, graph); } if(code.has(Constants.LABEL_LG1)){ @@ -532,7 +557,7 @@ private JSONArray getCodesForList(JSONArray codes, JSONObject list) { @Override public String getCode(String notationCodeList, String notationCode) throws RmesException{ JSONObject code = repoGestion.getResponseAsObject(CodeListQueries.getCodeByNotation(notationCodeList,notationCode)); - code.put("code", notationCode); + code.put(CODE, notationCode); code.put("notationCodeList", notationCodeList); return QueryUtils.correctEmptyGroupConcat(code.toString()); } diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/concepts/ConceptsImpl.java b/src/main/java/fr/insee/rmes/bauhaus_services/concepts/ConceptsImpl.java index 7951bf908..12296153c 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/concepts/ConceptsImpl.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/concepts/ConceptsImpl.java @@ -12,7 +12,6 @@ import org.apache.http.HttpStatus; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.eclipse.rdf4j.model.impl.SimpleIRI; import org.json.JSONArray; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; @@ -88,7 +87,7 @@ public String getConceptByID(String id) throws RmesException{ @Override public String getRelatedConcepts(String id) throws RmesException{ - String uriConcept = ((SimpleIRI)RdfUtils.objectIRI(ObjectType.CONCEPT,id)).toString(); + String uriConcept = RdfUtils.toString(RdfUtils.objectIRI(ObjectType.CONCEPT,id)); JSONArray resQuery = conceptsUtils.getRelatedConcepts(uriConcept); return QueryUtils.correctEmptyGroupConcat(resQuery.toString()); } @@ -101,7 +100,7 @@ public String getRelatedConcepts(String id) throws RmesException{ */ @Override public String deleteConcept(String id) throws RmesException { - String uriConcept = ((SimpleIRI)RdfUtils.objectIRI(ObjectType.CONCEPT,id)).toString(); + String uriConcept = RdfUtils.toString(RdfUtils.objectIRI(ObjectType.CONCEPT,id)); JSONArray graphArray = conceptsUtils.getGraphsWithConcept(uriConcept); /* check concept isn't used in several graphs */ @@ -234,7 +233,7 @@ public void setConceptsValidation(String body) throws RmesException { * Export concept(s) */ @Override - public Response getConceptExport(String id, String acceptHeader) throws RmesException { + public Response exportConcept(String id, String acceptHeader) throws RmesException { ConceptForExport concept; try { concept = conceptsExport.getConceptData(id); 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 37855f8fc..53d59c416 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 @@ -13,7 +13,6 @@ import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.model.impl.LinkedHashModel; -import org.eclipse.rdf4j.model.impl.SimpleIRI; import org.eclipse.rdf4j.model.vocabulary.DC; import org.eclipse.rdf4j.model.vocabulary.DCTERMS; import org.eclipse.rdf4j.model.vocabulary.RDF; @@ -200,9 +199,9 @@ public JSONArray getRelatedConcepts(String id) throws RmesException{ } public Response.Status deleteConcept(String id) throws RmesException{ - Response.Status result = repoGestion.executeUpdate(ConceptsQueries.deleteConcept(((SimpleIRI)RdfUtils.objectIRI(ObjectType.CONCEPT,id)).toString(),RdfUtils.conceptGraph().toString())); + Response.Status result = repoGestion.executeUpdate(ConceptsQueries.deleteConcept(RdfUtils.toString(RdfUtils.objectIRI(ObjectType.CONCEPT,id)),RdfUtils.conceptGraph().toString())); if (result.equals(Status.OK)) { - result = RepositoryPublication.executeUpdate(ConceptsQueries.deleteConcept(((SimpleIRI)RdfUtils.objectIRIPublication(ObjectType.CONCEPT,id)).toString(),RdfUtils.conceptGraph().toString())); + result = RepositoryPublication.executeUpdate(ConceptsQueries.deleteConcept(RdfUtils.toString(RdfUtils.objectIRIPublication(ObjectType.CONCEPT,id)),RdfUtils.conceptGraph().toString())); } return result; } 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 2a6d190dd..e9ec3190a 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 @@ -9,7 +9,7 @@ import org.eclipse.rdf4j.model.Resource; import org.eclipse.rdf4j.model.Statement; import org.eclipse.rdf4j.model.impl.LinkedHashModel; -import org.eclipse.rdf4j.model.impl.SimpleIRI; +import org.eclipse.rdf4j.model.vocabulary.DCTERMS; import org.eclipse.rdf4j.model.vocabulary.SKOS; import org.eclipse.rdf4j.repository.RepositoryConnection; import org.eclipse.rdf4j.repository.RepositoryException; @@ -50,7 +50,7 @@ public void publishConcepts(JSONArray conceptsToPublish) throws RmesException { RepositoryResult statements = repoGestion.getStatements(con, concept); String[] notes = {"scopeNote","definition","editorialNote"} ; - String[] links = {"inScheme","disseminationStatus","references","replaces","related"}; + String[] links = {"inScheme","disseminationStatus","references","isReplacedBy"}; String[] ignoredAttrs = {"isValidated","changeNote",Constants.CREATOR,"contributor"}; try { @@ -61,7 +61,7 @@ public void publishConcepts(JSONArray conceptsToPublish) throws RmesException { Statement st = statements.next(); subject = PublicationUtils.tranformBaseURIToPublish(st.getSubject()); graph = st.getContext(); - String predicat = ((SimpleIRI)st.getPredicate()).toString(); + String predicat = RdfUtils.toString(st.getPredicate()); // Notes, transform URI and get attributs if (PublicationUtils.stringEndsWithItemFromList(predicat,notes)) { model.add(subject, st.getPredicate(), PublicationUtils.tranformBaseURIToPublish((Resource) st.getObject()), @@ -74,8 +74,17 @@ else if (PublicationUtils.stringEndsWithItemFromList(predicat,links)) { model.add(subject, st.getPredicate(), PublicationUtils.tranformBaseURIToPublish((Resource) st.getObject()), graph); } - // Broader links - else if (predicat.endsWith("broader")) { + else if (predicat.endsWith("related")) { + hasBroader = true; + model.add(subject, st.getPredicate(), PublicationUtils.tranformBaseURIToPublish((Resource) st.getObject()), + graph); + model.add(PublicationUtils.tranformBaseURIToPublish((Resource) st.getObject()), SKOS.RELATED, subject, graph); + } else if (predicat.endsWith("replaces")) { + hasBroader = true; + model.add(subject, st.getPredicate(), PublicationUtils.tranformBaseURIToPublish((Resource) st.getObject()), + graph); + model.add(PublicationUtils.tranformBaseURIToPublish((Resource) st.getObject()), DCTERMS.IS_REPLACED_BY, subject, graph); + } else if (predicat.endsWith("broader")) { hasBroader = true; model.add(subject, st.getPredicate(), PublicationUtils.tranformBaseURIToPublish((Resource) st.getObject()), graph); @@ -100,8 +109,10 @@ else if (predicat.endsWith("narrower")) { graph); } } catch (RepositoryException e) { + repoGestion.closeStatements(statements); + con.close(); throw new RmesException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), Constants.REPOSITORY_EXCEPTION); - } + } repoGestion.closeStatements(statements); publishMemberLinks(concept, model, con); @@ -142,7 +153,7 @@ public void publishExplanatoryNotes(RepositoryConnection con, Resource note, Mod Resource graph = null; while (statements.hasNext()) { Statement st = statements.next(); - String predicat = ((SimpleIRI)st.getPredicate()).toString(); + String predicat = RdfUtils.toString(st.getPredicate()); subject = PublicationUtils.tranformBaseURIToPublish(st.getSubject()); graph = st.getContext(); if (predicat.endsWith("conceptVersion")) { @@ -209,12 +220,12 @@ public void publishCollection(JSONArray collectionsToValidate) throws RmesExcept while (statements.hasNext()) { Statement st = statements.next(); // Other URI to transform - if (((SimpleIRI)st.getPredicate()).toString().endsWith("member")) { + if (RdfUtils.toString(st.getPredicate()).endsWith("member")) { model.add(PublicationUtils.tranformBaseURIToPublish(st.getSubject()), st.getPredicate(), PublicationUtils.tranformBaseURIToPublish((Resource) st.getObject()), st.getContext()); - } else if (((SimpleIRI)st.getPredicate()).toString().endsWith("isValidated") - || ((SimpleIRI)st.getPredicate()).toString().endsWith(Constants.CREATOR) - || ((SimpleIRI)st.getPredicate()).toString().endsWith("contributor")) { + } else if (RdfUtils.toString(st.getPredicate()).endsWith("isValidated") + || (RdfUtils.toString(st.getPredicate()).endsWith(Constants.CREATOR)) + || (RdfUtils.toString(st.getPredicate()).endsWith("contributor"))) { // nothing, wouldn't copy this attr } // Literals diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/geography/GeographyServiceImpl.java b/src/main/java/fr/insee/rmes/bauhaus_services/geography/GeographyServiceImpl.java index caafa7868..c7cd88832 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/geography/GeographyServiceImpl.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/geography/GeographyServiceImpl.java @@ -119,7 +119,7 @@ public void updateFeature(String id, String body) throws RmesException { GeoFeature geoFeature = new GeoFeature(); try { geoFeature = mapper.readValue(body,GeoFeature.class); - geoFeature.setId(id.toString()); + geoFeature.setId(id); if (geoFeature.getCode()==null) { geoFeature.setCode(geoFeature.getId()); } @@ -188,7 +188,7 @@ public String createRdfGeoFeature(GeoFeature geoFeature) throws RmesException { }); repoGestion.loadSimpleObject(geoIRI, model); - return geoIRI.toString(); + return RdfUtils.toString(geoIRI); } } 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 43b75c719..a1a2f66df 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 @@ -5,6 +5,7 @@ import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.model.vocabulary.DCTERMS; +import org.eclipse.rdf4j.model.vocabulary.RDFS; import org.eclipse.rdf4j.model.vocabulary.SKOS; import fr.insee.rmes.bauhaus_services.rdf_utils.RdfUtils; @@ -18,7 +19,6 @@ public void createRdfLinks(IRI conceptURI, List links, Model model) { // Create links links.forEach(link -> { - if (link.getTypeOfLink().equals("narrower")) { addTripleNarrower(conceptURI, link.getIds(), model); } @@ -36,27 +36,33 @@ else if (link.getTypeOfLink().equals("related")) { } else if (link.getTypeOfLink().equals("closeMatch")){ addTripleCloseMatch(conceptURI, link.getUrn(), model); + } else if (link.getTypeOfLink().equals("succeededBy")){ + addTripleReplacedByMatch(conceptURI, link.getIds(), model); } }); } + private void addTripleReplacedByMatch(IRI conceptURI, List conceptsIDToLink, Model model) { + conceptsIDToLink.forEach(conceptIDToLink -> model.add(conceptURI, DCTERMS.IS_REPLACED_BY, RdfUtils.conceptIRI(conceptIDToLink), RdfUtils.conceptGraph())); + } + private void addTripleCloseMatch(IRI conceptURI, List urn, Model model) { urn.forEach(urnToAdd -> model.add(conceptURI, SKOS.CLOSE_MATCH, RdfUtils.toURI(urnToAdd), RdfUtils.conceptGraph())); } private void addTripleBroader(IRI conceptURI, List conceptsIDToLink, Model model) { conceptsIDToLink.forEach(conceptIDToLink -> { - model.add(conceptURI, SKOS.NARROWER, RdfUtils.conceptIRI(conceptIDToLink), RdfUtils.conceptGraph()); - model.add(RdfUtils.conceptIRI(conceptIDToLink), SKOS.BROADER, conceptURI, RdfUtils.conceptGraph()); + model.add(conceptURI, SKOS.BROADER, RdfUtils.conceptIRI(conceptIDToLink), RdfUtils.conceptGraph()); + model.add(RdfUtils.conceptIRI(conceptIDToLink), SKOS.NARROWER, conceptURI, RdfUtils.conceptGraph()); }); } private void addTripleNarrower(IRI conceptURI, List conceptsIDToLink, Model model) { conceptsIDToLink.forEach(conceptIDToLink -> { - model.add(conceptURI, SKOS.BROADER, RdfUtils.conceptIRI(conceptIDToLink), RdfUtils.conceptGraph()); - model.add(RdfUtils.conceptIRI(conceptIDToLink), SKOS.NARROWER, conceptURI, RdfUtils.conceptGraph()); + model.add(conceptURI, SKOS.NARROWER, RdfUtils.conceptIRI(conceptIDToLink), RdfUtils.conceptGraph()); + model.add(RdfUtils.conceptIRI(conceptIDToLink), SKOS.BROADER, conceptURI, RdfUtils.conceptGraph()); }); } @@ -67,14 +73,18 @@ private void addTripleReferences(IRI conceptURI, List conceptsIDToLink, } private void addTripleSucceed(IRI conceptURI, List conceptsIDToLink, Model model) { - conceptsIDToLink.forEach(conceptIDToLink -> + conceptsIDToLink.forEach(conceptIDToLink -> { model.add(conceptURI, DCTERMS.REPLACES, RdfUtils.conceptIRI(conceptIDToLink), - RdfUtils.conceptGraph())); + RdfUtils.conceptGraph()); + model.add(RdfUtils.conceptIRI(conceptIDToLink), DCTERMS.IS_REPLACED_BY, conceptURI, RdfUtils.conceptGraph()); + }); } private void addTripleRelated(IRI conceptURI, List conceptsIDToLink, Model model) { - conceptsIDToLink.forEach(conceptIDToLink -> - model.add(conceptURI, SKOS.RELATED, RdfUtils.conceptIRI(conceptIDToLink), RdfUtils.conceptGraph())); + conceptsIDToLink.forEach(conceptIDToLink -> { + model.add(conceptURI, SKOS.RELATED, RdfUtils.conceptIRI(conceptIDToLink), RdfUtils.conceptGraph()); + model.add(RdfUtils.conceptIRI(conceptIDToLink), SKOS.RELATED, conceptURI, RdfUtils.conceptGraph()); + }); } } diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/operations/OperationsImpl.java b/src/main/java/fr/insee/rmes/bauhaus_services/operations/OperationsImpl.java index 0da2fbc02..9488033fe 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/operations/OperationsImpl.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/operations/OperationsImpl.java @@ -11,15 +11,12 @@ import java.nio.charset.Charset; import java.text.Normalizer; import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; import java.util.List; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; -import fr.insee.rmes.config.auth.security.restrictions.StampsRestrictionsService; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.glassfish.jersey.media.multipart.ContentDisposition; @@ -96,9 +93,6 @@ public class OperationsImpl extends RdfService implements OperationsService { @Autowired MetadataStructureDefUtils msdUtils; - @Autowired - StampsRestrictionsService stampsRestrictionsService; - /*************************************************************************************************** * SERIES @@ -129,18 +123,15 @@ public String getSeriesWithSims() throws RmesException { public String getSeriesWithStamp(String stamp) throws RmesException { logger.info("Starting to get series list with sims"); JSONArray series = repoGestion.getResponseAsArray(SeriesQueries.seriesWithStampQuery(stamp, this.stampsRestrictionsService.isAdmin())); - List seriesList = new ArrayList(); + List seriesList = new ArrayList<>(); for (int i = 0; i < series.length(); i++) { seriesList.add(series.getJSONObject(i)); } - seriesList.sort(new Comparator() { - @Override - public int compare(JSONObject o1, JSONObject o2) { + seriesList.sort(( o1, o2) -> { String key1 = Normalizer.normalize(o1.getString("label"), Normalizer.Form.NFD); String key2 = Normalizer.normalize(o2.getString("label"), Normalizer.Form.NFD); return key1.compareTo(key2); - } - }); + }); return QueryUtils.correctEmptyGroupConcat(seriesList.toString()); } @@ -317,6 +308,13 @@ public String createFamily(String body) throws RmesException { return familiesUtils.createFamily(body); } + public String getSeriesWithReport(String idFamily) throws RmesException { + JSONArray resQuery = repoGestion.getResponseAsArray(OperationsQueries.seriesWithSimsQuery(idFamily)); + if (resQuery.length()==1 &&resQuery.getJSONObject(0).length()==0) {resQuery.remove(0);} + return QueryUtils.correctEmptyGroupConcat(resQuery.toString()); + } + + /*************************************************************************************************** * INDICATORS * @throws RmesException diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/operations/documentations/DocumentationPublication.java b/src/main/java/fr/insee/rmes/bauhaus_services/operations/documentations/DocumentationPublication.java index 489bd59b9..4f690e15b 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/operations/documentations/DocumentationPublication.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/operations/documentations/DocumentationPublication.java @@ -7,7 +7,6 @@ import org.eclipse.rdf4j.model.Statement; import org.eclipse.rdf4j.model.Value; import org.eclipse.rdf4j.model.impl.LinkedHashModel; -import org.eclipse.rdf4j.model.impl.SimpleIRI; import org.eclipse.rdf4j.repository.RepositoryConnection; import org.eclipse.rdf4j.repository.RepositoryException; import org.eclipse.rdf4j.repository.RepositoryResult; @@ -56,7 +55,7 @@ public void publishSims(String simsId) throws RmesException { while (metadataReportStatements.hasNext()) { Statement st = metadataReportStatements.next(); // Triplets that don't get published - String predicate = ((SimpleIRI)st.getPredicate()).toString(); + String predicate = RdfUtils.toString(st.getPredicate()); if (!isTripletForPublication(predicate)) { // nothing, wouldn't copy this attr } else { diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/operations/documentations/DocumentationsUtils.java b/src/main/java/fr/insee/rmes/bauhaus_services/operations/documentations/DocumentationsUtils.java index 814a479d6..13fae3606 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/operations/documentations/DocumentationsUtils.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/operations/documentations/DocumentationsUtils.java @@ -10,7 +10,6 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; -import fr.insee.rmes.utils.DateUtils; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpStatus; import org.apache.logging.log4j.LogManager; @@ -19,7 +18,6 @@ import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.model.Resource; import org.eclipse.rdf4j.model.impl.LinkedHashModel; -import org.eclipse.rdf4j.model.impl.SimpleIRI; import org.eclipse.rdf4j.model.vocabulary.DCTERMS; import org.eclipse.rdf4j.model.vocabulary.RDF; import org.eclipse.rdf4j.model.vocabulary.RDFS; @@ -61,6 +59,7 @@ import fr.insee.rmes.persistance.ontologies.INSEE; import fr.insee.rmes.persistance.ontologies.SDMX_MM; import fr.insee.rmes.persistance.sparql_queries.operations.documentations.DocumentationsQueries; +import fr.insee.rmes.utils.DateUtils; import fr.insee.rmes.utils.EncodingType; import fr.insee.rmes.utils.XMLUtils; @@ -203,7 +202,7 @@ public String setMetadataReport(String id, String body, boolean create) throws R // Create or update rdf IRI seriesOrIndicatorUri = targetUri; - if (((SimpleIRI) targetUri).toString().contains(Config.OPERATIONS_BASE_URI)) { + if (RdfUtils.toString(targetUri).contains(Config.OPERATIONS_BASE_URI)) { seriesOrIndicatorUri = operationsUtils.getSeriesUriByOperationId(idTarget); } if (create) { 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 c6ce5c534..67bb5d6b1 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 @@ -108,7 +108,7 @@ private Model getModelToPublish(String documentId, String filename) throws RmesE } while (documentStatements.hasNext()) { Statement st = documentStatements.next(); - if (((SimpleIRI)st.getPredicate()).toString().endsWith("url")) { + if (RdfUtils.toString(st.getPredicate()).endsWith("url")) { Resource subject = PublicationUtils.tranformBaseURIToPublish(st.getSubject()); IRI predicate = RdfUtils .createIRI(PublicationUtils.tranformBaseURIToPublish(st.getPredicate()).stringValue()); 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 fe3f85983..f02d6ccdb 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 @@ -5,7 +5,6 @@ import org.eclipse.rdf4j.model.Resource; import org.eclipse.rdf4j.model.Statement; import org.eclipse.rdf4j.model.impl.LinkedHashModel; -import org.eclipse.rdf4j.model.impl.SimpleIRI; import org.eclipse.rdf4j.repository.RepositoryConnection; import org.eclipse.rdf4j.repository.RepositoryException; import org.eclipse.rdf4j.repository.RepositoryResult; @@ -42,7 +41,7 @@ public void publishFamily(String familyId) throws RmesException { } while (statements.hasNext()) { Statement st = statements.next(); - String pred = ((SimpleIRI) st.getPredicate()).toString(); + String pred = RdfUtils.toString(st.getPredicate()); // Triplets that don't get published if (pred.endsWith("isValidated") || pred.endsWith("validationState") diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/operations/famopeserind_utils/FamOpeSerIndUtils.java b/src/main/java/fr/insee/rmes/bauhaus_services/operations/famopeserind_utils/FamOpeSerIndUtils.java index cbb30f4cf..9ab2007f7 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/operations/famopeserind_utils/FamOpeSerIndUtils.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/operations/famopeserind_utils/FamOpeSerIndUtils.java @@ -5,7 +5,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.eclipse.rdf4j.model.impl.SimpleIRI; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -39,7 +38,7 @@ public String createId() throws RmesException { } public boolean checkIfObjectExists(ObjectType type, String id) throws RmesException { - return repoGestion.getResponseAsBoolean(FamOpeSerQueries.checkIfFamOpeSerExists(((SimpleIRI)RdfUtils.objectIRI(type, id)).toString())); + return repoGestion.getResponseAsBoolean(FamOpeSerQueries.checkIfFamOpeSerExists(RdfUtils.toString(RdfUtils.objectIRI(type, id)))); } public String getValidationStatus(String id) throws RmesException{ 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 aa3a2d5db..0e9488d7e 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 @@ -5,7 +5,6 @@ import org.eclipse.rdf4j.model.Resource; import org.eclipse.rdf4j.model.Statement; import org.eclipse.rdf4j.model.impl.LinkedHashModel; -import org.eclipse.rdf4j.model.impl.SimpleIRI; import org.eclipse.rdf4j.repository.RepositoryConnection; import org.eclipse.rdf4j.repository.RepositoryException; import org.eclipse.rdf4j.repository.RepositoryResult; @@ -44,7 +43,7 @@ public void publishIndicator(String indicatorId) throws RmesException { while (statements.hasNext()) { Statement st = statements.next(); // Triplets that don't get published - String pred = ((SimpleIRI) st.getPredicate()).toString(); + String pred = RdfUtils.toString(st.getPredicate()); if (pred.endsWith("isValidated") || pred.endsWith("validationState")) { 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 53d4682a0..f75ea913f 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 @@ -5,7 +5,6 @@ import org.eclipse.rdf4j.model.Resource; import org.eclipse.rdf4j.model.Statement; import org.eclipse.rdf4j.model.impl.LinkedHashModel; -import org.eclipse.rdf4j.model.impl.SimpleIRI; import org.eclipse.rdf4j.repository.RepositoryConnection; import org.eclipse.rdf4j.repository.RepositoryException; import org.eclipse.rdf4j.repository.RepositoryResult; @@ -54,10 +53,10 @@ public void publishOperation(String operationId) throws RmesException { while (statements.hasNext()) { Statement st = statements.next(); // Other URI to transform - if (((SimpleIRI)st.getPredicate()).toString().endsWith("isPartOf")) { + if (RdfUtils.toString(st.getPredicate()).endsWith("isPartOf")) { model.add(PublicationUtils.tranformBaseURIToPublish(st.getSubject()), st.getPredicate(), PublicationUtils.tranformBaseURIToPublish((Resource) st.getObject()), st.getContext()); - } else if (PublicationUtils.stringEndsWithItemFromList(((SimpleIRI)st.getPredicate()).toString(), ignoredAttrs)) { + } else if (PublicationUtils.stringEndsWithItemFromList(RdfUtils.toString(st.getPredicate()), ignoredAttrs)) { // nothing, wouldn't copy this attr } // Literals 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 64df63b99..a22e241fa 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,7 +5,6 @@ import org.eclipse.rdf4j.model.Resource; import org.eclipse.rdf4j.model.Statement; import org.eclipse.rdf4j.model.impl.LinkedHashModel; -import org.eclipse.rdf4j.model.impl.SimpleIRI; import org.eclipse.rdf4j.repository.RepositoryConnection; import org.eclipse.rdf4j.repository.RepositoryException; import org.eclipse.rdf4j.repository.RepositoryResult; @@ -67,7 +66,7 @@ public void publishSeries(String seriesId) throws RmesException { } while (statements.hasNext()) { Statement st = statements.next(); - String pred = ((SimpleIRI) st.getPredicate()).toString(); + String pred = RdfUtils.toString(st.getPredicate()); // Other URI to transform if (pred.endsWith("isPartOf") || diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/operations/series/SeriesUtils.java b/src/main/java/fr/insee/rmes/bauhaus_services/operations/series/SeriesUtils.java index f35eb8205..69f65d359 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/operations/series/SeriesUtils.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/operations/series/SeriesUtils.java @@ -5,7 +5,6 @@ import java.util.List; import java.util.Optional; -import fr.insee.rmes.utils.*; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpStatus; import org.apache.logging.log4j.LogManager; @@ -13,7 +12,6 @@ import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.model.impl.LinkedHashModel; -import org.eclipse.rdf4j.model.impl.SimpleIRI; import org.eclipse.rdf4j.model.vocabulary.DC; import org.eclipse.rdf4j.model.vocabulary.DCTERMS; import org.eclipse.rdf4j.model.vocabulary.RDF; @@ -49,6 +47,11 @@ import fr.insee.rmes.model.operations.Series; import fr.insee.rmes.persistance.ontologies.INSEE; import fr.insee.rmes.persistance.sparql_queries.operations.series.SeriesQueries; +import fr.insee.rmes.utils.DateUtils; +import fr.insee.rmes.utils.EncodingType; +import fr.insee.rmes.utils.JSONUtils; +import fr.insee.rmes.utils.XMLUtils; +import fr.insee.rmes.utils.XhtmlToMarkdownUtils; @Component public class SeriesUtils extends RdfService { @@ -200,7 +203,7 @@ public JSONArray getSeriesCreators(String id) throws RmesException { } public JSONArray getSeriesCreators(IRI iri) throws RmesException { - return repoGestion.getResponseAsJSONList(SeriesQueries.getCreatorsBySeriesUri(((SimpleIRI)iri).toString())); + return repoGestion.getResponseAsJSONList(SeriesQueries.getCreatorsBySeriesUri(RdfUtils.toString(iri))); } /*WRITE*/ diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RdfUtils.java b/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RdfUtils.java index d90967435..5333709c3 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RdfUtils.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RdfUtils.java @@ -4,14 +4,12 @@ import java.time.LocalDate; import java.time.format.DateTimeFormatter; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.eclipse.rdf4j.model.BNode; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Literal; import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.model.Resource; import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.impl.SimpleIRI; import org.eclipse.rdf4j.model.impl.SimpleValueFactory; import org.eclipse.rdf4j.model.vocabulary.RDF; import org.eclipse.rdf4j.model.vocabulary.XSD; @@ -206,6 +204,10 @@ public static IRI toURI(String string) { return factory.createIRI(string.trim()); } + public static String toString(IRI iri) { + return ((SimpleIRI)iri).toString(); + } + /** * Utils to create triples if data exist */ 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 c0f4e6008..6b7476a89 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 @@ -5,6 +5,7 @@ import javax.ws.rs.core.Response; +import fr.insee.rmes.persistance.sparql_queries.concepts.ConceptsQueries; import org.apache.http.HttpStatus; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -12,7 +13,6 @@ import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.model.Resource; import org.eclipse.rdf4j.model.Statement; -import org.eclipse.rdf4j.model.impl.SimpleIRI; import org.eclipse.rdf4j.model.vocabulary.DCTERMS; import org.eclipse.rdf4j.model.vocabulary.SKOS; import org.eclipse.rdf4j.repository.Repository; @@ -132,7 +132,7 @@ private RepositoryResult getStatementsPredicatObject(RepositoryConnec try { statements = con.getStatements(null, predicate, object, false); } catch (RepositoryException e) { - throwsRmesException(e, "Failure get " +((SimpleIRI)predicate).toString() + " statements : " + object); + throwsRmesException(e, "Failure get " +RdfUtils.toString(predicate) + " statements : " + object); } return statements; } @@ -271,7 +271,7 @@ public void objectValidation(IRI ressourceURI, Model model) throws RmesException } public void clearConceptLinks(Resource concept, RepositoryConnection conn) throws RmesException { - List typeOfLink = Arrays.asList(SKOS.BROADER, SKOS.NARROWER); + List typeOfLink = Arrays.asList(SKOS.BROADER, SKOS.NARROWER, SKOS.RELATED, DCTERMS.IS_REPLACED_BY); getStatementsAndRemove(concept, conn, typeOfLink); } 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 78ed68038..dc3725522 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 @@ -7,6 +7,7 @@ import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status.Family; +import fr.insee.rmes.persistance.sparql_queries.concepts.ConceptsQueries; import org.apache.http.HttpStatus; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -128,6 +129,8 @@ public static void publishConcept(Resource concept, Model model, List private static void publishConcept(Resource concept, Model model, List noteToClear, List topConceptOfToDelete, Repository repo) throws RmesException { + + if (repo == null) {return ;} try { @@ -203,7 +206,7 @@ public static void clearStructureAndComponentForAllRepositories(Resource structu 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); + DCTERMS.REPLACES, SKOS.RELATED, DCTERMS.IS_REPLACED_BY); for (IRI predicat : typeOfLink) { RepositoryResult statements = null; diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/stamps/StampsRestrictionServiceImpl.java b/src/main/java/fr/insee/rmes/bauhaus_services/stamps/StampsRestrictionServiceImpl.java index a920440c8..f060e06c9 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/stamps/StampsRestrictionServiceImpl.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/stamps/StampsRestrictionServiceImpl.java @@ -6,7 +6,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.eclipse.rdf4j.model.IRI; -import org.eclipse.rdf4j.model.impl.SimpleIRI; import org.json.JSONArray; import org.json.JSONObject; import org.springframework.security.core.Authentication; @@ -19,6 +18,7 @@ import fr.insee.rmes.bauhaus_services.Constants; import fr.insee.rmes.bauhaus_services.rdf_utils.RdfService; +import fr.insee.rmes.bauhaus_services.rdf_utils.RdfUtils; import fr.insee.rmes.config.Config; import fr.insee.rmes.config.auth.roles.Roles; import fr.insee.rmes.config.auth.security.restrictions.StampsRestrictionsService; @@ -42,7 +42,7 @@ public boolean isConceptOrCollectionOwner(IRI uri) throws RmesException { if (isAdmin(user)) { return true; } - String uriAsString = "<" + ((SimpleIRI)uri).toString() + ">"; + String uriAsString = "<" + RdfUtils.toString(uri) + ">"; JSONObject owner = repoGestion.getResponseAsObject(ConceptsQueries.getOwner(uriAsString)); Boolean isConceptOwner = true; if (!owner.getString(Constants.OWNER).equals(user.getStamp())) { @@ -58,7 +58,7 @@ public boolean isConceptsOrCollectionsOwner(List uris) throws RmesException return true; } StringBuilder sb = new StringBuilder(); - uris.forEach(u -> sb.append("<" + ((SimpleIRI)u).toString() + "> ")); + uris.forEach(u -> sb.append("<" + RdfUtils.toString(u) + "> ")); String uriAsString = sb.toString(); JSONArray owners = repoGestion.getResponseAsArray(ConceptsQueries.getOwner(uriAsString)); Boolean isConceptsOwner = true; @@ -189,7 +189,7 @@ private boolean isCnis(User user) { private boolean isConceptOwner(List uris) throws RmesException { User user = getUser(); StringBuilder sb = new StringBuilder(); - uris.forEach(u -> sb.append("<" + ((SimpleIRI)u).toString() + "> ")); + uris.forEach(u -> sb.append("<" + RdfUtils.toString(u) + "> ")); String uriAsString = sb.toString(); JSONArray owners = repoGestion.getResponseAsArray(ConceptsQueries.getOwner(uriAsString)); Boolean isConceptOwner = true; @@ -204,7 +204,7 @@ private boolean isConceptOwner(List uris) throws RmesException { private boolean isConceptManager(List uris) throws RmesException { User user = getUser(); StringBuilder sb = new StringBuilder(); - uris.forEach(u -> sb.append("<" + ((SimpleIRI)u).toString() + "> ")); + uris.forEach(u -> sb.append("<" + RdfUtils.toString(u) + "> ")); String uriAsString = sb.toString(); JSONArray managers = repoGestion.getResponseAsArray(ConceptsQueries.getManager(uriAsString)); Boolean isConceptManager = true; @@ -218,7 +218,7 @@ private boolean isConceptManager(List uris) throws RmesException { public boolean isSeriesManager(IRI uri) throws RmesException { User user = getUser(); - JSONArray managers = repoGestion.getResponseAsArray(SeriesQueries.getCreatorsBySeriesUri(((SimpleIRI)uri).toString())); + JSONArray managers = repoGestion.getResponseAsArray(SeriesQueries.getCreatorsBySeriesUri(RdfUtils.toString(uri))); Boolean isSeriesManager = false; for (int i = 0; i < managers.length(); i++) { if (managers.getJSONObject(i).getString(Constants.CREATORS).equals(user.getStamp())) { @@ -230,7 +230,7 @@ public boolean isSeriesManager(IRI uri) throws RmesException { private boolean isIndicatorManager(IRI iri) throws RmesException { User user = getUser(); - String uriAsString = "<" + ((SimpleIRI)iri).toString() + "> "; + String uriAsString = "<" + RdfUtils.toString(iri) + "> "; JSONArray creators = repoGestion.getResponseAsArray(IndicatorsQueries.getCreatorsByIndicatorUri(uriAsString)); Boolean isIndicatorManager = false; if (creators.length() > 0) { diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/structures/impl/StructureImpl.java b/src/main/java/fr/insee/rmes/bauhaus_services/structures/impl/StructureImpl.java index 3c89b62d6..48ba1b74c 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/structures/impl/StructureImpl.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/structures/impl/StructureImpl.java @@ -2,7 +2,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.eclipse.rdf4j.model.impl.SimpleIRI; import org.json.JSONArray; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; @@ -11,6 +10,7 @@ import fr.insee.rmes.bauhaus_services.CodeListService; import fr.insee.rmes.bauhaus_services.Constants; import fr.insee.rmes.bauhaus_services.rdf_utils.RdfService; +import fr.insee.rmes.bauhaus_services.rdf_utils.RdfUtils; import fr.insee.rmes.bauhaus_services.structures.StructureService; import fr.insee.rmes.bauhaus_services.structures.utils.StructureUtils; import fr.insee.rmes.exceptions.RmesException; @@ -71,13 +71,13 @@ public String getStructureByIdWithDetails(String id) throws RmesException { // We first have to rename the type property String type = (String) component.get("type"); - if(type.equalsIgnoreCase(((SimpleIRI)QB.ATTRIBUTE_PROPERTY).toString())){ + if(type.equalsIgnoreCase(RdfUtils.toString(QB.ATTRIBUTE_PROPERTY))){ component.put("type", "attribute"); } - else if(type.equalsIgnoreCase(((SimpleIRI)QB.MEASURE_PROPERTY).toString())){ + else if(type.equalsIgnoreCase(RdfUtils.toString(QB.MEASURE_PROPERTY))){ component.put("type", "measure"); } - else if(type.equalsIgnoreCase(((SimpleIRI)QB.DIMENSION_PROPERTY).toString())){ + else if(type.equalsIgnoreCase(RdfUtils.toString(QB.DIMENSION_PROPERTY))){ component.put("type", "dimension"); } diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/structures/utils/ComponentPublication.java b/src/main/java/fr/insee/rmes/bauhaus_services/structures/utils/ComponentPublication.java index c1f11ee07..d718ee27f 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/structures/utils/ComponentPublication.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/structures/utils/ComponentPublication.java @@ -6,7 +6,6 @@ import org.eclipse.rdf4j.model.Resource; import org.eclipse.rdf4j.model.Statement; import org.eclipse.rdf4j.model.impl.LinkedHashModel; -import org.eclipse.rdf4j.model.impl.SimpleIRI; import org.eclipse.rdf4j.repository.RepositoryConnection; import org.eclipse.rdf4j.repository.RepositoryException; import org.eclipse.rdf4j.repository.RepositoryResult; @@ -15,6 +14,7 @@ import fr.insee.rmes.bauhaus_services.Constants; 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.bauhaus_services.rdf_utils.RepositoryPublication; import fr.insee.rmes.exceptions.RmesException; @@ -32,7 +32,7 @@ public void publishComponent(Resource component, IRI type) throws RmesException try { while (statements.hasNext()) { Statement st = statements.next(); - String pred = ((SimpleIRI) st.getPredicate()).toString(); + String pred = RdfUtils.toString(st.getPredicate()); if (pred.endsWith("validationState") || pred.endsWith(Constants.CONTRIBUTOR) || pred.endsWith(Constants.CREATOR)) { // nothing, wouldn't copy this attr }else if (pred.endsWith("attribute") @@ -61,7 +61,7 @@ public void publishComponent(Resource component, IRI type) throws RmesException con.close(); } Resource componentToPublishRessource = PublicationUtils.tranformBaseURIToPublish(component); - RepositoryPublication.publishResource(componentToPublishRessource, model, ((SimpleIRI) type).toString()); + RepositoryPublication.publishResource(componentToPublishRessource, model, RdfUtils.toString(type)); } diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/structures/utils/StructureComponentUtils.java b/src/main/java/fr/insee/rmes/bauhaus_services/structures/utils/StructureComponentUtils.java index 47c849527..3ae477ff2 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/structures/utils/StructureComponentUtils.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/structures/utils/StructureComponentUtils.java @@ -13,8 +13,12 @@ import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.model.Resource; import org.eclipse.rdf4j.model.impl.LinkedHashModel; -import org.eclipse.rdf4j.model.impl.SimpleIRI; -import org.eclipse.rdf4j.model.vocabulary.*; +import org.eclipse.rdf4j.model.vocabulary.DC; +import org.eclipse.rdf4j.model.vocabulary.DCTERMS; +import org.eclipse.rdf4j.model.vocabulary.RDF; +import org.eclipse.rdf4j.model.vocabulary.RDFS; +import org.eclipse.rdf4j.model.vocabulary.SKOS; +import org.eclipse.rdf4j.model.vocabulary.XSD; import org.json.JSONArray; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; @@ -41,7 +45,10 @@ @Component public class StructureComponentUtils extends RdfService { - private static final String IO_EXCEPTION = "IOException"; + private static final String MAX_LENGTH = "maxLength"; + private static final String MIN_LENGTH = "minLength"; + private static final String PATTERN = "pattern"; + private static final String IO_EXCEPTION = "IOException"; static final Logger logger = LogManager.getLogger(StructureComponentUtils.class); public static final String VALIDATED = "Validated"; public static final String MODIFIED = "Modified"; @@ -64,7 +71,7 @@ private void addStructures(JSONObject response, String id) throws RmesException private void addCodeListRange(JSONObject response) { if (response.has(Constants.CODELIST)) { - response.put("range", ((SimpleIRI)INSEE.CODELIST).toString()); + response.put("range", RdfUtils.toString(INSEE.CODELIST)); } } @@ -144,9 +151,9 @@ private void createRDFForComponent(MutualizedComponent component, ValidationStat } String type = component.getType(); - if (type.equals(((SimpleIRI)QB.ATTRIBUTE_PROPERTY).toString())) { + if (type.equals(RdfUtils.toString(QB.ATTRIBUTE_PROPERTY))) { createRDFForComponent(component, QB.ATTRIBUTE_PROPERTY, RdfUtils.structureComponentAttributeIRI(component.getId()), status); - } else if (type.equals(((SimpleIRI)QB.MEASURE_PROPERTY).toString())) { + } else if (type.equals(RdfUtils.toString(QB.MEASURE_PROPERTY))) { createRDFForComponent(component, QB.MEASURE_PROPERTY, RdfUtils.structureComponentMeasureIRI(component.getId()), status); } else { createRDFForComponent(component, QB.DIMENSION_PROPERTY, RdfUtils.structureComponentDimensionIRI(component.getId()), status); @@ -177,7 +184,7 @@ private void createRDFForComponent(MutualizedComponent component, Resource resou RdfUtils.addTripleUri(componentURI, QB.CONCEPT, INSEE.STRUCTURE_CONCEPT + component.getConcept(), model, graph); } - if (component.getRange() != null && component.getRange().equals(((SimpleIRI)INSEE.CODELIST).toString())) { + if (component.getRange() != null && component.getRange().equals(RdfUtils.toString(INSEE.CODELIST))) { RdfUtils.addTripleUri(componentURI, RDF.TYPE, QB.CODED_PROPERTY, model, graph); JSONObject object = repoGestion.getResponseAsObject(StructureQueries.getUriClasseOwl(component.getCodeList())); @@ -190,28 +197,28 @@ private void createRDFForComponent(MutualizedComponent component, Resource resou } else { RdfUtils.addTripleUri(componentURI, RDFS.RANGE, component.getRange(), model, graph); - if (component.getRange() != null && component.getRange().equals(XSD.DATE.toString())) { - RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI("pattern"), component.getPattern(), Config.LG1, model, graph); + if (component.getRange() != null && component.getRange().equals(RdfUtils.toString(XSD.DATE))) { + RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI(PATTERN), component.getPattern(), Config.LG1, model, graph); } - if (component.getRange() != null && component.getRange().equals(XSD.DATETIME.toString())) { - RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI("pattern"), component.getPattern(), Config.LG1, model, graph); + if (component.getRange() != null && component.getRange().equals(RdfUtils.toString(XSD.DATETIME))) { + RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI(PATTERN), component.getPattern(), Config.LG1, model, graph); } - if (component.getRange() != null && component.getRange().equals(XSD.INT.toString())) { - RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI("minLength"), component.getMinLength(), Config.LG1, model, graph); - RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI("maxLength"), component.getMaxLength(), Config.LG1, model, graph); + if (component.getRange() != null && component.getRange().equals(RdfUtils.toString(XSD.INT))) { + RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI(MIN_LENGTH), component.getMinLength(), Config.LG1, model, graph); + RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI(MAX_LENGTH), component.getMaxLength(), Config.LG1, model, graph); RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI("minInclusive"), component.getMinLength(), Config.LG1, model, graph); RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI("maxInclusive"), component.getMaxLength(), Config.LG1, model, graph); } - if (component.getRange() != null && component.getRange().equals(XSD.DOUBLE.toString())) { - RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI("minLength"), component.getMinLength(), Config.LG1, model, graph); - RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI("maxLength"), component.getMaxLength(), Config.LG1, model, graph); + if (component.getRange() != null && component.getRange().equals(RdfUtils.toString(XSD.DOUBLE))) { + RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI(MIN_LENGTH), component.getMinLength(), Config.LG1, model, graph); + RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI(MAX_LENGTH), component.getMaxLength(), Config.LG1, model, graph); RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI("minInclusive"), component.getMinLength(), Config.LG1, model, graph); RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI("maxInclusive"), component.getMaxLength(), Config.LG1, model, graph); } - if (component.getRange() != null && component.getRange().equals(XSD.STRING.toString())) { - RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI("minLength"), component.getMinLength(), Config.LG1, model, graph); - RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI("maxLength"), component.getMaxLength(), Config.LG1, model, graph); - RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI("pattern"), component.getPattern(), Config.LG1, model, graph); + if (component.getRange() != null && component.getRange().equals(RdfUtils.toString(XSD.STRING))) { + RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI(MIN_LENGTH), component.getMinLength(), Config.LG1, model, graph); + RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI(MAX_LENGTH), component.getMaxLength(), Config.LG1, model, graph); + RdfUtils.addTripleString(componentURI, RdfUtils.createXSDIRI(PATTERN), component.getPattern(), Config.LG1, model, graph); } } @@ -223,10 +230,10 @@ private void createRDFForComponent(MutualizedComponent component, Resource resou } private String generateNextId(String type) throws RmesException { - if (type.equals(((SimpleIRI)QB.ATTRIBUTE_PROPERTY).toString())) { + if (type.equals(RdfUtils.toString(QB.ATTRIBUTE_PROPERTY))) { return generateNextId("a", "attribut", QB.ATTRIBUTE_PROPERTY); } - if (type.equals(((SimpleIRI)QB.MEASURE_PROPERTY).toString())) { + if (type.equals(RdfUtils.toString(QB.MEASURE_PROPERTY))) { return generateNextId("m", "mesure", QB.MEASURE_PROPERTY); } return generateNextId("d", "dimension", QB.DIMENSION_PROPERTY); @@ -236,7 +243,7 @@ private String generateNextId(String type) throws RmesException { private String generateNextId(String prefix, String namespaceSuffix, IRI type) throws RmesException { logger.info("Generate id for component"); - JSONObject json = repoGestion.getResponseAsObject(StructureQueries.lastId(namespaceSuffix, ((SimpleIRI)type).toString())); + JSONObject json = repoGestion.getResponseAsObject(StructureQueries.lastId(namespaceSuffix, RdfUtils.toString(type))); logger.debug("JSON when generating the id of a component : {}", json); if (json.length() == 0) { return prefix + "1000"; @@ -298,9 +305,9 @@ public void deleteComponent(JSONObject component, String id, String type) throws throw new RmesException(ErrorCodes.COMPONENT_FORBIDDEN_DELETE, "You cannot delete a validated component", new JSONArray()); } IRI componentIri; - if (type.equalsIgnoreCase(((SimpleIRI)QB.ATTRIBUTE_PROPERTY).toString())) { + if (type.equalsIgnoreCase(RdfUtils.toString(QB.ATTRIBUTE_PROPERTY))) { componentIri = RdfUtils.structureComponentAttributeIRI(id); - } else if (type.equalsIgnoreCase(((SimpleIRI)QB.MEASURE_PROPERTY).toString())) { + } else if (type.equalsIgnoreCase(RdfUtils.toString(QB.MEASURE_PROPERTY))) { componentIri = RdfUtils.structureComponentMeasureIRI(id); } else { componentIri = RdfUtils.structureComponentDimensionIRI(id); @@ -338,13 +345,13 @@ public String publishComponent(JSONObject component) throws RmesException { String type = component.getString("type"); String id = component.getString("id"); - if (type.equals(((SimpleIRI)QB.ATTRIBUTE_PROPERTY).toString())) { + if (type.equals(RdfUtils.toString(QB.ATTRIBUTE_PROPERTY))) { componentPublication.publishComponent(RdfUtils.structureComponentAttributeIRI(id), QB.ATTRIBUTE_PROPERTY); } - else if (type.equals(((SimpleIRI)QB.MEASURE_PROPERTY).toString())) { + else if (type.equals(RdfUtils.toString(QB.MEASURE_PROPERTY))) { componentPublication.publishComponent(RdfUtils.structureComponentMeasureIRI(id), QB.MEASURE_PROPERTY); } - else if (type.equals(((SimpleIRI)QB.DIMENSION_PROPERTY).toString())) { + else if (type.equals(RdfUtils.toString(QB.DIMENSION_PROPERTY))) { componentPublication.publishComponent(RdfUtils.structureComponentDimensionIRI(id), QB.DIMENSION_PROPERTY); } 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 e2ee21b24..19a03eedb 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 @@ -5,7 +5,6 @@ import org.eclipse.rdf4j.model.Resource; import org.eclipse.rdf4j.model.Statement; import org.eclipse.rdf4j.model.impl.LinkedHashModel; -import org.eclipse.rdf4j.model.impl.SimpleIRI; import org.eclipse.rdf4j.repository.RepositoryConnection; import org.eclipse.rdf4j.repository.RepositoryException; import org.eclipse.rdf4j.repository.RepositoryResult; @@ -14,6 +13,7 @@ import fr.insee.rmes.bauhaus_services.Constants; 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.bauhaus_services.rdf_utils.RepositoryPublication; import fr.insee.rmes.exceptions.RmesException; @@ -29,7 +29,7 @@ private void copyTriplet(Resource structure, Model model, RepositoryConnection c while (statements.hasNext()) { Statement st = statements.next(); - String pred = ((SimpleIRI) st.getPredicate()).toString(); + String pred = RdfUtils.toString(st.getPredicate()); if (PublicationUtils.stringEndsWithItemFromList(pred,denyList)) { // nothing, wouldn't copy this attr } else if(pred.endsWith("component")){ diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/structures/utils/StructureUtils.java b/src/main/java/fr/insee/rmes/bauhaus_services/structures/utils/StructureUtils.java index 7636ead12..538a6a982 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/structures/utils/StructureUtils.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/structures/utils/StructureUtils.java @@ -7,7 +7,6 @@ import javax.ws.rs.BadRequestException; -import fr.insee.rmes.bauhaus_services.structures.StructureComponent; import org.apache.http.HttpStatus; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -15,8 +14,11 @@ import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.model.Resource; import org.eclipse.rdf4j.model.impl.LinkedHashModel; -import org.eclipse.rdf4j.model.impl.SimpleIRI; -import org.eclipse.rdf4j.model.vocabulary.*; +import org.eclipse.rdf4j.model.vocabulary.DC; +import org.eclipse.rdf4j.model.vocabulary.DCTERMS; +import org.eclipse.rdf4j.model.vocabulary.RDF; +import org.eclipse.rdf4j.model.vocabulary.RDFS; +import org.eclipse.rdf4j.model.vocabulary.SKOS; import org.json.JSONArray; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; @@ -28,6 +30,7 @@ import fr.insee.rmes.bauhaus_services.Constants; import fr.insee.rmes.bauhaus_services.rdf_utils.RdfService; import fr.insee.rmes.bauhaus_services.rdf_utils.RdfUtils; +import fr.insee.rmes.bauhaus_services.structures.StructureComponent; import fr.insee.rmes.config.Config; import fr.insee.rmes.exceptions.ErrorCodes; import fr.insee.rmes.exceptions.RmesException; @@ -286,7 +289,7 @@ public void createRdfComponentSpecification(IRI structureIRI, ComponentDefinitio IRI componentSpecificationIRI; - componentSpecificationIRI = getComponentDefinitionIRI(((SimpleIRI)structureIRI).toString(), componentDefinition.getId()); + componentSpecificationIRI = getComponentDefinitionIRI(RdfUtils.toString(structureIRI), componentDefinition.getId()); model.add(structureIRI, QB.COMPONENT, componentSpecificationIRI, graph); @@ -305,11 +308,11 @@ public void createRdfComponentSpecification(IRI structureIRI, ComponentDefinitio } MutualizedComponent component = componentDefinition.getComponent(); - if (component.getType().equals(((SimpleIRI)QB.DIMENSION_PROPERTY).toString())) { + if (component.getType().equals(RdfUtils.toString(QB.DIMENSION_PROPERTY))) { model.add(componentSpecificationIRI, QB.DIMENSION, getDimensionIRI(component.getId()), graph); } - if (component.getType().equals(((SimpleIRI)QB.ATTRIBUTE_PROPERTY).toString())) { + if (component.getType().equals(RdfUtils.toString(QB.ATTRIBUTE_PROPERTY))) { for(String attachment : componentDefinition.getAttachment()){ IRI attachmentIRI ; try { @@ -324,7 +327,7 @@ public void createRdfComponentSpecification(IRI structureIRI, ComponentDefinitio model.add(componentSpecificationIRI, QB.ATTRIBUTE, getAttributeIRI(component.getId()), graph); model.add(componentSpecificationIRI, QB.COMPONENT_REQUIRED, RdfUtils.setLiteralBoolean(componentDefinition.getRequired()), graph); } - if (component.getType().equals(((SimpleIRI)QB.MEASURE_PROPERTY).toString())) { + if (component.getType().equals(RdfUtils.toString(QB.MEASURE_PROPERTY))) { model.add(componentSpecificationIRI, QB.MEASURE, getMeasureIRI(component.getId()), graph); } repoGestion.loadSimpleObject(componentSpecificationIRI, model); diff --git a/src/main/java/fr/insee/rmes/config/auth/security/KeycloakSecurityContext.java b/src/main/java/fr/insee/rmes/config/auth/security/KeycloakSecurityContext.java index cda66daf8..4c3ccbc6b 100644 --- a/src/main/java/fr/insee/rmes/config/auth/security/KeycloakSecurityContext.java +++ b/src/main/java/fr/insee/rmes/config/auth/security/KeycloakSecurityContext.java @@ -45,6 +45,7 @@ protected void configure(HttpSecurity http) throws Exception { .antMatchers("/swagger-ui/*").permitAll() .antMatchers("/api/openapi.json").permitAll() .antMatchers("/api/documents/document/*/file").permitAll() + .antMatchers("/api/operations/operation/codebook").permitAll() .anyRequest().authenticated(); } diff --git a/src/main/java/fr/insee/rmes/config/auth/security/keycloak/RmesKeycloakConfigResolver.java b/src/main/java/fr/insee/rmes/config/auth/security/keycloak/RmesKeycloakConfigResolver.java index 480e1597e..0c7c50de8 100644 --- a/src/main/java/fr/insee/rmes/config/auth/security/keycloak/RmesKeycloakConfigResolver.java +++ b/src/main/java/fr/insee/rmes/config/auth/security/keycloak/RmesKeycloakConfigResolver.java @@ -1,8 +1,11 @@ package fr.insee.rmes.config.auth.security.keycloak; import java.io.File; +import java.io.IOException; import java.io.InputStream; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.keycloak.adapters.KeycloakConfigResolver; import org.keycloak.adapters.KeycloakDeployment; import org.keycloak.adapters.KeycloakDeploymentBuilder; @@ -12,6 +15,9 @@ public class RmesKeycloakConfigResolver implements KeycloakConfigResolver { + static final Logger logger = LogManager.getLogger(RmesKeycloakConfigResolver.class); + + private static final String CATALINA_BASE = "catalina.base"; private static final String S_WEBAPPS_S = "%s/webapps/%s"; @@ -30,8 +36,13 @@ public KeycloakDeployment resolve(OIDCHttpFacade.Request request) { url = String.format(S_WEBAPPS_S, System.getProperty(CATALINA_BASE), "keycloak-back-prod.json"); is = updateInputStreamIfFileExists(is, url); - - return KeycloakDeploymentBuilder.build(is); + KeycloakDeployment kd = KeycloakDeploymentBuilder.build(is); + try { + is.close(); + } catch (IOException e) { + logger.error("resolve : {}" , e.getMessage()); + } + return kd; } private InputStream updateInputStreamIfFileExists(InputStream is, String url) { diff --git a/src/main/java/fr/insee/rmes/exceptions/ErrorCodes.java b/src/main/java/fr/insee/rmes/exceptions/ErrorCodes.java index d3b9dcdf7..773bb7abc 100644 --- a/src/main/java/fr/insee/rmes/exceptions/ErrorCodes.java +++ b/src/main/java/fr/insee/rmes/exceptions/ErrorCodes.java @@ -76,6 +76,9 @@ public class ErrorCodes { public static final int COMPONENT_PUBLICATION_VALIDATED_CODESLIST = 1007; public static final int STRUCTURE_PUBLICATION_VALIDATED_COMPONENT = 1008; + public static final int CODE_LIST_UNICITY = 1101; + + /* * 404 NOTFOUNDEXCEPTIONS */ diff --git a/src/main/java/fr/insee/rmes/external_services/export/XDocReport.java b/src/main/java/fr/insee/rmes/external_services/export/XDocReport.java index 611cc8d0a..e482258d4 100644 --- a/src/main/java/fr/insee/rmes/external_services/export/XDocReport.java +++ b/src/main/java/fr/insee/rmes/external_services/export/XDocReport.java @@ -123,13 +123,15 @@ private OutputStream createOutputFile(boolean isPdf) throws IOException { @Deprecated //TODO use this for default value when template is ok private IXDocReport getReportTemplate(String odtTemplate) throws IOException, XDocReportException { - InputStream is = getClass().getClassLoader().getResourceAsStream("xdocreport/"+odtTemplate); - return XDocReportRegistry.getRegistry().loadReport(is,TemplateEngineKind.Freemarker); + try(InputStream is = getClass().getClassLoader().getResourceAsStream("xdocreport/"+odtTemplate)){ + return XDocReportRegistry.getRegistry().loadReport(is,TemplateEngineKind.Freemarker); + } } private IXDocReport getReportTemplate(File odtTemplate) throws IOException, XDocReportException { - InputStream is = new FileInputStream(odtTemplate); - return XDocReportRegistry.getRegistry().loadReport(is,TemplateEngineKind.Freemarker); + try(InputStream is = new FileInputStream(odtTemplate)){ + return XDocReportRegistry.getRegistry().loadReport(is,TemplateEngineKind.Freemarker); + } } diff --git a/src/main/java/fr/insee/rmes/external_services/mail_sender/RmesMailSenderImpl.java b/src/main/java/fr/insee/rmes/external_services/mail_sender/RmesMailSenderImpl.java index f5cb7dfab..1dd138ff3 100644 --- a/src/main/java/fr/insee/rmes/external_services/mail_sender/RmesMailSenderImpl.java +++ b/src/main/java/fr/insee/rmes/external_services/mail_sender/RmesMailSenderImpl.java @@ -10,6 +10,7 @@ import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.Entity; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Variant; import org.apache.http.HttpStatus; import org.eclipse.rdf4j.model.IRI; @@ -127,10 +128,12 @@ private boolean sendMail(Mail mail, InputStream is, String fileName) { mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("request").build(),request,MediaType.APPLICATION_XML_TYPE)); final StreamDataBodyPart bodyPart = new StreamDataBodyPart("attachments", is, fileName); mp.bodyPart(bodyPart); - + + Variant variant = new Variant(MediaType.MULTIPART_FORM_DATA_TYPE, Config.LG1, "utf-8"); + Entity entity = Entity.entity(mp, variant); String result = client.target(Config.SPOC_SERVICE_URL) .request() - .post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE.withCharset("utf-8")),String.class); + .post(entity,String.class); return isMailSent(result); } diff --git a/src/main/java/fr/insee/rmes/model/operations/documentations/Document.java b/src/main/java/fr/insee/rmes/model/operations/documentations/Document.java index 7a12f289d..f2d493cdb 100644 --- a/src/main/java/fr/insee/rmes/model/operations/documentations/Document.java +++ b/src/main/java/fr/insee/rmes/model/operations/documentations/Document.java @@ -1,7 +1,6 @@ package fr.insee.rmes.model.operations.documentations; import org.apache.commons.lang3.StringUtils; -import org.eclipse.rdf4j.model.impl.SimpleIRI; import com.fasterxml.jackson.annotation.JsonProperty; @@ -24,12 +23,12 @@ public Document() { } public Document(String id) { - this.uri = ((SimpleIRI)RdfUtils.documentIRI(id)).toString(); + this.uri = RdfUtils.toString(RdfUtils.documentIRI(id)); } public Document(String id, boolean isLink) { - if (isLink) {this.uri = ((SimpleIRI)RdfUtils.linkIRI(id)).toString();} - else {this.uri = ((SimpleIRI)RdfUtils.documentIRI(id)).toString();} + if (isLink) {this.uri = RdfUtils.toString(RdfUtils.linkIRI(id));} + else {this.uri = RdfUtils.toString(RdfUtils.documentIRI(id));} } public String getLabelLg1() { diff --git a/src/main/java/fr/insee/rmes/persistance/ontologies/QB.java b/src/main/java/fr/insee/rmes/persistance/ontologies/QB.java index 4750bb9d5..681403a1d 100644 --- a/src/main/java/fr/insee/rmes/persistance/ontologies/QB.java +++ b/src/main/java/fr/insee/rmes/persistance/ontologies/QB.java @@ -3,10 +3,11 @@ import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Namespace; import org.eclipse.rdf4j.model.ValueFactory; -import org.eclipse.rdf4j.model.impl.SimpleIRI; import org.eclipse.rdf4j.model.impl.SimpleNamespace; import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import fr.insee.rmes.bauhaus_services.rdf_utils.RdfUtils; + public class QB { private QB() { @@ -72,7 +73,7 @@ private QB() { } public static String[] getURIForComponent(){ - return new String[]{((SimpleIRI)MEASURE_PROPERTY).toString(), ((SimpleIRI)ATTRIBUTE_PROPERTY).toString(), ((SimpleIRI)DIMENSION_PROPERTY).toString()}; + return new String[]{RdfUtils.toString(MEASURE_PROPERTY), RdfUtils.toString(ATTRIBUTE_PROPERTY), RdfUtils.toString(DIMENSION_PROPERTY)}; } diff --git a/src/main/java/fr/insee/rmes/persistance/sparql_queries/code_list/CodeListQueries.java b/src/main/java/fr/insee/rmes/persistance/sparql_queries/code_list/CodeListQueries.java index 2c801914a..c3c3b6c3e 100644 --- a/src/main/java/fr/insee/rmes/persistance/sparql_queries/code_list/CodeListQueries.java +++ b/src/main/java/fr/insee/rmes/persistance/sparql_queries/code_list/CodeListQueries.java @@ -1,30 +1,33 @@ package fr.insee.rmes.persistance.sparql_queries.code_list; -import fr.insee.rmes.bauhaus_services.ConceptsService; -import fr.insee.rmes.bauhaus_services.Constants; +import java.util.HashMap; + import fr.insee.rmes.bauhaus_services.rdf_utils.FreeMarkerUtils; import fr.insee.rmes.config.Config; import fr.insee.rmes.exceptions.RmesException; -import java.util.HashMap; - public class CodeListQueries { + private static final String CODES_LISTS_GRAPH = "CODES_LISTS_GRAPH"; + private static final String CODES_LIST = "codes-list/"; + private static final String PARTIAL = "PARTIAL"; + private static final String NOTATION = "NOTATION"; + public static String isCodesListValidated(String codesListUri) throws RmesException { HashMap params = new HashMap<>(); - params.put("CODES_LISTS_GRAPH", Config.CODELIST_GRAPH); + params.put(CODES_LISTS_GRAPH, Config.CODELIST_GRAPH); params.put("IRI", codesListUri); - return FreeMarkerUtils.buildRequest("codes-list/", "isCodesListValidated.ftlh", params); + return FreeMarkerUtils.buildRequest(CODES_LIST, "isCodesListValidated.ftlh", params); } public static String getAllCodesLists(boolean partial) throws RmesException { HashMap params = new HashMap<>(); - params.put("CODES_LISTS_GRAPH", Config.CODELIST_GRAPH); + params.put(CODES_LISTS_GRAPH, Config.CODELIST_GRAPH); params.put("LG1", Config.LG1); params.put("LG2", Config.LG2); - params.put("PARTIAL", partial); - return FreeMarkerUtils.buildRequest("codes-list/", "getAllCodesLists.ftlh", params); + params.put(PARTIAL, partial); + return FreeMarkerUtils.buildRequest(CODES_LIST, "getAllCodesLists.ftlh", params); } public static String getCodeListItemsByNotation(String notation) { return "SELECT ?code ?labelLg1 ?labelLg2 \n" @@ -78,48 +81,48 @@ public static String getCodeUriByNotation(String notationCodeList, String notati public static String geCodesListByIRI(String id) throws RmesException { HashMap params = new HashMap<>(); - params.put("CODES_LISTS_GRAPH", Config.CODELIST_GRAPH); + params.put(CODES_LISTS_GRAPH, Config.CODELIST_GRAPH); params.put("CODE_LIST", id); params.put("LG1", Config.LG1); params.put("LG2", Config.LG2); - return FreeMarkerUtils.buildRequest("codes-list/", "getCodeListByIRI.ftlh", params); + return FreeMarkerUtils.buildRequest(CODES_LIST, "getCodeListByIRI.ftlh", params); } public static String getDetailedCodeListByNotation(String notation) throws RmesException { HashMap params = getInitParams(); - params.put("NOTATION", notation); + params.put(NOTATION, notation); params.put("CODE_LIST_BASE_URI", Config.CODE_LIST_BASE_URI); - return FreeMarkerUtils.buildRequest("codes-list/", "getDetailedCodesList.ftlh", params); + return FreeMarkerUtils.buildRequest(CODES_LIST, "getDetailedCodesList.ftlh", params); } public static String getCodesListsForSearch(boolean partial) throws RmesException { HashMap params = getInitParams(); - params.put("PARTIAL", partial); - return FreeMarkerUtils.buildRequest("codes-list/", "getDetailedCodesListForSearch.ftlh", params); + params.put(PARTIAL, partial); + return FreeMarkerUtils.buildRequest(CODES_LIST, "getDetailedCodesListForSearch.ftlh", params); } public static String getCodesForSearch(boolean partial) throws RmesException { HashMap params = getInitParams(); - params.put("PARTIAL", partial); - return FreeMarkerUtils.buildRequest("codes-list/", "getCodesForSearch.ftlh", params); + params.put(PARTIAL, partial); + return FreeMarkerUtils.buildRequest(CODES_LIST, "getCodesForSearch.ftlh", params); } public static String getDetailedCodes(String notation, boolean partial) throws RmesException { HashMap params = getInitParams(); - params.put("NOTATION", notation); - params.put("PARTIAL", partial); - return FreeMarkerUtils.buildRequest("codes-list/", "getDetailedCodes.ftlh", params); + params.put(NOTATION, notation); + params.put(PARTIAL, partial); + return FreeMarkerUtils.buildRequest(CODES_LIST, "getDetailedCodes.ftlh", params); } public static String getCodesSeq(String notation) throws RmesException { HashMap params = getInitParams(); - params.put("NOTATION", notation); - return FreeMarkerUtils.buildRequest("codes-list/", "getCodesSeq.ftlh", params); + params.put(NOTATION, notation); + return FreeMarkerUtils.buildRequest(CODES_LIST, "getCodesSeq.ftlh", params); } private static HashMap getInitParams() { HashMap params = new HashMap<>(); - params.put("CODES_LISTS_GRAPH", Config.CODELIST_GRAPH); + params.put(CODES_LISTS_GRAPH, Config.CODELIST_GRAPH); params.put("LG1", Config.LG1); params.put("LG2", Config.LG2); return params; @@ -130,4 +133,13 @@ private CodeListQueries() { } + public static String checkCodeListUnicity(String id, String iri, String seeAlso, boolean partial) throws RmesException { + HashMap params = getInitParams(); + params.put("ID", id); + params.put("IRI", iri); + params.put("SEE_ALSO", seeAlso); + params.put("PARTIAL", partial); + + return FreeMarkerUtils.buildRequest("codes-list/", "checkCodeListUnicity.ftlh", params); + } } \ No newline at end of file diff --git a/src/main/java/fr/insee/rmes/persistance/sparql_queries/links/LinksQueries.java b/src/main/java/fr/insee/rmes/persistance/sparql_queries/links/LinksQueries.java index bb483639c..a8af2c67f 100644 --- a/src/main/java/fr/insee/rmes/persistance/sparql_queries/links/LinksQueries.java +++ b/src/main/java/fr/insee/rmes/persistance/sparql_queries/links/LinksQueries.java @@ -1,8 +1,8 @@ package fr.insee.rmes.persistance.sparql_queries.links; import org.eclipse.rdf4j.model.IRI; -import org.eclipse.rdf4j.model.impl.SimpleIRI; +import fr.insee.rmes.bauhaus_services.rdf_utils.RdfUtils; import fr.insee.rmes.config.Config; public class LinksQueries { @@ -10,7 +10,7 @@ public class LinksQueries { public static String getLinksToDelete(IRI conceptURI) { return "SELECT ?concept \n" + "WHERE { GRAPH <"+Config.CONCEPTS_GRAPH+"> { \n" - + "?concept ?b <" + ((SimpleIRI)conceptURI).toString() + "> \n" + + "?concept ?b <" + RdfUtils.toString(conceptURI) + "> \n" + " }}"; } diff --git a/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/indicators/IndicatorsQueries.java b/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/indicators/IndicatorsQueries.java index c3a17dc3b..6fdc811ff 100644 --- a/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/indicators/IndicatorsQueries.java +++ b/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/indicators/IndicatorsQueries.java @@ -314,6 +314,6 @@ public static String indicatorsWithSimsQuery() { + "BIND(STRAFTER(STR(?report),'/rapport/') AS ?idSims) . \n" + "} \n" + "GROUP BY ?labelLg1 ?idSims \n" - + "ORDER BY ?label "; + + "ORDER BY ?labelLg1 "; } } diff --git a/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/operations/OperationsQueries.java b/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/operations/OperationsQueries.java index 65b4f437a..18f2beca1 100644 --- a/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/operations/OperationsQueries.java +++ b/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/operations/OperationsQueries.java @@ -1,8 +1,25 @@ package fr.insee.rmes.persistance.sparql_queries.operations.operations; +import fr.insee.rmes.bauhaus_services.rdf_utils.FreeMarkerUtils; import fr.insee.rmes.config.Config; +import fr.insee.rmes.exceptions.RmesException; + +import java.util.HashMap; +import java.util.Map; public class OperationsQueries { + static Map params ; + + private static void initParams() { + params = new HashMap<>(); + params.put("OPERATIONS_GRAPH",Config.OPERATIONS_GRAPH); + params.put("LG1", Config.LG1); + params.put("LG2", Config.LG2); + } + + private static String buildIndicatorRequest(String fileName, Map params) throws RmesException { + return FreeMarkerUtils.buildRequest("operations/series/", fileName, params); + } public static String operationsQuery() { return "SELECT DISTINCT ?id ?label (group_concat(?altLabelLg1;separator=' || ') as ?altLabel) \n" @@ -110,4 +127,9 @@ private OperationsQueries() { throw new IllegalStateException("Utility class"); } + public static String seriesWithSimsQuery(String idFamily) throws RmesException { + if (params==null) {initParams();} + params.put("ID_FAMILY", idFamily); + return buildIndicatorRequest("getSeriesWithSimsQuery.ftlh", params); + } } diff --git a/src/main/java/fr/insee/rmes/utils/ExportUtils.java b/src/main/java/fr/insee/rmes/utils/ExportUtils.java index ee72232d6..b4ec5241e 100644 --- a/src/main/java/fr/insee/rmes/utils/ExportUtils.java +++ b/src/main/java/fr/insee/rmes/utils/ExportUtils.java @@ -58,7 +58,7 @@ public Response exportAsResponse(String fileName, Map xmlContent InputStream input = exportAsInputStream(fileName, xmlContent, xslFile, xmlPattern, zip, objectType); logger.debug("End To export {} as Response", objectType); - + return Response.ok((StreamingOutput) out -> { IOUtils.copy(input, out); out.flush(); @@ -114,6 +114,8 @@ public InputStream exportAsInputStream(String fileName, Map xmlC odtFileIS.close(); if (xslFileIS != null) xslFileIS.close(); + if (zipToCompleteIS != null) + zipToCompleteIS.close(); } catch (IOException ioe) { logger.error(ioe.getMessage()); } @@ -148,7 +150,7 @@ public Response exportFilesAsResponse(Map xmlContent) throws Rme } catch (IOException e1) { throw new RmesException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e1.getMessage(), e1.getClass().getSimpleName()); - } + } } diff --git a/src/main/java/fr/insee/rmes/utils/FilesUtils.java b/src/main/java/fr/insee/rmes/utils/FilesUtils.java index 3202e01f4..8aa0c6fca 100644 --- a/src/main/java/fr/insee/rmes/utils/FilesUtils.java +++ b/src/main/java/fr/insee/rmes/utils/FilesUtils.java @@ -26,7 +26,7 @@ public static InputStream fileToIS(File file) { try { is = new FileInputStream(file); } catch (Exception e) { - log.error(e.getMessage()); + log.error("fileToIS" + e.getMessage()); } return is; } diff --git a/src/main/java/fr/insee/rmes/utils/XMLUtils.java b/src/main/java/fr/insee/rmes/utils/XMLUtils.java index 2945e369f..a984f0125 100644 --- a/src/main/java/fr/insee/rmes/utils/XMLUtils.java +++ b/src/main/java/fr/insee/rmes/utils/XMLUtils.java @@ -140,11 +140,15 @@ public static String encodeXml(String response) { final String regex3 = "&gt;"; final Pattern pattern3 = Pattern.compile(regex3, Pattern.MULTILINE | Pattern.DOTALL | Pattern.CASE_INSENSITIVE); ret = pattern3.matcher(ret).replaceAll(">"); - + final String regex4 = "&lt;"; final Pattern pattern4 = Pattern.compile(regex4, Pattern.MULTILINE | Pattern.DOTALL | Pattern.CASE_INSENSITIVE); ret = pattern4.matcher(ret).replaceAll("<"); - + + final String regex8 = "&quot;"; + final Pattern pattern8 = Pattern.compile(regex8, Pattern.MULTILINE | Pattern.DOTALL | Pattern.CASE_INSENSITIVE); + ret = pattern8.matcher(ret).replaceAll("""); + final String regex5 = Constants.XML_ESPERLUETTE_REPLACEMENT; final Pattern pattern5 = Pattern.compile(regex5, Pattern.MULTILINE | Pattern.DOTALL | Pattern.CASE_INSENSITIVE); ret = pattern5.matcher(ret).replaceAll(AMP); @@ -156,8 +160,7 @@ public static String encodeXml(String response) { final String regex7 = Constants.XML_INF_REPLACEMENT; final Pattern pattern7 = Pattern.compile(regex7, Pattern.MULTILINE | Pattern.DOTALL | Pattern.CASE_INSENSITIVE); ret = pattern7.matcher(ret).replaceAll("<"); - - + return new String(ret.getBytes(), StandardCharsets.UTF_8); } diff --git a/src/main/java/fr/insee/rmes/webservice/ConceptsResources.java b/src/main/java/fr/insee/rmes/webservice/ConceptsResources.java index 1c511c6e1..f1bc21e4f 100644 --- a/src/main/java/fr/insee/rmes/webservice/ConceptsResources.java +++ b/src/main/java/fr/insee/rmes/webservice/ConceptsResources.java @@ -315,9 +315,9 @@ public Response setConceptsValidation( @GET @Path("/concept/export/{id}") @Produces({ MediaType.APPLICATION_OCTET_STREAM, "application/vnd.oasis.opendocument.text" }) - @Operation(operationId = "getConceptExport", summary = "Blob of concept") - public Response getConceptExport(@PathParam(Constants.ID) String id, @HeaderParam("Accept") String acceptHeader) throws RmesException { - return conceptsService.getConceptExport(id, acceptHeader); + @Operation(operationId = "exportConcept", summary = "Blob of concept") + public Response exportConcept(@PathParam(Constants.ID) String id, @HeaderParam("Accept") String acceptHeader) throws RmesException { + return conceptsService.exportConcept(id, acceptHeader); } @Secured({ Roles.SPRING_ADMIN, Roles.SPRING_CONCEPTS_CONTRIBUTOR, Roles.SPRING_CONCEPT_CREATOR }) diff --git a/src/main/java/fr/insee/rmes/webservice/GeographyResources.java b/src/main/java/fr/insee/rmes/webservice/GeographyResources.java index 68e66a9fb..1b75965e0 100644 --- a/src/main/java/fr/insee/rmes/webservice/GeographyResources.java +++ b/src/main/java/fr/insee/rmes/webservice/GeographyResources.java @@ -1,12 +1,15 @@ package fr.insee.rmes.webservice; -import javax.ws.rs.*; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import fr.insee.rmes.model.operations.documentations.Document; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; import org.apache.http.HttpStatus; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -20,6 +23,8 @@ 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.Operation; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/src/main/java/fr/insee/rmes/webservice/operations/FamilyResources.java b/src/main/java/fr/insee/rmes/webservice/operations/FamilyResources.java index d5379e8a0..15e510d31 100644 --- a/src/main/java/fr/insee/rmes/webservice/operations/FamilyResources.java +++ b/src/main/java/fr/insee/rmes/webservice/operations/FamilyResources.java @@ -11,6 +11,7 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; +import fr.insee.rmes.model.operations.Operation; import org.apache.http.HttpStatus; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.security.access.annotation.Secured; @@ -56,6 +57,20 @@ public Response getFamiliesForSearch() throws RmesException { return Response.status(HttpStatus.SC_OK).entity(jsonResultat).build(); } + @GET + @Path("/families/{id}/seriesWithReport") + @Produces(MediaType.APPLICATION_JSON) + @io.swagger.v3.oas.annotations.Operation(operationId = "getSeriesWithReport", summary = "Series with metadataReport", responses = {@ApiResponse(content=@Content(schema=@Schema(type="array",implementation= Operation.class)))}) + public Response getSeriesWithReport(@PathParam(Constants.ID) String id) { + String jsonResultat; + try { + jsonResultat = operationsService.getSeriesWithReport(id); + } catch (RmesException e) { + return Response.status(e.getStatus()).entity(e.getDetails()).type(MediaType.TEXT_PLAIN).build(); + } + return Response.status(HttpStatus.SC_OK).entity(jsonResultat).build(); + } + @GET @Path("/family/{id}") @Produces(MediaType.APPLICATION_JSON) diff --git a/src/main/resources/request/codes-list/checkCodeListUnicity.ftlh b/src/main/resources/request/codes-list/checkCodeListUnicity.ftlh new file mode 100644 index 000000000..3c41d437a --- /dev/null +++ b/src/main/resources/request/codes-list/checkCodeListUnicity.ftlh @@ -0,0 +1,22 @@ +ASK +FROM <${CODES_LISTS_GRAPH}> +WHERE { + { + ?iri skos:notation "${ID}" + } + UNION + { + <${IRI}> rdf:type skos:ConceptScheme + } + UNION + { + <${IRI}> rdf:type skos:Collection + } +<#if !PARTIAL> + UNION + { + ?iri rdf:type skos:ConceptScheme . + ?iri rdfs:seeAlso <${SEE_ALSO}> + } + +} \ No newline at end of file diff --git a/src/main/resources/request/codes-list/getDetailedCodes.ftlh b/src/main/resources/request/codes-list/getDetailedCodes.ftlh index 0a472acc9..0545df060 100644 --- a/src/main/resources/request/codes-list/getDetailedCodes.ftlh +++ b/src/main/resources/request/codes-list/getDetailedCodes.ftlh @@ -1,4 +1,4 @@ -SELECT ?labelLg1 ?labelLg2 ?code ?descriptionLg1 ?descriptionLg2 ?parents <#if PARTIAL> ?codeUri +SELECT ?labelLg1 ?labelLg2 ?code ?descriptionLg1 ?descriptionLg2 ?parents ?codeUri FROM <${CODES_LISTS_GRAPH}> WHERE { <#if PARTIAL> @@ -15,13 +15,14 @@ WHERE { OPTIONAL { - ?codeUri skos:broader ?parentsParent . - ?parentsParent skos:notation ?parents + ?codeUri skos:broader ?parentsParent . + ?parentsParent skos:notation ?parents } . OPTIONAL {?codeUri skos:definition ?descriptionLg1 . FILTER(lang(?descriptionLg1) = '${LG1}') } . OPTIONAL {?codeUri skos:definition ?descriptionLg2 . FILTER (lang(?descriptionLg2) = '${LG2}') } . + } ORDER BY ?labelLg1 \ No newline at end of file diff --git a/src/main/resources/request/codes-list/getDetailedCodesList.ftlh b/src/main/resources/request/codes-list/getDetailedCodesList.ftlh index 1c3c76330..b1bd34ae0 100644 --- a/src/main/resources/request/codes-list/getDetailedCodesList.ftlh +++ b/src/main/resources/request/codes-list/getDetailedCodesList.ftlh @@ -1,51 +1,51 @@ -SELECT DISTINCT ?id ?labelLg1 ?labelLg2 ?created ?modified ?creator ?contributor ?validationState ?disseminationStatus +SELECT DISTINCT ?iri ?id ?labelLg1 ?labelLg2 ?created ?modified ?creator ?contributor ?validationState ?disseminationStatus ?descriptionLg1 ?descriptionLg2 ?lastListUriSegment ?lastClassUriSegment ?iriParent FROM <${CODES_LISTS_GRAPH}> WHERE { - ?list skos:notation '${NOTATION}' ; + ?iri skos:notation '${NOTATION}' ; skos:notation ?id . OPTIONAL { - ?list dcterms:created ?created . + ?iri dcterms:created ?created . } OPTIONAL { - ?list dc:creator ?creator . + ?iri dc:creator ?creator . } OPTIONAL { - ?list dc:contributor ?contributor . + ?iri dc:contributor ?contributor . } OPTIONAL { - ?list insee:validationState ?validationState . + ?iri insee:validationState ?validationState . } OPTIONAL { - ?list insee:disseminationStatus ?disseminationStatus . + ?iri insee:disseminationStatus ?disseminationStatus . } OPTIONAL { - ?list dc:contributor ?contributor . + ?iri dc:contributor ?contributor . } OPTIONAL { - ?list dcterms:modified ?modified . + ?iri dcterms:modified ?modified . } OPTIONAL { - ?list rdfs:seeAlso ?seeAlso . + ?iri rdfs:seeAlso ?seeAlso . BIND(STRAFTER(STR(?seeAlso),'concept/') AS ?lastClassUriSegment) . } OPTIONAL { - ?list prov:wasDerivedFrom ?iriParent . + ?iri prov:wasDerivedFrom ?iriParent . } . - BIND(STRAFTER(STR(?list),'${CODE_LIST_BASE_URI}/') AS ?lastListUriSegment) . + BIND(STRAFTER(STR(?iri),'${CODE_LIST_BASE_URI}/') AS ?lastListUriSegment) . - ?list skos:prefLabel ?labelLg1 . + ?iri skos:prefLabel ?labelLg1 . FILTER(lang(?labelLg1) = '${LG1}') . - OPTIONAL {?list skos:prefLabel ?labelLg2 . + OPTIONAL {?iri skos:prefLabel ?labelLg2 . FILTER (lang(?labelLg2) = '${LG2}') } . - OPTIONAL { ?list dc:contributor ?contributor } . - OPTIONAL {?list skos:definition ?descriptionLg1 . + OPTIONAL { ?iri dc:contributor ?contributor } . + OPTIONAL {?iri skos:definition ?descriptionLg1 . FILTER(lang(?descriptionLg1) = '${LG1}') } . - OPTIONAL {?list skos:definition ?descriptionLg2 . + OPTIONAL {?iri skos:definition ?descriptionLg2 . FILTER (lang(?descriptionLg2) = '${LG2}') } . } ORDER BY ?labelLg1 \ No newline at end of file diff --git a/src/main/resources/request/concepts/getConceptLinksById.ftlh b/src/main/resources/request/concepts/getConceptLinksById.ftlh index 64172864c..2e6d26940 100644 --- a/src/main/resources/request/concepts/getConceptLinksById.ftlh +++ b/src/main/resources/request/concepts/getConceptLinksById.ftlh @@ -25,6 +25,11 @@ WHERE { BIND('succeed' AS ?typeOfLink) } UNION + { + ?concept dcterms:isReplacedBy ?conceptlinked . + BIND('succeededBy' AS ?typeOfLink) + } + UNION { ?concept skos:related ?conceptlinked . BIND('related' AS ?typeOfLink) diff --git a/src/main/resources/request/operations/series/getSeriesWithSimsQuery.ftlh b/src/main/resources/request/operations/series/getSeriesWithSimsQuery.ftlh new file mode 100644 index 000000000..417c60ef9 --- /dev/null +++ b/src/main/resources/request/operations/series/getSeriesWithSimsQuery.ftlh @@ -0,0 +1,19 @@ +SELECT DISTINCT ?id ?labelLg1 ?labelLg2 ?idSims +WHERE { + ?serie a insee:StatisticalOperationSeries . + ?family dcterms:hasPart ?serie + FILTER(STRENDS(STR(?family),'/operations/famille/${ID_FAMILY}')) . + + ?serie skos:prefLabel ?labelLg1 . + FILTER (lang(?labelLg1) = '${LG1}') + + ?serie skos:prefLabel ?labelLg2 . + FILTER (lang(?labelLg2) = '${LG2}') + + BIND(STRAFTER(STR(?serie),'/operations/serie/') AS ?id) . + ?report rdf:type sdmx-mm:MetadataReport . + ?report sdmx-mm:target ?serie + BIND(STRAFTER(STR(?report),'/rapport/') AS ?idSims) . +} +GROUP BY ?id ?labelLg1 ?labelLg2 ?idSims +ORDER BY ?labelLg1 \ No newline at end of file diff --git a/src/main/resources/xslTransformerFiles/concept/conceptPatternContent.xml b/src/main/resources/xslTransformerFiles/concept/conceptPatternContent.xml index 4d880dd86..3f4ac7153 100644 --- a/src/main/resources/xslTransformerFiles/concept/conceptPatternContent.xml +++ b/src/main/resources/xslTransformerFiles/concept/conceptPatternContent.xml @@ -306,6 +306,9 @@ + + Identifiant : ${concept/id} + Libellé alternatif (fr) : ${concept/altLabelLg1/altLabelLg1} diff --git a/src/main/resources/xslTransformerFiles/rmes2odt.xsl b/src/main/resources/xslTransformerFiles/rmes2odt.xsl index 0ced5bba2..166364d6d 100644 --- a/src/main/resources/xslTransformerFiles/rmes2odt.xsl +++ b/src/main/resources/xslTransformerFiles/rmes2odt.xsl @@ -526,20 +526,22 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -592,20 +594,22 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/src/main/resources/xslTransformerFiles/sims2fodt.xsl b/src/main/resources/xslTransformerFiles/sims2fodt.xsl index 2b0e0aab0..f9b141293 100644 --- a/src/main/resources/xslTransformerFiles/sims2fodt.xsl +++ b/src/main/resources/xslTransformerFiles/sims2fodt.xsl @@ -500,20 +500,22 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -566,20 +568,22 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + + +