From dee3ac9fd58a9e604941dcac754f51788fef2196 Mon Sep 17 00:00:00 2001 From: "J.M" Date: Tue, 5 Mar 2024 16:26:37 +0100 Subject: [PATCH] updating raw description --- .../kohesio/controller/ProjectController.java | 10 +++- .../kohesio/controller/UpdateController.java | 53 +++++++++++++++++++ .../eu/ec/doris/kohesio/payload/Update.java | 9 ++++ 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/ec/doris/kohesio/controller/ProjectController.java b/src/main/java/eu/ec/doris/kohesio/controller/ProjectController.java index f9b342b7..63683959 100644 --- a/src/main/java/eu/ec/doris/kohesio/controller/ProjectController.java +++ b/src/main/java/eu/ec/doris/kohesio/controller/ProjectController.java @@ -114,10 +114,11 @@ public ResponseEntity euProjectID( + "?themeLabel ?themeIdInferred ?themeLabelInferred ?policyId ?policyLabel " + "?managingAuthorityLabel ?beneficiaryLink ?beneficiary ?beneficiaryLabelRight " + "?beneficiaryLabel ?transliteration ?beneficiaryWikidata ?beneficiaryWebsite " - + "?beneficiaryString ?source ?source2 ?keepUrl ?curatedLabel ?curatedSummary WHERE { " + + "?beneficiaryString ?source ?source2 ?keepUrl ?curatedLabel ?curatedSummary ?rawCuratedSummary WHERE { " + "VALUES ?s0 { <" + id + "> } " + " OPTIONAL { ?s0 ?curatedLabel . FILTER((LANG(?curatedLabel)) = \"" + language + "\") }" + " OPTIONAL { ?s0 ?curatedSummary . FILTER((LANG(?curatedSummary)) = \"" + language + "\") }" + + " OPTIONAL { ?s0 ?rawCuratedSummary . FILTER((LANG(?rawCuratedSummary)) = \"" + language + "\") }" + " OPTIONAL {?s0 ?label. FILTER((LANG(?label)) = \"" + language + "\") }" + " OPTIONAL { ?s0 wdt:P836 ?description. FILTER((LANG(?description)) = \"" + language + "\") } " + " OPTIONAL { ?s0 wdt:P1742 ?infoRegioUrl . }" @@ -215,6 +216,7 @@ public ResponseEntity euProjectID( result.put("link", id); result.put("label", ""); result.put("description", ""); + result.put("description_raw", ""); result.put("startTime", ""); result.put("endTime", ""); result.put("budget", ""); @@ -309,6 +311,12 @@ public ResponseEntity euProjectID( ((Literal) querySolution.getBinding("curatedSummary").getValue()).getLabel() ); } + if (querySolution.hasBinding("rawCuratedSummary")) { + result.put( + "description_raw", + ((Literal) querySolution.getBinding("rawCuratedSummary").getValue()).getLabel() + ); + } if (querySolution.getBinding("infoRegioUrl") != null) { result.put( diff --git a/src/main/java/eu/ec/doris/kohesio/controller/UpdateController.java b/src/main/java/eu/ec/doris/kohesio/controller/UpdateController.java index 01413108..e2b39a69 100644 --- a/src/main/java/eu/ec/doris/kohesio/controller/UpdateController.java +++ b/src/main/java/eu/ec/doris/kohesio/controller/UpdateController.java @@ -49,6 +49,7 @@ public ResponseEntity updateProject( String id = updatePayload.getId(); List labels = updatePayload.getLabels(); List descriptions = updatePayload.getDescriptions(); + List descriptionsRaw = updatePayload.getDescriptionsRaw(); logger.info("Project update by ID: id {} on {}", id, url); @@ -163,6 +164,58 @@ public ResponseEntity updateProject( } } } + + if (descriptionsRaw != null) { + for (MonolingualString descriptionRawObject: descriptionsRaw) { + String language = descriptionRawObject.getLanguage(); + String descriptionRaw = descriptionRawObject.getText(); + + StringBuilder tripleToDelete = new StringBuilder(); + StringBuilder tripleToInsert = new StringBuilder(); + StringBuilder tripleToWhere = new StringBuilder(); + if (descriptionRaw != null) { + descriptionRaw = descriptionRaw.replace("\"", "\\\""); + tripleToDelete + .append(" <") + .append(id) + .append("> ?description_raw_") + .append(language) + .append(" . ") + ; + tripleToWhere + .append(" <") + .append(id) + .append("> ?description_raw_") + .append(language) + .append(" . FILTER (LANG(?description_raw_") + .append(language) + .append(")") + .append(" = \"") + .append(language) + .append("\") ") + ; + tripleToInsert + .append(" <") + .append(id) + .append("> \"") + .append(descriptionRaw) + .append("\"@") + .append(language) + .append(" . ") + ; + + updateTriples.add( + new UpdateTriple( + tripleToDelete.toString(), + tripleToInsert.toString(), + tripleToWhere.toString() + ) + ); + } + } + } + + if (updateTriples.isEmpty()) { return new ResponseEntity<>( (JSONObject) (new JSONObject().put("message", "Bad Request - nothing to update")), diff --git a/src/main/java/eu/ec/doris/kohesio/payload/Update.java b/src/main/java/eu/ec/doris/kohesio/payload/Update.java index 861b8412..cc98a8e1 100644 --- a/src/main/java/eu/ec/doris/kohesio/payload/Update.java +++ b/src/main/java/eu/ec/doris/kohesio/payload/Update.java @@ -7,6 +7,15 @@ public class Update { String id; List labels; List descriptions; + List descriptionsRaw; + + public List getDescriptionsRaw() { + return descriptionsRaw; + } + + public void setDescriptionsRaw(List descriptionsRaw) { + this.descriptionsRaw = descriptionsRaw; + } public String getId() { return id;