Skip to content

Commit

Permalink
Use trailing slash as default for gnd/reconcile/ route
Browse files Browse the repository at this point in the history
- Allows usage of relative links both in `reconcile` subdomain
deployment as well as in lobid.org/gnd/reconcile/ deployment
- Switch back to the `@desc` block for query and extend GET sample
  • Loading branch information
fsteeg committed Sep 13, 2024
1 parent 98bfb35 commit e20d130
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
10 changes: 5 additions & 5 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 Down Expand Up @@ -62,8 +64,7 @@ <h3>View-API</h3>

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

<p><b>Query: GET</b><br/>
<a href='@controllers.HomeController.config("host")/?queries={"q1":{"query":"Twain, Mark"}}'>/?queries={"q1":{"query":"Twain, Mark"}}</a>
@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")</code></p>

Expand All @@ -79,8 +80,7 @@ <h3>Suggest-API <small>(<a href="https://www.w3.org/community/reports/reconcilia
<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",""))
<p><b>Query: GET (<a href=\"https://www.w3.org/community/reports/reconciliation/CG-FINAL-specs-0.2-20230410/#data-extension-service\">spec</a>)</b><br/>
<a href='@controllers.HomeController.config("host")/?extend={"ids":["1081942517","4791358-7"],"properties":[{"id":"preferredName"},{"id":"firstAuthor"}]}'>/?extend={"ids":["1081942517","4791358-7"],"properties":[{"id":"preferredName"},{"id":"firstAuthor"}]}</a>
@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")</code></p>

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.Default.redirect(to = "/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 e20d130

Please sign in to comment.