Skip to content

Commit

Permalink
Merge #1748 from remote-tracking branch 'origin/1316-addMarcDownload'
Browse files Browse the repository at this point in the history
  • Loading branch information
dr0i committed May 12, 2023
2 parents 0aeec1d + 8b9404e commit e02f12d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
3 changes: 2 additions & 1 deletion web/app/controllers/resources/Accept.java
Expand Up @@ -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;
Expand Down
20 changes: 17 additions & 3 deletions web/app/controllers/resources/Application.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> queryForm = Form.form(String.class);

Expand Down Expand Up @@ -483,6 +486,17 @@ public static Promise<Result> 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 + "\"");
});
Expand Down
4 changes: 2 additions & 2 deletions web/app/views/details.scala.html
Expand Up @@ -33,7 +33,7 @@ <h1>@((doc\"title").asOpt[String].getOrElse(q))@for(corporateBodyForTitle <- (do
@defining((doc\"almaMmsId").asOpt[String].getOrElse((doc\"hbzId").asOpt[String].getOrElse(q))){ id =>
<dt>@tags.star_button(id) Titeldetails:
<small style='float:right'>
<span class="source-link"><a title="Quelldaten anzeigen" href='@if((doc\"almaMmsId").asOpt[String].isDefined){@Application.CONFIG.getString("mrcx.api")/@id}else{@Application.CONFIG.getString("hbz01.api")/@id}'><small>&#12296;M&#12297;</small></a></span>
<a title="Quelldaten anzeigen" href='@if((doc\"almaMmsId").asOpt[String].isDefined){@Application.CONFIG.getString("mrcx.api")@id}else{@Application.CONFIG.getString("hbz01.api")/@id}'><small>&#12296;M&#12297;</small></a>
<a title="JSON-LD-Indexdaten anzeigen" href='@resources.routes.Application.resourceDotFormat(id, "json")'><img class='json-ld-icon' src='@routes.Assets.at("images/json-ld.png")'></a>
</small>
</dt>
Expand Down Expand Up @@ -83,4 +83,4 @@ <h1>@((doc\"title").asOpt[String].getOrElse(q))@for(corporateBodyForTitle <- (do
@if(!q.trim.isEmpty) {@map_credits()}
}
}
}
}
2 changes: 1 addition & 1 deletion 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"
Expand Down
7 changes: 0 additions & 7 deletions web/public/stylesheets/resources.css
Expand Up @@ -310,10 +310,3 @@ h5 {
height: 1.4em
}

.source-link a {
visibility:hidden;
}
.source-link:hover a {
visibility:visible;
text-decoration: none;
}
3 changes: 3 additions & 0 deletions web/test/tests/AcceptIntegrationTest.java
Expand Up @@ -58,10 +58,12 @@ public static Collection<Object[]> 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" },
Expand All @@ -71,6 +73,7 @@ public static Collection<Object[]> 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" },
Expand Down

0 comments on commit e02f12d

Please sign in to comment.