Skip to content

Commit

Permalink
Merge branch 'reconcileSubdomain' of https://github.com/hbz/lobid-gnd
Browse files Browse the repository at this point in the history
See #407
  • Loading branch information
fsteeg committed Sep 19, 2024
2 parents 346a9e5 + a66ab7b commit 475fda2
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 34 deletions.
6 changes: 3 additions & 3 deletions app/controllers/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static String configNested(String id, String sub) {
* @return A 301 MOVED_PERMANENTLY redirect to the path
*/
public Result redirectSlash(String path) {
return movedPermanently("/" + path);
return movedPermanently("/" + path).withHeader("Access-Control-Allow-Origin", "*");
}

public Result index() {
Expand Down Expand Up @@ -467,8 +467,8 @@ static String returnAsJson(String q, SearchResponse queryResponse) {
List<Map<String, Object>> hits = Arrays.asList(queryResponse.getHits().getHits()).stream()
.map(hit -> hit.getSource()).collect(Collectors.toList());
ObjectNode object = Json.newObject();
object.put("@context", config("host") + routes.HomeController.context());
object.put("id", config("host") + request().uri());
object.put("@context", configNested("host", "main") + routes.HomeController.context());
object.put("id", configNested("host", "main") + request().uri());
object.put("totalItems", queryResponse.getHits().getTotalHits());
object.set("member", Json.toJson(hits));

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/Reconcile.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public Result main(String callback, String queries, String extend) {
}

private ObjectNode metadata() {
final String host = HomeController.config("host");
final String host = HomeController.configNested("host", "reconcile");
ObjectNode result = Json.newObject();
result.putArray("versions").add("0.1").add("0.2");
result.put("name", "GND reconciliation for OpenRefine");
Expand Down Expand Up @@ -151,7 +151,7 @@ private ObjectNode metadata() {

private ObjectNode suggestService(String suggest) {
return Json.newObject()//
.put("service_url", HomeController.config("host") + "/gnd/reconcile")//
.put("service_url", HomeController.configNested("host", "reconcile"))//
.put("service_path", "/suggest/" + suggest)//
.put("flyout_service_path", "/flyout/" + suggest + "?id=${id}");
}
Expand Down
5 changes: 3 additions & 2 deletions app/views/gnd.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@
<div class="panel panel-default footer-gnd">
<div class="panel-body">
<span class="pull-left">
<img id='small-logo' src='@controllers.routes.Assets.versioned("images/gnd.png")' alt="GND-Logo"/> &nbsp;
GND Reconciliation | ein Dienst im <a href='https://gnd.network'>gnd.network</a>
<a href='https://gnd.network'><img id='small-logo' src='@controllers.routes.Assets.versioned("images/gnd.png")' alt="GND-Logo"/></a>
<a href='https://www.hbz-nrw.de'><img id='small-logo' src='@controllers.routes.Assets.versioned("images/hbz.png")' alt="hbz-Logo"/></a> &nbsp;
GND Reconciliation | ein <a href='https://lobid.org'>lobid</a>-Dienst im <a href='https://gnd.network'>gnd.network</a>
</span>
<span class="pull-right">
<a href="http://lobid.org/warranty">Gewährleistung</a> |
Expand Down
4 changes: 2 additions & 2 deletions app/views/preview.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@(resource: String)

@import play.api.libs.json._
@import controllers.HomeController.CONFIG
@import controllers.HomeController.configNested

<html><head><meta charset="utf-8" /></head>
<body style="margin: 0px; font-family: Arial; sans-serif">
Expand All @@ -16,7 +16,7 @@
details = elems.tail.mkString(" | ");
fullId <- (json \ "id").asOpt[String];
shortId = fullId.split("/").last;
url = CONFIG.getString("host") + routes.HomeController.authority(shortId,null);
url = configNested("host", "reconcile") + routes.HomeController.authority(shortId,null);
cat <- (json \ "category").asOpt[String];
image = (json \ "image").asOpt[String]) {
@for(img <- image){
Expand Down
16 changes: 9 additions & 7 deletions app/views/reconcile.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

@()

@desc(label: String, link: play.api.mvc.Call) = {
@desc(label: String, call: play.api.mvc.Call) = {
@defining(call.toString.replace("/gnd/reconcile/", "")) { link =>
<dt>@Html(label)</dt> <dd><a href='@link'>@java.net.URLDecoder.decode(link.toString.replaceAll("[&?]format=json$", ""), "UTF-8")</a></dd>
}
}

@gnd("GND Reconciliation") {
Expand All @@ -18,7 +20,7 @@ <h1>GND Reconciliation</h1>

<p>Dieser Dienst ermöglicht den Abgleich eigener Daten mit der Gemeinsamen Normdatei, insbesondere mit OpenRefine, einem nicht nur im Bibliotheksbereich weitverbreiteten Werkzeug. OpenRefine bietet zahlreiche Funktionalitäten zur Bereinigung und Transformation von Daten, sowie zum Abgleich (Reconciliation) mit externen Datenquellen und zur Anreicherung auf Basis der abgeglichenen Daten. Dieser Dienst stellt die GND als eine solche Datenquelle in OpenRefine bereit. Der Dienst kann zugleich auch in anderen Anwendungen verwendet werden, z. B. im Bibliotheksmanagementsystem Alma über Alma Refine (s. <a href="https://reconciliation-api.github.io/census/clients/">weitere Clients</a>).</p>

<p>Service-URL: <code>@controllers.HomeController.config("host")@routes.Reconcile.reconcile()</code></p>
<p>Service-URL: <code>@controllers.HomeController.configNested("host", "reconcile")</code></p>

<h2>Daten und Werkzeuge</h2>

Expand Down Expand Up @@ -48,11 +50,11 @@ <h2>API</h2>
<h3>Allgemeine API <small>(<a href="https://www.w3.org/community/reports/reconciliation/CG-FINAL-specs-0.2-20230410">spec</a>)</small></h3>

<p><b>Service</b><br/>
<code>curl @controllers.HomeController.config("host")@routes.Reconcile.reconcile()</code>
<code>curl @controllers.HomeController.configNested("host", "reconcile")</code>
<p><b>JSONP-callback</b><br/>
<code>curl @controllers.HomeController.config("host")@routes.Reconcile.main("jsonp")</code>
<code>curl @controllers.HomeController.configNested("host", "reconcile")?callback=jsonp</code>
<p><b>CORS-header</b><br/>
<code>curl --head @controllers.HomeController.config("host")@routes.Reconcile.reconcile() | grep Access-Control-Allow-Origin</code>
<code>curl --head @controllers.HomeController.configNested("host", "reconcile") | grep Access-Control-Allow-Origin</code>
</p>

<h3>View-API</h3>
Expand All @@ -64,7 +66,7 @@ <h3>Query-API <small>(<a href="https://www.w3.org/community/reports/reconciliati

@desc("Query: GET", routes.Reconcile.main(queries="{\"q1\":{\"query\":\"Twain, Mark\"}}"))
<p><b>Query: POST</b><br/>
<code>curl --data 'queries={"q1":{"query":"Twain, Mark"}}' @controllers.HomeController.config("host")@routes.Reconcile.reconcile()</code></p>
<code>curl --data 'queries={"q1":{"query":"Twain, Mark"}}' @controllers.HomeController.configNested("host", "reconcile")</code></p>

<h3>Suggest-API <small>(<a href="https://www.w3.org/community/reports/reconciliation/CG-FINAL-specs-0.2-20230410/#suggest-services">spec</a>)</small></h3>

Expand All @@ -80,6 +82,6 @@ <h3>Data-extension-API</h3>
@desc("Property-proposals (<a href=\"https://www.w3.org/community/reports/reconciliation/CG-FINAL-specs-0.2-20230410/#data-extension-property-proposals\">spec</a>)", routes.Reconcile.properties("","Work",""))
@desc("Extend: GET (<a href=\"https://www.w3.org/community/reports/reconciliation/CG-FINAL-specs-0.2-20230410/#data-extension-service\">spec</a>)", routes.Reconcile.main(extend="{\"ids\":[\"1081942517\",\"4791358-7\"],\"properties\":[{\"id\":\"preferredName\"},{\"id\":\"firstAuthor\"}]}"))
<p><b>Extend: POST</b><br/>
<code>curl --data 'extend={"ids":["1081942517","4791358-7"],"properties":[{"id":"preferredName"},{"id":"firstAuthor"}]}' @controllers.HomeController.config("host")@routes.Reconcile.reconcile()</code></p>
<code>curl --data 'extend={"ids":["1081942517","4791358-7"],"properties":[{"id":"preferredName"},{"id":"firstAuthor"}]}' @controllers.HomeController.configNested("host", "reconcile")</code></p>

}
5 changes: 4 additions & 1 deletion conf/application.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# This is the main configuration file for the application.
# https://www.playframework.com/documentation/latest/ConfigFile

host : "https://lobid.org"
host {
main: "https://lobid.org"
reconcile: "https://reconcile.gnd.network"
}

dontShowOnMainPage: ["1012979-0"]

Expand Down
14 changes: 7 additions & 7 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
# This file defines all application routes (Higher priority routes first)
# ~~~~

# Handle trailing slashes
GET /gnd/reconcile/ controllers.Reconcile.main(callback ?= "", queries ?= "", extend ?= "")
POST /gnd/reconcile/ controllers.Reconcile.reconcile()
GET /*path/ controllers.HomeController.redirectSlash(path: String)

#OpenRefine reconciliation endpoint
GET /gnd/reconcile controllers.Reconcile.main(callback ?= "", queries ?= "", extend ?= "")
POST /gnd/reconcile controllers.Reconcile.reconcile()
GET /gnd/reconcile controllers.HomeController.redirectSlash(path = "gnd/reconcile/")
POST /gnd/reconcile controllers.Reconcile.reconcile()
GET /gnd/reconcile/ controllers.Reconcile.main(callback ?= "", queries ?= "", extend ?= "")
POST /gnd/reconcile/ controllers.Reconcile.reconcile()
GET /gnd/reconcile/properties controllers.Reconcile.properties(callback ?= "", type ?= "", limit ?= "")
GET /gnd/reconcile/suggest/:service controllers.Reconcile.suggest(callback ?= "", service, prefix, type ?= "", type_strict ?= "", limit: Int ?= 10, start: Int ?= 0)
GET /gnd/reconcile/flyout/:service controllers.Reconcile.flyout(callback ?= "", service, id)

# Handle trailing slashes
GET /*path/ controllers.HomeController.redirectSlash(path: String)

GET /gnd controllers.HomeController.index

GET /gnd/api controllers.HomeController.api
Expand Down
15 changes: 5 additions & 10 deletions test/controllers/ReconcileIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ public class ReconcileIntegrationTest extends IndexTest {

@Test
public void reconcileMetadataRequestNoCallback() {
metadataRequest("/gnd/reconcile");
}

@Test
public void reconcileMetadataRequestNoCallbackTrailingSlash() {
metadataRequest("/gnd/reconcile/");
}

Expand Down Expand Up @@ -93,7 +88,7 @@ public void reconcileSuggestTypeRequest() {

@Test
public void reconcileMetadataRequestWithCallback() {
metadataRequestWithCallback("/gnd/reconcile?callback=jsonp");
metadataRequestWithCallback("/gnd/reconcile/?callback=jsonp");
}

@Test
Expand Down Expand Up @@ -166,15 +161,15 @@ private void reconcileRequest(String uri, String query, String gndId) {
}

@Test
// curl -g 'localhost:9000/gnd/reconcile?queries={"q99":{"query":"*"}}'
// curl -g 'localhost:9000/gnd/reconcile/?queries={"q99":{"query":"*"}}'
public void reconcileRequestGetWithReservedChars() {
Application application = fakeApplication();
running(application, () -> {
Result result = null;
try {
result = route(application,
fakeRequest(GET,
"/gnd/reconcile?queries=" + URLEncoder.encode(
"/gnd/reconcile/?queries=" + URLEncoder.encode(
"{\"q99\":{\"query\":\"Conference +=<>(){}[]^ (1997 : Kyoto / Japan)\"}}",
StandardCharsets.UTF_8.name())));
} catch (UnsupportedEncodingException e) {
Expand Down Expand Up @@ -234,7 +229,7 @@ public void reconcileRequestWithType() {

@Test
// curl -g
// 'localhost:9000/gnd/reconcile?extend=
// 'localhost:9000/gnd/reconcile/?extend=
// {"ids":[],"properties":[{"id":"geographicAreaCode"},{"id":"professionOrOccupation"}]}'
// See https://github.com/hbz/lobid-gnd/issues/241
public void extendRequestMeta() {
Expand All @@ -246,7 +241,7 @@ public void extendRequestMeta() {
"{\"id\":\"geographicAreaCode\"}," + //
"{\"id\":\"professionOrOccupation\"}]}";
result = route(application, fakeRequest(GET,
"/gnd/reconcile?extend=" + URLEncoder.encode(extensionQuery, StandardCharsets.UTF_8.name())));
"/gnd/reconcile/?extend=" + URLEncoder.encode(extensionQuery, StandardCharsets.UTF_8.name())));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 475fda2

Please sign in to comment.