Skip to content

Commit

Permalink
add HTTP Link headers for describedby/describes to link a fcr:content…
Browse files Browse the repository at this point in the history
… resource to its metadata
  • Loading branch information
cbeer committed Apr 14, 2014
1 parent 6c9cdca commit 8eefe10
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
Expand Up @@ -123,7 +123,7 @@ protected Response getDatastreamContentResponse(final Datastream ds, final Strin
return builder.type(ds.getMimeType()).header(
"Link",
subjects.getSubject(ds.getNode().getPath()) +
";rel=\"meta\"").header("Accept-Ranges",
";rel=\"describedby\"").header("Accept-Ranges",
"bytes").cacheControl(cc).lastModified(date).tag(etag)
.header("Content-Disposition", contentDisposition)
.build();
Expand Down
Expand Up @@ -219,6 +219,12 @@ public RdfStream describe(@PathParam("path") final List<PathSegment> pathList,
servletResponse.addDateHeader("Last-Modified", resource
.getLastModifiedDate().getTime());
}

if (resource.hasContent()) {
servletResponse.addHeader("Link", subjects.getSubject(
resource.getNode().getNode(JCR_CONTENT).getPath()) + ";rel=\"describes\"");
}

servletResponse.addHeader("Accept-Patch", contentTypeSPARQLUpdate);
servletResponse.addHeader("Link", LDP_NAMESPACE + "Resource;rel=\"type\"");

Expand Down
Expand Up @@ -270,7 +270,7 @@ public void testGetContent() throws RepositoryException, IOException {
verify(mockSession, never()).save();
final String actualContent =
IOUtils.toString((InputStream) actual.getEntity());
assertEquals("http://localhost/fcrepo" + path + ";rel=\"meta\"", actual
assertEquals("http://localhost/fcrepo" + path + ";rel=\"describedby\"", actual
.getMetadata().getFirst("Link"));
assertEquals("asdf", actualContent);
}
Expand Down
Expand Up @@ -255,7 +255,6 @@ public void testDeleteWithBadEtag() throws Exception {

@Test
public void testGetDatastream() throws Exception {

final String pid = UUID.randomUUID().toString();

createObject(pid);
Expand All @@ -266,6 +265,18 @@ public void testGetDatastream() throws Exception {
assertEquals(EntityUtils.toString(response.getEntity()), 200, response
.getStatusLine().getStatusCode());
assertEquals(TURTLE, response.getFirstHeader("Content-Type").getValue());

final Collection<String> links =
map(response.getHeaders("Link"), new Function<Header, String>() {

@Override
public String apply(final Header h) {
return h.getValue();
}
});
assertTrue("Didn't find 'describes' link header!",
links.contains(serverAddress + pid + "/ds1/fcr:content;rel=\"describes\""));

}

@Test
Expand Down

0 comments on commit 8eefe10

Please sign in to comment.