diff --git a/pom.xml b/pom.xml index ddfd5c798..4a6c82b1f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ fr.insee.rmes Bauhaus-BO war - 3.0.11 + 3.0.12 Bauhaus-Back-Office Back-office services for Bauhaus https://github.com/InseeFr/Bauhaus-Back-Office diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/CodeListService.java b/src/main/java/fr/insee/rmes/bauhaus_services/CodeListService.java index 9243558b4..a96f52a10 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/CodeListService.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/CodeListService.java @@ -11,15 +11,15 @@ public interface CodeListService { String getCodeUri(String notationCodeList, String notationCode) throws RmesException; - String getAllCodesLists() throws RmesException; + String getAllCodesLists(boolean partial) throws RmesException; String geCodesListByIRI(String iri) throws RmesException; - String getDetailedCodesList(String notation) throws RmesException; + String getDetailedCodesList(String notation, boolean partial) throws RmesException; - String getDetailedCodesListForSearch() throws RmesException; + String getDetailedCodesListForSearch(boolean partial) throws RmesException; - String setCodesList(String body) throws RmesException; + String setCodesList(String body, boolean partial) throws RmesException; - String setCodesList(String id, String body) throws RmesException; + String setCodesList(String id, String body, boolean partial) throws RmesException; } diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/GeographyService.java b/src/main/java/fr/insee/rmes/bauhaus_services/GeographyService.java index 84ab6083a..71af46f78 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/GeographyService.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/GeographyService.java @@ -20,5 +20,5 @@ public interface GeographyService { JSONObject getGeoFeature(IRI uri) throws RmesException; - + void updateFeature(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 db9554681..ead78a011 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/OperationsService.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/OperationsService.java @@ -87,6 +87,8 @@ public interface OperationsService { String getIndicators() throws RmesException; + String getIndicatorsWithSims() throws RmesException; + String getIndicatorsForSearch() throws RmesException; String getIndicatorJsonByID(String id) throws RmesException; @@ -158,4 +160,6 @@ public interface OperationsService { Response exportMetadataReportTempFiles(String id, Boolean includeEmptyMas, Boolean lg1, Boolean lg2) throws RmesException; + String getOperationsWithReport(String id) throws RmesException; + } 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 d31cbc3a5..e0ca749c2 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 @@ -9,13 +9,7 @@ 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.DC; -import org.eclipse.rdf4j.model.vocabulary.DCTERMS; -import org.eclipse.rdf4j.model.vocabulary.OWL; -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.*; import org.json.JSONArray; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; @@ -38,6 +32,10 @@ import fr.insee.rmes.persistance.sparql_queries.code_list.CodeListQueries; import fr.insee.rmes.utils.DateUtils; +import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; + @Service public class CodeListServiceImpl extends RdfService implements CodeListService { @@ -52,12 +50,12 @@ public class CodeListServiceImpl extends RdfService implements CodeListService @Autowired FamOpeSerIndUtils famOpeSerIndUtils; - - + + @Override public String getCodeListJson(String notation) throws RmesException{ JSONObject codeList = repoGestion.getResponseAsObject(CodeListQueries.getCodeListLabelByNotation(notation)); - codeList.put("notation",notation); + codeList.put(Constants.NOTATION,notation); JSONArray items = repoGestion.getResponseAsArray(CodeListQueries.getCodeListItemsByNotation(notation)); if (items.length() != 0){ codeList.put(CODES, items); @@ -81,48 +79,162 @@ public CodeList getCodeList(String notation) throws RmesException { } @Override - public String getDetailedCodesList(String notation) throws RmesException { + public String getDetailedCodesList(String notation, boolean partial) throws RmesException { JSONObject codeList = repoGestion.getResponseAsObject(CodeListQueries.getDetailedCodeListByNotation(notation)); - JSONArray codes = repoGestion.getResponseAsArray(CodeListQueries.getDetailedCodes(notation)); + JSONArray codes = repoGestion.getResponseAsArray(CodeListQueries.getDetailedCodes(notation, partial)); + + if(!partial){ + formatCodesForFullList(notation, codeList, codes); + } + else { + formatCodesForPartialList(codeList, codes); + } + + return codeList.toString(); + } + + private void formatCodesForFullList(String notation, JSONObject codeList, JSONArray codes) throws RmesException { + Map> parents = new HashMap<>(); if(codes.length() > 0){ JSONObject formattedCodes = new JSONObject(); codes.forEach(c -> { JSONObject tempCode = (JSONObject) c; String code = tempCode.getString("code"); - - if(!formattedCodes.has(code)){ - if(tempCode.has(Constants.PARENTS)){ - JSONArray parents = new JSONArray(); - parents.put(tempCode.getString(Constants.PARENTS)); - tempCode.put(Constants.PARENTS, parents); + if(tempCode.has(Constants.PARENTS)){ + String parentCode = tempCode.getString(Constants.PARENTS); + if(!parents.containsKey(parentCode)){ + parents.put(parentCode, Arrays.asList(code)); + formattedCodes.put(code, tempCode); + } else { + parents.get(parentCode).add(code); } + tempCode.remove(Constants.PARENTS); + } + formattedCodes.put(code, tempCode); + }); + + + JSONArray seq = repoGestion.getResponseAsArray(CodeListQueries.getCodesSeq(notation)); + + 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"); - formattedCodes.put(code, tempCode); - } else { - JSONObject previousCode = formattedCodes.getJSONObject(code); - JSONArray parents = new JSONArray(); - if(previousCode.has(Constants.PARENTS)){ - parents = previousCode.getJSONArray(Constants.PARENTS); + if(parents.containsKey(code)){ + for(int j = startPosition; j < i; j++){ + String childCode = seq.getJSONObject(j).getString("code"); + + JSONObject child = formattedCodes.getJSONObject(childCode); + + 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; + + rootPosition = setPositonForRootNode(formattedCodes, startPosition, code); + + } else if(isRootNodeWithoutChildren(code, parents)){ + rootPosition = setPositonForRootNode(formattedCodes, rootPosition, code); + startPosition = i + 1; } - parents.put(tempCode.getString(Constants.PARENTS)); - previousCode.put(Constants.PARENTS, parents); - formattedCodes.put(code, previousCode); + + } - }); + } 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); + } + codeList.put(CODES, formattedCodes); } + } - return codeList.toString(); + private int setPositonForRootNode(JSONObject formattedCodes, int rootPosition, String code) { + JSONObject child = formattedCodes.getJSONObject(code); + + if(!child.has(Constants.PARENTS)){ + child.put(Constants.PARENTS, new JSONArray()); + } + child.getJSONArray(Constants.PARENTS).put(new JSONObject().put("code", "").put("position", rootPosition)); + formattedCodes.put(code, child); + rootPosition = rootPosition + 1; + return rootPosition; + } + + /** + * + * @param code the identifier of a code + * @param parents a data structure with all Parent -> Children relationship { parent1: [child1, child2]} + * @return true if the code is a rootNode without any children + */ + 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; + } + + /** + * Format the codes list for a partial code list. + * We just need to remove the parents property. + * + * @param codeList + * @param codes + */ + private void formatCodesForPartialList(JSONObject codeList, JSONArray codes) { + JSONObject formattedCodes = new JSONObject(); + codes.forEach(c -> { + JSONObject tempCode = (JSONObject) c; + String code = tempCode.getString("code"); + if (tempCode.has(Constants.PARENTS)) { + tempCode.remove(Constants.PARENTS); + } + formattedCodes.put(code, tempCode); + }); + codeList.put(CODES, formattedCodes); + } + + 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) { + for(int i = 0; i < rootCodes.size(); i++) { + JSONObject parent = new JSONObject().put("code", "").put("position", i + 1); + formattedCodes.getJSONObject(rootCodes.get(i)).put(Constants.PARENTS, new JSONArray().put(parent)); + } + } } @Override - public String getDetailedCodesListForSearch() throws RmesException { - JSONArray lists = repoGestion.getResponseAsArray(CodeListQueries.getCodesListsForSearch()); - JSONArray codes = repoGestion.getResponseAsArray(CodeListQueries.getCodesForSearch()); + public String getDetailedCodesListForSearch(boolean partial) throws RmesException { + JSONArray lists = repoGestion.getResponseAsArray(CodeListQueries.getCodesListsForSearch(partial)); + JSONArray codes = repoGestion.getResponseAsArray(CodeListQueries.getCodesForSearch(partial)); for (int i = 0 ; i < lists.length(); i++) { JSONObject list = lists.getJSONObject(i); @@ -132,7 +244,7 @@ public String getDetailedCodesListForSearch() throws RmesException { return lists.toString(); } - public void validateCodeList(JSONObject codeList){ + public void validateCodeList(JSONObject codeList, boolean partial){ if (!codeList.has(Constants.ID)) { throw new BadRequestException("The id of the list should be defined"); } @@ -142,7 +254,7 @@ public void validateCodeList(JSONObject codeList){ if (!codeList.has(Constants.LABEL_LG2)) { throw new BadRequestException("The labelLg2 of the list should be defined"); } - if (!codeList.has("lastClassUriSegment")) { + if (!partial && !codeList.has("lastClassUriSegment")) { throw new BadRequestException("The lastClassUriSegment of the list should be defined"); } if (!codeList.has(LAST_LIST_URI_SEGMENT)) { @@ -150,13 +262,13 @@ public void validateCodeList(JSONObject codeList){ } } @Override - public String setCodesList(String body) throws RmesException { + public String setCodesList(String body, boolean partial) throws RmesException { ObjectMapper mapper = new ObjectMapper(); mapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JSONObject codesList = new JSONObject(body); - this.validateCodeList(codesList); + this.validateCodeList(codesList, partial); IRI codeListIri = RdfUtils.codeListIRI(codesList.getString(LAST_LIST_URI_SEGMENT)); repoGestion.clearStructureNodeAndComponents(codeListIri); @@ -164,17 +276,17 @@ public String setCodesList(String body) throws RmesException { Resource graph = RdfUtils.codesListGraph(); RdfUtils.addTripleDateTime(codeListIri, DCTERMS.CREATED, DateUtils.getCurrentDate(), model, graph); RdfUtils.addTripleDateTime(codeListIri, DCTERMS.MODIFIED, DateUtils.getCurrentDate(), model, graph); - return this.createOrUpdateCodeList(model, graph, codesList, codeListIri); + return this.createOrUpdateCodeList(model, graph, codesList, codeListIri, partial); } @Override - public String setCodesList(String id, String body) throws RmesException { + public String setCodesList(String id, String body, boolean partial) throws RmesException { ObjectMapper mapper = new ObjectMapper(); mapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JSONObject codesList = new JSONObject(body); - this.validateCodeList(codesList); + this.validateCodeList(codesList, partial); IRI codeListIri = RdfUtils.codeListIRI(codesList.getString(LAST_LIST_URI_SEGMENT)); repoGestion.clearStructureNodeAndComponents(codeListIri); @@ -184,22 +296,29 @@ public String setCodesList(String id, String body) throws RmesException { RdfUtils.addTripleDateTime(codeListIri, DCTERMS.CREATED, codesList.getString("created"), model, graph); RdfUtils.addTripleDateTime(codeListIri, DCTERMS.MODIFIED, DateUtils.getCurrentDate(), model, graph); - return this.createOrUpdateCodeList(model, graph, codesList, codeListIri); + return this.createOrUpdateCodeList(model, graph, codesList, codeListIri, partial); } - private String createOrUpdateCodeList(Model model, Resource graph, JSONObject codesList, IRI codeListIri) throws RmesException { + private String createOrUpdateCodeList(Model model, Resource graph, JSONObject codesList, IRI codeListIri, boolean partial) throws RmesException { String codeListId = codesList.getString(Constants.ID); model.add(codeListIri, INSEE.VALIDATION_STATE, RdfUtils.setLiteralString(ValidationStatus.UNPUBLISHED), graph); - RdfUtils.addTripleUri(codeListIri, RDF.TYPE, SKOS.CONCEPT_SCHEME, model, graph); + if(partial){ + RdfUtils.addTripleUri(codeListIri, RDF.TYPE, SKOS.COLLECTION, model, graph); + } else { + RdfUtils.addTripleUri(codeListIri, RDF.TYPE, SKOS.CONCEPT_SCHEME, model, graph); + } model.add(codeListIri, SKOS.NOTATION, RdfUtils.setLiteralString(codeListId), graph); - 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(!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); @@ -222,69 +341,153 @@ private String createOrUpdateCodeList(Model model, Resource graph, JSONObject co RdfUtils.addTripleString(codeListIri, DC.CONTRIBUTOR, codesList.getString(Constants.CONTRIBUTOR), model, graph); } - CodeList original = getCodeList(codeListId); - if(original.getCodes() != null) { - original.getCodes().forEach(code -> { - IRI codeIri = RdfUtils.codeListIRI(codesList.getString(LAST_LIST_URI_SEGMENT) + "/" + code.getCode()); - try { - repoGestion.deleteObject(codeIri, null); - } catch (RmesException e) { - logger.error(e.getMessage()); + if(partial){ + if(codesList.has(CODES)) { + JSONObject codes = codesList.getJSONObject(CODES); + for (String key : codes.keySet()) { + JSONObject code = codes.getJSONObject(key); + RdfUtils.addTripleUri(codeListIri, SKOS.MEMBER, RdfUtils.createIRI(code.getString("codeUri")), model, graph); } - }); + } + if(codesList.has("iriParent")){ + RdfUtils.addTripleUri(codeListIri, PROV.WAS_DERIVED_FROM, codesList.getString("iriParent"), model, graph); + } + } else { + CodeList original = getCodeList(codeListId); + if(original.getCodes() != null) { + original.getCodes().forEach(code -> { + IRI codeIri = RdfUtils.codeListIRI(codesList.getString(LAST_LIST_URI_SEGMENT) + "/" + code.getCode()); + try { + repoGestion.deleteObject(codeIri, null); + } catch (RmesException e) { + logger.error(e.getMessage()); + } + }); + } + createCodeTriplet(graph, codesList, codeListIri, model); } - createCodeTriplet(graph, codesList, codeListIri); + repoGestion.loadSimpleObject(codeListIri, model, null); - return ((SimpleIRI)codeListIri).toString(); + return codeListId; } - private void createCodeTriplet(Resource graph, JSONObject codesList, IRI codeListIri) { + private void createCodeTriplet(Resource graph, JSONObject codesList, IRI codeListIri, Model codeListModel) { if(codesList.has(CODES)){ JSONObject parentsModel = new JSONObject(); JSONObject codes = codesList.getJSONObject(CODES); - codes.keySet().forEach(key -> { + for (String key : codes.keySet()) { try { JSONObject code = codes.getJSONObject(key); - Model codeListModel = new LinkedHashModel(); + Model codeModel = new LinkedHashModel(); IRI codeIri = RdfUtils.codeListIRI(codesList.getString(LAST_LIST_URI_SEGMENT) + "/" + code.get("code")); - createMainCodeTriplet(graph, codeListIri, code, codeListModel, codeIri); - - if(code.has("parents")){ - JSONArray parents = code.getJSONArray("parents"); - parents.forEach( parent -> { - IRI parentIRI = RdfUtils.codeListIRI(codesList.getString(LAST_LIST_URI_SEGMENT) + "/" + parent); - RdfUtils.addTripleUri(codeIri, SKOS.BROADER, parentIRI, codeListModel, graph); - - if(parentsModel.has((String) parent)){ - parentsModel.getJSONArray((String) parent).put(((SimpleIRI) codeIri).toString()); - } else { - parentsModel.put((String) parent, new JSONArray().put(((SimpleIRI) codeListIri).toString())); + createMainCodeTriplet(graph, codeListIri, code, codeModel, codeIri); + + if (code.has("parents")) { + JSONArray parentsWithPosition = code.getJSONArray(Constants.PARENTS); + parentsWithPosition.forEach(parentWithPosition -> { + 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")); + } else { + parentsModel.put(parentCode, new JSONArray().put(code.get("code"))); + } + } + else { + if (parentsModel.has("")) { + parentsModel.getJSONArray("").put(code.get("code")); + } else { + parentsModel.put("", new JSONArray().put(code.get("code"))); + } } }); } - repoGestion.loadSimpleObject(codeIri, codeListModel, null); + repoGestion.loadSimpleObject(codeIri, codeModel, null); } catch (Exception e) { logger.debug(e.getMessage()); } - }); + } + createCodesSeq(graph, codeListIri, parentsModel, codeListModel, codesList); createParentChildRelationForCodes(graph, codesList, parentsModel); } } + /** + * We will create triplets to define the Sequence of codes + * @param graph + * @param codeListIri + * @param parentsModel + * @param codeListModel + * @param codesList + */ + private void createCodesSeq(Resource graph, IRI codeListIri, JSONObject parentsModel, Model codeListModel, JSONObject codesList) { + //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"); + + 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"); + }); + 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"); + }); + + children.forEach(child -> { + IRI childIri = RdfUtils.codeListIRI(codesList.getString(LAST_LIST_URI_SEGMENT) + "/" + child); + RdfUtils.addTripleUri(codeListIri, RdfUtils.createIRI(RDF.NAMESPACE + "_" + i), childIri, codeListModel, graph); + i.getAndIncrement(); + }); + } + IRI parentIRI = RdfUtils.codeListIRI(codesList.getString(LAST_LIST_URI_SEGMENT) + "/" + rootNodeCode); + RdfUtils.addTripleUri(codeListIri, RdfUtils.createIRI(RDF.NAMESPACE + "_" + i), parentIRI, codeListModel, graph); + i.getAndIncrement(); + }); + } + + private JSONObject findParentPositionForCode(Object childCode, String parentCode, JSONObject codes, IRI codeListIri) { + 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)){ + parentWithPosition = parents.getJSONObject(i); + break; + } + } + return parentWithPosition; + } + private void createParentChildRelationForCodes(Resource graph, JSONObject codesList, JSONObject parentsModel) { parentsModel.keySet().forEach(key -> { Model parentModel = new LinkedHashModel(); IRI parentIRI = RdfUtils.codeListIRI(codesList.getString(LAST_LIST_URI_SEGMENT) + "/" + key); JSONArray children = parentsModel.getJSONArray(key); - children.forEach(child -> - RdfUtils.addTripleUri(parentIRI, SKOS.NARROWER, (String) child, parentModel, graph) - ); + children.forEach(child -> { + IRI childIri = RdfUtils.codeListIRI(codesList.getString(LAST_LIST_URI_SEGMENT) + "/" + child); + RdfUtils.addTripleUri(parentIRI, SKOS.NARROWER, childIri.toString(), parentModel, graph); + }); try { repoGestion.getConnection().add(parentModel); } catch (RmesException e) { @@ -342,8 +545,8 @@ public String getCodeUri(String notationCodeList, String notationCode) throws Rm } @Override - public String getAllCodesLists() throws RmesException { - return repoGestion.getResponseAsArray(CodeListQueries.getAllCodesLists()).toString(); + public String getAllCodesLists(boolean partial) throws RmesException { + return repoGestion.getResponseAsArray(CodeListQueries.getAllCodesLists(partial)).toString(); } @Override diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/consutation_gestion/ConsultationGestionServiceImpl.java b/src/main/java/fr/insee/rmes/bauhaus_services/consutation_gestion/ConsultationGestionServiceImpl.java index 54aa43f0f..aa9b8a019 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/consutation_gestion/ConsultationGestionServiceImpl.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/consutation_gestion/ConsultationGestionServiceImpl.java @@ -232,14 +232,41 @@ public String getComponent(String id) throws RmesException { } if(component.has("representation")){ - if(component.getString("representation").endsWith("date")){ + if(component.getString("representation").endsWith("dateTime")){ + component.put("representation", "date et heure"); + } else if(component.getString("representation").endsWith("date")){ component.put("representation", "date"); - } else if(component.getString("representation").endsWith("int")){ + } else if(component.getString("representation").endsWith("integer")){ component.put("representation", "entier"); - } else if(component.getString("representation").endsWith("float")){ + } else if(component.getString("representation").endsWith("double")){ component.put("representation", "décimal"); + } else if(component.getString("representation").endsWith("string")){ + component.put("representation", "texte"); + } else if(component.getString("representation").endsWith("paysOuTerritoire")){ + component.put("representation", "Pays ou territoire"); } } + + if(component.has("minLength") || component.has("maxLength") || component.has("minInclusive") || component.has("maxInclusive") || component.has("pattern")){ + JSONObject format = new JSONObject(); + + if (component.has("minLength")) { + format.put("longueurMin", component.get("minLength")); + } + if (component.has("maxLength")) { + format.put("longueurMax", component.get("maxLength")); + } + if (component.has("minInclusive")) { + format.put("valeurMin", component.get("minInclusive")); + } + if (component.has("maxInclusive")) { + format.put("valeurMax", component.get("maxInclusive")); + } + if (component.has("pattern")) { + format.put("expressionReguliere", component.get("pattern")); + } + component.put("format", format); + } return component.toString(); } @@ -372,7 +399,6 @@ private JSONArray getCodes(String notation) throws RmesException { JSONArray levels = repoGestion.getResponseAsArray(buildRequest("getCodeLevel.ftlh", params)); JSONObject childrenMapping = new JSONObject(); - JSONObject formattedCodes = new JSONObject(); for (int i = 0; i < codes.length(); i++) { 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 afeeb95cb..caafa7868 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 @@ -76,7 +76,9 @@ public JSONObject getGeoFeature(IRI uri) throws RmesException { } return feature; } - + + + @Override public JSONObject getGeoFeatureById(String id) throws RmesException { return getGeoFeature(getGeoUriFromId(id)); @@ -107,6 +109,26 @@ private void addUnionsAndDifferenceToJsonObject(JSONObject feature) throws RmesE feature.put("difference", diff); } + @Override + public void updateFeature(String id, String body) throws RmesException { + if(!stampsRestrictionsService.canManageDocumentsAndLinks()) { + throw new RmesUnauthorizedException(ErrorCodes.DOCUMENT_CREATION_RIGHTS_DENIED, "Only an admin or a manager can create a new geo feature."); + } + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + GeoFeature geoFeature = new GeoFeature(); + try { + geoFeature = mapper.readValue(body,GeoFeature.class); + geoFeature.setId(id.toString()); + if (geoFeature.getCode()==null) { + geoFeature.setCode(geoFeature.getId()); + } + } catch (IOException e) { + logger.error(e.getMessage()); + } + createRdfGeoFeature(geoFeature); + } + @Override public String createFeature(String body) throws RmesException { if(!stampsRestrictionsService.canManageDocumentsAndLinks()) { @@ -139,6 +161,13 @@ public String createRdfGeoFeature(GeoFeature geoFeature) throws RmesException { throw new RmesNotFoundException(ErrorCodes.GEOFEATURE_INCORRECT_BODY, "LabelLg1 not found", CAN_T_READ_REQUEST_BODY); } IRI geoIRI = RdfUtils.objectIRI(ObjectType.GEO_STAT_TERRITORY, geoFeature.getId()); + + //We check the unicity of the label + JSONObject checkUnicityTerritory = repoGestion.getResponseAsObject(GeoQueries.checkUnicityTerritory(geoFeature.getLabelLg1())); + if(checkUnicityTerritory.has("territory") && !checkUnicityTerritory.getString("territory").equalsIgnoreCase(geoFeature.getUri())){ + throw new RmesUnauthorizedException(ErrorCodes.GEOFEATURE_EXISTING_LABEL, "The label already exists", new JSONArray()); + } + /*Const*/ model.add(geoIRI, RDF.TYPE, IGEO.TERRITOIRE_STATISTIQUE, RdfUtils.simsGeographyGraph()); /*Required*/ 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 c02abc1ea..0da2fbc02 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 @@ -9,11 +9,17 @@ import java.io.OutputStream; import java.lang.reflect.Field; 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; @@ -90,6 +96,10 @@ public class OperationsImpl extends RdfService implements OperationsService { @Autowired MetadataStructureDefUtils msdUtils; + @Autowired + StampsRestrictionsService stampsRestrictionsService; + + /*************************************************************************************************** * SERIES * @@ -118,8 +128,20 @@ public String getSeriesWithSims() throws RmesException { @Override public String getSeriesWithStamp(String stamp) throws RmesException { logger.info("Starting to get series list with sims"); - String resQuery = repoGestion.getResponseAsArray(SeriesQueries.seriesWithStampQuery(stamp)).toString(); - return QueryUtils.correctEmptyGroupConcat(resQuery); + JSONArray series = repoGestion.getResponseAsArray(SeriesQueries.seriesWithStampQuery(stamp, this.stampsRestrictionsService.isAdmin())); + 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) { + 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()); } @Override @@ -158,6 +180,13 @@ public String getOperationsWithoutReport(String idSeries) throws RmesException { return QueryUtils.correctEmptyGroupConcat(resQuery.toString()); } + @Override + public String getOperationsWithReport(String idSeries) throws RmesException { + JSONArray resQuery = repoGestion.getResponseAsArray(OperationsQueries.operationsWithSimsQuery(idSeries)); + if (resQuery.length()==1 &&resQuery.getJSONObject(0).length()==0) {resQuery.remove(0);} + return QueryUtils.correctEmptyGroupConcat(resQuery.toString()); + } + @Override public String createSeries(String body) throws RmesException { // TODO: check if there is already a series with the same name ? @@ -301,6 +330,13 @@ public String getIndicators() throws RmesException { return QueryUtils.correctEmptyGroupConcat(resQuery); } + @Override + public String getIndicatorsWithSims() throws RmesException { + logger.info("Starting to get indicators list with sims"); + String resQuery = repoGestion.getResponseAsArray(IndicatorsQueries.indicatorsWithSimsQuery()).toString(); + return QueryUtils.correctEmptyGroupConcat(resQuery); + } + @Override public String getIndicatorsForSearch() throws RmesException { return indicatorsUtils.getIndicatorsForSearch(); @@ -453,4 +489,6 @@ public Response exportMetadataReportTempFiles(String id, Boolean includeEmptyMas return documentationsUtils.exportMetadataReportFiles(id,includeEmptyMas, lg1, lg2); } + + } 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 b73019e3c..814a479d6 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,6 +10,7 @@ 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,6 +20,7 @@ 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; import org.json.JSONArray; @@ -209,12 +211,15 @@ public String setMetadataReport(String id, String body, boolean create) throws R throw new RmesUnauthorizedException(ErrorCodes.SIMS_CREATION_RIGHTS_DENIED, "Only an admin or a manager can create a new sims."); } + sims.setCreated(DateUtils.getCurrentDate()); + sims.setUpdated(DateUtils.getCurrentDate()); saveRdfMetadataReport(sims, targetUri, ValidationStatus.UNPUBLISHED); } else { if (!stampsRestrictionsService.canModifySims(seriesOrIndicatorUri)) { throw new RmesUnauthorizedException(ErrorCodes.SIMS_MODIFICATION_RIGHTS_DENIED, "Only an admin, CNIS, or a manager can modify this sims.", id); } + sims.setUpdated(DateUtils.getCurrentDate()); if (status.equals(ValidationStatus.UNPUBLISHED.getValue()) || status.equals(Constants.UNDEFINED)) { saveRdfMetadataReport(sims, targetUri, ValidationStatus.UNPUBLISHED); } else { @@ -417,6 +422,9 @@ private void saveRdfMetadataReport(Documentation sims, IRI target, ValidationSta RdfUtils.addTripleString(simsUri, RDFS.LABEL, sims.getLabelLg1(), Config.LG1, model, graph); RdfUtils.addTripleString(simsUri, RDFS.LABEL, sims.getLabelLg2(), Config.LG2, model, graph); + RdfUtils.addTripleDateTime(simsUri, DCTERMS.CREATED, sims.getCreated(), model, graph); + RdfUtils.addTripleDateTime(simsUri, DCTERMS.MODIFIED, sims.getUpdated(), model, graph); + documentationsRubricsUtils.addRubricsToModel(model, sims.getId(), graph, sims.getRubrics()); repoGestion.replaceGraph(graph, model, null); diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/operations/families/FamiliesUtils.java b/src/main/java/fr/insee/rmes/bauhaus_services/operations/families/FamiliesUtils.java index d6a32fa60..9043b7514 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/operations/families/FamiliesUtils.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/operations/families/FamiliesUtils.java @@ -2,6 +2,7 @@ import java.io.IOException; +import fr.insee.rmes.utils.DateUtils; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpStatus; import org.apache.logging.log4j.LogManager; @@ -96,7 +97,7 @@ public void setFamily(String id, String body) throws RmesException { if (!familyExists) { throw new RmesNotFoundException(ErrorCodes.FAMILY_UNKNOWN_ID, "Family "+id+" doesn't exist", "Can't update non-existant family"); } - + family.setUpdated(DateUtils.getCurrentDate()); String status= famOpeSerUtils.getValidationStatus(id); if(status.equals(ValidationStatus.UNPUBLISHED.getValue()) || status.equals(Constants.UNDEFINED)) { createRdfFamily(family,ValidationStatus.UNPUBLISHED); @@ -125,6 +126,8 @@ public void createRdfFamily(Family family, ValidationStatus newStatus) throws Rm RdfUtils.addTripleString(familyURI, SKOS.PREF_LABEL, family.getPrefLabelLg2(), Config.LG2, model, RdfUtils.operationsGraph()); RdfUtils.addTripleStringMdToXhtml(familyURI, DCTERMS.ABSTRACT, family.getAbstractLg1(), Config.LG1, model, RdfUtils.operationsGraph()); RdfUtils.addTripleStringMdToXhtml(familyURI, DCTERMS.ABSTRACT, family.getAbstractLg2(), Config.LG2, model, RdfUtils.operationsGraph()); + RdfUtils.addTripleDateTime(familyURI, DCTERMS.CREATED, family.getCreated(), model, RdfUtils.operationsGraph()); + RdfUtils.addTripleDateTime(familyURI, DCTERMS.MODIFIED, family.getUpdated(), model, RdfUtils.operationsGraph()); repoGestion.keepHierarchicalOperationLinks(familyURI,model); @@ -143,6 +146,8 @@ public String createFamily(String body) throws RmesException { try { family = mapper.readValue(body,Family.class); family.setId(id); + family.setCreated(DateUtils.getCurrentDate()); + family.setUpdated(DateUtils.getCurrentDate()); createRdfFamily(family,ValidationStatus.UNPUBLISHED); logger.info("Create family : {} - {}", id , family.getPrefLabelLg1()); } catch (IOException e) { diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/operations/indicators/IndicatorsUtils.java b/src/main/java/fr/insee/rmes/bauhaus_services/operations/indicators/IndicatorsUtils.java index f102e492d..b311c14ff 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/operations/indicators/IndicatorsUtils.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/operations/indicators/IndicatorsUtils.java @@ -5,6 +5,7 @@ import java.util.List; import fr.insee.rmes.bauhaus_services.operations.documentations.DocumentationsUtils; +import fr.insee.rmes.utils.DateUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.eclipse.rdf4j.model.IRI; @@ -216,6 +217,8 @@ public String setIndicator(String body) throws RmesException { } catch (IOException e) { logger.error(e.getMessage()); } + indicator.setCreated(DateUtils.getCurrentDate()); + indicator.setUpdated(DateUtils.getCurrentDate()); createRdfIndicator(indicator,ValidationStatus.UNPUBLISHED); logger.info("Create indicator : {} - {}" , indicator.getId() , indicator.getPrefLabelLg1()); return indicator.getId(); @@ -242,6 +245,9 @@ public void setIndicator(String id, String body) throws RmesException { } catch (IOException e) { logger.error(e.getMessage()); } + + indicator.setUpdated(DateUtils.getCurrentDate()); + String status=getValidationStatus(id); documentationsUtils.updateDocumentationTitle(indicator.getIdSims(), indicator.getPrefLabelLg1(), indicator.getPrefLabelLg2()); @@ -283,6 +289,8 @@ private void createRdfIndicator(Indicator indicator, ValidationStatus newStatus) RdfUtils.addTripleString(indicURI, SKOS.PREF_LABEL, indicator.getPrefLabelLg2(), Config.LG2, model, RdfUtils.productsGraph()); RdfUtils.addTripleString(indicURI, SKOS.ALT_LABEL, indicator.getAltLabelLg1(), Config.LG1, model, RdfUtils.productsGraph()); RdfUtils.addTripleString(indicURI, SKOS.ALT_LABEL, indicator.getAltLabelLg2(), Config.LG2, model, RdfUtils.productsGraph()); + RdfUtils.addTripleDateTime(indicURI, DCTERMS.CREATED, indicator.getCreated(), model, RdfUtils.operationsGraph()); + RdfUtils.addTripleDateTime(indicURI, DCTERMS.MODIFIED, indicator.getUpdated(), model, RdfUtils.operationsGraph()); RdfUtils.addTripleStringMdToXhtml(indicURI, DCTERMS.ABSTRACT, indicator.getAbstractLg1(), Config.LG1, model, RdfUtils.productsGraph()); RdfUtils.addTripleStringMdToXhtml(indicURI, DCTERMS.ABSTRACT, indicator.getAbstractLg2(), Config.LG2, model, RdfUtils.productsGraph()); diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/operations/operations/OperationsUtils.java b/src/main/java/fr/insee/rmes/bauhaus_services/operations/operations/OperationsUtils.java index 675b8ac63..c065cc86f 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/operations/operations/OperationsUtils.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/operations/operations/OperationsUtils.java @@ -2,6 +2,7 @@ import java.io.IOException; +import fr.insee.rmes.utils.DateUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.eclipse.rdf4j.model.IRI; @@ -142,6 +143,9 @@ public String setOperation(String body) throws RmesException { if(!stampsRestrictionsService.canCreateOperation(seriesURI)) { throw new RmesUnauthorizedException(ErrorCodes.OPERATION_CREATION_RIGHTS_DENIED, "Only an admin or a series manager can create a new operation."); } + operation.setCreated(DateUtils.getCurrentDate()); + operation.setUpdated(DateUtils.getCurrentDate()); + createRdfOperation(operation, seriesURI, ValidationStatus.UNPUBLISHED); logger.info("Create operation : {} - {}" , operation.getId() , operation.getPrefLabelLg1()); @@ -170,6 +174,8 @@ public String setOperation(String id, String body) throws RmesException { logger.error(e.getMessage()); } + operation.setUpdated(DateUtils.getCurrentDate()); + String status= famOpeSerIndUtils.getValidationStatus(id); documentationsUtils.updateDocumentationTitle(operation.getIdSims(), operation.getPrefLabelLg1(), operation.getPrefLabelLg2()); if(status.equals(ValidationStatus.UNPUBLISHED.getValue()) || status.equals(Constants.UNDEFINED)) { @@ -193,6 +199,8 @@ private void createRdfOperation(Operation operation, IRI serieUri, ValidationSta RdfUtils.addTripleString(operationURI, SKOS.PREF_LABEL, operation.getPrefLabelLg2(), Config.LG2, model, RdfUtils.operationsGraph()); RdfUtils.addTripleString(operationURI, SKOS.ALT_LABEL, operation.getAltLabelLg1(), Config.LG1, model, RdfUtils.operationsGraph()); RdfUtils.addTripleString(operationURI, SKOS.ALT_LABEL, operation.getAltLabelLg2(), Config.LG2, model, RdfUtils.operationsGraph()); + RdfUtils.addTripleDateTime(operationURI, DCTERMS.CREATED, operation.getCreated(), model, RdfUtils.operationsGraph()); + RdfUtils.addTripleDateTime(operationURI, DCTERMS.MODIFIED, operation.getUpdated(), model, RdfUtils.operationsGraph()); if (serieUri != null) { //case CREATION : link operation to series 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 f1b025e15..f35eb8205 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,6 +5,7 @@ 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; @@ -48,10 +49,6 @@ 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.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 { @@ -224,6 +221,8 @@ private void createRdfSeries(Series series, IRI familyURI, ValidationStatus newS RdfUtils.addTripleString(seriesURI, SKOS.PREF_LABEL, series.getPrefLabelLg2(), Config.LG2, model, RdfUtils.operationsGraph()); RdfUtils.addTripleString(seriesURI, SKOS.ALT_LABEL, series.getAltLabelLg1(), Config.LG1, model, RdfUtils.operationsGraph()); RdfUtils.addTripleString(seriesURI, SKOS.ALT_LABEL, series.getAltLabelLg2(), Config.LG2, model, RdfUtils.operationsGraph()); + RdfUtils.addTripleDateTime(seriesURI, DCTERMS.CREATED, series.getCreated(), model, RdfUtils.operationsGraph()); + RdfUtils.addTripleDateTime(seriesURI, DCTERMS.MODIFIED, series.getUpdated(), model, RdfUtils.operationsGraph()); RdfUtils.addTripleStringMdToXhtml(seriesURI, DCTERMS.ABSTRACT, series.getAbstractLg1(), Config.LG1, model, RdfUtils.operationsGraph()); RdfUtils.addTripleStringMdToXhtml(seriesURI, DCTERMS.ABSTRACT, series.getAbstractLg2(), Config.LG2, model, RdfUtils.operationsGraph()); @@ -332,6 +331,9 @@ public String createSeries(String body) throws RmesException { } IRI familyURI = RdfUtils.objectIRI(ObjectType.FAMILY, idFamily); + series.setCreated(DateUtils.getCurrentDate()); + series.setUpdated(DateUtils.getCurrentDate()); + createRdfSeries(series, familyURI, ValidationStatus.UNPUBLISHED); logger.info("Create series : {} - {}", series.getId(), series.getPrefLabelLg1()); @@ -375,6 +377,8 @@ public void setSeries(String id, String body) throws RmesException { checkSimsWithOperations(series); + series.setUpdated(DateUtils.getCurrentDate()); + String status = famOpeSerIndUtils.getValidationStatus(id); documentationsUtils.updateDocumentationTitle(series.getIdSims(), series.getPrefLabelLg1(), series.getPrefLabelLg2()); if (status.equals(ValidationStatus.UNPUBLISHED.getValue()) || status.equals(Constants.UNDEFINED)) { 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 6230ac16b..d90967435 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 @@ -27,8 +27,6 @@ public class RdfUtils { private static final String DATE_FORMAT = "yyyy-MM-dd"; - static final Logger logger = LogManager.getLogger(RdfUtils.class); - static ValueFactory factory = SimpleValueFactory.getInstance(); private static final String CONCEPTS_SCHEME = Config.BASE_URI_GESTION + Config.CONCEPTS_SCHEME; @@ -259,17 +257,9 @@ public static void addTripleUri(Resource objectURI, IRI predicat, String value, model.add(objectURI, predicat, toURI(value), graph); } } - - public static void addTripleBNode(IRI objectURI, IRI predicat, BNode value, Model model,Resource graph) { - if (value != null) { - model.add(objectURI, predicat, value, graph); - } - } - - public static void addTripleBNode(BNode bnode, IRI predicat, String value,String lang, Model model,Resource graph) { - if (value != null && !value.isEmpty()) { - model.add(bnode, predicat, RdfUtils.setLiteralString(value, lang), graph); - } + + public static IRI createXSDIRI(String suffix){ + return factory.createIRI("http://www.w3.org/2001/XMLSchema#", suffix); } private RdfUtils() { 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 761a10ce7..a920440c8 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 @@ -104,7 +104,7 @@ public void setFakeUser(String user) throws JsonProcessingException { this.fakeUser = new User(roles, userObject.getString("stamp")); } - private boolean isAdmin() { + public boolean isAdmin() { User user = getUser(); return (isAdmin(user)); } 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 3c2fe70e8..47c849527 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 @@ -14,11 +14,7 @@ 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.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.*; import org.json.JSONArray; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; @@ -193,6 +189,30 @@ 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(XSD.DATETIME.toString())) { + 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); + 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); + 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); + } } RdfUtils.addTripleUri(componentURI, QB.CODE_LIST, component.getCodeList(), model, graph); diff --git a/src/main/java/fr/insee/rmes/config/auth/security/restrictions/StampsRestrictionsService.java b/src/main/java/fr/insee/rmes/config/auth/security/restrictions/StampsRestrictionsService.java index 7de02efe8..bde26de26 100644 --- a/src/main/java/fr/insee/rmes/config/auth/security/restrictions/StampsRestrictionsService.java +++ b/src/main/java/fr/insee/rmes/config/auth/security/restrictions/StampsRestrictionsService.java @@ -31,8 +31,9 @@ public interface StampsRestrictionsService { boolean canModifyConcept(IRI uri) throws RmesException; - - + boolean isAdmin(); + + /* * INDICATORS */ diff --git a/src/main/java/fr/insee/rmes/exceptions/ErrorCodes.java b/src/main/java/fr/insee/rmes/exceptions/ErrorCodes.java index d88f6b0f1..d3b9dcdf7 100644 --- a/src/main/java/fr/insee/rmes/exceptions/ErrorCodes.java +++ b/src/main/java/fr/insee/rmes/exceptions/ErrorCodes.java @@ -111,6 +111,7 @@ public class ErrorCodes { //GEOFEATURES public static final int GEOFEATURE_UNKNOWN = 845; public static final int GEOFEATURE_INCORRECT_BODY = 846; + public static final int GEOFEATURE_EXISTING_LABEL = 847; /* 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 4ce0ecf75..f5cb7dfab 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 @@ -130,7 +130,7 @@ private boolean sendMail(Mail mail, InputStream is, String fileName) { String result = client.target(Config.SPOC_SERVICE_URL) .request() - .post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),String.class); + .post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE.withCharset("utf-8")),String.class); return isMailSent(result); } diff --git a/src/main/java/fr/insee/rmes/model/operations/Family.java b/src/main/java/fr/insee/rmes/model/operations/Family.java index 750b6f3af..f743fd401 100644 --- a/src/main/java/fr/insee/rmes/model/operations/Family.java +++ b/src/main/java/fr/insee/rmes/model/operations/Family.java @@ -29,8 +29,14 @@ public class Family { @Schema(description = "Series") public List series; - - + + @Schema(description = "Creation date") + private String created; + + @Schema(description = "Update date") + private String updated; + + public Family() { //empty constructor for Jackson mapper } @@ -60,6 +66,19 @@ public void setId(String id) { } + public void setCreated(String currentDate) { + this.created = currentDate; + } - + public void setUpdated(String currentDate) { + this.updated = currentDate; + } + + public String getUpdated() { + return updated; + } + + public String getCreated() { + return created; + } } diff --git a/src/main/java/fr/insee/rmes/model/operations/Indicator.java b/src/main/java/fr/insee/rmes/model/operations/Indicator.java index 15289c907..bae986e47 100644 --- a/src/main/java/fr/insee/rmes/model/operations/Indicator.java +++ b/src/main/java/fr/insee/rmes/model/operations/Indicator.java @@ -73,7 +73,13 @@ public class Indicator { @Schema(description="Id of Sims documentation") public String idSims; - @Schema(description = "validationState") + @Schema(description = "Creation date") + private String created; + + @Schema(description = "Update date") + private String updated; + + @Schema(description = "validationState") public String validationState; public Indicator(String id) { @@ -292,4 +298,19 @@ public boolean equals(Object obj) { } + public String getCreated() { + return created; + } + + public void setCreated(String created) { + this.created = created; + } + + public String getUpdated() { + return updated; + } + + public void setUpdated(String updated) { + this.updated = updated; + } } diff --git a/src/main/java/fr/insee/rmes/model/operations/Operation.java b/src/main/java/fr/insee/rmes/model/operations/Operation.java index 3fc4f78db..6369a7b84 100644 --- a/src/main/java/fr/insee/rmes/model/operations/Operation.java +++ b/src/main/java/fr/insee/rmes/model/operations/Operation.java @@ -27,6 +27,12 @@ public class Operation { @Schema(description = "Sims Id") public String idSims; + @Schema(description = "Creation date") + private String created; + + @Schema(description = "Update date") + private String updated; + public Operation(String id, String prefLabelLg1, String prefLabelLg2, String altLabelLg1, String altLabelLg2, IdLabelTwoLangs series, String idSims) { super(); @@ -112,4 +118,19 @@ public void setIdSims(String idSims) { } + public String getCreated() { + return created; + } + + public void setCreated(String created) { + this.created = created; + } + + public String getUpdated() { + return updated; + } + + public void setUpdated(String updated) { + this.updated = updated; + } } diff --git a/src/main/java/fr/insee/rmes/model/operations/Series.java b/src/main/java/fr/insee/rmes/model/operations/Series.java index 84dbd4066..62438cf2c 100644 --- a/src/main/java/fr/insee/rmes/model/operations/Series.java +++ b/src/main/java/fr/insee/rmes/model/operations/Series.java @@ -85,6 +85,12 @@ public class Series { @Schema(description= "SIMS id") public String idSims; + + @Schema(description = "Creation date") + private String created; + + @Schema(description = "Update date") + private String updated; /* * Getters @@ -287,5 +293,19 @@ public void setIdSims(String idSims) { } + public String getCreated() { + return created; + } + + public void setCreated(String created) { + this.created = created; + } + + public String getUpdated() { + return updated; + } + public void setUpdated(String updated) { + this.updated = updated; + } } diff --git a/src/main/java/fr/insee/rmes/model/operations/documentations/Documentation.java b/src/main/java/fr/insee/rmes/model/operations/documentations/Documentation.java index 70e25f352..a976a09d6 100644 --- a/src/main/java/fr/insee/rmes/model/operations/documentations/Documentation.java +++ b/src/main/java/fr/insee/rmes/model/operations/documentations/Documentation.java @@ -2,6 +2,7 @@ import java.util.List; +import io.swagger.v3.oas.annotations.media.Schema; import org.apache.commons.lang3.StringUtils; import com.fasterxml.jackson.annotation.JsonFormat; @@ -14,6 +15,12 @@ public class Documentation { private String idSeries; private String idIndicator; + @Schema(description = "Creation date") + private String created; + + @Schema(description = "Update date") + private String updated; + private String labelLg1; private String labelLg2; @@ -76,4 +83,19 @@ public void setIdOperation(String idOperation) { this.idOperation = idOperation; } + public String getCreated() { + return created; + } + + public void setCreated(String created) { + this.created = created; + } + + public String getUpdated() { + return updated; + } + + public void setUpdated(String updated) { + this.updated = updated; + } } diff --git a/src/main/java/fr/insee/rmes/model/structures/MutualizedComponent.java b/src/main/java/fr/insee/rmes/model/structures/MutualizedComponent.java index c4a0c93fe..c914b8fd2 100644 --- a/src/main/java/fr/insee/rmes/model/structures/MutualizedComponent.java +++ b/src/main/java/fr/insee/rmes/model/structures/MutualizedComponent.java @@ -26,6 +26,11 @@ public class MutualizedComponent { private String contributor; private String disseminationStatus; + private String minLength; + private String maxLength; + private String minInclusive; + private String maxInclusive; + private String pattern; public MutualizedComponent() throws RmesException { //nothing to do @@ -158,4 +163,44 @@ public String getDisseminationStatus() { public void setDisseminationStatus(String disseminationStatus) { this.disseminationStatus = disseminationStatus; } + + public String getPattern() { + return pattern; + } + + public void setPattern(String pattern) { + this.pattern = pattern; + } + + public String getMaxInclusive() { + return maxInclusive; + } + + public void setMaxInclusive(String maxInclusive) { + this.maxInclusive = maxInclusive; + } + + public String getMinInclusive() { + return minInclusive; + } + + public void setMinInclusive(String minInclusive) { + this.minInclusive = minInclusive; + } + + public String getMaxLength() { + return maxLength; + } + + public void setMaxLength(String maxLength) { + this.maxLength = maxLength; + } + + public String getMinLength() { + return minLength; + } + + public void setMinLength(String minLength) { + this.minLength = minLength; + } } 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 ec1b27295..2c801914a 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,5 +1,7 @@ package fr.insee.rmes.persistance.sparql_queries.code_list; +import fr.insee.rmes.bauhaus_services.ConceptsService; +import fr.insee.rmes.bauhaus_services.Constants; import fr.insee.rmes.bauhaus_services.rdf_utils.FreeMarkerUtils; import fr.insee.rmes.config.Config; import fr.insee.rmes.exceptions.RmesException; @@ -15,12 +17,13 @@ public static String isCodesListValidated(String codesListUri) throws RmesExcept return FreeMarkerUtils.buildRequest("codes-list/", "isCodesListValidated.ftlh", params); } - public static String getAllCodesLists() throws RmesException { + public static String getAllCodesLists(boolean partial) throws RmesException { HashMap params = new HashMap<>(); 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); } public static String getCodeListItemsByNotation(String notation) { @@ -89,22 +92,31 @@ public static String getDetailedCodeListByNotation(String notation) throws RmesE return FreeMarkerUtils.buildRequest("codes-list/", "getDetailedCodesList.ftlh", params); } - public static String getCodesListsForSearch() throws RmesException { + public static String getCodesListsForSearch(boolean partial) throws RmesException { HashMap params = getInitParams(); + params.put("PARTIAL", partial); return FreeMarkerUtils.buildRequest("codes-list/", "getDetailedCodesListForSearch.ftlh", params); } - public static String getCodesForSearch() throws RmesException { + public static String getCodesForSearch(boolean partial) throws RmesException { HashMap params = getInitParams(); + params.put("PARTIAL", partial); return FreeMarkerUtils.buildRequest("codes-list/", "getCodesForSearch.ftlh", params); } - public static String getDetailedCodes(String notation) throws RmesException { + 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); } + public static String getCodesSeq(String notation) throws RmesException { + HashMap params = getInitParams(); + 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); diff --git a/src/main/java/fr/insee/rmes/persistance/sparql_queries/geography/GeoQueries.java b/src/main/java/fr/insee/rmes/persistance/sparql_queries/geography/GeoQueries.java index 26eeea557..caafb4d25 100644 --- a/src/main/java/fr/insee/rmes/persistance/sparql_queries/geography/GeoQueries.java +++ b/src/main/java/fr/insee/rmes/persistance/sparql_queries/geography/GeoQueries.java @@ -78,6 +78,10 @@ private GeoQueries() { } + public static String checkUnicityTerritory(String labelLg1) throws RmesException { + if (params==null) {initParams();} + params.put("LABEL", labelLg1); - + return buildRequest("checkUnicityTerritory.ftlh", params); + } } diff --git a/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/families/FamiliesQueries.java b/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/families/FamiliesQueries.java index 4a4e6b90f..54e969393 100644 --- a/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/families/FamiliesQueries.java +++ b/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/families/FamiliesQueries.java @@ -43,8 +43,9 @@ public static String familiesQuery() { + "ORDER BY ?label "; } + public static String familyQuery(String id) { - return "SELECT ?id ?prefLabelLg1 ?prefLabelLg2 ?abstractLg1 ?abstractLg2 ?validationState\n" + return "SELECT ?id ?prefLabelLg1 ?prefLabelLg2 ?abstractLg1 ?abstractLg2 ?validationState ?created ?modified\n" + "WHERE { GRAPH <"+Config.OPERATIONS_GRAPH+"> { \n" + "?family skos:prefLabel ?prefLabelLg1 . \n" + "FILTER(STRENDS(STR(?family),'/operations/famille/" + id+ "')) . \n" @@ -54,6 +55,8 @@ public static String familyQuery(String id) { + "OPTIONAL {?family skos:prefLabel ?prefLabelLg2 . \n" + "FILTER (lang(?prefLabelLg2) = '" + Config.LG2 + "') } . \n" + "OPTIONAL {?family insee:validationState ?validationState} . \n" + + "OPTIONAL { ?family dcterms:created ?created } . \n" + + "OPTIONAL { ?family dcterms:modified ?modified } . \n" + "OPTIONAL {?family dcterms:abstract ?abstractLg1 . \n" + "FILTER (lang(?abstractLg1) = '" + Config.LG1 + "') } . \n" + "OPTIONAL {?family dcterms:abstract ?abstractLg2 . \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 c834bff91..c3a17dc3b 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 @@ -180,12 +180,15 @@ private static void getSimpleAttr(String id) { addClauseToWhereClause("BIND(STRAFTER(STR(?indic),'/"+Config.PRODUCTS_BASE_URI+"/') AS ?id) . "); } - addVariableToList("?id ?prefLabelLg1 ?prefLabelLg2 "); + addVariableToList("?id ?prefLabelLg1 ?prefLabelLg2 ?created ?modified"); + addClauseToWhereClause( "OPTIONAL { ?indic dcterms:created ?created } . \n "); + addClauseToWhereClause( "OPTIONAL { ?indic dcterms:modified ?modified } . \n "); + addClauseToWhereClause( "?indic skos:prefLabel ?prefLabelLg1 \n"); addClauseToWhereClause( "FILTER (lang(?prefLabelLg1) = '" + Config.LG1 + "') \n "); addClauseToWhereClause( "OPTIONAL{?indic skos:prefLabel ?prefLabelLg2 \n"); addClauseToWhereClause( "FILTER (lang(?prefLabelLg2) = '" + Config.LG2 + "') } \n "); - + addVariableToList(" ?altLabelLg1 ?altLabelLg2 "); @@ -298,7 +301,19 @@ private IndicatorsQueries() { throw new IllegalStateException("Utility class"); } - - + public static String indicatorsWithSimsQuery() { + //Config.OPERATIONS_GRAPH + return "SELECT DISTINCT ?labelLg1 ?idSims \n" + + "WHERE { \n" + + "?indic a insee:StatisticalIndicator . \n" + + "?indic skos:prefLabel ?labelLg1 . \n" + + "FILTER (lang(?labelLg1) = '" + Config.LG1 + "') \n" + + "?report rdf:type sdmx-mm:MetadataReport . \n" + + "?report sdmx-mm:target ?indic \n" + + "BIND(STRAFTER(STR(?report),'/rapport/') AS ?idSims) . \n" + + "} \n" + + "GROUP BY ?labelLg1 ?idSims \n" + + "ORDER BY ?label "; + } } 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 68fe300d9..65b4f437a 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 @@ -19,7 +19,7 @@ public static String operationsQuery() { } public static String operationQuery(String id){ - return "SELECT ?id ?prefLabelLg1 ?prefLabelLg2 ?altLabelLg1 ?altLabelLg2 ?idSims ?validationState \n" + return "SELECT ?id ?prefLabelLg1 ?prefLabelLg2 ?altLabelLg1 ?altLabelLg2 ?idSims ?validationState ?created ?modified \n" + "WHERE { " + "GRAPH <"+Config.OPERATIONS_GRAPH+"> { \n" + "?operation skos:prefLabel ?prefLabelLg1 . \n" @@ -35,7 +35,8 @@ public static String operationQuery(String id){ + "OPTIONAL {?operation skos:altLabel ?altLabelLg2 . \n" + "FILTER (lang(?altLabelLg2) = '" + Config.LG2 + "') } . \n" + "}" - + + "OPTIONAL { ?operation dcterms:created ?created } . \n" + + "OPTIONAL { ?operation dcterms:modified ?modified } . \n" + "OPTIONAL{ ?report rdf:type sdmx-mm:MetadataReport ." + " ?report sdmx-mm:target ?operation " + " BIND(STRAFTER(STR(?report),'/rapport/') AS ?idSims) . \n" @@ -83,6 +84,27 @@ public static String operationsWithoutSimsQuery(String idSeries) { + "GROUP BY ?id ?labelLg1 ?labelLg2 \n" + "ORDER BY ?labelLg1 "; } + + public static String operationsWithSimsQuery(String idSeries) { + return "SELECT DISTINCT ?id ?labelLg1 ?labelLg2 ?idSims \n" + + "WHERE { \n" + + "?operation a insee:StatisticalOperation . \n" + + "?series dcterms:hasPart ?operation \n " + + "FILTER(STRENDS(STR(?series),'/operations/serie/" + idSeries+ "')) . \n" + + + "?operation skos:prefLabel ?labelLg1 . \n" + + "FILTER (lang(?labelLg1) = '" + Config.LG1 + "') \n" + + "?operation skos:prefLabel ?labelLg2 . \n" + + "FILTER (lang(?labelLg2) = '" + Config.LG2 + "') \n" + + + "BIND(STRAFTER(STR(?operation),'/operations/operation/') AS ?id) . \n" + + "?report rdf:type sdmx-mm:MetadataReport ." + + " ?report sdmx-mm:target ?operation " + + " BIND(STRAFTER(STR(?report),'/rapport/') AS ?idSims) . \n" + + "} \n" + + "GROUP BY ?id ?labelLg1 ?labelLg2 ?idSims \n" + + "ORDER BY ?labelLg1 "; + } private OperationsQueries() { throw new IllegalStateException("Utility class"); diff --git a/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/series/SeriesQueries.java b/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/series/SeriesQueries.java index 00741abf1..635e7c47e 100644 --- a/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/series/SeriesQueries.java +++ b/src/main/java/fr/insee/rmes/persistance/sparql_queries/operations/series/SeriesQueries.java @@ -62,12 +62,17 @@ private static void getSimpleAttr(String id) { addClauseToWhereClause("BIND(STRAFTER(STR(?series),'/operations/serie/') AS ?id) . "); } - addVariableToList("?id ?prefLabelLg1 ?prefLabelLg2 "); + addVariableToList("?id ?prefLabelLg1 ?prefLabelLg2 ?created ?modified"); addClauseToWhereClause("?series skos:prefLabel ?prefLabelLg1 \n"); + addClauseToWhereClause( "OPTIONAL { ?series dcterms:created ?created } . \n "); + addClauseToWhereClause( "OPTIONAL { ?series dcterms:modified ?modified } . \n "); + addClauseToWhereClause("FILTER (lang(?prefLabelLg1) = '" + Config.LG1 + "') \n "); addClauseToWhereClause("OPTIONAL{?series skos:prefLabel ?prefLabelLg2 \n"); addClauseToWhereClause("FILTER (lang(?prefLabelLg2) = '" + Config.LG2 + "') } \n "); + + addVariableToList(" ?altLabelLg1 ?altLabelLg2 "); addOptionalClause("skos:altLabel", "?altLabel"); @@ -234,10 +239,11 @@ public static String seriesWithSimsQuery() throws RmesException { * @return String * @throws RmesException */ - public static String seriesWithStampQuery(String stamp) throws RmesException { + public static String seriesWithStampQuery(String stamp, boolean isAdmin) throws RmesException { if (params==null) {initParams();} params.put(STAMP, stamp); - return buildSeriesRequest("getSeriesWithStampQuery.ftlh", params); + params.put("ADMIN", isAdmin); + return buildSeriesRequest("getSeriesWithStampQuery.ftlh", params); } diff --git a/src/main/java/fr/insee/rmes/webservice/CodeListsResources.java b/src/main/java/fr/insee/rmes/webservice/CodeListsResources.java index e7391bfc2..48501c481 100644 --- a/src/main/java/fr/insee/rmes/webservice/CodeListsResources.java +++ b/src/main/java/fr/insee/rmes/webservice/CodeListsResources.java @@ -50,7 +50,7 @@ public class CodeListsResources { public Response setCodesList(@RequestBody(description = "Code List", required = true) String body) { String id = null; try { - id = codeListService.setCodesList(body); + id = codeListService.setCodesList(body, false); } catch (RmesException e) { return Response.status(e.getStatus()).entity(e.getDetails()).type(TEXT_PLAIN).build(); } @@ -64,7 +64,35 @@ public Response setCodesList(@RequestBody(description = "Code List", required = public Response updateCodesList(@PathParam(Constants.ID) String componentId, @RequestBody(description = "Code List", required = true) String body) { String id = null; try { - id = codeListService.setCodesList(id, body); + id = codeListService.setCodesList(id, body, false); + } catch (RmesException e) { + return Response.status(e.getStatus()).entity(e.getDetails()).type(TEXT_PLAIN).build(); + } + return Response.status(HttpStatus.SC_OK).entity(id).build(); + } + + @POST + @Path("/partial") + @Consumes(MediaType.APPLICATION_JSON) + @Operation(operationId = "createPartialCodeList", summary = "Create a codes list") + public Response createPartialCodeList(@RequestBody(description = "Code List", required = true) String body) { + String id = null; + try { + id = codeListService.setCodesList(body, true); + } catch (RmesException e) { + return Response.status(e.getStatus()).entity(e.getDetails()).type(TEXT_PLAIN).build(); + } + return Response.status(HttpStatus.SC_OK).entity(id).build(); + } + + @PUT + @Path("/partial/{id}") + @Consumes(MediaType.APPLICATION_JSON) + @Operation(operationId = "setCodesList", summary = "Create a codes list") + public Response updatePartialCodeList(@PathParam(Constants.ID) String componentId, @RequestBody(description = "Code List", required = true) String body) { + String id = null; + try { + id = codeListService.setCodesList(id, body, true); } catch (RmesException e) { return Response.status(e.getStatus()).entity(e.getDetails()).type(TEXT_PLAIN).build(); } @@ -78,7 +106,22 @@ public Response updateCodesList(@PathParam(Constants.ID) String componentId, @Re public Response getallCodesLists() { String jsonResultat; try { - jsonResultat = codeListService.getAllCodesLists(); + jsonResultat = codeListService.getAllCodesLists(false); + } catch (RmesException e) { + return Response.status(e.getStatus()).entity(e.getDetails()).type(TEXT_PLAIN).build(); + } + return Response.status(HttpStatus.SC_OK).entity(jsonResultat).build(); + } + + @GET + @Path("/partial") + @Produces(MediaType.APPLICATION_JSON) + @Operation(operationId = "getallPartialCodesLists", summary = "Partial List of codes", + responses = { @ApiResponse(content = @Content(mediaType = "application/json", schema = @Schema(type = "array", implementation = CodeList.class)))}) + public Response getallPartialCodesLists() { + String jsonResultat; + try { + jsonResultat = codeListService.getAllCodesLists(true); } catch (RmesException e) { return Response.status(e.getStatus()).entity(e.getDetails()).type(TEXT_PLAIN).build(); } @@ -93,7 +136,22 @@ public Response getallCodesLists() { public Response getDetailedCodesLisForSearch() { String jsonResultat; try { - jsonResultat = codeListService.getDetailedCodesListForSearch(); + jsonResultat = codeListService.getDetailedCodesListForSearch(false); + } catch (RmesException e) { + return Response.status(e.getStatus()).entity(e.getDetails()).type(TEXT_PLAIN).build(); + } + return Response.status(HttpStatus.SC_OK).entity(jsonResultat).build(); + } + + @GET + @Path("/partial/search") + @Produces(MediaType.APPLICATION_JSON) + @Operation(operationId = "getDetailedPartialCodesLisForSearch", summary = "Return all lists for Advanced Search", + responses = { @ApiResponse(content = @Content(mediaType = "application/json", schema = @Schema(implementation = CodeList.class)))}) + public Response getDetailedPartialCodesLisForSearch() { + String jsonResultat; + try { + jsonResultat = codeListService.getDetailedCodesListForSearch(true); } catch (RmesException e) { return Response.status(e.getStatus()).entity(e.getDetails()).type(TEXT_PLAIN).build(); } @@ -108,7 +166,22 @@ public Response getDetailedCodesLisForSearch() { public Response getDetailedCodesListByNotation(@PathParam("notation") String notation) { String jsonResultat; try { - jsonResultat = codeListService.getDetailedCodesList(notation); + jsonResultat = codeListService.getDetailedCodesList(notation, false); + } catch (RmesException e) { + return Response.status(e.getStatus()).entity(e.getDetails()).type(TEXT_PLAIN).build(); + } + return Response.status(HttpStatus.SC_OK).entity(jsonResultat).build(); + } + + @GET + @Path("/partial/{notation}") + @Produces(MediaType.APPLICATION_JSON) + @Operation(operationId = "getDetailedPartialCodesListByNotation", summary = "Get a partial list of code", + responses = { @ApiResponse(content = @Content(mediaType = "application/json", schema = @Schema(implementation = CodeList.class)))}) + public Response getDetailedPartialCodesListByNotation(@PathParam("notation") String notation) { + String jsonResultat; + try { + jsonResultat = codeListService.getDetailedCodesList(notation, true); } catch (RmesException e) { return Response.status(e.getStatus()).entity(e.getDetails()).type(TEXT_PLAIN).build(); } diff --git a/src/main/java/fr/insee/rmes/webservice/GeographyResources.java b/src/main/java/fr/insee/rmes/webservice/GeographyResources.java index 6f2d46af7..68e66a9fb 100644 --- a/src/main/java/fr/insee/rmes/webservice/GeographyResources.java +++ b/src/main/java/fr/insee/rmes/webservice/GeographyResources.java @@ -1,14 +1,12 @@ package fr.insee.rmes.webservice; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; +import javax.ws.rs.*; 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; @@ -84,8 +82,8 @@ public Response getGeoFeature(@PathParam(Constants.ID) String id) throws RmesExc @POST @Path("/territory") @Consumes(MediaType.APPLICATION_JSON) - @io.swagger.v3.oas.annotations.Operation(operationId = "createFeature", summary = "Create feature") - public Response createFamily( + @io.swagger.v3.oas.annotations.Operation(operationId = "createGeograohy", summary = "Create feature") + public Response createGeography( @RequestBody(description = "Geo Feature to create", required = true, content = @Content(schema = @Schema(implementation = GeoFeature.class))) String body) { String id = null; @@ -96,6 +94,21 @@ public Response createFamily( } return Response.status(HttpStatus.SC_OK).entity(id).build(); } - - + + @Secured({ Roles.SPRING_ADMIN }) + @PUT + @Path("/territory/{id}") + @Consumes(MediaType.APPLICATION_JSON) + @Operation(operationId = "updateGeography", summary = "Update geography ") + public Response updateGeography( + @Parameter(description = "Id", required = true) @PathParam(Constants.ID) String id, + @RequestBody(description = "Geo Feature to update", required = true) + @Parameter(schema = @Schema(implementation= GeoFeature.class)) String body) { + try { + geoService.updateFeature(id, body); + } catch (RmesException e) { + return Response.status(e.getStatus()).entity(e.getDetails()).type(MediaType.TEXT_PLAIN).build(); + } + return Response.status(Response.Status.OK).build(); + } } diff --git a/src/main/java/fr/insee/rmes/webservice/operations/IndicatorsResources.java b/src/main/java/fr/insee/rmes/webservice/operations/IndicatorsResources.java index 6eb5cf835..63d9651cf 100644 --- a/src/main/java/fr/insee/rmes/webservice/operations/IndicatorsResources.java +++ b/src/main/java/fr/insee/rmes/webservice/operations/IndicatorsResources.java @@ -13,6 +13,7 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; +import fr.insee.rmes.config.swagger.model.IdLabelAltLabelSims; import org.apache.http.HttpStatus; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.security.access.annotation.Secured; @@ -52,6 +53,15 @@ public Response getIndicators() throws RmesException { } + @GET + @Path("/indicators/withSims") + @Produces(MediaType.APPLICATION_JSON) + @io.swagger.v3.oas.annotations.Operation(operationId = "annotations", summary = "List of series with related sims", responses = {@ApiResponse(content=@Content(schema=@Schema(type="array",implementation= IdLabelAltLabelSims.class)))}) + public Response getIndicatorsWIthSims() throws RmesException { + String jsonResultat = operationsService.getIndicatorsWithSims(); + return Response.status(HttpStatus.SC_OK).entity(jsonResultat).build(); + } + @GET @Path("/indicators/advanced-search") @Produces(MediaType.APPLICATION_JSON) diff --git a/src/main/java/fr/insee/rmes/webservice/operations/SeriesResources.java b/src/main/java/fr/insee/rmes/webservice/operations/SeriesResources.java index 9c30b1b2a..1cd3e1fef 100644 --- a/src/main/java/fr/insee/rmes/webservice/operations/SeriesResources.java +++ b/src/main/java/fr/insee/rmes/webservice/operations/SeriesResources.java @@ -150,6 +150,21 @@ public Response getOperationsWithoutReport(@PathParam(Constants.ID) String id) { return Response.status(HttpStatus.SC_OK).entity(jsonResultat).build(); } + @GET + @Path("/series/{id}/operationsWithReport") + @Produces(MediaType.APPLICATION_JSON) + @io.swagger.v3.oas.annotations.Operation(operationId = "getOperationsWithReport", summary = "Operations with metadataReport", responses = {@ApiResponse(content=@Content(schema=@Schema(type="array",implementation=Operation.class)))}) + public Response getOperationsWithReport(@PathParam(Constants.ID) String id) { + String jsonResultat; + try { + jsonResultat = operationsService.getOperationsWithReport(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(); + } + + /** * CREATE diff --git a/src/main/resources/request/codes-list/getAllCodesLists.ftlh b/src/main/resources/request/codes-list/getAllCodesLists.ftlh index 5a7d452b8..5739bd7c0 100644 --- a/src/main/resources/request/codes-list/getAllCodesLists.ftlh +++ b/src/main/resources/request/codes-list/getAllCodesLists.ftlh @@ -1,14 +1,19 @@ SELECT ?uri ?labelLg1 ?labelLg2 ?range ?id WHERE { + GRAPH <${CODES_LISTS_GRAPH}> { +<#if PARTIAL> + ?uri rdf:type skos:Collection . +<#else> + ?uri rdf:type skos:ConceptScheme . + -GRAPH <${CODES_LISTS_GRAPH}> { -?uri rdf:type skos:ConceptScheme . -?uri skos:prefLabel ?labelLg1 . -?uri skos:notation ?id . -FILTER(lang(?labelLg1) = '${LG1}') . -OPTIONAL {?uri skos:prefLabel ?labelLg2 . -FILTER (lang(?labelLg2) = '${LG2}') } . -?range rdfs:seeAlso ?uri -} + ?uri skos:prefLabel ?labelLg1 . + ?uri skos:notation ?id . + FILTER(lang(?labelLg1) = '${LG1}') . + OPTIONAL {?uri skos:prefLabel ?labelLg2 . + FILTER (lang(?labelLg2) = '${LG2}') } . + OPTIONAL { ?range rdfs:seeAlso ?uri } . + + } } \ No newline at end of file diff --git a/src/main/resources/request/codes-list/getCodesForSearch.ftlh b/src/main/resources/request/codes-list/getCodesForSearch.ftlh index 8edb414d1..81b66eed2 100644 --- a/src/main/resources/request/codes-list/getCodesForSearch.ftlh +++ b/src/main/resources/request/codes-list/getCodesForSearch.ftlh @@ -1,7 +1,11 @@ SELECT ?labelLg1 ?code ?id FROM <${CODES_LISTS_GRAPH}> WHERE { +<#if PARTIAL> + ?list skos:member ?codeUri . +<#else> ?codeUri skos:inScheme ?list . + ?list skos:notation ?id . ?codeUri skos:notation ?code . ?codeUri skos:prefLabel ?labelLg1 . diff --git a/src/main/resources/request/codes-list/getCodesSeq.ftlh b/src/main/resources/request/codes-list/getCodesSeq.ftlh new file mode 100644 index 000000000..33ee3bedd --- /dev/null +++ b/src/main/resources/request/codes-list/getCodesSeq.ftlh @@ -0,0 +1,11 @@ +SELECT ?position ?code +FROM <${CODES_LISTS_GRAPH}> +WHERE { + ?list skos:notation '${NOTATION}' ; + rdf:type rdf:Seq ; + ?predicate ?uri . + BIND(xsd:integer(STRAFTER(STR(?predicate),'#_')) AS ?position) . + FILTER(!ISBLANK(?position)) + ?uri skos:notation ?code +} +ORDER BY ASC(xsd:integer(?position)) diff --git a/src/main/resources/request/codes-list/getDetailedCodes.ftlh b/src/main/resources/request/codes-list/getDetailedCodes.ftlh index 0de64deaa..0a472acc9 100644 --- a/src/main/resources/request/codes-list/getDetailedCodes.ftlh +++ b/src/main/resources/request/codes-list/getDetailedCodes.ftlh @@ -1,7 +1,11 @@ -SELECT ?labelLg1 ?labelLg2 ?code ?descriptionLg1 ?descriptionLg2 ?parents +SELECT ?labelLg1 ?labelLg2 ?code ?descriptionLg1 ?descriptionLg2 ?parents <#if PARTIAL> ?codeUri FROM <${CODES_LISTS_GRAPH}> WHERE { +<#if PARTIAL> + ?list skos:member ?codeUri . +<#else> ?codeUri skos:inScheme ?list . + ?list skos:notation '${NOTATION}' . ?codeUri skos:notation ?code . ?codeUri skos:prefLabel ?labelLg1 . diff --git a/src/main/resources/request/codes-list/getDetailedCodesList.ftlh b/src/main/resources/request/codes-list/getDetailedCodesList.ftlh index e80fc763f..1c3c76330 100644 --- a/src/main/resources/request/codes-list/getDetailedCodesList.ftlh +++ b/src/main/resources/request/codes-list/getDetailedCodesList.ftlh @@ -1,4 +1,5 @@ -SELECT DISTINCT ?id ?labelLg1 ?labelLg2 ?created ?modified ?creator ?contributor ?validationState ?disseminationStatus ?descriptionLg1 ?descriptionLg2 ?lastListUriSegment ?lastClassUriSegment +SELECT DISTINCT ?id ?labelLg1 ?labelLg2 ?created ?modified ?creator ?contributor ?validationState ?disseminationStatus +?descriptionLg1 ?descriptionLg2 ?lastListUriSegment ?lastClassUriSegment ?iriParent FROM <${CODES_LISTS_GRAPH}> WHERE { ?list skos:notation '${NOTATION}' ; @@ -31,6 +32,9 @@ WHERE { BIND(STRAFTER(STR(?seeAlso),'concept/') AS ?lastClassUriSegment) . } + OPTIONAL { + ?list prov:wasDerivedFrom ?iriParent . + } . BIND(STRAFTER(STR(?list),'${CODE_LIST_BASE_URI}/') AS ?lastListUriSegment) . ?list skos:prefLabel ?labelLg1 . diff --git a/src/main/resources/request/codes-list/getDetailedCodesListForSearch.ftlh b/src/main/resources/request/codes-list/getDetailedCodesListForSearch.ftlh index 0c0bb263d..e63e0f39d 100644 --- a/src/main/resources/request/codes-list/getDetailedCodesListForSearch.ftlh +++ b/src/main/resources/request/codes-list/getDetailedCodesListForSearch.ftlh @@ -1,6 +1,11 @@ SELECT DISTINCT ?id ?labelLg1 ?creator ?validationState FROM <${CODES_LISTS_GRAPH}> WHERE { +<#if PARTIAL> + ?list rdf:type skos:Collection . +<#else> + ?list rdf:type skos:ConceptScheme . + ?list skos:notation ?id ; dc:creator ?creator ; insee:validationState ?validationState ; diff --git a/src/main/resources/request/consultation-gestion/getComponent.ftlh b/src/main/resources/request/consultation-gestion/getComponent.ftlh index e8cdd7f54..6c7613009 100644 --- a/src/main/resources/request/consultation-gestion/getComponent.ftlh +++ b/src/main/resources/request/consultation-gestion/getComponent.ftlh @@ -1,7 +1,8 @@ SELECT ?id (?uriComposant as ?uri) ?type ?notation ?dateMiseAJour ?statutValidation ?prefLabelLg1 ?prefLabelLg2 ?uriConcept ?idConcept ?representation - ?uriListeCode ?idListeCode ?version ?uriComponentParentId ?uriComponentParentNotation + ?uriListeCode ?idListeCode ?version ?uriComponentParentId ?uriComponentParentNotation ?dateCreation + ?minLength ?maxLength ?minInclusive ?maxInclusive ?pattern FROM <${STRUCTURES_COMPONENTS_GRAPH}> FROM <${CODELIST_GRAPH}> WHERE { @@ -37,6 +38,9 @@ WHERE { ?uriComponentParent skos:notation ?uriComponentParentNotation . } + OPTIONAL { + ?uriComposant dcterms:created ?dateCreation . + } OPTIONAL { ?uriComposant qb:concept ?uriConcept . BIND(STRAFTER(STR(?uriConcept), "${CONCEPTS_BASE_URI}/") AS ?idConcept) @@ -51,4 +55,20 @@ WHERE { OPTIONAL { ?uriComposant pav:version ?version . } + + OPTIONAL { + ?uriComposant xsd:minLength ?minLength . + } + OPTIONAL { + ?uriComposant xsd:maxLength ?maxLength . + } + OPTIONAL { + ?uriComposant xsd:minInclusive ?minInclusive . + } + OPTIONAL { + ?uriComposant xsd:maxInclusive ?maxInclusive . + } + OPTIONAL { + ?uriComposant xsd:pattern ?pattern . + } } \ No newline at end of file diff --git a/src/main/resources/request/geography/checkUnicityTerritory.ftlh b/src/main/resources/request/geography/checkUnicityTerritory.ftlh new file mode 100644 index 000000000..d7d3ba0d8 --- /dev/null +++ b/src/main/resources/request/geography/checkUnicityTerritory.ftlh @@ -0,0 +1,5 @@ +SELECT ?territory +FROM<${GEO_SIMS_GRAPH}> +WHERE { + ?territory skos:prefLabel "${LABEL}"@${LG1} +} \ No newline at end of file diff --git a/src/main/resources/request/operations/documentations/getDocumentationTitleQuery.ftlh b/src/main/resources/request/operations/documentations/getDocumentationTitleQuery.ftlh index 35b9393d3..45f317c0b 100644 --- a/src/main/resources/request/operations/documentations/getDocumentationTitleQuery.ftlh +++ b/src/main/resources/request/operations/documentations/getDocumentationTitleQuery.ftlh @@ -1,12 +1,18 @@ -SELECT ?labelLg1 ?labelLg2 ?idOperation ?idSeries ?idIndicator ?validationState +SELECT ?labelLg1 ?labelLg2 ?idOperation ?idSeries ?idIndicator ?validationState ?created ?updated FROM <${DOCUMENTATIONS_GRAPH}/${idSims}> WHERE { ?report rdf:type sdmx-mm:MetadataReport . OPTIONAL{ ?report sdmx-mm:target ?operation . BIND(STRAFTER(STR(?operation),'/operation/') AS ?idOperation) . } OPTIONAL{ ?report sdmx-mm:target ?series . BIND(STRAFTER(STR(?series),'/serie/') AS ?idSeries) . } - OPTIONAL{ ?report sdmx-mm:target ?indicator . BIND(STRAFTER(STR(?indicator),'/indicateur/') AS ?idIndicator) . } - + OPTIONAL{ ?report sdmx-mm:target ?indicator . BIND(STRAFTER(STR(?indicator),'/indicateur/') AS ?idIndicator) . } + OPTIONAL { + ?report dcterms:created ?created . + } . + + OPTIONAL { + ?report dcterms:modified ?updated . + } . OPTIONAL{ ?report rdfs:label ?labelLg1 . diff --git a/src/main/resources/request/operations/series/getSeriesGeneratedWithQuery.ftlh b/src/main/resources/request/operations/series/getSeriesGeneratedWithQuery.ftlh index 26e23b172..b60c13c55 100644 --- a/src/main/resources/request/operations/series/getSeriesGeneratedWithQuery.ftlh +++ b/src/main/resources/request/operations/series/getSeriesGeneratedWithQuery.ftlh @@ -6,8 +6,8 @@ SELECT ?id ?typeOfObject ?labelLg1 ?labelLg2 FILTER (lang(?labelLg1) = '${LG1}') . ?uri skos:prefLabel ?labelLg2 . FILTER (lang(?labelLg2) = '${LG2}') . - ?uri rdf:type ?typeOfObject . - BIND(REPLACE( STR(?uri) , '(.*/)(\\\\w+$)', '$2' ) AS ?id) . - FILTER(STRENDS(STR(?series),'/operations/serie/${ID_SERIES}')) . + ?uri rdf:type ?typeOfObject . + BIND(REPLACE( STR(?uri) , '.*/(p.*)', '$1' ) AS ?id) . + FILTER(STRENDS(STR(?series),'/operations/serie/${ID_SERIES}')) . } ORDER BY ?id \ No newline at end of file diff --git a/src/main/resources/request/operations/series/getSeriesWithStampQuery.ftlh b/src/main/resources/request/operations/series/getSeriesWithStampQuery.ftlh index 8d9d8b205..50479325a 100644 --- a/src/main/resources/request/operations/series/getSeriesWithStampQuery.ftlh +++ b/src/main/resources/request/operations/series/getSeriesWithStampQuery.ftlh @@ -4,10 +4,16 @@ SELECT DISTINCT ?id ?label (group_concat(?altLabelLg1;separator=' || ') as ?altL GRAPH <${OPERATIONS_GRAPH}> { ?series a insee:StatisticalOperationSeries . ?series skos:prefLabel ?label . - ?series dc:creator ?creators - FILTER (lang(?label) = '${LG1}') - FILTER (STR(?creators) = "${STAMP}") - BIND(STRAFTER(STR(?series),'/operations/serie/') AS ?id) . + + FILTER (lang(?label) = '${LG1}') + OPTIONAL { + ?series dc:creator ?creators + } +<#if !ADMIN> + FILTER (STR(?creators) = "${STAMP}") + + + BIND(STRAFTER(STR(?series),'/operations/serie/') AS ?id) . OPTIONAL{ ?series skos:altLabel ?altLabelLg1 . FILTER (lang(?altLabelLg1) = '${LG1}') diff --git a/src/main/resources/request/structures/getMutualizedComponent.ftlh b/src/main/resources/request/structures/getMutualizedComponent.ftlh index 52e33c379..d1b08bde0 100644 --- a/src/main/resources/request/structures/getMutualizedComponent.ftlh +++ b/src/main/resources/request/structures/getMutualizedComponent.ftlh @@ -1,4 +1,5 @@ -SELECT DISTINCT ?id ?identifiant ?labelLg1 ?labelLg2 ?type ?concept ?codeList ?range ?descriptionLg1 ?descriptionLg2 ?validationState ?created ?modified ?creator ?contributor ?disseminationStatus +SELECT DISTINCT ?id ?identifiant ?labelLg1 ?labelLg2 ?type ?concept ?codeList ?range ?descriptionLg1 ?descriptionLg2 ?validationState +?created ?modified ?creator ?contributor ?disseminationStatus ?minLength ?maxLength ?minInclusive ?maxInclusive ?pattern FROM <${STRUCTURES_COMPONENTS_GRAPH}> WHERE { ?component dcterms:identifier '${ID}' ; @@ -48,6 +49,21 @@ WHERE { OPTIONAL {?component rdfs:comment ?descriptionLg2 . FILTER (lang(?descriptionLg2) = '${LG2}') } . + OPTIONAL { + ?component xsd:minLength ?minLength . + } + OPTIONAL { + ?component xsd:maxLength ?maxLength . + } + OPTIONAL { + ?component xsd:minInclusive ?minInclusive . + } + OPTIONAL { + ?component xsd:maxInclusive ?maxInclusive . + } + OPTIONAL { + ?component xsd:pattern ?pattern . + } BIND(STRAFTER(STR(?conceptObject),'concepts/definition/') AS ?concept) . } ORDER BY ?labelLg1 \ No newline at end of file diff --git a/src/main/resources/request/structures/getStructure.ftlh b/src/main/resources/request/structures/getStructure.ftlh index 7418f3f40..bd9bd29bf 100644 --- a/src/main/resources/request/structures/getStructure.ftlh +++ b/src/main/resources/request/structures/getStructure.ftlh @@ -17,16 +17,15 @@ WHERE { } . OPTIONAL { - ?structure dc:creator ?creator . + ?structure dcterms:modified ?modified . } . OPTIONAL { - ?structure dc:contributor ?contributor . + ?structure dc:creator ?creator . } . OPTIONAL { - - ?structure dcterms:modified ?modified . + ?structure dc:contributor ?contributor . } . OPTIONAL {