From c7cdd7393a75b069f369fce2f4da9931059759f2 Mon Sep 17 00:00:00 2001 From: Pascal Christoph Date: Tue, 9 May 2023 12:15:58 +0200 Subject: [PATCH 1/2] Unhide Marc download link (#1316) - update css --- web/app/views/details.scala.html | 4 ++-- web/public/stylesheets/resources.css | 7 ------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/web/app/views/details.scala.html b/web/app/views/details.scala.html index 4ae04d4891..098945d0ef 100644 --- a/web/app/views/details.scala.html +++ b/web/app/views/details.scala.html @@ -33,7 +33,7 @@

@((doc\"title").asOpt[String].getOrElse(q))@for(corporateBodyForTitle <- (do @defining((doc\"almaMmsId").asOpt[String].getOrElse((doc\"hbzId").asOpt[String].getOrElse(q))){ id =>
@tags.star_button(id) Titeldetails: - 〈M〉 + 〈M〉
@@ -83,4 +83,4 @@

@((doc\"title").asOpt[String].getOrElse(q))@for(corporateBodyForTitle <- (do @if(!q.trim.isEmpty) {@map_credits()} } } -} \ No newline at end of file +} diff --git a/web/public/stylesheets/resources.css b/web/public/stylesheets/resources.css index 6f60771a0b..38261d2a57 100644 --- a/web/public/stylesheets/resources.css +++ b/web/public/stylesheets/resources.css @@ -310,10 +310,3 @@ h5 { height: 1.4em } -.source-link a { - visibility:hidden; -} -.source-link:hover a { - visibility:visible; - text-decoration: none; -} From 8b9404e42adb7b8bb3a374cc7c49558ec6789e3b Mon Sep 17 00:00:00 2001 From: Pascal Christoph Date: Tue, 9 May 2023 15:25:54 +0200 Subject: [PATCH 2/2] Provide MARC XML via API (#1316) - add suffixing "xml" to id lookup (#1316) - add retrieving via accept header - add retrieving via "foramt" parameter - suffix slash to config of mrcx.api - proide tests --- web/app/controllers/resources/Accept.java | 3 ++- .../controllers/resources/Application.java | 20 ++++++++++++++++--- web/app/views/details.scala.html | 2 +- web/conf/resources.conf_template | 2 +- web/test/tests/AcceptIntegrationTest.java | 3 +++ 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/web/app/controllers/resources/Accept.java b/web/app/controllers/resources/Accept.java index ef7ea80151..bbc2546370 100644 --- a/web/app/controllers/resources/Accept.java +++ b/web/app/controllers/resources/Accept.java @@ -25,7 +25,8 @@ enum Format { RDF_XML("rdf", "application/rdf+xml", "application/xml", "text/xml"), // N_TRIPLE("nt", "application/n-triples", "text/plain"), // TURTLE("ttl", "text/turtle", "application/x-turtle"), // - RSS("rss", "application/rss+xml"); + RSS("rss", "application/rss+xml"), // + MARC_XML("mrcx", "application/marcxml+xml"); String[] types; String queryParamString; diff --git a/web/app/controllers/resources/Application.java b/web/app/controllers/resources/Application.java index 4cea925c9b..ab6b21e0bf 100644 --- a/web/app/controllers/resources/Application.java +++ b/web/app/controllers/resources/Application.java @@ -2,10 +2,11 @@ package controllers.resources; -import java.io.File; -import java.io.IOException; -import java.io.UnsupportedEncodingException; +import java.io.*; +import java.net.URL; +import java.net.URLConnection; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.text.Collator; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -101,6 +102,8 @@ public class Application extends Controller { new File("conf/resources.conf") : new File("conf/resources.conf_template") ; public final static Config CONFIG = ConfigFactory.parseFile(RESOURCES_CONF).resolve(); + public final static String MARC_XML_API = CONFIG.getString("mrcx.api"); + static Form queryForm = Form.form(String.class); @@ -483,6 +486,17 @@ public static Promise resource(final String id, String format) { ? ok(details.render(CONFIG, result.toString(), id)) : notFound(details.render(CONFIG, "", id)); } + boolean marcxmlRequested = + responseFormat.equals(Accept.Format.MARC_XML.queryParamString); + if (marcxmlRequested) { + URLConnection conn = new URL(MARC_XML_API + id).openConnection(); + String marcxml; + try (BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) { + marcxml = reader.lines().collect(Collectors.joining("\n")); + } + return marcxml.isEmpty() ? internalServerError("No content") + : ok(marcxml).as(Format.MARC_XML.types[0] + "; charset=utf-8"); + } return result != null ? responseFor(result, responseFormat) : notFound("\"Not found: " + id + "\""); }); diff --git a/web/app/views/details.scala.html b/web/app/views/details.scala.html index 098945d0ef..097ea60a46 100644 --- a/web/app/views/details.scala.html +++ b/web/app/views/details.scala.html @@ -33,7 +33,7 @@

@((doc\"title").asOpt[String].getOrElse(q))@for(corporateBodyForTitle <- (do @defining((doc\"almaMmsId").asOpt[String].getOrElse((doc\"hbzId").asOpt[String].getOrElse(q))){ id =>
@tags.star_button(id) Titeldetails: - 〈M〉 + 〈M〉
diff --git a/web/conf/resources.conf_template b/web/conf/resources.conf_template index 09e6b5d8ba..d9faa97a79 100644 --- a/web/conf/resources.conf_template +++ b/web/conf/resources.conf_template @@ -1,6 +1,6 @@ host="http://lobid.org" hbz01.api="http://lobid.org/hbz01" -mrcx.api="https://alma.lobid.org/marcxml" +mrcx.api="https://alma.lobid.org/marcxml/" orgs.api="http://lobid.org/organisations/" isil2opac_hbzid = "https://raw.githubusercontent.com/hbz/link-templates/master/isil2opac_hbzid.json" diff --git a/web/test/tests/AcceptIntegrationTest.java b/web/test/tests/AcceptIntegrationTest.java index 8755c67cee..93e7512aaf 100644 --- a/web/test/tests/AcceptIntegrationTest.java +++ b/web/test/tests/AcceptIntegrationTest.java @@ -58,10 +58,12 @@ public static Collection data() { { fakeRequest(GET, "/resources/990210781980206441").header("Accept", "application/pdf"), /*->*/ "application/json" }, // get, other formats as query param: { fakeRequest(GET, "/resources/990210781980206441?format=html"), /*->*/ "text/html" }, + { fakeRequest(GET, "/resources/990210781980206441?format=mrcx"), /*->*/ "application/marcxml+xml" }, { fakeRequest(GET, "/resources/990210781980206441?format=rdf"), /*->*/ "application/rdf+xml" }, { fakeRequest(GET, "/resources/990210781980206441?format=ttl"), /*->*/ "text/turtle" }, { fakeRequest(GET, "/resources/990210781980206441?format=nt"), /*->*/ "application/n-triples" }, // get, formats as URL path elem: + { fakeRequest(GET, "/resources/990210781980206441.mrcx"), /*->*/ "application/marcxml+xml" }, { fakeRequest(GET, "/resources/990210781980206441.html"), /*->*/ "text/html" }, { fakeRequest(GET, "/resources/990210781980206441.json"), /*->*/ "application/json" }, { fakeRequest(GET, "/resources/990210781980206441.rdf"), /*->*/ "application/rdf+xml" }, @@ -71,6 +73,7 @@ public static Collection data() { { fakeRequest(GET, "/resources/990210781980206441").header("Accept", "application/json"), /*->*/ "application/json" }, { fakeRequest(GET, "/resources/990210781980206441").header("Accept", "text/html"), /*->*/ "text/html" }, { fakeRequest(GET, "/resources/990210781980206441").header("Accept", "text/xml"), /*->*/ "application/rdf+xml" }, + { fakeRequest(GET, "/resources/990210781980206441").header("Accept", "application/marcxml+xml"), /*->*/ "application/marcxml+xml" }, { fakeRequest(GET, "/resources/990210781980206441").header("Accept", "application/xml"), /*->*/ "application/rdf+xml" }, { fakeRequest(GET, "/resources/990210781980206441").header("Accept", "application/rdf+xml"), /*->*/ "application/rdf+xml" }, { fakeRequest(GET, "/resources/990210781980206441").header("Accept", "text/turtle"), /*->*/ "text/turtle" },