Skip to content

Commit

Permalink
Merge pull request #161 from InseeFr/release3.0.8
Browse files Browse the repository at this point in the history
Release3.0.8
  • Loading branch information
MichaelC67 authored Sep 30, 2021
2 parents e08edbb + 74b685e commit 5916924
Show file tree
Hide file tree
Showing 95 changed files with 941 additions and 405 deletions.
6 changes: 6 additions & 0 deletions bauhaus-back-changeLog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
3.0.8 : - Suppression de la page blanche à la première connexion
- Titres spécifiques aux pages (pour l'historique des navigateurs notamment)
- Améliorations des sims :
recherche des documents et liens avec la langue,
rapport qualité mis à jour quand l'opération change de label
- Corrections mineures pour Sonar
3.0.7 : Changement du lien vers l'aide dans l'offre de services
3.0.6 : - Passage de l'export des concepts et collections de JasperReport à XSLT
- Montée de version spring (4 à 5)
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.7</version>
<version>3.0.8</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 @@ -13,7 +13,7 @@ public interface CodeListService {

String getAllCodesLists() throws RmesException;

String geCodesListByIRI(String IRI) throws RmesException;
String geCodesListByIRI(String iri) throws RmesException;

String getDetailedCodesList(String notation) throws RmesException;

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/fr/insee/rmes/bauhaus_services/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public class Constants {
public static final String SERIES_UP = "SERIES";
public static final String SEEALSO = "seeAlso";
public static final String STAMP = "stamp";
public static final String STATUT_VALIDATION = "statutValidation";


/*T*/
public static final String TEXT_LG1 = "texte";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,19 @@ public interface OperationsService {

String publishMetadataReport(String id) throws RmesException;

Response exportMetadataReport(String id, boolean includeEmptyMas, boolean lg1, boolean lg2) throws RmesException;

String getMetadataReportOwner(String id) throws RmesException;

String getMSDJson() throws RmesException;

String getMetadataReportDefaultValue() throws IOException;

Status deleteMetadataReport(String id) throws RmesException;

/** export **/
Response exportMetadataReport(String id, boolean includeEmptyMas, boolean lg1, boolean lg2) throws RmesException;

Response exportMetadataReportForLabel(String id) throws RmesException;

Response exportMetadataReportTempFiles(String id, Boolean includeEmptyMas, Boolean lg1, Boolean lg2) throws RmesException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public class CodeListItem {

private static String classLink = "fr.insee.rmes.bauhaus_services.code_list.CodeListItem";

@Schema(description = "Code", required = true)
private String code;
Expand Down Expand Up @@ -51,7 +52,7 @@ public void setCode(String code) {
}

public static String getClassOperationsLink() {
return "fr.insee.rmes.bauhaus_services.code_list.CodeListItem";
return classLink;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
@Service
public class CodeListServiceImpl extends RdfService implements CodeListService {

private static final String CODES = "codes";

private static final String LAST_LIST_URI_SEGMENT = "lastListUriSegment";

static final Logger logger = LogManager.getLogger(CodeListServiceImpl.class);

@Autowired
Expand All @@ -56,7 +60,7 @@ public String getCodeListJson(String notation) throws RmesException{
codeList.put("notation",notation);
JSONArray items = repoGestion.getResponseAsArray(CodeListQueries.getCodeListItemsByNotation(notation));
if (items.length() != 0){
codeList.put("codes", items);
codeList.put(CODES, items);
}
return QueryUtils.correctEmptyGroupConcat(codeList.toString());
}
Expand Down Expand Up @@ -109,7 +113,7 @@ public String getDetailedCodesList(String notation) throws RmesException {
});


codeList.put("codes", formattedCodes);
codeList.put(CODES, formattedCodes);
}

return codeList.toString();
Expand All @@ -122,26 +126,26 @@ public String getDetailedCodesListForSearch() throws RmesException {

for (int i = 0 ; i < lists.length(); i++) {
JSONObject list = lists.getJSONObject(i);
list.put("codes", this.getCodesForList(codes, list));
list.put(CODES, this.getCodesForList(codes, list));
}

return lists.toString();
}

public void validateCodeList(JSONObject codeList){
if (!codeList.has("id")) {
if (!codeList.has(Constants.ID)) {
throw new BadRequestException("The id of the list should be defined");
}
if (!codeList.has("labelLg1")) {
if (!codeList.has(Constants.LABEL_LG1)) {
throw new BadRequestException("The labelLg1 of the list should be defined");
}
if (!codeList.has("labelLg2")) {
if (!codeList.has(Constants.LABEL_LG2)) {
throw new BadRequestException("The labelLg2 of the list should be defined");
}
if (!codeList.has("lastClassUriSegment")) {
throw new BadRequestException("The lastClassUriSegment of the list should be defined");
}
if (!codeList.has("lastListUriSegment")) {
if (!codeList.has(LAST_LIST_URI_SEGMENT)) {
throw new BadRequestException("The lastListUriSegment of the list should be defined");
}
}
Expand All @@ -154,7 +158,7 @@ public String setCodesList(String body) throws RmesException {

this.validateCodeList(codesList);

IRI codeListIri = RdfUtils.codeListIRI(codesList.getString("lastListUriSegment"));
IRI codeListIri = RdfUtils.codeListIRI(codesList.getString(LAST_LIST_URI_SEGMENT));
repoGestion.clearStructureNodeAndComponents(codeListIri);
Model model = new LinkedHashModel();
Resource graph = RdfUtils.codesListGraph();
Expand All @@ -172,7 +176,7 @@ public String setCodesList(String id, String body) throws RmesException {

this.validateCodeList(codesList);

IRI codeListIri = RdfUtils.codeListIRI(codesList.getString("lastListUriSegment"));
IRI codeListIri = RdfUtils.codeListIRI(codesList.getString(LAST_LIST_URI_SEGMENT));
repoGestion.clearStructureNodeAndComponents(codeListIri);
Model model = new LinkedHashModel();
Resource graph = RdfUtils.codesListGraph();
Expand All @@ -185,10 +189,12 @@ public String setCodesList(String id, String body) throws RmesException {

private String createOrUpdateCodeList(Model model, Resource graph, JSONObject codesList, IRI codeListIri) 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);
model.add(codeListIri, SKOS.NOTATION, RdfUtils.setLiteralString(codesList.getString("id")), 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);
Expand All @@ -199,32 +205,121 @@ private String createOrUpdateCodeList(Model model, Resource graph, JSONObject co
RdfUtils.addTripleUri(codeListIri, INSEE.DISSEMINATIONSTATUS, codesList.getString("disseminationStatus"), model, graph);
}

model.add(codeListIri, SKOS.PREF_LABEL, RdfUtils.setLiteralString(codesList.getString("labelLg1"), Config.LG1), graph);
model.add(codeListIri, SKOS.PREF_LABEL, RdfUtils.setLiteralString(codesList.getString("labelLg2"), Config.LG2), graph);
model.add(codeListIri, SKOS.PREF_LABEL, RdfUtils.setLiteralString(codesList.getString(Constants.LABEL_LG1), Config.LG1), graph);
model.add(codeListIri, SKOS.PREF_LABEL, RdfUtils.setLiteralString(codesList.getString(Constants.LABEL_LG2), Config.LG2), graph);


if(codesList.has("descriptionLg1")){
model.add(codeListIri, SKOS.DEFINITION, RdfUtils.setLiteralString(codesList.getString("descriptionLg1"), Config.LG1), graph);
if(codesList.has(Constants.DESCRIPTION_LG1)){
model.add(codeListIri, SKOS.DEFINITION, RdfUtils.setLiteralString(codesList.getString(Constants.DESCRIPTION_LG1), Config.LG1), graph);
}
if(codesList.has("descriptionLg2")){
model.add(codeListIri, SKOS.DEFINITION, RdfUtils.setLiteralString(codesList.getString("descriptionLg2"), Config.LG2), graph);
if(codesList.has(Constants.DESCRIPTION_LG2)){
model.add(codeListIri, SKOS.DEFINITION, RdfUtils.setLiteralString(codesList.getString(Constants.DESCRIPTION_LG2), Config.LG2), graph);
}
if(codesList.has("creator")){
RdfUtils.addTripleString(codeListIri, DC.CREATOR, codesList.getString("creator"), model, graph);
if(codesList.has(Constants.CREATOR)){
RdfUtils.addTripleString(codeListIri, DC.CREATOR, codesList.getString(Constants.CREATOR), model, graph);
}
if(codesList.has("contributor")){
RdfUtils.addTripleString(codeListIri, DC.CONTRIBUTOR, codesList.getString("contributor"), model, graph);
if(codesList.has(Constants.CONTRIBUTOR)){
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());
}
});
}
createCodeTriplet(graph, codesList, codeListIri);

repoGestion.loadSimpleObject(codeListIri, model, null);
return ((SimpleIRI)codeListIri).toString();
}

private void createCodeTriplet(Resource graph, JSONObject codesList, IRI codeListIri) {
if(codesList.has(CODES)){
JSONObject parentsModel = new JSONObject();

JSONObject codes = codesList.getJSONObject(CODES);
codes.keySet().forEach(key -> {
try {
JSONObject code = codes.getJSONObject(key);

Model codeListModel = 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()));
}
});
}
repoGestion.loadSimpleObject(codeIri, codeListModel, null);
} catch (Exception e) {
logger.debug(e.getMessage());
}
});

createParentChildRelationForCodes(graph, codesList, parentsModel);

}
}

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)
);
try {
repoGestion.getConnection().add(parentModel);
} catch (RmesException e) {
logger.debug(e.getMessage());
}
});
}

private void createMainCodeTriplet(Resource graph, IRI codeListIri, JSONObject code, Model codeListModel, IRI codeIri) {
RdfUtils.addTripleUri(codeIri, SKOS.IN_SCHEME, codeListIri, codeListModel, graph);
if(code.has("code")){
RdfUtils.addTripleString(codeIri, SKOS.NOTATION, code.getString("code"), codeListModel, graph);
}

if(code.has(Constants.LABEL_LG1)){
codeListModel.add(codeIri, SKOS.PREF_LABEL, RdfUtils.setLiteralString(code.getString(Constants.LABEL_LG1), Config.LG1), graph);
}
if(code.has(Constants.LABEL_LG2)){
codeListModel.add(codeIri, SKOS.PREF_LABEL, RdfUtils.setLiteralString(code.getString(Constants.LABEL_LG2), Config.LG2), graph);
}

if(code.has(Constants.DESCRIPTION_LG1)){
codeListModel.add(codeIri, SKOS.DEFINITION, RdfUtils.setLiteralString(code.getString(Constants.DESCRIPTION_LG1), Config.LG1), graph);
}
if(code.has(Constants.DESCRIPTION_LG2)){
codeListModel.add(codeIri, SKOS.DEFINITION, RdfUtils.setLiteralString(code.getString(Constants.DESCRIPTION_LG2), Config.LG2), graph);
}
}


private JSONArray getCodesForList(JSONArray codes, JSONObject list) {
JSONArray codesList = new JSONArray();
for (int i = 0 ; i < codes.length(); i++) {
JSONObject code = codes.getJSONObject(i);
if(code.getString("id").equalsIgnoreCase(list.getString("id"))){
if(code.getString(Constants.ID).equalsIgnoreCase(list.getString(Constants.ID))){
codesList.put(code);
}
}
Expand All @@ -241,7 +336,7 @@ public String getCode(String notationCodeList, String notationCode) throws RmesE

@Override
public String getCodeUri(String notationCodeList, String notationCode) throws RmesException{
if (StringUtils.isEmpty(notationCodeList) ||StringUtils.isEmpty(notationCode)) {return null;}
if (StringUtils.isEmpty(notationCodeList) || StringUtils.isEmpty(notationCode)) {return null;}
JSONObject code = repoGestion.getResponseAsObject(CodeListQueries.getCodeUriByNotation(notationCodeList,notationCode));
return QueryUtils.correctEmptyGroupConcat(code.getString(Constants.URI));
}
Expand All @@ -252,7 +347,7 @@ public String getAllCodesLists() throws RmesException {
}

@Override
public String geCodesListByIRI(String IRI) throws RmesException {
return repoGestion.getResponseAsArray(CodeListQueries.geCodesListByIRI(IRI)).toString();
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 @@ -48,9 +48,9 @@ public CollectionForExport getCollectionData(String id) throws RmesException {
collection.addMembers(members);

// format specific data
collection.setCreated(toDate(collection.getCreated()));
collection.setModified(toDate(collection.getModified()));
collection.setIsValidated(toValidationStatus(collection.getIsValidated()));
collection.setCreated(ExportUtils.toDate(collection.getCreated()));
collection.setModified(ExportUtils.toDate(collection.getModified()));
collection.setIsValidated(ExportUtils.toValidationStatus(collection.getIsValidated(),true));

} catch (JsonProcessingException e) {
throw new RmesException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), e.getClass().getSimpleName());
Expand All @@ -59,20 +59,7 @@ public CollectionForExport getCollectionData(String id) throws RmesException {
return collection;
}

private String toDate(String dateTime) {
if (dateTime != null && dateTime.length() > 10) {
return dateTime.substring(8, 10) + "/" + dateTime.substring(5, 7) + "/" + dateTime.substring(0, 4);
}
return dateTime;
}

private String toValidationStatus(String boolStatus) {
if (boolStatus.equals("true")) {
return "Publiée";
} else {
return "Provisoire";
}
}


public Response exportAsResponse(String fileName, Map<String, String> xmlContent, boolean lg1, boolean lg2, boolean includeEmptyFields) throws RmesException {
Expand Down
Loading

0 comments on commit 5916924

Please sign in to comment.