Skip to content

Commit 18dc60b

Browse files
committed
Link to RPB if superordinate resource is found in RPB (RPB-263)
1 parent f555c6a commit 18dc60b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

app/views/TableRow.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ String[] refAndLabel(String property, String value,
226226
if ((property.equals("containedIn") || property.equals("hasPart")
227227
|| property.equals("isPartOf") || property.equals("hasSuperordinate")
228228
|| property.equals("bibliographicCitation")) && value.contains("lobid.org")) {
229-
return new String[] { value.matches(".*?[asf]\\d+.*|.*?\\d{3}[a-z]\\d+.*") // rpbId
229+
return new String[] { value.contains("rpb") // replaced via rpbUrlIfInRpb()
230230
? value.replaceAll("http.+/", "/") // full URL -> relative link
231231
: value, Lobid.resourceLabel(value) };
232232
}
@@ -237,6 +237,13 @@ String[] refAndLabel(String property, String value,
237237
}
238238

239239
String rpbUrlIfInRpb(String value) {
240+
String rpbUrl = value.replaceAll("https?://lobid.org/resources/([^#]+)(#!)", "https://rpb.lobid.org/$1");
241+
WSRequest rpbRequest = WS.url(rpbUrl).setQueryParameter("format", "json");
242+
JsonNode rpbJson = rpbRequest.get().map(WSResponse::asJson).get(Lobid.API_TIMEOUT);
243+
return rpbJson.get("member").elements().hasNext() ? rpbUrl : rpbUrlIfhasRpbId(value);
244+
}
245+
246+
String rpbUrlIfhasRpbId(String value) {
240247
WSRequest lobidRequest = WS.url(value).setHeader("Content-Type", "application/json");
241248
JsonNode lobidJson = lobidRequest.get().map(WSResponse::asJson).get(Lobid.API_TIMEOUT);
242249
return lobidJson.has("rpbId") ? "https://rpb.lobid.org/" + lobidJson.get("rpbId").textValue() : value;

0 commit comments

Comments
 (0)