Skip to content

Commit

Permalink
Return the propLabel in case of missing URI error - refs #25021
Browse files Browse the repository at this point in the history
In case the property have not been saved in CEDAR, its propName is its UUID. For better readability, we will use the propLabel in the error message.
  • Loading branch information
fintanorbert committed Jun 19, 2024
1 parent 6ca0b71 commit 0a48255
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/main/java/edu/harvard/iq/dataverse/arp/ArpServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -961,8 +961,9 @@ public CedarTemplateErrors checkCedarTemplate(String cedarTemplate, CedarTemplat
JsonObject cedarTemplateJson = gson.fromJson(cedarTemplate, JsonObject.class);

List<String> propNames = getStringList(cedarTemplateJson, "_ui.order");
List<String> propLabels = getJsonObject(cedarTemplateJson, "_ui.propertyLabels").entrySet().stream()
.map(e -> e.getValue().getAsString()).collect(Collectors.toList());
JsonElement propsAndLabels = getJsonElement(cedarTemplateJson, "_ui.propertyLabels");
List<String> propLabels = propsAndLabels.getAsJsonObject().entrySet().stream()
.map(e -> e.getValue().getAsString()).toList();

// The "schema:identifier" property is used as the type of the property in AROMA
String aromaType = cedarTemplateJson.has("schema:identifier") ? cedarTemplateJson.get("schema:identifier").getAsString() : cedarTemplateJson.get("schema:name").getAsString();
Expand All @@ -988,7 +989,7 @@ public CedarTemplateErrors checkCedarTemplate(String cedarTemplate, CedarTemplat
for (String prop : propNames) {
var termUri = getStringList(cedarTemplateJson, "properties.@context.properties." + prop + ".enum");
if (termUri == null || termUri.isEmpty() || termUri.get(0).isBlank()) {
cedarTemplateErrors.errors.add(String.format("Term URI for property '%s' is missing", prop));
cedarTemplateErrors.errors.add(String.format("Term URI for property '%s' is missing", getPropertyLabel(propsAndLabels, prop)));
}
// It turns out that collision of prop names with MDB names doesn't cause a problem so no need to check.
// ie. we can have an MDB named "journal" and a prop name "journal" as well.
Expand Down Expand Up @@ -1029,6 +1030,25 @@ public CedarTemplateErrors checkCedarTemplate(String cedarTemplate, CedarTemplat
return cedarTemplateErrors;
}

private String getPropertyLabel(JsonElement propertyLabels, String propName) {
String propLabel = propName;
if (propertyLabels.isJsonArray()) {
for (JsonElement prop : propertyLabels.getAsJsonArray()) {
JsonObject propObj = prop.getAsJsonObject();
if (propObj.keySet().contains(propName)) {
propLabel = propObj.get(propName).getAsString();
}
}
} else if (propertyLabels.isJsonObject()) {
JsonObject propObj = propertyLabels.getAsJsonObject();
if (propObj.keySet().contains(propName)) {
propLabel = propObj.get(propName).getAsString();
}
}

return propLabel;
}

// props that require DatasetFieldTypeOverride creation are stored in the cedarTemplateErrors.incompatiblePairs
// these values are processed later when the override(s) are actually saved in: edu.harvard.iq.dataverse.arp.ArpServiceBean.createOrUpdateMdbFromCedarTemplate
private void createOverrideIfRequired(JsonObject actProp, String propName, JsonObject cedarTemplateJson, CedarTemplateErrors cedarTemplateErrors, Map<String, String> dvPropTermUriPairs, String mdbName) {
Expand Down

0 comments on commit 0a48255

Please sign in to comment.