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

add a call to a milliner versioning endpoint for media #70

Merged
merged 1 commit into from
Sep 11, 2020
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 @@ -167,7 +167,8 @@ public void configure() {
.simple("${exchangeProperty.event.object.isNewVersion}")
//pass it to milliner
.toD(
getMillinerBaseUrl() + "version/${exchangeProperty.uuid}?connectionClose=true"
getMillinerBaseUrl() +
"node/${exchangeProperty.uuid}/version?connectionClose=true"
).endChoice();


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

// Pass it to milliner.
.toD(getMillinerBaseUrl() + "media/${exchangeProperty.sourceField}?connectionClose=true");
.toD(getMillinerBaseUrl() + "media/${exchangeProperty.sourceField}?connectionClose=true")
.choice()
.when()
.simple("${exchangeProperty.event.object.isNewVersion}")
.setHeader("Content-Location", simple(
"${exchangeProperty.jsonUrl}"))

//pass it to milliner
.toD(
getMillinerBaseUrl() +
"media/${exchangeProperty.sourceField}/version?connectionClose=true"
).endChoice();
Copy link
Contributor

@dannylamb dannylamb Sep 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funky indentation here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean because i put 'getMillinerBaseUrl....' on the next line?
i'm pretty sure it was throwing an error about the line being too long.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting the ending parenthesis before .endChoice to be aligned with .toD. Maybe that's just me.

No biggie though. It passes codestyle checks so I'm fine pulling in this now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok i can fix it


from("{{file.stream}}")
.routeId("FcrepoIndexerFile")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,24 @@ public void configure() throws Exception {
}

@Test
public void testVersion() throws Exception {
public void testNodeVersion() 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"
"http://localhost:8000/milliner/node/72358916-51e9-"
+ "4712-b756-4b0404c91b/version?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"
"mock:http:localhost:8000/milliner/"
+ "node/72358916-51e9-4712-b756-4b0404c91b/version"
);
milliner.expectedMessageCount(1);
milliner.expectedHeaderReceived("Authorization", "Bearer islandora");
Expand Down Expand Up @@ -268,4 +270,34 @@ public void configure() throws Exception {
assertMockEndpointsSatisfied();
}

@Test
public void testVersionMedia() throws Exception {
final String route = "FcrepoIndexerMedia";
context.getRouteDefinition(route).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith("direct:start");
mockEndpointsAndSkip("http://localhost:8000/milliner/media/field_media_image/"
+ "version?connectionClose=true");
}
});
context.start();

// Assert we POST the event to milliner with creds.
final MockEndpoint milliner = getMockEndpoint("mock:http:localhost:8000/milliner/media/"
+ "field_media_image/version");
milliner.expectedHeaderReceived("Authorization", "Bearer islandora");
milliner.expectedHeaderReceived("Content-Location", "http://localhost:8000/media/7?_format=json");
milliner.expectedHeaderReceived(Exchange.HTTP_METHOD, "POST");

// Send an event.
template.send(exchange -> {
exchange.getIn().setHeader("Authorization", "Bearer islandora");
exchange.getIn().setBody(IOUtils.toString(loadResourceAsStream("MediaVersionAS2Event.jsonld"), "UTF-8"),
String.class);
});

assertMockEndpointsSatisfied();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"@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:4f528a92-4be2-4a9d-85e6-c5f4d36b1bce",
"url":[
{
"name":"Canonical",
"type":"Link",
"href":"http:\/\/localhost:8000\/media\/7",
"mediaType":"text\/html",
"rel":"canonical"
},
{
"name":"JSON",
"type":"Link",
"href":"http:\/\/localhost:8000\/media\/7?_format=json",
"mediaType":"application\/json",
"rel":"alternate"
},
{
"name":"JSONLD",
"type":"Link",
"href":"http:\/\/localhost:8000\/media\/7?_format=jsonld",
"mediaType":"application\/ld+json",
"rel":"alternate"
}
],
"isNewVersion":"true"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, shoulda caught this sooner, but "isNewVersion" should be down in the "attachment" section under "content" if we want to follow the schema to the letter of the law. Not the end of the world (thank goodness the AS2 police aren't a thing), but we should probably get in alignment with the ontology. I suppose this would affect node versioning as well. It's probably a lot to address here and now, so I'll make a ticket. There'll have to be work done in the islandora module to get this in the right place.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok, i was unaware of the schema for this

},
"type":"Update",
"summary":"Update a Media",
"target":"http://localhost:8080/fcrepo/rest/media",
"attachment":{
"type":"Object",
"content":{
"source_field":"field_media_image"
},
"mediaType":"application\/json"
}
}