Skip to content

Commit 8bd207f

Browse files
committed
Merge branch '129-switchToJava11AndUpdateMFDependencies' of https://github.com/hbz/rpb into main
Resolves https://jira.hbz-nrw.de/browse/RPB-266
2 parents 7ca98cc + a5fcd74 commit 8bd207f

13 files changed

+163
-121
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,15 @@ jobs:
77
runs-on: ubuntu-22.04
88
steps:
99
- uses: actions/checkout@v2
10-
- name: Set up JDK 1.8
10+
- name: Set up JDK 11
1111
uses: actions/setup-java@v1
1212
with:
13-
java-version: 1.8
14-
- name: Install metafacture-core 5.7.1
13+
java-version: 11
14+
- name: Install metafacture-core 7.0.0-rc1
1515
run: |
16-
git clone https://github.com/metafacture/metafacture-core.git -b metafacture-core-5.7.1
16+
git clone https://github.com/metafacture/metafacture-core.git -b metafacture-core-7.0.0-rc1
1717
cd metafacture-core
18-
./gradlew publishToMavenLocal
19-
cd ..
20-
- name: Install metafacture-fix 0.7.1
21-
run: |
22-
git clone https://github.com/metafacture/metafacture-fix.git -b 0.7.1
23-
cd metafacture-fix
18+
touch .temp # don't build release, which requires signing
2419
./gradlew publishToMavenLocal
2520
cd ..
2621
- name: Run tests

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,19 @@ sh transformAndIndex.sh
188188

189189
Start the web application:
190190

191+
### Test mode
192+
191193
```
192194
sbt run
193195
```
194196

197+
### Prod mode
198+
199+
```
200+
sbt stage
201+
./target/universal/stage/bin/rpb -no-version-check
202+
```
203+
195204
http://localhost:9000
196205

197206
## Java development

app/controllers/nwbib/Application.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.io.UnsupportedEncodingException;
1010
import java.net.URL;
1111
import java.net.URLEncoder;
12+
import java.nio.charset.Charset;
1213
import java.nio.file.Files;
1314
import java.nio.file.Paths;
1415
import java.text.Collator;
@@ -32,10 +33,9 @@
3233
import java.util.stream.StreamSupport;
3334

3435
import org.antlr.runtime.RecognitionException;
36+
import org.apache.commons.io.IOUtils;
3537
import org.apache.commons.lang3.tuple.Pair;
36-
import org.elasticsearch.common.base.Charsets;
3738
import org.elasticsearch.common.geo.GeoPoint;
38-
import org.elasticsearch.common.io.Streams;
3939

4040
import com.fasterxml.jackson.core.JsonProcessingException;
4141
import com.fasterxml.jackson.databind.JsonMappingException;
@@ -80,6 +80,8 @@
8080
*/
8181
public class Application extends Controller {
8282

83+
private static final String UTF_8 = "UTF-8";
84+
8385
static final int MAX_FACETS = 150;
8486

8587
private static final String STARRED = "starred";
@@ -154,7 +156,7 @@ public static Result advanced() {
154156
*/
155157
public static String currentUri() {
156158
try {
157-
return URLEncoder.encode(request().host() + request().uri(), "UTF-8");
159+
return URLEncoder.encode(request().host() + request().uri(), UTF_8);
158160
} catch (UnsupportedEncodingException e) {
159161
Logger.error("Could not get current URI", e);
160162
}
@@ -353,7 +355,7 @@ public static Result register(final String t) {
353355
public static Result journals() throws IOException {
354356
try (InputStream stream = Play.application().classloader()
355357
.getResourceAsStream("nwbib-journals.csv")) {
356-
String csv = new String(Streams.copyToByteArray(stream), Charsets.UTF_8);
358+
String csv = IOUtils.toString(stream, UTF_8);
357359
List<String> lines = Arrays.asList(csv.split("\n"));
358360
List<HashMap<String, String>> maps = lines.stream()
359361
.filter(line -> line.split("\",\"").length == 2).map(line -> {
@@ -1007,10 +1009,9 @@ private static JsonNode transform(JsonNode jsonBody)
10071009
throws IOException, FileNotFoundException, RecognitionException {
10081010
File input = new File("conf/output/test-output-strapi.json");
10091011
File output = new File("conf/output/test-output-0.json");
1010-
Files.write(Paths.get(input.getAbsolutePath()), jsonBody.toString().getBytes(Charsets.UTF_8));
1011-
ETL.main(new String[] { "conf/rpb-test-titel-to-lobid.flux" });
1012-
String result = Files.readAllLines(Paths.get(output.getAbsolutePath())).stream()
1013-
.collect(Collectors.joining("\n"));
1012+
Files.write(Paths.get(input.getAbsolutePath()), jsonBody.toString().getBytes(Charset.forName(UTF_8)));
1013+
ETL.main(new String[] {"conf/rpb-test-titel-to-lobid.flux"});
1014+
String result = Files.readAllLines(Paths.get(output.getAbsolutePath())).stream().collect(Collectors.joining("\n"));
10141015
return Json.parse(result);
10151016
}
10161017

@@ -1050,6 +1051,6 @@ private static Object mergeValues(Object transformedObject, Object lobidObject)
10501051

10511052
private static String elasticsearchUrl(String id) throws UnsupportedEncodingException {
10521053
return "http://weywot3:9200/resources-rpb-test/resource/"
1053-
+ URLEncoder.encode("https://lobid.org/resources/" + id, "UTF-8");
1054+
+ URLEncoder.encode("https://lobid.org/resources/" + id, UTF_8);
10541055
}
10551056
}

app/controllers/nwbib/Classification.java

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.text.Collator;
1414
import java.util.ArrayList;
1515
import java.util.Arrays;
16+
import java.util.Collection;
1617
import java.util.Collections;
1718
import java.util.Comparator;
1819
import java.util.HashMap;
@@ -42,14 +43,17 @@
4243
import org.elasticsearch.action.search.SearchResponse;
4344
import org.elasticsearch.action.search.SearchType;
4445
import org.elasticsearch.client.Client;
45-
import org.elasticsearch.common.settings.ImmutableSettings;
4646
import org.elasticsearch.common.settings.Settings;
47+
import org.elasticsearch.common.xcontent.XContentType;
4748
import org.elasticsearch.index.query.MatchAllQueryBuilder;
4849
import org.elasticsearch.index.query.QueryBuilder;
4950
import org.elasticsearch.index.query.QueryBuilders;
51+
import org.elasticsearch.node.InternalSettingsPreparer;
5052
import org.elasticsearch.node.Node;
51-
import org.elasticsearch.node.NodeBuilder;
53+
import org.elasticsearch.node.NodeValidationException;
54+
import org.elasticsearch.plugins.Plugin;
5255
import org.elasticsearch.search.SearchHit;
56+
import org.elasticsearch.transport.Netty4Plugin;
5357

5458
import com.fasterxml.jackson.databind.JsonNode;
5559
import com.github.jsonldjava.core.JsonLdError;
@@ -194,6 +198,12 @@ public static Comparator<JsonNode> comparator(Function<JsonNode, String> fun) {
194198
.compare(fun.apply(o1), fun.apply(o2));
195199
}
196200

201+
private static class EmbeddedNode extends Node {
202+
public EmbeddedNode(Settings preparedSettings, Collection<Class<? extends Plugin>> classpathPlugins) {
203+
super(InternalSettingsPreparer.prepareEnvironment(preparedSettings, null), classpathPlugins);
204+
}
205+
}
206+
197207
private Classification() {
198208
/* Use via static functions, no instantiation. */
199209
}
@@ -237,7 +247,7 @@ public static List<String> toJsonLd(final URL turtleUrl) {
237247
public static JsonNode ids(String q, String t) {
238248
QueryBuilder queryBuilder = QueryBuilders.boolQuery()
239249
.must(QueryBuilders.idsQuery(Type.NWBIB.elasticsearchType,
240-
Type.SPATIAL.elasticsearchType).ids(q));
250+
Type.SPATIAL.elasticsearchType).addIds(q));
241251
SearchRequestBuilder requestBuilder = client.prepareSearch(INDEX)
242252
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setQuery(queryBuilder);
243253
if (t.isEmpty()) {
@@ -473,16 +483,21 @@ public static String shortId(String uri) {
473483

474484
/** Start up the embedded Elasticsearch classification index. */
475485
public static void indexStartup() {
476-
Settings clientSettings = ImmutableSettings.settingsBuilder()
477-
.put("path.home", new File(".").getAbsolutePath())
478-
.put("http.port",
479-
play.Play.application().isTest() ? "8855"
480-
: CONFIG.getString("index.es.port.http"))
481-
.put("transport.tcp.port", play.Play.application().isTest() ? "8856"
482-
: CONFIG.getString("index.es.port.tcp"))
483-
.build();
484-
node =
485-
NodeBuilder.nodeBuilder().settings(clientSettings).local(true).node();
486+
boolean isTest = play.Play.application().isTest();
487+
String httpPort = isTest ? "8855" : CONFIG.getString("index.es.port.http");
488+
String tcpPort = isTest ? "8856" : CONFIG.getString("index.es.port.tcp");
489+
node = new EmbeddedNode(Settings.builder().put("transport.type", "netty4")//
490+
.put("http.type", "netty4")//
491+
.put("http.enabled", "true")//
492+
.put("path.home", new File(".").getAbsolutePath())//
493+
.put("http.port", httpPort)//
494+
.put("transport.tcp.port", tcpPort)//
495+
.build(), Arrays.asList(Netty4Plugin.class));
496+
try {
497+
node.start();
498+
} catch (NodeValidationException e) {
499+
e.printStackTrace();
500+
}
486501
client = node.client();
487502
client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute()
488503
.actionGet();
@@ -502,8 +517,8 @@ private static void indexData(String dataUrl, Type type) {
502517
List<String> jsonLd = toJsonLd(new URL(dataUrl));
503518
for (String concept : jsonLd) {
504519
String id = Json.parse(concept).findValue("@id").textValue();
505-
IndexRequestBuilder indexRequest = client
506-
.prepareIndex(INDEX, type.elasticsearchType, id).setSource(concept);
520+
IndexRequestBuilder indexRequest = client.prepareIndex(INDEX, type.elasticsearchType, id)
521+
.setSource(concept.getBytes(), XContentType.JSON);
507522
bulkRequest.add(indexRequest);
508523
}
509524
} catch (MalformedURLException e) {
@@ -517,7 +532,11 @@ private static void indexData(String dataUrl, Type type) {
517532

518533
/** Shut down the embedded Elasticsearch classification index. */
519534
public static void indexShutdown() {
520-
node.close();
535+
try {
536+
node.close();
537+
} catch (IOException e) {
538+
e.printStackTrace();
539+
}
521540
}
522541

523542
/**

app/controllers/nwbib/Lobid.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
import java.util.stream.StreamSupport;
2121

2222
import org.apache.commons.lang3.tuple.Pair;
23-
import org.elasticsearch.common.collect.Lists;
2423

2524
import com.fasterxml.jackson.databind.JsonNode;
2625
import com.google.common.collect.ImmutableMap;
26+
import com.google.common.collect.Lists;
2727
import com.google.common.html.HtmlEscapers;
2828

2929
import controllers.nwbib.Classification.Type;

build.sbt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,28 @@ name := "rpb"
22

33
version := "0.1.1-SNAPSHOT"
44

5-
scalaVersion := "2.11.11"
5+
scalaVersion := "2.11.12"
66

77
resolvers += Resolver.mavenLocal
88

99
libraryDependencies ++= Seq(
1010
cache,
1111
javaWs,
1212
"com.typesafe.play" % "play-test_2.11" % "2.4.11",
13-
"org.metafacture" % "metafacture-elasticsearch" % "5.7.1",
14-
"org.metafacture" % "metafacture-io" % "5.7.1",
15-
"org.metafacture" % "metafacture-strings" % "5.7.1",
16-
"org.metafacture" % "metafacture-json" % "5.7.1",
17-
"org.metafacture" % "metafacture-flux" % "5.7.1",
18-
"org.metafacture" % "metafacture-triples" % "5.7.1",
19-
"org.metafacture" % "metafacture-formatting" % "5.7.1",
20-
"org.metafacture" % "metafacture-monitoring" % "5.7.1",
21-
"org.metafacture" % "metafacture-csv" % "5.7.1",
22-
"org.metafacture" % "metafix" % "0.7.1",
23-
"org.metafacture" % "metafacture-linkeddata" % "5.7.1",
24-
"org.elasticsearch" % "elasticsearch" % "1.7.5" withSources(),
13+
"org.metafacture" % "metafacture-elasticsearch" % "commit-b9eebb41b26bac5b1083b90112c0eefdc17ad25e-SNAPSHOT",
14+
"org.metafacture" % "metafacture-io" % "commit-b9eebb41b26bac5b1083b90112c0eefdc17ad25e-SNAPSHOT",
15+
"org.metafacture" % "metafacture-strings" % "commit-b9eebb41b26bac5b1083b90112c0eefdc17ad25e-SNAPSHOT",
16+
"org.metafacture" % "metafacture-json" % "commit-b9eebb41b26bac5b1083b90112c0eefdc17ad25e-SNAPSHOT",
17+
"org.metafacture" % "metafacture-flux" % "commit-b9eebb41b26bac5b1083b90112c0eefdc17ad25e-SNAPSHOT",
18+
"org.metafacture" % "metafacture-triples" % "commit-b9eebb41b26bac5b1083b90112c0eefdc17ad25e-SNAPSHOT",
19+
"org.metafacture" % "metafacture-formatting" % "commit-b9eebb41b26bac5b1083b90112c0eefdc17ad25e-SNAPSHOT",
20+
"org.metafacture" % "metafacture-monitoring" % "commit-b9eebb41b26bac5b1083b90112c0eefdc17ad25e-SNAPSHOT",
21+
"org.metafacture" % "metafacture-csv" % "commit-b9eebb41b26bac5b1083b90112c0eefdc17ad25e-SNAPSHOT",
22+
"org.metafacture" % "metafacture-linkeddata" % "commit-b9eebb41b26bac5b1083b90112c0eefdc17ad25e-SNAPSHOT",
23+
"org.metafacture" % "metafix" % "commit-b9eebb41b26bac5b1083b90112c0eefdc17ad25e-SNAPSHOT",
24+
"org.elasticsearch" % "elasticsearch" % "5.6.16" withSources(),
25+
"org.elasticsearch.plugin" % "transport-netty4-client" % "5.6.16" withSources(),
26+
"com.sun.xml.bind" % "jaxb-impl" % "2.3.3" withSources(),
2527
"com.github.jsonld-java" % "jsonld-java" % "0.5.0",
2628
"org.apache.commons" % "commons-rdf-jena" % "0.5.0",
2729
"org.apache.commons" % "commons-csv" % "1.6",
@@ -43,7 +45,7 @@ dependencyOverrides ++= Set(
4345

4446
lazy val root = (project in file(".")).enablePlugins(PlayJava)
4547

46-
javacOptions ++= Seq("-source", "1.8", "-target", "1.8")
48+
javacOptions ++= Seq("-source", "11", "-target", "11")
4749

4850
import com.typesafe.sbteclipse.core.EclipsePlugin.EclipseKeys
4951

monit_restart.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ HOME="/home/sol"
2525

2626
# it is important to set the proper locale
2727
. $HOME/.locale
28+
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/
2829
JAVA_OPTS=$(echo "$JAVA_OPTS" |sed 's#,#\ #g')
2930

3031
cd $HOME/git/$REPO
@@ -34,10 +35,15 @@ case $ACTION in
3435
kill $(cat target/universal/stage/RUNNING_PID)
3536
rm target/universal/stage/RUNNING_PID
3637
fi
37-
JAVA_OPTS="$JAVA_OPTS -XX:+ExitOnOutOfMemoryError" sbt "start $PORT"
38+
export JAVA_OPTS="$JAVA_OPTS -XX:+ExitOnOutOfMemoryError -DpreferIPv4Stack"
39+
sbt --java-home $JAVA_HOME stage >> ./target/universal/stage/logs/application.log 2>&1
40+
./target/universal/stage/bin/rpb -Dhttp.port=$PORT -no-version-check >> ./target/universal/stage/logs/application.log 2>&1
3841
;;
3942
stop)
4043
kill $(cat target/universal/stage/RUNNING_PID)
44+
sleep 14
45+
kill -9 $(cat target/universal/stage/RUNNING_PID)
46+
rm target/universal/stage/RUNNING_PID
4147
;;
4248
*)
4349
echo "usage: $USAGE"

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.13.16
1+
sbt.version=0.13.18

transformAndImportFull.sh

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,31 @@ HOST=$1
99
# Create token in Strapi admin UI (Settings > API Tokens), set here or in environment
1010
API_TOKEN=$API_TOKEN
1111

12+
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/
13+
1214
# Notationen
1315
# curl --request DELETE "http://$HOST:1337/api/rpb-notations/[1-5]"
14-
sbt "runMain rpb.ETL conf/rpb-systematik-import.flux INPUT=rpb.ndjson PATH=rpb-notations HOST=$HOST API_TOKEN=$API_TOKEN"
16+
sbt --java-home $JAVA_HOME "runMain rpb.ETL conf/rpb-systematik-import.flux INPUT=rpb.ndjson PATH=rpb-notations HOST=$HOST API_TOKEN=$API_TOKEN"
1517
# curl --request DELETE "http://$HOST:1337/api/rpb-spatials/[1-5]"
16-
sbt "runMain rpb.ETL conf/rpb-systematik-import.flux INPUT=rpb-spatial.ndjson PATH=rpb-spatials HOST=$HOST API_TOKEN=$API_TOKEN"
18+
sbt --java-home $JAVA_HOME "runMain rpb.ETL conf/rpb-systematik-import.flux INPUT=rpb-spatial.ndjson PATH=rpb-spatials HOST=$HOST API_TOKEN=$API_TOKEN"
1719
# curl --request DELETE "http://$HOST:1337/api/fachgebiete/[1-5]"
18-
sbt "runMain rpb.ETL conf/rpb-systematik-import.flux INPUT=rpb-fachgebiete.ndjson PATH=fachgebiete HOST=$HOST API_TOKEN=$API_TOKEN"
20+
sbt --java-home $JAVA_HOME "runMain rpb.ETL conf/rpb-systematik-import.flux INPUT=rpb-fachgebiete.ndjson PATH=fachgebiete HOST=$HOST API_TOKEN=$API_TOKEN"
1921

2022
# Personen
2123
# curl --request DELETE "http://$HOST:1337/api/persons/[1-5]"
22-
sbt "runMain rpb.ETL conf/rppd-to-strapi.flux IN_FILE=RPB-Export_HBZ_Bio.txt OUT_FILE=output-rppd-strapi.ndjson"
23-
sbt "runMain rpb.ETL conf/rppd-import.flux IN_FILE=output-rppd-strapi.ndjson HOST=$HOST API_TOKEN=$API_TOKEN"
24+
sbt --java-home $JAVA_HOME "runMain rpb.ETL conf/rppd-to-strapi.flux IN_FILE=RPB-Export_HBZ_Bio.txt OUT_FILE=output-rppd-strapi.ndjson"
25+
sbt --java-home $JAVA_HOME "runMain rpb.ETL conf/rppd-import.flux IN_FILE=output-rppd-strapi.ndjson HOST=$HOST API_TOKEN=$API_TOKEN"
2426

2527
# Normdaten
2628
# curl --request DELETE "http://$HOST:1337/api/rpb-authorities/[1-5]"
27-
sbt "runMain rpb.ETL conf/rpb-sw-to-strapi.flux IN_FILE=RPB-Export_HBZ_SW.txt OUT_FILE=output-sw-strapi.ndjson"
28-
sbt "runMain rpb.ETL conf/rpb-sw-import.flux IN_FILE=output-sw-strapi.ndjson HOST=$HOST API_TOKEN=$API_TOKEN"
29+
sbt --java-home $JAVA_HOME "runMain rpb.ETL conf/rpb-sw-to-strapi.flux IN_FILE=RPB-Export_HBZ_SW.txt OUT_FILE=output-sw-strapi.ndjson"
30+
sbt --java-home $JAVA_HOME "runMain rpb.ETL conf/rpb-sw-import.flux IN_FILE=output-sw-strapi.ndjson HOST=$HOST API_TOKEN=$API_TOKEN"
2931

3032
# Titeldaten
31-
sbt "runMain rpb.ETL conf/rpb-titel-to-strapi.flux"
33+
sbt --java-home $JAVA_HOME "runMain rpb.ETL conf/rpb-titel-to-strapi.flux"
3234
# curl --request DELETE "http://$HOST:1337/api/articles/[1-5]"
33-
sbt "runMain rpb.ETL conf/rpb-titel-import.flux PICK=all_equal('type','u') PATH=articles HOST=$HOST API_TOKEN=$API_TOKEN"
35+
sbt --java-home $JAVA_HOME "runMain rpb.ETL conf/rpb-titel-import.flux PICK=all_equal('type','u') PATH=articles HOST=$HOST API_TOKEN=$API_TOKEN"
3436
# curl --request DELETE "http://$HOST:1337/api/independent-works/[1-5]"
35-
sbt "runMain rpb.ETL conf/rpb-titel-import.flux PICK=all_equal('type','Monografie') PATH=independent-works HOST=$HOST API_TOKEN=$API_TOKEN"
36-
sbt "runMain rpb.ETL conf/rpb-titel-import.flux PICK=all_equal('type','Band') PATH=independent-works HOST=$HOST API_TOKEN=$API_TOKEN"
37-
sbt "runMain rpb.ETL conf/rpb-titel-import.flux PICK=all_contain('type','Mehrt') PATH=independent-works HOST=$HOST API_TOKEN=$API_TOKEN"
37+
sbt --java-home $JAVA_HOME "runMain rpb.ETL conf/rpb-titel-import.flux PICK=all_equal('type','Monografie') PATH=independent-works HOST=$HOST API_TOKEN=$API_TOKEN"
38+
sbt --java-home $JAVA_HOME "runMain rpb.ETL conf/rpb-titel-import.flux PICK=all_equal('type','Band') PATH=independent-works HOST=$HOST API_TOKEN=$API_TOKEN"
39+
sbt --java-home $JAVA_HOME "runMain rpb.ETL conf/rpb-titel-import.flux PICK=all_contain('type','Mehrt') PATH=independent-works HOST=$HOST API_TOKEN=$API_TOKEN"

0 commit comments

Comments
 (0)