diff --git a/islandora-connector-derivative/src/main/java/ca/islandora/alpaca/connector/derivative/event/AS2Object.java b/islandora-connector-derivative/src/main/java/ca/islandora/alpaca/connector/derivative/event/AS2Object.java index 86a20b42..47936432 100644 --- a/islandora-connector-derivative/src/main/java/ca/islandora/alpaca/connector/derivative/event/AS2Object.java +++ b/islandora-connector-derivative/src/main/java/ca/islandora/alpaca/connector/derivative/event/AS2Object.java @@ -70,5 +70,4 @@ public void setUrl(final AS2Url[] url) { private String type; private String id; private AS2Url[] url; - } diff --git a/islandora-indexing-fcrepo/src/main/java/ca/islandora/alpaca/indexing/fcrepo/FcrepoIndexer.java b/islandora-indexing-fcrepo/src/main/java/ca/islandora/alpaca/indexing/fcrepo/FcrepoIndexer.java index c87864c1..6d0534bf 100644 --- a/islandora-indexing-fcrepo/src/main/java/ca/islandora/alpaca/indexing/fcrepo/FcrepoIndexer.java +++ b/islandora-indexing-fcrepo/src/main/java/ca/islandora/alpaca/indexing/fcrepo/FcrepoIndexer.java @@ -31,10 +31,12 @@ import org.apache.camel.http.common.HttpOperationFailedException; import org.apache.camel.model.dataformat.JsonLibrary; import org.slf4j.Logger; +// import com.fasterxml.jackson.annotation.JsonIgnoreProperties; /** * @author Danny Lamb */ +// @JsonIgnoreProperties(ignoreUnknown = true) public class FcrepoIndexer extends RouteBuilder { /** @@ -118,7 +120,6 @@ public void configure() { LOGGER, "Error indexing resource in fcrepo: ${exception.message}\n\n${exception.stacktrace}" ); - from("{{node.stream}}") .routeId("FcrepoIndexerNode") @@ -135,9 +136,18 @@ public void configure() { .setHeader(Exchange.HTTP_METHOD, constant("POST")) .setHeader("Content-Location", simple("${exchangeProperty.jsonldUrl}")) .setBody(simple("${null}")) + .multicast().parallelProcessing() + //pass it to milliner + .toD(getMillinerBaseUrl() + "node/${exchangeProperty.uuid}?connectionClose=true") + .choice() + .when() + .simple("${exchangeProperty.event.object.isNewVersion}") + //pass it to milliner + .toD( + getMillinerBaseUrl() + "version/${exchangeProperty.uuid}?connectionClose=true" + ).endChoice(); + - // Pass it to milliner. - .toD(getMillinerBaseUrl() + "node/${exchangeProperty.uuid}?connectionClose=true"); from("{{node.delete.stream}}") .routeId("FcrepoIndexerDeleteNode") diff --git a/islandora-indexing-fcrepo/src/main/java/ca/islandora/alpaca/indexing/fcrepo/event/AS2Object.java b/islandora-indexing-fcrepo/src/main/java/ca/islandora/alpaca/indexing/fcrepo/event/AS2Object.java index 0441ebd4..f71fc2b5 100644 --- a/islandora-indexing-fcrepo/src/main/java/ca/islandora/alpaca/indexing/fcrepo/event/AS2Object.java +++ b/islandora-indexing-fcrepo/src/main/java/ca/islandora/alpaca/indexing/fcrepo/event/AS2Object.java @@ -17,6 +17,7 @@ */ package ca.islandora.alpaca.indexing.fcrepo.event; +import com.fasterxml.jackson.annotation.JsonProperty; /** * POJO for a user performing an action. Part of a AS2Event. @@ -67,8 +68,23 @@ public void setUrl(final AS2Url[] url) { this.url = url; } + /** + * @return true or false + */ + @JsonProperty(value = "isNewVersion") + public Boolean getIsNewVersion() { + return isNewVersion; + } + + /** + * @param isNewVersion true or false + */ + public void setIsNewVersion(final Boolean isNewVersion) { + this.isNewVersion = isNewVersion; + } + private String type; private String id; private AS2Url[] url; - + private Boolean isNewVersion; } diff --git a/islandora-indexing-fcrepo/src/test/java/ca/islandora/alpaca/indexing/fcrepo/FcrepoIndexerTest.java b/islandora-indexing-fcrepo/src/test/java/ca/islandora/alpaca/indexing/fcrepo/FcrepoIndexerTest.java index 690a6c01..11ea5e3c 100644 --- a/islandora-indexing-fcrepo/src/test/java/ca/islandora/alpaca/indexing/fcrepo/FcrepoIndexerTest.java +++ b/islandora-indexing-fcrepo/src/test/java/ca/islandora/alpaca/indexing/fcrepo/FcrepoIndexerTest.java @@ -87,6 +87,40 @@ public void configure() throws Exception { assertMockEndpointsSatisfied(); } + @Test + public void testVersion() throws Exception { + final String route = "FcrepoIndexerNode"; + context.getRouteDefinition(route).adviceWith(context, new AdviceWithRouteBuilder() { + @Override + public void configure() throws Exception { + replaceFromWith("direct:start"); + mockEndpointsAndSkip( + "http://localhost:8000/milliner/version/72358916-51e9-4712-b756-4b0404c91b?connectionClose=true" + ); + } + }); + context.start(); + + // Assert we POST to milliner with creds. + final MockEndpoint milliner = getMockEndpoint( + "mock:http:localhost:8000/milliner/version/72358916-51e9-4712-b756-4b0404c91b" + ); + milliner.expectedMessageCount(1); + milliner.expectedHeaderReceived("Authorization", "Bearer islandora"); + milliner.expectedHeaderReceived("Content-Location", "http://localhost:8000/node/2?_format=jsonld"); + milliner.expectedHeaderReceived(Exchange.HTTP_METHOD, "POST"); + + // Send an event. + template.send(exchange -> { + exchange.getIn().setHeader("Authorization", "Bearer islandora"); + exchange.getIn().setBody( + IOUtils.toString(loadResourceAsStream("VersionAS2Event.jsonld"), "UTF-8"), + String.class); + }); + + assertMockEndpointsSatisfied(); + } + @Test public void testNodeDelete() throws Exception { final String route = "FcrepoIndexerDeleteNode"; diff --git a/islandora-indexing-fcrepo/src/test/resources/VersionAS2Event.jsonld b/islandora-indexing-fcrepo/src/test/resources/VersionAS2Event.jsonld new file mode 100644 index 00000000..5ebf7b37 --- /dev/null +++ b/islandora-indexing-fcrepo/src/test/resources/VersionAS2Event.jsonld @@ -0,0 +1,45 @@ +{ + "@context":"https:\/\/www.w3.org\/ns\/activitystreams", + "actor":{ + "type":"Person", + "id":"urn:uuid:9029a0c0-d845-4ddd-864c-2198d45839da", + "url":[ + { + "name":"Canonical", + "type":"Link", + "href":"http:\/\/localhost:8000\/user\/1", + "mediaType":"text\/html", + "rel":"canonical" + } + ] + }, + "object":{ + "id":"urn:uuid:72358916-51e9-4712-b756-4b0404c91b", + "url":[ + { + "name":"Canonical", + "type":"Link", + "href":"http:\/\/localhost:8000\/node\/2", + "mediaType":"text\/html", + "rel":"canonical" + }, + { + "name":"JSON", + "type":"Link", + "href":"http:\/\/localhost:8000\/node\/2?_format=json", + "mediaType":"application\/json", + "rel":"alternate" + }, + { + "name":"JSONLD", + "type":"Link", + "href":"http:\/\/localhost:8000\/node\/2?_format=jsonld", + "mediaType":"application\/ld+json", + "rel":"alternate" + } + ], + "isNewVersion":"true" + }, + "type":"Update", + "summary":"Update a Node" +}