Skip to content

Commit

Permalink
Merge pull request #137 from InseeFr/acceptance
Browse files Browse the repository at this point in the history
3.0.5
  • Loading branch information
alicela authored Jun 16, 2021
2 parents c84b831 + ef3626d commit c57e32d
Show file tree
Hide file tree
Showing 33 changed files with 435 additions and 213 deletions.
3 changes: 3 additions & 0 deletions bauhaus-back-changeLog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
3.0.5 : - Correction d'un bug qui ouvrait une connexion à chaque requete + bugs mineurs
- Initialisation de dockerisation
- Changement du richtext dans les concepts (gras, italisque)
3.0.4 : Correction des liens dans la documentation SIMS (l'uri était celle d'un document)
3.0.3 : Mise à jour de spring-security + correction des droits de créations de documents/liens
3.0.2 : Corrections de l'url des documents à la publication
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>fr.insee.rmes</groupId>
<artifactId>Bauhaus-BO</artifactId>
<packaging>war</packaging>
<version>3.0.4</version>
<version>3.0.5</version>
<name>Bauhaus-Back-Office</name>
<description>Back-office services for Bauhaus</description>
<url>https://github.com/InseeFr/Bauhaus-Back-Office</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ public interface CodeListService {
String getDetailedCodesList(String notation) throws RmesException;

String getDetailedCodesListForSearch() throws RmesException;

String setCodesList(String body) throws RmesException;

String setCodesList(String id, String body) throws RmesException;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
package fr.insee.rmes.bauhaus_services.code_list;

import com.fasterxml.jackson.databind.DeserializationFeature;
import fr.insee.rmes.bauhaus_services.rdf_utils.RdfUtils;
import fr.insee.rmes.config.Config;
import fr.insee.rmes.model.ValidationStatus;
import fr.insee.rmes.model.structures.MutualizedComponent;
import fr.insee.rmes.persistance.ontologies.INSEE;
import fr.insee.rmes.persistance.ontologies.QB;
import fr.insee.rmes.persistance.sparql_queries.structures.StructureQueries;
import fr.insee.rmes.utils.DateUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.rdf4j.model.IRI;
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.RDF;
import org.eclipse.rdf4j.model.vocabulary.SKOS;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -83,7 +101,7 @@ public String getDetailedCodesList(String notation) throws RmesException {
if(previousCode.has(Constants.PARENTS)){
parents = previousCode.getJSONArray(Constants.PARENTS);
}
parents.put(tempCode.getString("parents"));
parents.put(tempCode.getString(Constants.PARENTS));
previousCode.put(Constants.PARENTS, parents);
formattedCodes.put(code, previousCode);
}
Expand All @@ -109,6 +127,71 @@ public String getDetailedCodesListForSearch() throws RmesException {
return lists.toString();
}

@Override
public String setCodesList(String body) throws RmesException {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(
DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
JSONObject codesList = new JSONObject(body);

IRI codeListIri = RdfUtils.codeListIRI(codesList.getString("id"));
repoGestion.clearStructureNodeAndComponents(codeListIri);
Model model = new LinkedHashModel();
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);
}

@Override
public String setCodesList(String id, String body) throws RmesException {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(
DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
JSONObject codesList = new JSONObject(body);

IRI codeListIri = RdfUtils.codeListIRI(codesList.getString("id"));
repoGestion.clearStructureNodeAndComponents(codeListIri);
Model model = new LinkedHashModel();
Resource graph = RdfUtils.codesListGraph();

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);
}

private String createOrUpdateCodeList(Model model, Resource graph, JSONObject codesList, IRI codeListIri) throws RmesException {
model.add(codeListIri, INSEE.VALIDATION_STATE, RdfUtils.setLiteralString(ValidationStatus.UNPUBLISHED), graph);

if(codesList.has("disseminationStatus")){
RdfUtils.addTripleUri(codeListIri, INSEE.DISSEMINATIONSTATUS, codesList.getString("disseminationStatus"), model, graph);
}

if(codesList.has("labelLg1")){
model.add(codeListIri, SKOS.PREF_LABEL, RdfUtils.setLiteralString(codesList.getString("labelLg1"), Config.LG1), graph);
}
if(codesList.has("labelLg2")){
model.add(codeListIri, SKOS.PREF_LABEL, RdfUtils.setLiteralString(codesList.getString("labelLg2"), Config.LG2), graph);
}
if(codesList.has("descriptionLg1")){
model.add(codeListIri, SKOS.DEFINITION, RdfUtils.setLiteralString(codesList.getString("descriptionLg1"), Config.LG1), graph);
}
if(codesList.has("descriptionLg2")){
model.add(codeListIri, SKOS.DEFINITION, RdfUtils.setLiteralString(codesList.getString("descriptionLg2"), Config.LG2), graph);
}
if(codesList.has("creator")){
RdfUtils.addTripleString(codeListIri, DC.CREATOR, codesList.getString("creator"), model, graph);
}
if(codesList.has("contributor")){
RdfUtils.addTripleString(codeListIri, DC.CONTRIBUTOR, codesList.getString("contributor"), model, graph);
}
model.add(codeListIri, SKOS.NOTATION, RdfUtils.setLiteralString(codesList.getString("id")), graph);
repoGestion.loadSimpleObject(codeListIri, model, null);
return codeListIri.toString();
}


private JSONArray getCodesForList(JSONArray codes, JSONObject list) {
JSONArray codesList = new JSONArray();
for (int i = 0 ; i < codes.length(); i++) {
Expand Down Expand Up @@ -144,8 +227,4 @@ public String getAllCodesLists() throws RmesException {
public String geCodesListByIRI(String IRI) throws RmesException {
return repoGestion.getResponseAsArray(CodeListQueries.geCodesListByIRI(IRI)).toString();
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ else if (predicat.endsWith("narrower")) {

repoGestion.closeStatements(statements);
publishMemberLinks(concept, model, con);
con.close();

Resource conceptToPublish = PublicationUtils.tranformBaseURIToPublish(concept);
RepositoryPublication.publishConcept(conceptToPublish, model, noteToClear, topConceptOfToDelete);
Expand Down Expand Up @@ -165,16 +166,19 @@ public void publishExplanatoryNotes(RepositoryConnection con, Resource note, Mod
}
model.add(PublicationUtils.tranformBaseURIToPublish(subject), XKOS.PLAIN_TEXT, plainText, graph);
} catch (RepositoryException e) {
repoGestion.closeStatements(statements);
throw new RmesException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), Constants.REPOSITORY_EXCEPTION);

}
repoGestion.closeStatements(statements);
}

public void publishMemberLinks(Resource concept, Model model, RepositoryConnection conn) throws RmesException {
RepositoryResult<Statement> statements = null;
try {
statements = conn.getStatements(null, SKOS.MEMBER, concept, false);
} catch (RepositoryException e) {
repoGestion.closeStatements(statements);
throw new RmesException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), Constants.REPOSITORY_EXCEPTION);
}
try {
Expand All @@ -184,9 +188,10 @@ public void publishMemberLinks(Resource concept, Model model, RepositoryConnecti
PublicationUtils.tranformBaseURIToPublish((Resource) st.getObject()), st.getContext());
}
} catch (RepositoryException e) {
repoGestion.closeStatements(statements);
throw new RmesException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), Constants.REPOSITORY_EXCEPTION);
}
}
repoGestion.closeStatements(statements); }

public void publishCollection(JSONArray collectionsToValidate) throws RmesException {

Expand Down Expand Up @@ -223,6 +228,7 @@ public void publishCollection(JSONArray collectionsToValidate) throws RmesExcept
}
} finally {
repoGestion.closeStatements(statements);
con.close();
}
Resource collectionToPublish = PublicationUtils.tranformBaseURIToPublish(collection);
RepositoryPublication.publishResource(collectionToPublish, model, "collection");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.insee.rmes.bauhaus_services.consutation_gestion;

import fr.insee.rmes.bauhaus_services.Constants;
import fr.insee.rmes.bauhaus_services.rdf_utils.FreeMarkerUtils;
import fr.insee.rmes.bauhaus_services.rdf_utils.RdfService;
import fr.insee.rmes.config.Config;
Expand All @@ -10,6 +11,7 @@
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Iterator;

@Service
public class ConsultationGestionServiceImpl extends RdfService implements ConsultationGestionService {
Expand Down Expand Up @@ -170,7 +172,7 @@ private void getStructureComponents(String id, JSONObject structure) throws Rmes

JSONObject listCode = new JSONObject();
listCode.put("uri", component.getString("listeCodeUri"));
listCode.put("notation", component.getString("listeCodeNotation"));
listCode.put("id", component.getString("listeCodeNotation"));
component.put("listCode", listCode);
component.remove("listeCodeUri");
component.remove("listeCodeNotation");
Expand Down Expand Up @@ -255,14 +257,63 @@ private JSONArray getCodes(String notation) throws RmesException {

JSONArray codes = repoGestion.getResponseAsArray(buildRequest("getCodes.ftlh", params));

JSONObject childrenMapping = new JSONObject();

JSONObject formattedCodes = new JSONObject();

for (int i = 0; i < codes.length(); i++) {
JSONObject code = codes.getJSONObject(i);
code.put("label", this.formatLabel(code));
code.remove("prefLabelLg1");
code.remove("prefLabelLg2");

if(code.has(Constants.PARENTS)){
JSONArray children = new JSONArray();
String parentCode = code.getString(Constants.PARENTS);
if(childrenMapping.has(parentCode)){
children = childrenMapping.getJSONArray(parentCode);
}
children.put(code.get("code"));
childrenMapping.put(parentCode, children);
}


if(formattedCodes.has(code.getString(Constants.URI))){
JSONObject c = formattedCodes.getJSONObject(code.getString(Constants.URI));

if(code.has(Constants.PARENTS)){
JSONArray parents = c.getJSONArray(Constants.PARENTS);
parents.put(code.getString(Constants.PARENTS));
c.put(Constants.PARENTS, parents);
}
} else {
code.put("label", this.formatLabel(code));
code.remove(Constants.PREF_LABEL_LG1);
code.remove(Constants.PREF_LABEL_LG2);

if(code.has(Constants.PARENTS)){
JSONArray parents = new JSONArray();
parents.put(code.getString(Constants.PARENTS));
code.put(Constants.PARENTS, parents);
} else {
code.put(Constants.PARENTS, new JSONArray());
}
formattedCodes.put(code.getString(Constants.URI), code);
}
}

return codes;
JSONArray result = new JSONArray();
Iterator<String> keys = formattedCodes.keys();

while(keys.hasNext()) {
String key = keys.next();
JSONObject code = formattedCodes.getJSONObject(key);
if(childrenMapping.has(code.getString("code"))){
code.put("enfants", childrenMapping.getJSONArray(code.getString("code")));
}
if(code.getJSONArray(Constants.PARENTS).length() == 0){
code.remove(Constants.PARENTS);
}
result.put(code);
}
return result;
}

private JSONArray formatLabel(JSONObject obj) {
Expand Down
Loading

0 comments on commit c57e32d

Please sign in to comment.