Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache table "isil2opac_hbzid" #1911

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ This should result in *BUILD SUCCESS*. Push your changes. You're done :)
h2. Tables as gitsubmodules
Some lookup tables are provided through gitsubmodules. To make a @git pull@ also
update these tables you can e.g. do @git config --local submodule.recurse true@ once.
If you update an already cloned repo you need to do @git submodule update --init --recursive@ first.

h2. Propagate the context.json to lobid-resources-web

Expand Down
21 changes: 21 additions & 0 deletions web/app/Global.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,6 +23,7 @@
import play.Application;
import play.GlobalSettings;
import play.Logger;
import play.libs.Json;

/**
* Application global settings.
Expand Down Expand Up @@ -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);
Expand All @@ -71,6 +79,7 @@ else if (!app.isTest()) {
if (client != null) {
Search.elasticsearchClient = client;
}
Lobid.isil2opac = loadIsil2Opac();
}

@Override
Expand All @@ -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;
}
}
13 changes: 3 additions & 10 deletions web/app/controllers/resources/Lobid.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 0 additions & 2 deletions web/conf/resources.conf_template
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down