From ee75519debe5e98b0414549efbf4837b1c156b15 Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Fri, 7 Oct 2022 13:14:35 +0200 Subject: [PATCH 1/8] Pretty-print single-resource JSON responses, like others (#275) --- app/controllers/HomeController.java | 5 ++-- test/controllers/JsonResponseTest.java | 32 ++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/app/controllers/HomeController.java b/app/controllers/HomeController.java index 4bea084..93597fb 100644 --- a/app/controllers/HomeController.java +++ b/app/controllers/HomeController.java @@ -208,8 +208,9 @@ public Result authority(String id, String format) { return ok(views.html.details.render(entity)); } default: { - return rdfResultFor(Json.parse(jsonLd), responseFormat.queryParamString).orElseGet(() -> { - return result(jsonLd, Accept.Format.JSON_LD.types[0]); + JsonNode jsonLdObject = Json.parse(jsonLd); + return rdfResultFor(jsonLdObject, responseFormat.queryParamString).orElseGet(() -> { + return result(prettyJsonString(jsonLdObject), Accept.Format.JSON_LD.types[0]); }); } } diff --git a/test/controllers/JsonResponseTest.java b/test/controllers/JsonResponseTest.java index ac8dc2a..e6fc4ca 100644 --- a/test/controllers/JsonResponseTest.java +++ b/test/controllers/JsonResponseTest.java @@ -1,4 +1,4 @@ -/* Copyright 2018, hbz. Licensed under the Eclipse Public License 1.0 */ +/* Copyright 2018, 2022 hbz. Licensed under the Eclipse Public License 1.0 */ package controllers; @@ -15,7 +15,15 @@ import static play.test.Helpers.route; import static play.test.Helpers.running; +import java.util.Arrays; +import java.util.Collection; + import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import com.fasterxml.jackson.databind.JsonNode; import modules.IndexTest; import play.Application; @@ -23,17 +31,33 @@ import play.mvc.Result; @SuppressWarnings("javadoc") +@RunWith(Parameterized.class) public class JsonResponseTest extends IndexTest { + @Parameters(name = "{0}") + public static Collection data() { + return Arrays.asList(new Object[][] { { "/gnd/search?format=json" }, { "/gnd/2136169-1" } }); + } + + private String path; + + public JsonResponseTest(String path) { + this.path = path; + } + @Test public void jsonRequestNoInternalUrl() { Application application = fakeApplication(); running(application, () -> { - Result result = route(application, fakeRequest(GET, "/gnd/search?format=json")); + Result result = route(application, fakeRequest(GET, path)); assertNotNull(result); assertThat(result.contentType().get(), is(equalTo("application/json"))); - assertNotNull(Json.parse(contentAsString(result))); - assertThat(contentAsString(result), not(containsString("localhost"))); + String content = contentAsString(result); + assertNotNull(content); + assertThat(content, not(containsString("localhost"))); + JsonNode json = Json.parse(content); + assertNotNull(json); + assertThat(content, equalTo(Json.prettyPrint(json))); }); } } \ No newline at end of file From c3cfcbea5f96dcd908eb71a84e90646f18cfd583 Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Fri, 7 Oct 2022 13:44:43 +0200 Subject: [PATCH 2/8] Add test for updated label (#324, #325) --- test/models/GndOntologyLabelTests.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/models/GndOntologyLabelTests.java b/test/models/GndOntologyLabelTests.java index 30b5b19..6315c0c 100644 --- a/test/models/GndOntologyLabelTests.java +++ b/test/models/GndOntologyLabelTests.java @@ -36,7 +36,8 @@ public static Collection data() { { "professionalRelationship", "Berufliche Beziehung" }, // { "broadMatch", "Oberbegriff" }, // { "exactMatch", "Entspricht" }, // - { "relatedMatch", "Verwandter Begriff" } }); + { "relatedMatch", "Verwandter Begriff" }, // + { "SubjectHeadingSensoStricto", "Schlagwort sensu stricto" } }); } private String id; From f623bc3df8b012b8ad1ba6a254a6f8ab9ab9f1bd Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Fri, 7 Oct 2022 14:10:59 +0200 Subject: [PATCH 3/8] Support gndo:abbreviatedName in context and reconciliation (#229) --- app/controllers/Reconcile.java | 1 + conf/context.jsonld | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/app/controllers/Reconcile.java b/app/controllers/Reconcile.java index 46e000d..10fa17a 100644 --- a/app/controllers/Reconcile.java +++ b/app/controllers/Reconcile.java @@ -485,6 +485,7 @@ private SearchResponse executeQuery(Entry entry, String queryS .field("preferredName", 4f)// .field("variantName", 2f)// .field("temporaryName")// + .field("abbreviatedName")// .field("abbreviatedNameForTheConferenceOrEvent")// .field("abbreviatedNameForThePlaceOrGeographicName")// .field("abbreviatedNameForTheWork")// diff --git a/conf/context.jsonld b/conf/context.jsonld index 9f5c92a..9aa2863 100644 --- a/conf/context.jsonld +++ b/conf/context.jsonld @@ -996,6 +996,10 @@ "@type":"@id", "@container":"@set" }, + "abbreviatedName": { + "@id":"https://d-nb.info/standards/elementset/gnd#abbreviatedName", + "@container":"@set" + }, "abbreviatedNameForTheConferenceOrEvent": { "@id":"https://d-nb.info/standards/elementset/gnd#abbreviatedNameForTheConferenceOrEvent", "@container":"@set" From bd52135562e0c5a6a02fba259986fb7957e0eb60 Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Mon, 10 Oct 2022 15:34:22 +0200 Subject: [PATCH 4/8] Add specific `temporaryName*` fields to reconciliation query (#227) --- app/controllers/Reconcile.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/controllers/Reconcile.java b/app/controllers/Reconcile.java index 10fa17a..54571b9 100644 --- a/app/controllers/Reconcile.java +++ b/app/controllers/Reconcile.java @@ -485,6 +485,9 @@ private SearchResponse executeQuery(Entry entry, String queryS .field("preferredName", 4f)// .field("variantName", 2f)// .field("temporaryName")// + .field("temporaryNameOfTheConferenceOrEvent")// + .field("temporaryNameOfTheCorporateBody")// + .field("temporaryNameOfThePlaceOrGeographicName")// .field("abbreviatedName")// .field("abbreviatedNameForTheConferenceOrEvent")// .field("abbreviatedNameForThePlaceOrGeographicName")// From 3872262564dde3ef4d8c54cbfb6faeaf820ce861 Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Mon, 10 Oct 2022 17:00:20 +0200 Subject: [PATCH 5/8] Don't display deprecated URI in sameAs (#203) --- app/models/AuthorityResource.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/AuthorityResource.java b/app/models/AuthorityResource.java index b585011..4f7d584 100644 --- a/app/models/AuthorityResource.java +++ b/app/models/AuthorityResource.java @@ -365,7 +365,11 @@ private List getLinks() { String dnbIcon = "https://portal.dnb.de/favicon.ico"; String dnbLabel = "Deutsche Nationalbibliothek (DNB)"; String dnbSubstring = "d-nb.info/gnd"; - List result = sameAs == null ? Collections.emptyList() : sameAs.stream().map(map -> { + JsonNode deprecatedUriNode = json.get("deprecatedUri"); + List result = sameAs == null ? Collections.emptyList() + : (deprecatedUriNode == null || deprecatedUriNode.size() == 0 ? sameAs.stream() + : nonDeprecated(deprecatedUriNode)) + .map(map -> { String url = map.get("id").toString(); Object icon = null; Object label = null; @@ -384,6 +388,11 @@ private List getLinks() { return result; } + private Stream> nonDeprecated(JsonNode deprecatedUriNode) { + return sameAs.stream() + .filter(sameAsObject -> !sameAsObject.get("id").equals(deprecatedUriNode.get(0).textValue())); + } + private String html(String field, ArrayList links, int i) { LinkWithImage link = links.get(i); boolean hasImage = !link.image.isEmpty(); From 2c3f79d70025742d4040bd8a6f9d2a9b5eb71b4d Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Mon, 10 Oct 2022 18:04:25 +0200 Subject: [PATCH 6/8] Show `dateModified` in UI (#244) --- app/models/AuthorityResource.java | 4 ++++ app/views/details.scala.html | 1 + 2 files changed, 5 insertions(+) diff --git a/app/models/AuthorityResource.java b/app/models/AuthorityResource.java index 4f7d584..0aab437 100644 --- a/app/models/AuthorityResource.java +++ b/app/models/AuthorityResource.java @@ -468,4 +468,8 @@ private static String year(JsonNode node) { String text = node.elements().next().asText(); return text.matches("\\d{4}-\\d{2}-\\d{2}") ? text.split("-")[0] : text; } + + public String dateModified() { + return json.findValue("dateModified").asText().split("T")[0]; + } } diff --git a/app/views/details.scala.html b/app/views/details.scala.html index 7a65260..e35644d 100644 --- a/app/views/details.scala.html +++ b/app/views/details.scala.html @@ -156,6 +156,7 @@ Turtle) @if(entityFacts){und EntityFacts (JSON-LD)} | CC0 + | @resource.dateModified

}} From e2b4e0c5cc9fa469fe128e3d3b08cc24fafe9175 Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Mon, 10 Oct 2022 18:20:27 +0200 Subject: [PATCH 7/8] Add setup to avoid specific entities on start page (#301) --- app/controllers/HomeController.java | 6 +++++- conf/application.conf | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/HomeController.java b/app/controllers/HomeController.java index 93597fb..592e309 100644 --- a/app/controllers/HomeController.java +++ b/app/controllers/HomeController.java @@ -121,7 +121,11 @@ public Result redirectSlash(String path) { } public Result index() { - QueryStringQueryBuilder query = index.queryStringQuery("depiction:*"); + String queryString = "depiction:*"; + for (String dont : CONFIG.getStringList("dontShowOnMainPage")) { + queryString += " AND NOT gndIdentifier:" + dont; + } + QueryStringQueryBuilder query = index.queryStringQuery(queryString); FunctionScoreQueryBuilder functionScoreQuery = QueryBuilders.functionScoreQuery(query, ScoreFunctionBuilders.randomFunction(System.currentTimeMillis())); SearchRequestBuilder requestBuilder = index.client().prepareSearch(config("index.prod.name")) diff --git a/conf/application.conf b/conf/application.conf index 321d369..4e505ae 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -3,6 +3,8 @@ host : "https://lobid.org" +dontShowOnMainPage: ["1012979-0"] + play { http.secret.key="" filters.disabled+=play.filters.hosts.AllowedHostsFilter From 3131fc1bf0430e50be79dd79baae033a4933d67e Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Tue, 11 Oct 2022 17:53:12 +0200 Subject: [PATCH 8/8] Revert showing `dateModified` in UI (2c3f79d, #244) --- app/models/AuthorityResource.java | 4 ---- app/views/details.scala.html | 1 - 2 files changed, 5 deletions(-) diff --git a/app/models/AuthorityResource.java b/app/models/AuthorityResource.java index 0aab437..4f7d584 100644 --- a/app/models/AuthorityResource.java +++ b/app/models/AuthorityResource.java @@ -468,8 +468,4 @@ private static String year(JsonNode node) { String text = node.elements().next().asText(); return text.matches("\\d{4}-\\d{2}-\\d{2}") ? text.split("-")[0] : text; } - - public String dateModified() { - return json.findValue("dateModified").asText().split("T")[0]; - } } diff --git a/app/views/details.scala.html b/app/views/details.scala.html index e35644d..7a65260 100644 --- a/app/views/details.scala.html +++ b/app/views/details.scala.html @@ -156,7 +156,6 @@ Turtle) @if(entityFacts){und EntityFacts (JSON-LD)} | CC0 - | @resource.dateModified

}}