Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection of misc minor changes #328

Merged
merged 9 commits into from
Oct 11, 2022
11 changes: 8 additions & 3 deletions app/controllers/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -208,8 +212,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]);
});
}
}
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/Reconcile.java
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,10 @@ private SearchResponse executeQuery(Entry<String, JsonNode> entry, String queryS
.field("preferredName", 4f)//
.field("variantName", 2f)//
.field("temporaryName")//
.field("temporaryNameOfTheConferenceOrEvent")//
.field("temporaryNameOfTheCorporateBody")//
.field("temporaryNameOfThePlaceOrGeographicName")//
.field("abbreviatedName")//
.field("abbreviatedNameForTheConferenceOrEvent")//
.field("abbreviatedNameForThePlaceOrGeographicName")//
.field("abbreviatedNameForTheWork")//
Expand Down
15 changes: 14 additions & 1 deletion app/models/AuthorityResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,11 @@ private List<LinkWithImage> getLinks() {
String dnbIcon = "https://portal.dnb.de/favicon.ico";
String dnbLabel = "Deutsche Nationalbibliothek (DNB)";
String dnbSubstring = "d-nb.info/gnd";
List<LinkWithImage> result = sameAs == null ? Collections.emptyList() : sameAs.stream().map(map -> {
JsonNode deprecatedUriNode = json.get("deprecatedUri");
List<LinkWithImage> 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;
Expand All @@ -384,6 +388,11 @@ private List<LinkWithImage> getLinks() {
return result;
}

private Stream<Map<String, Object>> nonDeprecated(JsonNode deprecatedUriNode) {
return sameAs.stream()
.filter(sameAsObject -> !sameAsObject.get("id").equals(deprecatedUriNode.get(0).textValue()));
}

private String html(String field, ArrayList<LinkWithImage> links, int i) {
LinkWithImage link = links.get(i);
boolean hasImage = !link.image.isEmpty();
Expand Down Expand Up @@ -459,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];
}
}
1 change: 1 addition & 0 deletions app/views/details.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
<a title='Turtle aus GND anzeigen' href='https://d-nb.info/gnd/@resource.getId()/about/lds.ttl'>Turtle</a>)
@if(entityFacts){und <a href='https://www.dnb.de/entityfacts'>EntityFacts</a> (<a title="JSON-LD in EntityFacts anzeigen" href='@(controllers.HomeController.config("entityfacts.live")+resource.getId)'>JSON-LD</a>)}
| <a href='https://creativecommons.org/publicdomain/zero/1.0/'>CC0</a>
| @resource.dateModified
</div></p>
}}

Expand Down
2 changes: 2 additions & 0 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

host : "https://lobid.org"

dontShowOnMainPage: ["1012979-0"]

play {
http.secret.key=""
filters.disabled+=play.filters.hosts.AllowedHostsFilter
Expand Down
4 changes: 4 additions & 0 deletions conf/context.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
32 changes: 28 additions & 4 deletions test/controllers/JsonResponseTest.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -15,25 +15,49 @@
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;
import play.libs.Json;
import play.mvc.Result;

@SuppressWarnings("javadoc")
@RunWith(Parameterized.class)
public class JsonResponseTest extends IndexTest {

@Parameters(name = "{0}")
public static Collection<Object[]> 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)));
});
}
}
3 changes: 2 additions & 1 deletion test/models/GndOntologyLabelTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public static Collection<Object[]> data() {
{ "professionalRelationship", "Berufliche Beziehung" }, //
{ "broadMatch", "Oberbegriff" }, //
{ "exactMatch", "Entspricht" }, //
{ "relatedMatch", "Verwandter Begriff" } });
{ "relatedMatch", "Verwandter Begriff" }, //
{ "SubjectHeadingSensoStricto", "Schlagwort sensu stricto" } });
}

private String id;
Expand Down