Skip to content

Commit

Permalink
Merge pull request #60 from futures/graph-subjects
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed May 16, 2013
2 parents 4075e2c + 7b80be2 commit 35fdbdb
Show file tree
Hide file tree
Showing 24 changed files with 627 additions and 169 deletions.
Expand Up @@ -27,7 +27,11 @@ public void testJcrPropertiesBasedOaiDc() throws Exception {
final HttpPost post = postObjMethod("DublinCoreTest1");
post.setHeader("Content-Type", "application/sparql-update");
BasicHttpEntity entity = new BasicHttpEntity();
entity.setContent(new ByteArrayInputStream("INSERT { <info:fedora/objects/DublinCoreTest1> <http://purl.org/dc/terms/identifier> \"this is an identifier\" } WHERE {}".getBytes()));
String subjectURI = serverAddress + "objects/DublinCoreTest1";
entity.setContent(new ByteArrayInputStream(
("INSERT { <" + subjectURI +
"> <http://purl.org/dc/terms/identifier> \"this is an identifier\" } WHERE {}")
.getBytes()));
post.setEntity(entity);
assertEquals(204, getStatus( post));
final HttpGet getWorstCaseOaiMethod =
Expand Down
63 changes: 35 additions & 28 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraNodes.java
@@ -1,7 +1,6 @@

package org.fcrepo.api;

import static javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM_TYPE;
import static javax.ws.rs.core.Response.created;
import static javax.ws.rs.core.Response.noContent;
import static javax.ws.rs.core.Response.ok;
Expand Down Expand Up @@ -41,14 +40,14 @@
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.core.Variant;

import org.apache.commons.io.IOUtils;
import org.apache.http.HttpStatus;
import org.apache.jena.riot.WebContent;
import org.fcrepo.AbstractResource;
import org.fcrepo.FedoraObject;
import org.fcrepo.FedoraResource;
import org.fcrepo.api.rdf.HttpGraphSubjects;
import org.fcrepo.exception.InvalidChecksumException;
import org.fcrepo.provider.GraphStreamingOutput;
import org.fcrepo.services.DatastreamService;
Expand All @@ -68,15 +67,16 @@
public class FedoraNodes extends AbstractResource {

private static final Logger logger = getLogger(FedoraNodes.class);

@Autowired
private LowLevelStorageService llStoreService;

@Autowired
private LowLevelStorageService llStoreService;
@GET
@Produces({N3, N3_ALT1, N3_ALT2, TURTLE, RDF_XML, RDF_JSON, NTRIPLES})
public Response describeRdf(@PathParam("path")
final List<PathSegment> pathList, @Context
final Request request) throws RepositoryException, IOException {
public Response describeRdf(
@PathParam("path") final List<PathSegment> pathList,
@Context final Request request,
@Context UriInfo uriInfo) throws RepositoryException, IOException {

final String path = toPath(pathList);
logger.trace("Getting profile for {}", path);
Expand All @@ -98,8 +98,9 @@ public Response describeRdf(@PathParam("path")

if (builder == null) {
builder =
ok(new GraphStreamingOutput(resource.getGraphStore(),
bestPossibleResponse.getMediaType()));
ok(new GraphStreamingOutput(resource.getGraphStore(
new HttpGraphSubjects(FedoraNodes.class, uriInfo)),
bestPossibleResponse.getMediaType()));
}

final CacheControl cc = new CacheControl();
Expand All @@ -124,8 +125,10 @@ public Response describeRdf(@PathParam("path")
@PUT
@Consumes({contentTypeSPARQLUpdate})
@Timed
public Response modifyObject(@PathParam("path")
final List<PathSegment> pathList, final InputStream requestBodyStream)
public Response modifyObject(
@PathParam("path") final List<PathSegment> pathList,
@Context UriInfo uriInfo,
final InputStream requestBodyStream)
throws RepositoryException, IOException {
final Session session = getAuthenticatedSession();
final String path = toPath(pathList);
Expand All @@ -137,7 +140,7 @@ public Response modifyObject(@PathParam("path")

if (requestBodyStream != null) {
UpdateAction.parseExecute(IOUtils.toString(requestBodyStream),
result.getGraphStore());
result.getGraphStore(new HttpGraphSubjects(FedoraNodes.class, uriInfo)));
}
session.save();

Expand All @@ -159,8 +162,9 @@ public Response modifyObject(@PathParam("path")
@POST
@Consumes({contentTypeSPARQLUpdate})
@Timed
public Response updateSparql(@PathParam("path")
final List<PathSegment> pathList, final InputStream requestBodyStream)
public Response updateSparql(
@PathParam("path") final List<PathSegment> pathList,
@Context UriInfo uriInfo, final InputStream requestBodyStream)
throws RepositoryException, IOException {

final String path = toPath(pathList);
Expand All @@ -175,7 +179,8 @@ public Response updateSparql(@PathParam("path")
final FedoraResource result =
nodeService.getObject(session, path);

result.updateGraph(IOUtils.toString(requestBodyStream));
result.updateGraph(new HttpGraphSubjects(FedoraNodes.class, uriInfo),
IOUtils.toString(requestBodyStream));
final Problems problems = result.getGraphProblems();
if (problems != null && problems.hasProblems()) {
logger.info(
Expand Down Expand Up @@ -210,13 +215,14 @@ public Response updateSparql(@PathParam("path")
*/
@POST
@Timed
public Response createObject(@PathParam("path")
final List<PathSegment> pathList, @QueryParam("mixin")
@DefaultValue(FedoraJcrTypes.FEDORA_OBJECT)
final String mixin, @QueryParam("checksumType")
final String checksumType, @QueryParam("checksum")
final String checksum, @HeaderParam("Content-Type")
final MediaType requestContentType, final InputStream requestBodyStream)
public Response createObject(
@PathParam("path") final List<PathSegment> pathList,
@QueryParam("mixin") @DefaultValue(FedoraJcrTypes.FEDORA_OBJECT) final String mixin,
@QueryParam("checksumType") final String checksumType,
@QueryParam("checksum") final String checksum,
@HeaderParam("Content-Type") final MediaType requestContentType,
@Context UriInfo uriInfo,
final InputStream requestBodyStream)
throws RepositoryException, IOException, InvalidChecksumException {

final String path = toPath(pathList);
Expand All @@ -230,7 +236,7 @@ public Response createObject(@PathParam("path")
path + " is an existing resource").build();
}

createObjectOrDatastreamFromRequestContent(session, path, mixin, requestBodyStream, requestContentType, checksumType, checksum);
createObjectOrDatastreamFromRequestContent(FedoraNodes.class, session, path, mixin, uriInfo, requestBodyStream, requestContentType, checksumType, checksum);

session.save();
logger.debug("Finished creating {} with path: {}", mixin, path);
Expand All @@ -250,8 +256,9 @@ public Response createObject(@PathParam("path")
*/
@DELETE
@Timed
public Response deleteObject(@PathParam("path")
final List<PathSegment> path) throws RepositoryException {
public Response deleteObject(
@PathParam("path") final List<PathSegment> path)
throws RepositoryException {
final Session session = getAuthenticatedSession();

try {
Expand Down
Expand Up @@ -15,9 +15,11 @@
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

import org.apache.http.HttpStatus;
import org.fcrepo.AbstractResource;
Expand Down Expand Up @@ -45,7 +47,7 @@ public Response ingestAndMint(@PathParam("path") final List<PathSegment> pathLis
@QueryParam("checksumType") final String checksumType,
@QueryParam("checksum") final String checksum,
@HeaderParam("Content-Type") final MediaType requestContentType,
final InputStream requestBodyStream) throws RepositoryException, IOException, InvalidChecksumException {
final InputStream requestBodyStream, @Context UriInfo uriInfo) throws RepositoryException, IOException, InvalidChecksumException {
final String pid = pidMinter.mintPid();

String path = toPath(pathList) + "/" + pid;
Expand All @@ -59,7 +61,7 @@ public Response ingestAndMint(@PathParam("path") final List<PathSegment> pathLis
return Response.status(HttpStatus.SC_CONFLICT).entity(path + " is an existing resource").build();
}

createObjectOrDatastreamFromRequestContent(session, path, mixin, requestBodyStream, requestContentType, checksumType, checksum);
createObjectOrDatastreamFromRequestContent(FedoraNodes.class, session, path, mixin, uriInfo, requestBodyStream, requestContentType, checksumType, checksum);

session.save();
logger.debug("Finished creating {} with path: {}", mixin, path);
Expand Down
26 changes: 17 additions & 9 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraVersions.java
Expand Up @@ -25,10 +25,12 @@
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.core.Variant;

import org.fcrepo.AbstractResource;
import org.fcrepo.FedoraResource;
import org.fcrepo.api.rdf.HttpGraphSubjects;
import org.fcrepo.provider.GraphStreamingOutput;
import org.slf4j.Logger;
import org.springframework.stereotype.Component;
Expand All @@ -41,8 +43,10 @@ public class FedoraVersions extends AbstractResource {

@GET
@Produces({N3, N3_ALT1, N3_ALT2, TURTLE, RDF_XML, RDF_JSON, NTRIPLES})
public Response getVersionList(@PathParam("path")
final List<PathSegment> pathList, @Context Request request) throws RepositoryException {
public Response getVersionList(
@PathParam("path") final List<PathSegment> pathList,
@Context Request request,
@Context UriInfo uriInfo) throws RepositoryException {
final String path = toPath(pathList);

LOGGER.trace("getting versions list for {}", path);
Expand All @@ -53,8 +57,9 @@ public Response getVersionList(@PathParam("path")
try {
final FedoraResource resource = nodeService.getObject(session, path);

return Response.ok(new GraphStreamingOutput(resource.getVersionGraphStore(),
bestPossibleResponse.getMediaType())).build();
return Response.ok(new GraphStreamingOutput(
resource.getVersionGraphStore(new HttpGraphSubjects(FedoraNodes.class, uriInfo)),
bestPossibleResponse.getMediaType())).build();

} finally {
session.logout();
Expand Down Expand Up @@ -82,9 +87,11 @@ public Response addVersionLabel(@PathParam("path")
@Path("/{versionLabel}")
@GET
@Produces({N3, N3_ALT1, N3_ALT2, TURTLE, RDF_XML, RDF_JSON, NTRIPLES})
public Response getVersion(@PathParam("path")
final List<PathSegment> pathList, @PathParam("versionLabel")
final String versionLabel, @Context Request request) throws RepositoryException, IOException {
public Response getVersion(
@PathParam("path") final List<PathSegment> pathList,
@PathParam("versionLabel") final String versionLabel,
@Context Request request,
@Context UriInfo uriInfo) throws RepositoryException, IOException {
final String path = toPath(pathList);
LOGGER.trace("getting version profile for {} at version {}", path, versionLabel);

Expand All @@ -98,8 +105,9 @@ public Response getVersion(@PathParam("path")
return Response.status(Response.Status.NOT_FOUND).build();
} else {

return Response.ok(new GraphStreamingOutput(resource.getGraphStore(),
bestPossibleResponse.getMediaType())).build();
return Response.ok(new GraphStreamingOutput(
resource.getGraphStore(new HttpGraphSubjects(FedoraNodes.class, uriInfo)),
bestPossibleResponse.getMediaType())).build();
}

} finally {
Expand Down
Expand Up @@ -2,6 +2,7 @@

import org.apache.http.HttpStatus;
import org.fcrepo.AbstractResource;
import org.fcrepo.api.FedoraNodes;
import org.fcrepo.exception.InvalidChecksumException;
import org.fcrepo.utils.FedoraJcrTypes;
import org.slf4j.Logger;
Expand All @@ -14,8 +15,10 @@
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.io.IOException;
import java.io.InputStream;

Expand All @@ -38,7 +41,7 @@ public Response ingestAndMint(
@QueryParam("checksumType") final String checksumType,
@QueryParam("checksum") final String checksum,
@HeaderParam("Content-Type") final MediaType requestContentType,
final InputStream requestBodyStream) throws RepositoryException, IOException, InvalidChecksumException {
final InputStream requestBodyStream, @Context UriInfo uriInfo) throws RepositoryException, IOException, InvalidChecksumException {
final String pid = pidMinter.mintPid();

String path = "/" + pid;
Expand All @@ -52,7 +55,7 @@ public Response ingestAndMint(
return Response.status(HttpStatus.SC_CONFLICT).entity(path + " is an existing resource").build();
}

createObjectOrDatastreamFromRequestContent(session, path, mixin, requestBodyStream, requestContentType, checksumType, checksum);
createObjectOrDatastreamFromRequestContent(FedoraNodes.class, session, path, mixin, uriInfo, requestBodyStream, requestContentType, checksumType, checksum);

session.save();
logger.debug("Finished creating {} with path: {}", mixin, path);
Expand Down
Expand Up @@ -35,6 +35,7 @@
import org.fcrepo.FedoraObject;
import org.fcrepo.exception.InvalidChecksumException;
import org.fcrepo.identifiers.UUIDPidMinter;
import org.fcrepo.rdf.GraphSubjects;
import org.fcrepo.services.DatastreamService;
import org.fcrepo.services.LowLevelStorageService;
import org.fcrepo.services.NodeService;
Expand Down Expand Up @@ -102,7 +103,7 @@ public void testIngestAndMint() throws RepositoryException {
@Test
public void testModify() throws RepositoryException, IOException {
final String pid = "testObject";
final Response actual = testObj.modifyObject(createPathList(pid), null);
final Response actual = testObj.modifyObject(createPathList(pid), TestHelpers.getUriInfoImpl(), null);
assertNotNull(actual);
assertEquals(Status.NO_CONTENT.getStatusCode(), actual.getStatus());
// this verify will fail when modify is actually implemented, thus encouraging the unit test to be updated appropriately.
Expand All @@ -118,7 +119,7 @@ public void testCreateObject() throws RepositoryException, IOException,
final String path = "/" + pid;
final Response actual =
testObj.createObject(createPathList(pid),
FedoraJcrTypes.FEDORA_OBJECT, null, null, null, null);
FedoraJcrTypes.FEDORA_OBJECT, null, null, null, TestHelpers.getUriInfoImpl(), null);
assertNotNull(actual);
assertEquals(Status.CREATED.getStatusCode(), actual.getStatus());
assertTrue(actual.getEntity().toString().endsWith(pid));
Expand All @@ -144,7 +145,7 @@ public void testCreateDatastream() throws RepositoryException, IOException,
final Response actual =
testObj.createObject(createPathList(pid, dsId),
FedoraJcrTypes.FEDORA_DATASTREAM, null, null, null,
dsContentStream);
TestHelpers.getUriInfoImpl(), dsContentStream);
assertEquals(Status.CREATED.getStatusCode(), actual.getStatus());
verify(mockDatastreams).createDatastreamNode(any(Session.class),
eq(dsPath), anyString(), any(InputStream.class), anyString(),
Expand Down Expand Up @@ -178,7 +179,7 @@ public void testDescribeRdfObject() throws RepositoryException, IOException {
when(mockDataset.getDefaultModel()).thenReturn(mockModel);

when(mockObject.getLastModifiedDate()).thenReturn(new Date());
when(mockObject.getGraphStore()).thenReturn(mockStore);
when(mockObject.getGraphStore(any(GraphSubjects.class))).thenReturn(mockStore);
when(mockNodes.getObject(mockSession, path)).thenReturn(mockObject);
final Request mockRequest = mock(Request.class);

Expand All @@ -188,7 +189,7 @@ public void testDescribeRdfObject() throws RepositoryException, IOException {

final OutputStream mockStream = mock(OutputStream.class);
((StreamingOutput) testObj
.describeRdf(createPathList(pid), mockRequest).getEntity())
.describeRdf(createPathList(pid), mockRequest, TestHelpers.getUriInfoImpl()).getEntity())
.write(mockStream);

verify(mockModel).write(mockStream, "N-TRIPLES");
Expand Down Expand Up @@ -220,7 +221,7 @@ public void testDescribeRdfCached() throws RepositoryException, IOException {
when(mockRequest.evaluatePreconditions(any(Date.class))).thenReturn(
Response.notModified());
final Response actual =
testObj.describeRdf(createPathList(pid), mockRequest);
testObj.describeRdf(createPathList(pid), mockRequest, TestHelpers.getUriInfoImpl());
assertNotNull(actual);
assertEquals(Status.NOT_MODIFIED.getStatusCode(), actual.getStatus());
verify(mockSession, never()).save();
Expand All @@ -238,9 +239,9 @@ public void testSparqlUpdate() throws RepositoryException, IOException {
new ByteArrayInputStream("my-sparql-statement".getBytes());
when(mockNodes.getObject(mockSession, path)).thenReturn(mockObject);

testObj.updateSparql(createPathList(pid), mockStream);
testObj.updateSparql(createPathList(pid), TestHelpers.getUriInfoImpl(), mockStream);

verify(mockObject).updateGraph("my-sparql-statement");
verify(mockObject).updateGraph(any(GraphSubjects.class), eq("my-sparql-statement"));
verify(mockSession).save();
verify(mockSession).logout();
}
Expand Down
Expand Up @@ -15,6 +15,8 @@
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;

import org.fcrepo.exception.InvalidChecksumException;
import org.fcrepo.identifiers.UUIDPidMinter;
Expand Down Expand Up @@ -59,7 +61,7 @@ public void testIngestAndMint() throws RepositoryException, IOException,

final Response actual =
testObj.ingestAndMint(createPathList("objects"),
FedoraJcrTypes.FEDORA_OBJECT, null, null, null, null);
FedoraJcrTypes.FEDORA_OBJECT, null, null, null, null, TestHelpers.getUriInfoImpl());
assertNotNull(actual);
assertEquals(Response.Status.CREATED.getStatusCode(), actual.getStatus());
assertTrue(actual.getEntity().toString().endsWith("uuid-123"));
Expand Down
Expand Up @@ -56,7 +56,7 @@ public void testIngestAndMint() throws RepositoryException, IOException,
when(mockMint.mintPid()).thenReturn("uuid-123");

final Response actual =
testObj.ingestAndMint(FedoraJcrTypes.FEDORA_OBJECT, null, null, null, null);
testObj.ingestAndMint(FedoraJcrTypes.FEDORA_OBJECT, null, null, null, null, TestHelpers.getUriInfoImpl());
assertNotNull(actual);
assertEquals(Response.Status.CREATED.getStatusCode(), actual.getStatus());
assertTrue(actual.getEntity().toString().endsWith("uuid-123"));
Expand Down

0 comments on commit 35fdbdb

Please sign in to comment.