Skip to content

Commit

Permalink
updating raw description
Browse files Browse the repository at this point in the history
  • Loading branch information
DiaZork committed Mar 5, 2024
1 parent 73b0a06 commit dee3ac9
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://linkedopendata.eu/prop/direct/P581563> ?curatedLabel . FILTER((LANG(?curatedLabel)) = \"" + language + "\") }"
+ " OPTIONAL { ?s0 <https://linkedopendata.eu/prop/direct/P581562> ?curatedSummary . FILTER((LANG(?curatedSummary)) = \"" + language + "\") }"
+ " OPTIONAL { ?s0 <https://linkedopendata.eu/prop/direct/P589596> ?rawCuratedSummary . FILTER((LANG(?rawCuratedSummary)) = \"" + language + "\") }"
+ " OPTIONAL {?s0 <http://www.w3.org/2000/01/rdf-schema#label> ?label. FILTER((LANG(?label)) = \"" + language + "\") }"
+ " OPTIONAL { ?s0 wdt:P836 ?description. FILTER((LANG(?description)) = \"" + language + "\") } "
+ " OPTIONAL { ?s0 wdt:P1742 ?infoRegioUrl . }"
Expand Down Expand Up @@ -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", "");
Expand Down Expand Up @@ -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(
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/eu/ec/doris/kohesio/controller/UpdateController.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public ResponseEntity<JSONObject> updateProject(
String id = updatePayload.getId();
List<MonolingualString> labels = updatePayload.getLabels();
List<MonolingualString> descriptions = updatePayload.getDescriptions();
List<MonolingualString> descriptionsRaw = updatePayload.getDescriptionsRaw();

logger.info("Project update by ID: id {} on {}", id, url);

Expand Down Expand Up @@ -163,6 +164,58 @@ public ResponseEntity<JSONObject> 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("> <https://linkedopendata.eu/prop/direct/P589596> ?description_raw_")
.append(language)
.append(" . ")
;
tripleToWhere
.append(" <")
.append(id)
.append("> <https://linkedopendata.eu/prop/direct/P589596> ?description_raw_")
.append(language)
.append(" . FILTER (LANG(?description_raw_")
.append(language)
.append(")")
.append(" = \"")
.append(language)
.append("\") ")
;
tripleToInsert
.append(" <")
.append(id)
.append("> <https://linkedopendata.eu/prop/direct/P589596> \"")
.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")),
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/eu/ec/doris/kohesio/payload/Update.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ public class Update {
String id;
List<MonolingualString> labels;
List<MonolingualString> descriptions;
List<MonolingualString> descriptionsRaw;

public List<MonolingualString> getDescriptionsRaw() {
return descriptionsRaw;
}

public void setDescriptionsRaw(List<MonolingualString> descriptionsRaw) {
this.descriptionsRaw = descriptionsRaw;
}

public String getId() {
return id;
Expand Down

0 comments on commit dee3ac9

Please sign in to comment.