Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass event type as event header to milliner #61

Merged
merged 14 commits into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,4 @@ public void setUrl(final AS2Url[] url) {
private String type;
private String id;
private AS2Url[] url;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down Expand Up @@ -118,7 +120,6 @@ public void configure() {
LOGGER,
"Error indexing resource in fcrepo: ${exception.message}\n\n${exception.stacktrace}"
);

from("{{node.stream}}")
.routeId("FcrepoIndexerNode")

Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}