Skip to content

Commit

Permalink
Adapt OPAC link changes in lobid-resources for nwbib (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsteeg committed Oct 16, 2023
1 parent 9e8d17b commit fcc6986
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 43 deletions.
29 changes: 2 additions & 27 deletions app/controllers/nwbib/Lobid.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

package controllers.nwbib;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand All @@ -28,7 +26,6 @@

import controllers.nwbib.Classification.Type;
import play.Logger;
import play.Play;
import play.cache.Cache;
import play.libs.F.Promise;
import play.libs.Json;
Expand Down Expand Up @@ -231,7 +228,8 @@ public static long getTotalHitsNwbibClassification(String value) {
initAggregation("subject.id");
}
return (AGGREGATION_COUNT.containsKey(value) || isWikidata(value))
? AGGREGATION_COUNT.getOrDefault(value, 0L) : lobidRequest(value);
? AGGREGATION_COUNT.getOrDefault(value, 0L)
: lobidRequest(value);
}

private static Long lobidRequest(String value) {
Expand Down Expand Up @@ -739,29 +737,6 @@ private static void mapIsilsToUris(JsonNode items,
}
}

/**
* @param itemUri The lobid item URI
* @return The OPAC URL for the given item, or null
*/
public static String opacUrl(String itemUri) {
try (InputStream stream =
Play.application().resourceAsStream("isil2opac_hbzid.json")) {
JsonNode json = Json.parse(stream);
String[] hbzId_isil_sig =
itemUri.substring(itemUri.indexOf("items/") + 6).split(":");
String hbzId = hbzId_isil_sig[0];
String isil = hbzId_isil_sig[1];
Logger.debug("From item URI {}, got ISIL {} and HBZ-ID {}", itemUri, isil,
hbzId);
JsonNode urlTemplate = json.get(isil);
if (urlTemplate != null)
return urlTemplate.asText().replace("{hbzid}", hbzId);
} catch (IOException e) {
Logger.error("Could not create OPAC URL", e);
}
return null;
}

/**
* Compare ISILs for sorting.
*
Expand Down
32 changes: 16 additions & 16 deletions app/views/tags/items_map.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,6 @@
json = Json.parse(Lobid.cachedJsonCall(owner).toString);
ownerUrl = if((json\\"url").isEmpty) owner else (json\\"url")(0).as[String];
ownerName = if((json\\"name").isEmpty) "" else (json\\"name")(0).as[String]) {

var details = '<tr><td><i>Bibliothek:</i></td><td>'+
'<i>@if(!ownerName.isEmpty){<a href="@ownerUrl">@ownerName</a>}else{&lt;Keine Angabe&gt;}</i></td></tr>'
@defining(Lobid.opacUrl(items(key).head)){ opacLink =>
@if(opacLink!=null){+'<tr><td>Verfügbarkeit:</td>'+'<td><a href="@opacLink">Lokalen Katalog abfragen</a></td></tr>'};
}
tableDetails = details;
if(allTableDetails=='')
allTableDetails += tableDetails;
else
allTableDetails += '<tr><th style="width: 30%"/><th style="width: 70%"/></tr>' + tableDetails;
@for((itemId,i) <- items(key).zipWithIndex;
shortItemId = itemId.substring(itemId.lastIndexOf(":") + 1, itemId.lastIndexOf("#"));
itemJson = Json.parse(itemDetails(itemId));
Expand All @@ -77,11 +66,22 @@
signatures = (itemJson\\"callNumber");
signature = if(signatures.isEmpty) "" else signatures(0).as[String];
urls = (itemJson\\"electronicLocator");
url = if(urls.isEmpty) "" else urls(0).as[String]) {
var sig = '<tr><td>@if(!signature.isEmpty){Signatur}@if(!urls.isEmpty){Elektronische Ressource}:</td>'+
'<td>@if(!url.isEmpty){<a href="@url">@shortItemId</a>} else {@if(!signature.isEmpty){@signature}else{&lt;Keine Angabe&gt;}}</td></tr>';
tableDetails += sig;
allTableDetails += sig;
url = if(urls.isEmpty) "" else urls(0).as[String];
seeAlso = (itemJson\\"seeAlso");
opacLink = if(seeAlso.isEmpty) null else seeAlso(0).as[Seq[JsValue]].map(_.as[String])) {
var details = '<tr><td><i>Bibliothek:</i></td><td>'+
'<i>@if(!ownerName.isEmpty){<a href="@ownerUrl">@ownerName</a>}else{&lt;Keine Angabe&gt;}</i></td></tr>'
@if(opacLink!=null){+'<tr><td>Verfügbarkeit:</td>'+'<td><a href="@opacLink">Lokalen Katalog abfragen</a></td></tr>'};
tableDetails = details;
if(allTableDetails=='')
allTableDetails += tableDetails;
else
allTableDetails += '<tr><th style="width: 30%"/><th style="width: 70%"/></tr>' + tableDetails;
var sig = '<tr><td>@if(!signature.isEmpty){Signatur:}@if(!urls.isEmpty){Elektronische Ressource:}</td>'+
'<td>@if(!url.isEmpty){<a href="@url">@shortItemId</a>} else {@if(!signature.isEmpty){@signature}}</td></tr>';
@for(noteSeq <- (itemJson\"note").asOpt[Seq[String]]; note = noteSeq(0)) {sig += '<tr><td>Notiz:</td><td>' + '@note' + '</td></tr>';}
tableDetails += sig;
allTableDetails += sig;
}
@if(
!(json \\ "lon").isEmpty && (json \\ "lon").head.asOpt[String].isDefined &&
Expand Down

0 comments on commit fcc6986

Please sign in to comment.