Skip to content

Commit

Permalink
Merge #1920 from remote-tracking branch 'origin/1915-useOwnJsonToGetO…
Browse files Browse the repository at this point in the history
…pacLinks'
  • Loading branch information
dr0i committed Oct 13, 2023
2 parents 3534bf4 + de2bd77 commit 7809673
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 46 deletions.
24 changes: 1 addition & 23 deletions web/app/controllers/resources/Lobid.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.common.html.HtmlEscapers;

import play.Logger;
import play.api.libs.json.JsValue;
import play.cache.Cache;
import play.libs.F.Promise;
import play.libs.Json;
Expand Down Expand Up @@ -386,29 +387,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 =
new URL(Application.CONFIG.getString("isil2opac_hbzid")).openStream()) {
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
39 changes: 16 additions & 23 deletions web/app/views/tags/items_map.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@

@(items: Map[String,List[String]], itemDetails: Map[String,String])

@import play.api.libs.ws.WS
@import play.api.libs.json.JsArray
@import play.api.libs.json.Json
@import play.api.libs.json.JsValue
@import scala.concurrent._
@import ExecutionContext.Implicits.global
@import scala.concurrent.duration._
@import play.api.Play.current
@import controllers.resources._
@import play.api.cache.Cache
@import play.Logger

@string(value: JsValue) = { @value.asOpt[String].getOrElse("--") }

Expand Down Expand Up @@ -59,16 +51,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,12 +59,23 @@
signatures = (itemJson\\"callNumber");
signature = if(signatures.isEmpty) "" else signatures(0).as[String];
urls = (itemJson\\"electronicLocator");
seeAlso=if((itemJson\\"seeAlso").isEmpty) null else (itemJson\\"seeAlso")(0).as[Seq[JsValue]].map(_.as[String]);
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}}</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;
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(seeAlso){ 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;
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 7809673

Please sign in to comment.