diff --git a/web/app/Global.java b/web/app/Global.java index 5548ad5b2..d87685a73 100644 --- a/web/app/Global.java +++ b/web/app/Global.java @@ -1,9 +1,14 @@ /* Copyright 2017, hbz. Licensed under the EPL 2.0 */ +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; import java.net.InetAddress; import java.util.List; import java.util.stream.Collectors; +import com.fasterxml.jackson.databind.JsonNode; +import controllers.resources.Lobid; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.settings.Settings; @@ -18,6 +23,7 @@ import play.Application; import play.GlobalSettings; import play.Logger; +import play.libs.Json; /** * Application global settings. @@ -48,6 +54,8 @@ public class Global extends GlobalSettings { private LocalIndex localIndex = null; private Client client = null; + private static final String ISIL2OPAC ="../link-templates/isil2opac_hbzid.json"; + @Override public void onStart(Application app) { super.onStart(app); @@ -71,6 +79,7 @@ else if (!app.isTest()) { if (client != null) { Search.elasticsearchClient = client; } + Lobid.isil2opac = loadIsil2Opac(); } @Override @@ -96,4 +105,16 @@ private static void addHosts(TransportClient client) { } } } + + private static JsonNode loadIsil2Opac() { + JsonNode node = null; + try (InputStream stream = + new FileInputStream(ISIL2OPAC)) { + node = Json.parse(stream); + } + catch (IOException e) { + Logger.error("Could not create OPAC URL", e); + } + return node; + } } diff --git a/web/app/controllers/resources/Lobid.java b/web/app/controllers/resources/Lobid.java index 7a1b80154..a77e663b2 100644 --- a/web/app/controllers/resources/Lobid.java +++ b/web/app/controllers/resources/Lobid.java @@ -2,9 +2,6 @@ package controllers.resources; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -51,6 +48,7 @@ public class Lobid { static final String ORGS_ROOT = Application.CONFIG.getString("orgs.api"); /** Timeout for API calls in milliseconds. */ public static final int API_TIMEOUT = 50000; + public static JsonNode isil2opac = null; /** * @param url The URL to call @@ -391,21 +389,16 @@ private static void mapIsilsToUris(JsonNode items, * @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); + JsonNode urlTemplate = isil2opac.get(isil); if (urlTemplate != null) return urlTemplate.asText().replace("{hbzid}", hbzId); - } catch (IOException e) { - Logger.error("Could not create OPAC URL", e); - } return null; } diff --git a/web/conf/resources.conf_template b/web/conf/resources.conf_template index 1e2fb1907..3642ada01 100644 --- a/web/conf/resources.conf_template +++ b/web/conf/resources.conf_template @@ -3,8 +3,6 @@ hbz01.api="http://lobid.org/hbz01" mrcx.api="https://lobid.org/marcxml/" orgs.api="http://lobid.org/organisations/" -isil2opac_hbzid = "https://raw.githubusercontent.com/hbz/link-templates/master/isil2opac_hbzid.json" - webhook = { alma = { update = {