Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into biblioVino_rpb-231-text
Browse files Browse the repository at this point in the history
  • Loading branch information
fsteeg committed Dec 27, 2024
2 parents b232421 + 3849672 commit ce59d03
Show file tree
Hide file tree
Showing 16 changed files with 44,914 additions and 123,778 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push
jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
Expand Down
45 changes: 34 additions & 11 deletions app/controllers/nwbib/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -951,20 +951,43 @@ private static List<String> starredIds() {
}

public static Promise<Result> put(String id, String secret) throws FileNotFoundException, RecognitionException, IOException {
File input = new File("conf/output/test-output-strapi.json");
File output = new File("conf/output/test-output-0.json");
Files.write(Paths.get(input.getAbsolutePath()), request().body().asJson().toString().getBytes(Charsets.UTF_8));
ETL.main(new String[] {"conf/rpb-test-titel-to-lobid.flux"});
String result = Files.readAllLines(Paths.get(output.getAbsolutePath())).stream().collect(Collectors.joining("\n"));
boolean authorized = !secret.trim().isEmpty() && secret.equals(CONFIG.getString("secret"));
if (authorized) {
Cache.remove(String.format("/%s", id));
String url = "http://weywot3:9200/resources-rpb-test/resource/"
+ URLEncoder.encode("https://lobid.org/resources/" + id, "UTF-8");
WSRequest request = WS.url(url).setHeader("Content-Type", "application/json");
return request.put(result).map(response -> status(response.getStatus(), response.getBody()));
return transformAndIndex(id, request().body().asJson());
} else {
return Promise.pure(unauthorized(secret));
}
}

public static Promise<Result> delete(String id, String secret) throws FileNotFoundException, RecognitionException, IOException {
boolean authorized = !secret.trim().isEmpty() && secret.equals(CONFIG.getString("secret"));
if (authorized) {
return deleteFromIndex(id);
} else {
return Promise.pure(unauthorized());
return Promise.pure(unauthorized(secret));
}
}

private static Promise<Result> deleteFromIndex(String id) throws UnsupportedEncodingException {
Cache.remove(String.format("/%s", id));
WSRequest request = WS.url(elasticsearchUrl(id)).setHeader("Content-Type", "application/json");
return request.delete().map(response -> status(response.getStatus(), response.getBody()));
}

private static Promise<Result> transformAndIndex(String id, JsonNode jsonBody)
throws IOException, FileNotFoundException, RecognitionException, UnsupportedEncodingException {
File input = new File("conf/output/test-output-strapi.json");
File output = new File("conf/output/test-output-0.json");
Files.write(Paths.get(input.getAbsolutePath()), jsonBody.toString().getBytes(Charsets.UTF_8));
ETL.main(new String[] {"conf/rpb-test-titel-to-lobid.flux"});
String result = Files.readAllLines(Paths.get(output.getAbsolutePath())).stream().collect(Collectors.joining("\n"));
Cache.remove(String.format("/%s", id));
WSRequest request = WS.url(elasticsearchUrl(id)).setHeader("Content-Type", "application/json");
return request.put(result).map(response -> status(response.getStatus(), response.getBody()));
}

private static String elasticsearchUrl(String id) throws UnsupportedEncodingException {
return "http://weywot3:9200/resources-rpb-test/resource/"
+ URLEncoder.encode("https://lobid.org/resources/" + id, "UTF-8");
}
}
5 changes: 4 additions & 1 deletion app/rpb/ETL.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -47,7 +48,9 @@ public static void main(final String[] args) throws FileNotFoundException, Recog
}
vars.put(matcher.group(1), matcher.group(2));
}
FluxCompiler.compile(ResourceUtil.getStream(fluxFile), vars).start();
try (InputStream stream = ResourceUtil.getStream(fluxFile)) {
FluxCompiler.compile(stream, vars).start();
}
}
}
}
8 changes: 6 additions & 2 deletions app/views/TableRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,18 @@ public String process(JsonNode doc, String property, String param,
private String label(JsonNode doc, String value, List<String> properties) {
List<String> results = new ArrayList<>();
List<String> resultValues = labelsFor(doc, value, properties);
JsonNode labelNode = doc.get(properties.get(0)).iterator().next().get("label");
for (int i = 0; i < resultValues.size(); i++) {
String currentValue = resultValues.get(i);
String[] refAndLabel =
refAndLabel(properties.get(i), currentValue, Optional.empty());
String label = labelNode != null ? labelNode.textValue() : refAndLabel[1];
String result =
properties.get(i).equals("numbering") || value.equals("--")
? currentValue
: String.format(
"<a title=\"Titeldetails anzeigen\" href=\"%s\">%s</a>",
refAndLabel[0], refAndLabel[1]);
refAndLabel[0], label);
results.add(result.replace("Band", "").trim());
}
return results.stream().collect(Collectors.joining(", Band "));
Expand Down Expand Up @@ -215,7 +217,9 @@ String[] refAndLabel(String property, String value,
if ((property.equals("containedIn") || property.equals("hasPart")
|| property.equals("isPartOf") || property.equals("hasSuperordinate")
|| property.equals("bibliographicCitation")) && value.contains("lobid.org")) {
return new String[] { value, Lobid.resourceLabel(value) };
return new String[] { value.matches(".*?[as]\\d+.*|.*?\\d{3}[a-z]\\d+.*") // rpbId
? value.replace("https://lobid.org/resources/", "/")
: value, Lobid.resourceLabel(value) };
}
String label =
labels.isPresent() && labels.get().size() > 0 ? labels.get().get(0)
Expand Down
6 changes: 4 additions & 2 deletions app/views/tags/result_doc.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@

@part_of(field: String, subField: String) = {
@if(!(doc \ field).isInstanceOf[JsUndefined]){
@defining((doc \ field).as[Seq[JsValue]].sortBy((v: JsValue) => (v\"numbering").isInstanceOf[JsUndefined]).get(0)) { case (isPartOf) =>
@defining((doc \ field).as[Seq[JsValue]].sortBy((v: JsValue) => (v\"numbering").isInstanceOf[JsUndefined])) { case (isPartOfs) =>
@for((isPartOf) <- isPartOfs) {
@Html(TableRow.VALUES_MULTI.process(new com.fasterxml.jackson.databind.ObjectMapper().readTree(String.format("{\"%s\":[%s]}", field, isPartOf)),
field,
"q",
if((isPartOf \ "numbering").asOpt[String].isDefined) {"Erschienen als"} else {"Erschienen in"},
if(isPartOf == isPartOfs.head) { if((isPartOf \ "numbering").asOpt[String].isDefined) {"Erschienen als"} else {"Erschienen in"} } else {""},
Seq(((isPartOf \ subField)(0) \ "id").asOpt[String].getOrElse("--")),
Optional.of(Seq(subField, "numbering"))))
}
}
}
}
Expand Down
Loading

0 comments on commit ce59d03

Please sign in to comment.