Skip to content

Commit 762a433

Browse files
authored
add a call to a milliner versioning endpoint for media (#70)
1 parent f4af9b9 commit 762a433

File tree

3 files changed

+102
-5
lines changed

3 files changed

+102
-5
lines changed

islandora-indexing-fcrepo/src/main/java/ca/islandora/alpaca/indexing/fcrepo/FcrepoIndexer.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ public void configure() {
167167
.simple("${exchangeProperty.event.object.isNewVersion}")
168168
//pass it to milliner
169169
.toD(
170-
getMillinerBaseUrl() + "version/${exchangeProperty.uuid}?connectionClose=true"
170+
getMillinerBaseUrl() +
171+
"node/${exchangeProperty.uuid}/version?connectionClose=true"
171172
).endChoice();
172173

173174

@@ -225,7 +226,18 @@ public void configure() {
225226
.setBody(simple("${null}"))
226227

227228
// Pass it to milliner.
228-
.toD(getMillinerBaseUrl() + "media/${exchangeProperty.sourceField}?connectionClose=true");
229+
.toD(getMillinerBaseUrl() + "media/${exchangeProperty.sourceField}?connectionClose=true")
230+
.choice()
231+
.when()
232+
.simple("${exchangeProperty.event.object.isNewVersion}")
233+
.setHeader("Content-Location", simple(
234+
"${exchangeProperty.jsonUrl}"))
235+
236+
//pass it to milliner
237+
.toD(
238+
getMillinerBaseUrl() +
239+
"media/${exchangeProperty.sourceField}/version?connectionClose=true"
240+
).endChoice();
229241

230242
from("{{file.stream}}")
231243
.routeId("FcrepoIndexerFile")

islandora-indexing-fcrepo/src/test/java/ca/islandora/alpaca/indexing/fcrepo/FcrepoIndexerTest.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,24 @@ public void configure() throws Exception {
8989
}
9090

9191
@Test
92-
public void testVersion() throws Exception {
92+
public void testNodeVersion() throws Exception {
9393
final String route = "FcrepoIndexerNode";
9494
context.getRouteDefinition(route).adviceWith(context, new AdviceWithRouteBuilder() {
9595
@Override
9696
public void configure() throws Exception {
9797
replaceFromWith("direct:start");
9898
mockEndpointsAndSkip(
99-
"http://localhost:8000/milliner/version/72358916-51e9-4712-b756-4b0404c91b?connectionClose=true"
99+
"http://localhost:8000/milliner/node/72358916-51e9-"
100+
+ "4712-b756-4b0404c91b/version?connectionClose=true"
100101
);
101102
}
102103
});
103104
context.start();
104105

105106
// Assert we POST to milliner with creds.
106107
final MockEndpoint milliner = getMockEndpoint(
107-
"mock:http:localhost:8000/milliner/version/72358916-51e9-4712-b756-4b0404c91b"
108+
"mock:http:localhost:8000/milliner/"
109+
+ "node/72358916-51e9-4712-b756-4b0404c91b/version"
108110
);
109111
milliner.expectedMessageCount(1);
110112
milliner.expectedHeaderReceived("Authorization", "Bearer islandora");
@@ -268,4 +270,34 @@ public void configure() throws Exception {
268270
assertMockEndpointsSatisfied();
269271
}
270272

273+
@Test
274+
public void testVersionMedia() throws Exception {
275+
final String route = "FcrepoIndexerMedia";
276+
context.getRouteDefinition(route).adviceWith(context, new AdviceWithRouteBuilder() {
277+
@Override
278+
public void configure() throws Exception {
279+
replaceFromWith("direct:start");
280+
mockEndpointsAndSkip("http://localhost:8000/milliner/media/field_media_image/"
281+
+ "version?connectionClose=true");
282+
}
283+
});
284+
context.start();
285+
286+
// Assert we POST the event to milliner with creds.
287+
final MockEndpoint milliner = getMockEndpoint("mock:http:localhost:8000/milliner/media/"
288+
+ "field_media_image/version");
289+
milliner.expectedHeaderReceived("Authorization", "Bearer islandora");
290+
milliner.expectedHeaderReceived("Content-Location", "http://localhost:8000/media/7?_format=json");
291+
milliner.expectedHeaderReceived(Exchange.HTTP_METHOD, "POST");
292+
293+
// Send an event.
294+
template.send(exchange -> {
295+
exchange.getIn().setHeader("Authorization", "Bearer islandora");
296+
exchange.getIn().setBody(IOUtils.toString(loadResourceAsStream("MediaVersionAS2Event.jsonld"), "UTF-8"),
297+
String.class);
298+
});
299+
300+
assertMockEndpointsSatisfied();
301+
}
302+
271303
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"@context":"https:\/\/www.w3.org\/ns\/activitystreams",
3+
"actor":{
4+
"type":"Person",
5+
"id":"urn:uuid:9029a0c0-d845-4ddd-864c-2198d45839da",
6+
"url":[
7+
{
8+
"name":"Canonical",
9+
"type":"Link",
10+
"href":"http:\/\/localhost:8000\/user\/1",
11+
"mediaType":"text\/html",
12+
"rel":"canonical"
13+
}
14+
]
15+
},
16+
"object":{
17+
"id":"urn:uuid:4f528a92-4be2-4a9d-85e6-c5f4d36b1bce",
18+
"url":[
19+
{
20+
"name":"Canonical",
21+
"type":"Link",
22+
"href":"http:\/\/localhost:8000\/media\/7",
23+
"mediaType":"text\/html",
24+
"rel":"canonical"
25+
},
26+
{
27+
"name":"JSON",
28+
"type":"Link",
29+
"href":"http:\/\/localhost:8000\/media\/7?_format=json",
30+
"mediaType":"application\/json",
31+
"rel":"alternate"
32+
},
33+
{
34+
"name":"JSONLD",
35+
"type":"Link",
36+
"href":"http:\/\/localhost:8000\/media\/7?_format=jsonld",
37+
"mediaType":"application\/ld+json",
38+
"rel":"alternate"
39+
}
40+
],
41+
"isNewVersion":"true"
42+
},
43+
"type":"Update",
44+
"summary":"Update a Media",
45+
"target":"http://localhost:8080/fcrepo/rest/media",
46+
"attachment":{
47+
"type":"Object",
48+
"content":{
49+
"source_field":"field_media_image"
50+
},
51+
"mediaType":"application\/json"
52+
}
53+
}

0 commit comments

Comments
 (0)