Commit 2d8cb9d9 authored by bseeger's avatar bseeger
Browse files

Merge branch 'update_to_jdk11' into 'master'

Update to jdk11

See merge request !103
parents 5affc003 3a963a8e
......@@ -43,16 +43,6 @@ These modules listen to repository events and react accordingly.
* [`acrepo-connector-idiomatic-pgsql`](acrepo-connector-idiomatic-pgsql): Id Mapping Service Database: This exposes a Postgres datastore for use with the Id Mapping service
* [`acrepo-connector-triplestore`](acrepo-connector-triplestore): Triplestore Indexing Service: This indexes LDP resources into named graphs in an external triplestore.
Other OSGi Features
-------------------
In addition to what is listed above, a number of Karaf features are made available to make it easier to install
sets of related bundles in an OSGi container.
* `acrepo-libs-jackson`: The [Jackson](http://wiki.fasterxml.com/JacksonHome) JSON libraries
* `acrepo-libs-jena`: The [Jena 3.x](http://jena.apache.org/) libraries
* `acrepo-libs-jsonld`: The [JSON-LD](https://github.com/jsonld-java/jsonld-java) libraries
Building
--------
......
apply plugin: 'osgi'
description = 'Message Broadcaster'
ext {
moduleName = 'edu.amherst.acdc.connector.broadcast'
}
dependencies {
compile group: 'org.apache.camel', name: 'camel-core', version: camelVersion
compile group: 'org.apache.camel', name: 'camel-blueprint', version: camelVersion
compile(group: 'org.fcrepo.camel', name: 'fcrepo-camel', version: fcrepoCamelVersion) {
exclude(module: 'slf4j-log4j12')
}
testCompile group: 'org.apache.camel', name: 'camel-test-blueprint', version: camelVersion
testCompile group: 'ch.qos.logback', name: 'logback-classic', version: logbackVersion
api("org.apache.camel:camel-core:${camelVersion}")
implementation("org.apache.camel:camel-blueprint:${camelVersion}")
testImplementation("org.apache.camel:camel-test-blueprint:${camelVersion}")
testRuntimeOnly("ch.qos.logback:logback-classic:${logbackVersion}")
testRuntimeOnly("javax.activation:javax.activation-api:${activationApiVersion}")
testRuntimeOnly("javax.xml.bind:jaxb-api:${jaxbVersion}")
}
jar {
......@@ -18,14 +25,18 @@ jar {
vendor project.vendor
license project.license
instruction 'Automatic-Module-Name', moduleName
instruction 'Import-Package', "org.apache.camel,${defaultOsgiImports}"
instruction 'Export-Package', "edu.amherst.acdc.connector.broadcast;version=${projectOsgiVersion}"
instruction 'Export-Package', "${moduleName};version=${projectOsgiVersion}"
}
}
artifacts {
archives (file('build/cfg/main/edu.amherst.acdc.connector.broadcast.cfg')) {
classifier 'configuration'
type 'cfg'
publishing.publications {
maven(MavenPublication) {
artifact ('build/cfg/main/edu.amherst.acdc.connector.broadcast.cfg') {
classifier 'configuration'
extension 'cfg'
}
}
}
group = 'edu.amherst.acdc'
description = 'ID Mapping MySQL Connector'
artifacts {
archives (file('build/cfg/main/edu.amherst.acdc.connector.idiomatic.mysql.cfg')) {
classifier 'configuration'
type 'cfg'
publishing.publications {
maven(MavenPublication) {
artifact ('build/cfg/main/edu.amherst.acdc.connector.idiomatic.mysql.cfg') {
classifier 'configuration'
extension 'cfg'
}
}
}
group = 'edu.amherst.acdc'
description = 'ID Mapping Postgresql Connector'
artifacts {
archives (file('build/cfg/main/edu.amherst.acdc.connector.idiomatic.pgsql.cfg')) {
classifier 'configuration'
type 'cfg'
publishing.publications {
maven(MavenPublication) {
artifact ('build/cfg/main/edu.amherst.acdc.connector.idiomatic.pgsql.cfg') {
classifier 'configuration'
extension 'cfg'
}
}
}
......@@ -2,23 +2,29 @@ apply plugin: 'osgi'
description = 'Camel-based service for mapping public IDs to Fedora IDs'
ext {
moduleName = 'edu.amherst.acdc.connector.idiomatic'
}
dependencies {
compile group: 'org.apache.camel', name: 'camel-core', version: camelVersion
compile group: 'org.apache.camel', name: 'camel-sql', version: camelVersion
compile group: 'org.apache.camel', name: 'camel-jetty9', version: camelVersion
compile group: 'org.apache.camel', name: 'camel-blueprint', version: camelVersion
compile(group: 'org.fcrepo.camel', name: 'fcrepo-camel', version: fcrepoCamelVersion) {
exclude(module: 'slf4j-log4j12')
}
compile group: 'org.codehaus.woodstox', name: 'woodstox-core-asl', version: woodstoxVersion
testCompile project(':acrepo-services-mint')
testCompile group: 'xerces', name: 'xercesImpl', version: xercesVersion
testCompile group: 'junit', name: 'junit', version: junitVersion
testCompile group: 'org.apache.derby', name: 'derby', version: derbyVersion
testCompile group: 'org.apache.camel', name: 'camel-test-blueprint', version: camelVersion
testCompile group: 'commons-io', name: 'commons-io', version: commonsIoVersion
testCompile group: 'ch.qos.logback', name: 'logback-classic', version: logbackVersion
api("org.apache.camel:camel-core:${camelVersion}")
implementation("org.apache.camel:camel-sql:${camelVersion}")
implementation("org.apache.camel:camel-jetty9:${camelVersion}")
implementation("org.apache.camel:camel-blueprint:${camelVersion}")
implementation("org.apache.camel:camel-jackson:${camelVersion}")
implementation("org.apache.camel:camel-http4:${camelVersion}")
implementation("org.codehaus.woodstox:woodstox-core-asl:${woodstoxVersion}")
testImplementation project(':acrepo-services-mint')
testImplementation("junit:junit:${junitVersion}")
testImplementation("org.apache.derby:derby:${derbyVersion}")
testImplementation("org.apache.camel:camel-test-blueprint:${camelVersion}")
testImplementation("commons-io:commons-io:${commonsIoVersion}")
testRuntimeOnly("ch.qos.logback:logback-classic:${logbackVersion}")
testRuntimeOnly("javax.activation:javax.activation-api:${activationApiVersion}")
testRuntimeOnly("javax.xml.bind:jaxb-api:${jaxbVersion}")
}
jar {
......@@ -27,15 +33,19 @@ jar {
docURL project.docURL
vendor project.vendor
license project.license
instruction 'Automatic-Module-Name', moduleName
instruction 'Import-Package', "org.apache.camel,org.apache.camel.component.sql,javax.sql,${defaultOsgiImports}"
instruction 'Export-Package', "edu.amherst.acdc.connector.idiomatic;version=${projectOsgiVersion}"
instruction 'Export-Package', "${moduleName};version=${projectOsgiVersion}"
}
}
artifacts {
archives (file('build/cfg/main/edu.amherst.acdc.connector.idiomatic.cfg')) {
classifier 'configuration'
type 'cfg'
publishing.publications {
maven(MavenPublication) {
artifact ('build/cfg/main/edu.amherst.acdc.connector.idiomatic.cfg') {
classifier 'configuration'
extension 'cfg'
}
}
}
......
/*
* Copyright 2016 Amherst College
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.amherst.acdc.connector.idiomatic;
import static java.util.Collections.singletonList;
import static java.util.Objects.nonNull;
import static java.util.stream.Collectors.toList;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
/**
* Converts a Fedora Message into camel-based headers.
*
* @author acoburn
*/
public class EventProcessor implements Processor {
private static final String FCREPO_AGENT = "CamelFcrepoAgent";
private static final String FCREPO_DATE_TIME = "CamelFcrepoDateTime";
private static final String FCREPO_EVENT_ID = "CamelFcrepoEventId";
private static final String FCREPO_EVENT_TYPE = "CamelFcrepoEventType";
private static final String FCREPO_RESOURCE_TYPE = "CamelFcrepoResourceType";
private static final String FCREPO_URI = "CamelFcrepoUri";
private static final Set<String> singleValuedFields = new HashSet<>();
static {
singleValuedFields.add(FCREPO_URI);
singleValuedFields.add(FCREPO_DATE_TIME);
singleValuedFields.add(FCREPO_EVENT_ID);
}
/**
* Process the Fedora message
*
* @param exchange the current camel message exchange
*/
public void process(final Exchange exchange) throws IOException {
final Map<String, List<String>> data = new HashMap<>();
data.putAll(getValuesFromMap(exchange.getIn().getBody(Map.class)));
data.entrySet().stream().filter(entry -> nonNull(entry.getValue())).filter(entry -> !entry.getValue().isEmpty())
.forEach(entry -> exchange.getIn().setHeader(entry.getKey(), getValue(entry)));
}
private static Object getValue(final Map.Entry<String, List<String>> entry) {
if (singleValuedFields.contains(entry.getKey())) {
return entry.getValue().get(0);
}
return entry.getValue();
}
@SuppressWarnings("unchecked")
private static Map<String, List<String>> getValuesFromMap(final Map body) {
final Map<String, Object> values = (Map<String, Object>)body;
final Map<String, List<String>> data = new HashMap<>();
if (values.containsKey("@id")) {
data.put(FCREPO_URI, singletonList((String)values.get("@id")));
}
if (values.containsKey("id")) {
data.putIfAbsent(FCREPO_URI, singletonList((String)values.get("id")));
}
if (values.containsKey("@type")) {
data.put(FCREPO_RESOURCE_TYPE, (List<String>)values.get("@type"));
}
if (values.containsKey("type")) {
data.putIfAbsent(FCREPO_RESOURCE_TYPE, (List<String>)values.get("type"));
}
final Map<String, Object> wasGeneratedBy = (Map<String, Object>)values.get("wasGeneratedBy");
if (wasGeneratedBy != null) {
if (wasGeneratedBy.containsKey("type")) {
data.put(FCREPO_EVENT_TYPE, (List<String>)wasGeneratedBy.get("type"));
}
data.put(FCREPO_EVENT_ID, singletonList((String)wasGeneratedBy.get("identifier")));
data.put(FCREPO_DATE_TIME, singletonList((String)wasGeneratedBy.get("atTime")));
}
final List<Map<String, String>> wasAttributedTo = (List<Map<String, String>>)values.get("wasAttributedTo");
if (wasAttributedTo != null) {
data.put(FCREPO_AGENT,
wasAttributedTo.stream().map(agent -> agent.get("name")).collect(toList()));
}
return data;
}
}
......@@ -18,15 +18,15 @@ package edu.amherst.acdc.connector.idiomatic;
import static edu.amherst.acdc.connector.idiomatic.IdiomaticHeaders.FEDORA;
import static edu.amherst.acdc.connector.idiomatic.IdiomaticHeaders.ID;
import static org.apache.camel.Exchange.HTTP_RESPONSE_CODE;
import static org.apache.camel.Exchange.HTTP_URI;
import static org.apache.camel.builder.PredicateBuilder.not;
import static org.apache.camel.model.dataformat.JsonLibrary.Jackson;
import static org.fcrepo.camel.FcrepoHeaders.FCREPO_URI;
import java.util.List;
import java.util.Map;
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
import org.fcrepo.camel.processor.EventProcessor;
/**
* A message router for handling ID mappings.
......@@ -35,6 +35,8 @@ import org.fcrepo.camel.processor.EventProcessor;
*/
public class IdRouter extends RouteBuilder {
private static final String FCREPO_URI = "CamelFcrepoUri";
/**
* Configure the message route workflow.
*/
......@@ -51,9 +53,17 @@ public class IdRouter extends RouteBuilder {
* Process a message via JMS
*/
from("{{input.stream}}").routeId("IdMappingRouter")
.unmarshal().json(Jackson, Map.class)
.process(new EventProcessor())
.log(LoggingLevel.INFO, "IdMapping Event: ${headers[CamelFcrepoUri]}")
.to("fcrepo:{{fcrepo.baseUrl}}?preferOmit=PreferContainment&accept=application/ld+json")
.to("direct:fetch");
from("direct:fetch").routeId("IdFetchResource")
.removeHeaders("CamelHttp*")
.setHeader(HTTP_URI).simple("${headers.CamelFcrepoUri}")
.setHeader("Prefer").constant("return=representation; omit=\"http://www.w3.org/ns/ldp#PreferContainment\"")
.setHeader("Accept").constant("application/ld+json")
.to("http4:localhost?username={{fcrepo.authUsername}}&password={{fcrepo.authPassword}}")
.unmarshal().json(Jackson, List.class)
.split(simple("${body}"))
.filter(simple("${body[@id]} == ${header.CamelFcrepoUri}"))
......
......@@ -17,6 +17,8 @@
<cm:property name="rest.port" value="9101"/>
<cm:property name="id.property" value="http://purl.org/dc/elements/1.1/identifier"/>
<cm:property name="fcrepo.baseUrl" value="http://localhost:8080/fcrepo/rest"/>
<cm:property name="fcrepo.authUsername" value=""/>
<cm:property name="fcrepo.authPassword" value=""/>
</cm:default-properties>
</cm:property-placeholder>
......
......@@ -15,7 +15,7 @@
*/
package edu.amherst.acdc.connector.idiomatic;
import static org.fcrepo.camel.FcrepoHeaders.FCREPO_URI;
import static org.apache.camel.util.ObjectHelper.loadResourceAsStream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
......@@ -36,9 +36,8 @@ import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.component.seda.SedaComponent;
import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
import org.apache.camel.util.KeyValueHolder;
import org.apache.camel.util.ObjectHelper;
import org.apache.derby.jdbc.EmbeddedDataSource;
import org.apache.commons.io.IOUtils;
import org.apache.derby.jdbc.EmbeddedDataSource;
import org.junit.Test;
/**
......@@ -110,8 +109,8 @@ public class RouteTest extends CamelBlueprintTestSupport {
getMockEndpoint("mock:result").expectedMessageCount(2);
template.sendBody("direct:minter", null);
template.sendBody("direct:minter", null);
template.sendBody("direct:minter", "{}");
template.sendBody("direct:minter", "{}");
final String id1 = resultEndpoint.getExchanges().get(0).getIn().getBody(String.class);
final String id2 = resultEndpoint.getExchanges().get(1).getIn().getBody(String.class);
......@@ -125,11 +124,11 @@ public class RouteTest extends CamelBlueprintTestSupport {
@Test
public void testEvent() throws Exception {
context.getRouteDefinition("IdMappingRouter").adviceWith(context, new AdviceWithRouteBuilder() {
context.getRouteDefinition("IdFetchResource").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith("direct:start");
mockEndpointsAndSkip("fcrepo*");
mockEndpointsAndSkip("http*");
mockEndpoints("direct:update");
}
});
......@@ -149,9 +148,8 @@ public class RouteTest extends CamelBlueprintTestSupport {
"http://localhost/foo/bar", "http://localhost/foo/bar");
getMockEndpoint("mock:direct:update").expectedHeaderValuesReceivedInAnyOrder(IdiomaticHeaders.ID,
"http://example.org/object/1", "http://example.org/object/2");
template.sendBodyAndHeader(
IOUtils.toString(ObjectHelper.loadResourceAsStream("indexable.json"),
"UTF-8"), FCREPO_URI, "http://localhost/foo/bar");
template.sendBodyAndHeader(IOUtils.toString(loadResourceAsStream("indexable.json"), "UTF-8"),
"CamelFcrepoUri", "http://localhost/foo/bar");
assertMockEndpointsSatisfied();
}
......
apply plugin: 'osgi'
description = 'Triplestore Indexer'
ext {
moduleName = 'edu.amherst.acdc.connector.triplestore'
}
dependencies {
compile group: 'org.apache.camel', name: 'camel-core', version: camelVersion
compile group: 'org.apache.camel', name: 'camel-http4', version: camelVersion
compile group: 'org.apache.camel', name: 'camel-blueprint', version: camelVersion
compile(group: 'org.fcrepo.camel', name: 'fcrepo-camel', version: fcrepoCamelVersion) {
exclude(module: 'slf4j-log4j12')
}
api("org.apache.camel:camel-core:${camelVersion}")
implementation("org.apache.camel:camel-http4:${camelVersion}")
implementation("org.apache.camel:camel-blueprint:${camelVersion}")
implementation("org.apache.jena:jena-osgi:${jenaVersion}")
runtimeOnly("org.apache.commons:commons-compress:${commonsCompressVersion}")
testRuntimeOnly("javax.activation:javax.activation-api:${activationApiVersion}")
testRuntimeOnly("javax.xml.bind:jaxb-api:${jaxbVersion}")
}
jar {
......@@ -17,14 +26,18 @@ jar {
vendor project.vendor
license project.license
instruction 'Import-Package', "org.apache.camel,org.fcrepo.camel,org.apache.camel.component.http4,${defaultOsgiImports}"
instruction 'Export-Package', "edu.amherst.acdc.connector.triplestore;version=${projectOsgiVersion}"
instruction 'Automatic-Module-Name', moduleName
instruction 'Import-Package', "org.apache.camel,${defaultOsgiImports}"
instruction 'Export-Package', "${moduleName};version=${projectOsgiVersion}"
}
}
artifacts {
archives (file('build/cfg/main/edu.amherst.acdc.connector.triplestore.cfg')) {
classifier 'configuration'
type 'cfg'
publishing.publications {
maven(MavenPublication) {
artifact ('build/cfg/main/edu.amherst.acdc.connector.triplestore.cfg') {
classifier 'configuration'
extension 'cfg'
}
}
}
......@@ -5,8 +5,7 @@ input.stream=broker:queue:fedora
error.maxRedeliveries=10
# Control prefer headers
prefer.omit=http://www.w3.org/ns/ldp#PreferContainment
prefer.include=
prefer.header=return=representation; omit="http://www.w3.org/ns/ldp#PreferContainment"; include=""
# The Camel URI for handling reindexing events
triplestore.reindex.stream=broker:queue:triplestore.reindex
......
/*
* Copyright 2016 Amherst College
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.amherst.acdc.connector.triplestore;
import static java.util.Collections.singletonList;
import static java.util.Objects.nonNull;
import static java.util.stream.Collectors.toList;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
/**
* Converts a Fedora Message into camel-based headers.
*
* @author acoburn
*/
public class EventProcessor implements Processor {
private static final String FCREPO_AGENT = "CamelFcrepoAgent";
private static final String FCREPO_DATE_TIME = "CamelFcrepoDateTime";
private static final String FCREPO_EVENT_ID = "CamelFcrepoEventId";
private static final String FCREPO_EVENT_TYPE = "CamelFcrepoEventType";
private static final String FCREPO_RESOURCE_TYPE = "CamelFcrepoResourceType";
private static final String FCREPO_URI = "CamelFcrepoUri";
private static final Set<String> singleValuedFields = new HashSet<>();
static {
singleValuedFields.add(FCREPO_URI);
singleValuedFields.add(FCREPO_DATE_TIME);
singleValuedFields.add(FCREPO_EVENT_ID);
}
/**
* Process the Fedora message
*
* @param exchange the current camel message exchange
*/
public void process(final Exchange exchange) throws IOException {
final Map<String, List<String>> data = new HashMap<>();
data.putAll(getValuesFromMap(exchange.getIn().getBody(Map.class)));
data.entrySet().stream().filter(entry -> nonNull(entry.getValue())).filter(entry -> !entry.getValue().isEmpty())
.forEach(entry -> exchange.getIn().setHeader(entry.getKey(), getValue(entry)));
}
private static Object getValue(final Map.Entry<String, List<String>> entry) {
if (singleValuedFields.contains(entry.getKey())) {
return entry.getValue().get(0);
}
return entry.getValue();
}
@SuppressWarnings("unchecked")
private static Map<String, List<String>> getValuesFromMap(final Map body) {
final Map<String, Object> values = (Map<String, Object>)body;
final Map<String, List<String>> data = new HashMap<>();
if (values.containsKey("@id")) {
data.put(FCREPO_URI, singletonList((String)values.get("@id")));
}
if (values.containsKey("id")) {
data.putIfAbsent(FCREPO_URI, singletonList((String)values.get("id")));
}
if (values.containsKey("@type")) {
data.put(FCREPO_RESOURCE_TYPE, (List<String>)values.get("@type"));
}
if (values.containsKey("type")) {
data.putIfAbsent(FCREPO_RESOURCE_TYPE, (List<String>)values.get("type"));
}
final Map<String, Object> wasGeneratedBy = (Map<String, Object>)values.get("wasGeneratedBy");
if (wasGeneratedBy != null) {
if (wasGeneratedBy.containsKey("type")) {
data.put(FCREPO_EVENT_TYPE, (List<String>)wasGeneratedBy.get("type"));
}
data.put(FCREPO_EVENT_ID, singletonList((String)wasGeneratedBy.get("identifier")));
data.put(FCREPO_DATE_TIME, singletonList((String)wasGeneratedBy.get("atTime")));
}
final List<Map<String, String>> wasAttributedTo = (List<Map<String, String>>)values.get("wasAttributedTo");
if (wasAttributedTo != null) {
data.put(FCREPO_AGENT,
wasAttributedTo.stream().map(agent -> agent.get("name")).collect(toList()));
}
return data;
}