Skip to content
Permalink
Browse files

Merge pull request #60 from futures/graph-subjects

  • Loading branch information...
cbeer committed May 16, 2013
2 parents 4075e2c + 7b80be2 commit 35fdbdb7be2eb3a019be46dd216fd42cfbc3d033
Showing with 627 additions and 169 deletions.
  1. +5 −1 fcrepo-generator-dc/src/test/java/org/fcrepo/integration/generator/DublinCoreGeneratorIT.java
  2. +35 −28 fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraNodes.java
  3. +4 −2 fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraUnnamedObjects.java
  4. +17 −9 fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraVersions.java
  5. +5 −2 fcrepo-http-api/src/main/java/org/fcrepo/api/repository/FedoraRepositoryUnnamedObjects.java
  6. +9 −8 fcrepo-http-api/src/test/java/org/fcrepo/api/FedoraNodesTest.java
  7. +3 −1 fcrepo-http-api/src/test/java/org/fcrepo/api/FedoraUnnamedObjectsTest.java
  8. +1 −1 fcrepo-http-api/src/test/java/org/fcrepo/api/repository/FedoraRepositoryUnnamedObjectsTest.java
  9. +7 −5 fcrepo-http-api/src/test/java/org/fcrepo/integration/api/FedoraDatastreamsIT.java
  10. +19 −12 fcrepo-http-api/src/test/java/org/fcrepo/integration/api/FedoraNodesIT.java
  11. +4 −3 fcrepo-http-api/src/test/java/org/fcrepo/integration/api/FedoraRepositoryIT.java
  12. +7 −3 fcrepo-http-commons/src/main/java/org/fcrepo/AbstractResource.java
  13. +95 −0 fcrepo-http-commons/src/main/java/org/fcrepo/api/rdf/HttpGraphSubjects.java
  14. +113 −0 fcrepo-http-commons/src/test/java/org/fcrepo/api/rdf/HttpGraphSubjectsTest.java
  15. +1 −1 fcrepo-http-commons/src/test/java/org/fcrepo/test/util/TestHelpers.java
  16. +36 −14 fcrepo-kernel/src/main/java/org/fcrepo/FedoraResource.java
  17. +33 −0 fcrepo-kernel/src/main/java/org/fcrepo/rdf/GraphSubjects.java
  18. +56 −0 fcrepo-kernel/src/main/java/org/fcrepo/rdf/impl/DefaultGraphSubjects.java
  19. +1 −0 fcrepo-kernel/src/main/java/org/fcrepo/spring/ModeShapeRepositoryFactoryBean.java
  20. +10 −5 fcrepo-kernel/src/main/java/org/fcrepo/utils/JcrPropertyStatementListener.java
  21. +44 −51 fcrepo-kernel/src/main/java/org/fcrepo/utils/JcrRdfTools.java
  22. +77 −0 fcrepo-kernel/src/test/java/org/fcrepo/rdf/impl/DefaultGraphSubjectsTest.java
  23. +27 −14 fcrepo-kernel/src/test/java/org/fcrepo/utils/JcrPropertyStatementListenerTest.java
  24. +18 −9 fcrepo-kernel/src/test/java/org/fcrepo/utils/JcrRdfToolsTest.java
@@ -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 =
@@ -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;
@@ -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;
@@ -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);
@@ -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();
@@ -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);
@@ -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();

@@ -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);
@@ -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(
@@ -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);
@@ -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);
@@ -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 {
@@ -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;
@@ -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;
@@ -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);
@@ -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;
@@ -41,8 +43,10 @@

@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);
@@ -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();
@@ -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);

@@ -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 {
@@ -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;
@@ -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;

@@ -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;
@@ -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);
@@ -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;
@@ -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.
@@ -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));
@@ -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(),
@@ -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);

@@ -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");
@@ -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();
@@ -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();
}
@@ -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;
@@ -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"));
@@ -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"));
Oops, something went wrong.

0 comments on commit 35fdbdb

Please sign in to comment.
You can’t perform that action at this time.