Skip to content

Commit

Permalink
Merge branch 'misc' of https://github.com/hbz/lobid-gnd
Browse files Browse the repository at this point in the history
See #328
  • Loading branch information
fsteeg committed Oct 11, 2022
2 parents f7bf080 + 3131fc1 commit a921ed8
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 9 deletions.
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
11 changes: 10 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
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

0 comments on commit a921ed8

Please sign in to comment.