diff --git a/app/controllers/nwbib/Application.java b/app/controllers/nwbib/Application.java index c56dd0d..089db9a 100644 --- a/app/controllers/nwbib/Application.java +++ b/app/controllers/nwbib/Application.java @@ -3,11 +3,14 @@ package controllers.nwbib; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.URL; import java.net.URLEncoder; +import java.nio.file.Files; +import java.nio.file.Paths; import java.text.Collator; import java.util.ArrayList; import java.util.Arrays; @@ -28,6 +31,7 @@ import java.util.stream.Stream; import java.util.stream.StreamSupport; +import org.antlr.runtime.RecognitionException; import org.apache.commons.lang3.tuple.Pair; import org.elasticsearch.common.base.Charsets; import org.elasticsearch.common.geo.GeoPoint; @@ -54,6 +58,7 @@ import play.mvc.Result; import play.mvc.Results; import play.twirl.api.HtmlFormat; +import rpb.ETL; import views.html.browse_classification; import views.html.browse_register; import views.html.classification; @@ -943,4 +948,21 @@ private static List starredIds() { return new ArrayList<>(Arrays.asList(currentlyStarred().split(" ")).stream() .filter(s -> !s.trim().isEmpty()).collect(Collectors.toList())); } + + public static Promise 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) { + 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())); + } else { + return Promise.pure(unauthorized()); + } + } } diff --git a/app/controllers/nwbib/Lobid.java b/app/controllers/nwbib/Lobid.java index 834908f..98bed8d 100644 --- a/app/controllers/nwbib/Lobid.java +++ b/app/controllers/nwbib/Lobid.java @@ -324,7 +324,7 @@ public static String resourceLabel(String id) { Callable getLabel = () -> { // e.g. take TT000086525 from http://lobid.org/resources/TT000086525#! String simpleId = - id.replaceAll("https?://[^/]+/resources?/(?:search\\?q=rpbId:)?(.+?)[^A-Z0-9]*$", "$1"); + id.replaceAll("https?://[^/]+/(?:resources?/)?(?:search\\?q=rpbId:)?(.+?)[^A-Z0-9]*$", "$1"); JsonNode json = getResource(simpleId).findValue("title"); String label = json == null ? "" : HtmlEscapers.htmlEscaper().escape(json.asText()); diff --git a/app/views/TableRow.java b/app/views/TableRow.java index b9b3750..cd3fbc3 100644 --- a/app/views/TableRow.java +++ b/app/views/TableRow.java @@ -38,6 +38,7 @@ public String process(JsonNode doc, String property, String param, return filtered.isEmpty() ? "" : String.format("%s%s", label, filtered.stream() + .flatMap(s -> Arrays.asList(s.split("; ")).stream()) .map(val -> label(doc, property, param, val, keys)) .collect(Collectors.joining( property.equals("subjectChain") ? "
" : " | "))); @@ -48,7 +49,9 @@ private String label(JsonNode doc, String property, String param, String value = property.equals("subjectChain") ? val.replaceAll("\\([\\d,]+\\)$", "").trim() : val; if (!labels.isPresent()) { - return refAndLabel(property, value, labels)[0]; + String[] refAndLabel = refAndLabel(property, value, labels); + return value.startsWith("http") ? String.format("%s", + refAndLabel[0], refAndLabel[0], refAndLabel[1]) : refAndLabel[0]; } String term = value; if (param.equals("q")) { @@ -210,11 +213,9 @@ private static String lifeDates(JsonNode node) { String[] refAndLabel(String property, String value, Optional> labels) { if ((property.equals("containedIn") || property.equals("hasPart") - || property.equals("isPartOf") || property.equals("hasSuperordinate")) - && value.contains("lobid.org")) { - return new String[] { - value.replaceAll("https://lobid.org/resources?/", "http://rpb.lobid.org/"), - Lobid.resourceLabel(value) }; + || property.equals("isPartOf") || property.equals("hasSuperordinate") + || property.equals("bibliographicCitation")) && value.contains("lobid.org")) { + return new String[] { value, Lobid.resourceLabel(value) }; } String label = labels.isPresent() && labels.get().size() > 0 ? labels.get().get(0) diff --git a/app/views/tags/result_doc.scala.html b/app/views/tags/result_doc.scala.html index c869143..86a069f 100644 --- a/app/views/tags/result_doc.scala.html +++ b/app/views/tags/result_doc.scala.html @@ -137,6 +137,7 @@ } @subjects(subjects: Seq[JsValue]) = { + @if(!subjects.isEmpty) { Schlagwörter @@ -157,6 +158,7 @@ } else { | } } + } } @sortedPublications(seq: Seq[JsValue]) = @{ diff --git a/build.sbt b/build.sbt index 1178a7b..538a59f 100644 --- a/build.sbt +++ b/build.sbt @@ -45,6 +45,8 @@ lazy val root = (project in file(".")).enablePlugins(PlayJava) javacOptions ++= Seq("-source", "1.8", "-target", "1.8") +javaOptions += "-Dnet.sf.ehcache.disabled=true" + import com.typesafe.sbteclipse.core.EclipsePlugin.EclipseKeys EclipseKeys.projectFlavor := EclipseProjectFlavor.Java // Java project. Don't expect Scala IDE diff --git a/conf/nwbib.conf b/conf/nwbib.conf index 114cd0c..23343b8 100644 --- a/conf/nwbib.conf +++ b/conf/nwbib.conf @@ -4,6 +4,7 @@ item.api="http://lobid.org/items" hbz01.api="http://lobid.org/hbz01" orgs.api="http://lobid.org/organisations" nwbib.filter="inCollection.id:\"http://lobid.org/resources/HT013494180#!\"" +secret="" # Embedded Elasticsearch index for classification data index { diff --git a/conf/nwbib.routes b/conf/nwbib.routes index ee232ad..b445db6 100644 --- a/conf/nwbib.routes +++ b/conf/nwbib.routes @@ -33,4 +33,5 @@ GET /robots.txt controllers.Assets.at(path="/public",file="robots. GET /cgi-bin/wwwalleg/:name.pl controllers.nwbib.Application.showPl(name, db ?= "rnam", index: Int ?= 1, zeilen: Int ?= 1, s1) GET /sw/:rpbId controllers.nwbib.Application.showSw(rpbId) GET /o:id controllers.nwbib.Application.searchSpatial(id, from:Int?=0, size:Int?=25, format?="html") -GET /:id controllers.nwbib.Application.show(id, format ?= "") \ No newline at end of file +GET /:id controllers.nwbib.Application.show(id, format ?= "") +PUT /:id controllers.nwbib.Application.put(id, secret ?= "") \ No newline at end of file diff --git a/conf/rpb-titel-to-lobid.fix b/conf/rpb-titel-to-lobid.fix index e3eec46..34b52e7 100644 --- a/conf/rpb-titel-to-lobid.fix +++ b/conf/rpb-titel-to-lobid.fix @@ -28,6 +28,9 @@ copy_field("rpbId", "_id") # ------- Set "type" ------- set_array("type[]", "BibliographicResource") +unless exists("type") + set_field("type[].$append", "Article") +end if all_equal("type", "u") set_field("type[].$append", "Article") end @@ -40,7 +43,10 @@ end if any_equal("type", "Band") set_field("type[].$append", "Book") call_macro("move_here", field: "isPartOf[]") - copy_field("isPartOf[].value", "superordinateLabel") + copy_field("isPartOf[].label", "superordinateLabel") + unless exists("superordinateLabel") + copy_field("isPartOf[].value", "superordinateLabel") + end set_array("isPartOf[]") set_array("isPartOf[].$append.type[]", "IsPartOfRelation") set_array("isPartOf[].$last.hasSuperordinate[]") @@ -120,9 +126,14 @@ if exists("isPartOf[]") set_array("temp") set_array("temp.$append.type[]", "IsPartOfRelation") set_array("temp.$last.hasSuperordinate[]") - split_field("isPartOf[].1.value", " ; ") - copy_field("isPartOf[].1.value.1", "temp.$last.hasSuperordinate[].$append.label") - copy_field("isPartOf[].1.value.2", "temp.$last.numbering") + if exists("isPartOf[].1.label") + copy_field("isPartOf[].1.value", "temp.$last.hasSuperordinate[].$append.id") + copy_field("isPartOf[].1.label", "temp.$last.hasSuperordinate[].$last.label") + else + split_field("isPartOf[].1.value", " ; ") + copy_field("isPartOf[].1.value.1", "temp.$last.hasSuperordinate[].$append.label") + copy_field("isPartOf[].1.value.2", "temp.$last.numbering") + end move_field("temp", "isPartOf[]") end end @@ -204,10 +215,12 @@ end do list (path:"temp_subject.*.componentList[]", "var": "$i") move_field("$i.value", "$i.id") - copy_field("$i.id", "$i.label") - replace_all("$i.label","^http.+[/#](.+)$","$1") - replace_all("$i.label","^(\\d+)-(\\d+)$","$1n$2") - lookup("$i.label", "./RPB-Export_HBZ_SW.tsv","sep_char":"\t") + unless exists("$i.label") + copy_field("$i.id", "$i.label") + replace_all("$i.label","^http.+[/#](.+)$","$1") + replace_all("$i.label","^(\\d+)-(\\d+)$","$1n$2") + lookup("$i.label", "./RPB-Export_HBZ_SW.tsv","sep_char":"\t") + end if all_match("$i.id","^http://rpb.lobid.org/sw/.*$") add_field("$i.source.id", "http://rpb.lobid.org/sw") add_field("$i.source.label", "RPB-Sachsystematik") @@ -283,11 +296,14 @@ do put_macro("contributions") set_array("_temp") copy_field("$[from][].*.value", "_temp.$append.agent.id") do list_as(f: "$[from][]", c: "_temp") - copy_field("c.agent.id", "c.agent.label") + copy_field("f.label", "c.agent.label") + unless exists("c.agent.label") + copy_field("c.agent.id", "c.agent.label") + replace_all("c.agent.label","^http.+[/#](.+)$","$1") + replace_all("c.agent.label","^(\\d+)-(\\d+)$","$1n$2") + lookup("c.agent.label", "./RPB-Export_HBZ_SW.tsv","sep_char":"\t") + end set_array("c.agent.type[]", "Person") - replace_all("c.agent.label","^http.+[/#](.+)$","$1") - replace_all("c.agent.label","^(\\d+)-(\\d+)$","$1n$2") - lookup("c.agent.label", "./RPB-Export_HBZ_SW.tsv","sep_char":"\t") copy_field("f.type", "c.role.id") copy_field("f.type", "c.role.label") lookup("c.role.id", "role-to-uri")