Skip to content

Commit

Permalink
Refactor fcr:fixity to use ContentExposingResource machinery
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Oct 31, 2014
1 parent a97d8b0 commit d55d2fd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 32 deletions.
60 changes: 36 additions & 24 deletions fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraFixity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;

import com.google.common.annotations.VisibleForTesting;
import org.fcrepo.http.commons.responses.HtmlTemplate;
import org.fcrepo.kernel.models.FedoraBinary;
import org.fcrepo.kernel.models.FedoraResource;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.springframework.context.annotation.Scope;

Expand All @@ -52,43 +49,53 @@
* @author ajs6f
* @since Jun 12, 2013
*/
@Scope("prototype")
@Scope("request")
@Path("/{path: .*}/fcr:fixity")
public class FedoraFixity extends FedoraBaseResource {
public class FedoraFixity extends ContentExposingResource {

@Inject
protected Session session;

@PathParam("path") protected String externalPath;


/**
* Default JAX-RS entry point
*/
public FedoraFixity() {
super();
}

/**
* Create a new FedoraNodes instance for a given path
* @param externalPath
*/
@VisibleForTesting
public FedoraFixity(final String externalPath) {
this.externalPath = externalPath;
}

/**
* Get the results of a fixity check for a path
*
* GET /path/to/some/datastream/fcr:fixity
*
* @param externalPath
* @param request
* @param uriInfo
* @return datastream fixity in the given format
*/
@GET
@Timed
@HtmlTemplate(value = "fcr:fixity")
@Produces({TURTLE, N3, N3_ALT2, RDF_XML, NTRIPLES, APPLICATION_XML, TEXT_PLAIN, TURTLE_X,
TEXT_HTML, APPLICATION_XHTML_XML, JSON_LD})
public RdfStream getDatastreamFixity(@PathParam("path")
final String externalPath,
@Context
final Request request,
@Context
final UriInfo uriInfo) {

final FedoraResource resource = getResourceFromPath(externalPath);

if (!(resource instanceof FedoraBinary)) {
throw new NotFoundException(resource + " is not a binary");
@Produces({TURTLE + ";qs=10", JSON_LD + ";qs=8",
N3, N3_ALT2, RDF_XML, NTRIPLES, APPLICATION_XML, TEXT_PLAIN, TURTLE_X,
TEXT_HTML, APPLICATION_XHTML_XML, "*/*"})
public RdfStream getDatastreamFixity() {

if (!(resource() instanceof FedoraBinary)) {
throw new NotFoundException(resource() + " is not a binary");
}

return ((FedoraBinary)resource).getFixity(translator())
.topic(translator().reverse().convert(resource).asNode())
return ((FedoraBinary)resource()).getFixity(translator())
.topic(translator().reverse().convert(resource()).asNode())
.session(session);

}
Expand All @@ -97,4 +104,9 @@ public RdfStream getDatastreamFixity(@PathParam("path")
protected Session session() {
return session;
}

@Override
protected String externalPath() {
return externalPath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,28 @@ public class FedoraFixityTest {
@Mock
private FedoraBinary mockBinary;

private String externalPath = "objects/FedoraDatastreamsTest1/testDS";

@Before
public void setUp() {
public void setUp() throws RepositoryException {
initMocks(this);
testObj = spy(new FedoraFixity());
testObj = spy(new FedoraFixity(externalPath));
this.uriInfo = getUriInfoImpl();
setField(testObj, "uriInfo", uriInfo);
mockSession = mockSession(testObj);
setField(testObj, "session", mockSession);
when(mockNode.getSession()).thenReturn(mockSession);
when(mockBinary.getPath()).thenReturn(externalPath);
doReturn(mockBinary).when(testObj).getResourceFromPath(externalPath);
}

@Test
public void testGetDatastreamFixity() throws RepositoryException {
final RdfStream expected = new RdfStream();
final String externalPath = "objects/FedoraDatastreamsTest1/testDS";

when(mockNode.getSession()).thenReturn(mockSession);

doReturn(mockBinary).when(testObj).getResourceFromPath(externalPath);
when(mockBinary.getFixity(any(IdentifierConverter.class))).thenReturn(expected);
when(mockBinary.getPath()).thenReturn(externalPath);

final RdfStream actual = testObj.getDatastreamFixity(externalPath, mockRequest, uriInfo);
final RdfStream actual = testObj.getDatastreamFixity();

assertEquals(expected, actual);
}
Expand Down

0 comments on commit d55d2fd

Please sign in to comment.