Skip to content

Commit

Permalink
Include transactions and workspace identifiers in HTTP Graph Subjects.
Browse files Browse the repository at this point in the history
- use the graph subjects API extensively to create URIs
for objects.

- add an API to create a graph subject for an object that may not
exist yet (using the path instead of a node reference)
  • Loading branch information
cbeer committed Jun 17, 2013
1 parent ebc126b commit 706d838
Show file tree
Hide file tree
Showing 28 changed files with 376 additions and 97 deletions.
28 changes: 18 additions & 10 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraContent.java
Expand Up @@ -8,6 +8,8 @@

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Date;
import java.util.List;

Expand All @@ -33,8 +35,10 @@

import org.fcrepo.AbstractResource;
import org.fcrepo.Datastream;
import org.fcrepo.api.rdf.HttpGraphSubjects;
import org.fcrepo.exception.InvalidChecksumException;
import org.fcrepo.session.InjectedSession;
import org.modeshape.jcr.api.JcrConstants;
import org.slf4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -64,7 +68,7 @@ public Response create(@PathParam("path")
final String checksumType, @QueryParam("checksum")
final String checksum, @HeaderParam("Content-Type")
final MediaType requestContentType, final InputStream requestBodyStream)
throws IOException, InvalidChecksumException, RepositoryException {
throws IOException, InvalidChecksumException, RepositoryException, URISyntaxException {
final MediaType contentType =
requestContentType != null ? requestContentType
: APPLICATION_OCTET_STREAM_TYPE;
Expand All @@ -78,15 +82,18 @@ public Response create(@PathParam("path")

logger.debug("create Datastream {}", path);
try {
datastreamService.createDatastreamNode(session, path, contentType
.toString(), requestBodyStream, checksumType, checksum);
final Node datastreamNode = datastreamService.createDatastreamNode(session, path, contentType.toString(), requestBodyStream, checksumType, checksum);


final HttpGraphSubjects subjects =
new HttpGraphSubjects(FedoraNodes.class, uriInfo, session);

return created(new URI(subjects.getGraphSubject(datastreamNode.getNode(JcrConstants.JCR_CONTENT)).getURI())).build();

} finally {
session.save();
session.logout();
}
return created(
uriInfo.getBaseUriBuilder().path(FedoraContent.class).build(
path.substring(1))).build();
}

/**
Expand All @@ -109,7 +116,7 @@ public Response modifyContent(@PathParam("path")
final MediaType requestContentType, final InputStream requestBodyStream,
@Context
final Request request) throws RepositoryException, IOException,
InvalidChecksumException {
InvalidChecksumException, URISyntaxException {
try {
final String path = toPath(pathList);
final MediaType contentType =
Expand Down Expand Up @@ -142,9 +149,10 @@ public Response modifyContent(@PathParam("path")
session.save();

if (isNew) {
return created(
uriInfo.getBaseUriBuilder().path(FedoraContent.class)
.build(path.substring(1))).build();
final HttpGraphSubjects subjects =
new HttpGraphSubjects(FedoraNodes.class, uriInfo, session);

return created(new URI(subjects.getGraphSubject(datastreamNode.getNode(JcrConstants.JCR_CONTENT)).getURI())).build();
} else {
return noContent().build();
}
Expand Down
Expand Up @@ -9,6 +9,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
Expand Down Expand Up @@ -37,6 +38,7 @@

import org.fcrepo.AbstractResource;
import org.fcrepo.Datastream;
import org.fcrepo.api.rdf.HttpGraphSubjects;
import org.fcrepo.exception.InvalidChecksumException;
import org.fcrepo.session.InjectedSession;
import org.fcrepo.utils.ContentDigest;
Expand Down Expand Up @@ -78,7 +80,7 @@ public class FedoraDatastreams extends AbstractResource {
public Response modifyDatastreams(@PathParam("path")
final List<PathSegment> pathList, @QueryParam("delete")
final List<String> dsidList, final MultiPart multipart)
throws RepositoryException, IOException, InvalidChecksumException {
throws RepositoryException, IOException, InvalidChecksumException, URISyntaxException {

final String path = toPath(pathList);
try {
Expand Down Expand Up @@ -107,9 +109,12 @@ public Response modifyDatastreams(@PathParam("path")
}

session.save();
return created(
uriInfo.getAbsolutePathBuilder().path(FedoraNodes.class)
.build(path.substring(1))).build();

final HttpGraphSubjects subjects =
new HttpGraphSubjects(FedoraNodes.class, uriInfo, session);

return created(new URI(subjects.getGraphSubject(session.getNode(path)).getURI())).build();

} finally {
session.logout();
}
Expand Down
Expand Up @@ -112,7 +112,7 @@ private Dataset getSearchDataset(final String terms, final long offset,

final Dataset dataset =
nodeService.searchRepository(new HttpGraphSubjects(
FedoraNodes.class, uriInfo), searchResult, session,
FedoraNodes.class, uriInfo, session), searchResult, session,
terms, limit, offset);

final Model searchModel = createDefaultModel();
Expand Down
Expand Up @@ -61,7 +61,7 @@ public Dataset getDatastreamFixity(@PathParam("path")
datastreamService.getDatastream(session, path);

return datastreamService.getFixityResultsModel(
new HttpGraphSubjects(FedoraNodes.class, uriInfo), ds);
new HttpGraphSubjects(FedoraNodes.class, uriInfo, session), ds);
} finally {
session.logout();
}
Expand Down
Expand Up @@ -10,6 +10,7 @@
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
import static com.hp.hpl.jena.update.GraphStoreFactory.create;
import static javax.ws.rs.core.MediaType.TEXT_HTML;
import static javax.ws.rs.core.Response.created;
import static org.fcrepo.RdfLexicon.HAS_MEMBER_OF_RESULT;
import static org.fcrepo.http.RDFMediaType.N3;
import static org.fcrepo.http.RDFMediaType.N3_ALT1;
Expand All @@ -19,10 +20,12 @@
import static org.fcrepo.http.RDFMediaType.RDF_XML;
import static org.fcrepo.http.RDFMediaType.TURTLE;

import java.net.URI;
import java.util.Collection;
import java.util.List;

import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
Expand All @@ -35,6 +38,9 @@
import javax.ws.rs.core.UriInfo;

import org.fcrepo.AbstractResource;
import org.fcrepo.api.rdf.HttpGraphSubjects;
import org.fcrepo.session.InjectedSession;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.codahale.metrics.annotation.Timed;
Expand All @@ -51,9 +57,13 @@
*
*/
@Component
@Scope("prototype")
@Path("/{path: .*}/fcr:pid")
public class FedoraIdentifiers extends AbstractResource {

@InjectedSession
protected Session session;

/**
* @param numPids number of PIDs to return
* @return HTTP 200 with block of PIDs
Expand All @@ -79,27 +89,30 @@ public Dataset getNextPid(@PathParam("path")
transform(create(closed(1, numPids), integers()), pidMinter
.makePid());

final UriBuilder builder =
uriInfo.getBaseUriBuilder().path(FedoraNodes.class);
final HttpGraphSubjects subjects =
new HttpGraphSubjects(FedoraNodes.class, uriInfo, session);


for (final String identifier : identifiers) {

final String absPath;
if (path.equals("/")) {
absPath = identifier;
absPath = "/" + identifier;
} else {
absPath = path.substring(1) + "/" + identifier;
absPath = path + "/" + identifier;
}

final String s =
builder.buildFromMap(of("path", absPath)).toASCIIString();
final Resource s = subjects.getGraphSubject(absPath);

model.add(pidsResult, HAS_MEMBER_OF_RESULT, ResourceFactory
.createResource(s));
model.add(pidsResult, HAS_MEMBER_OF_RESULT, s);
}

return create(model).toDataset();

}

public void setSession(final Session session) {
this.session = session;
}

}
13 changes: 9 additions & 4 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraImport.java
Expand Up @@ -6,6 +6,8 @@

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
Expand All @@ -18,6 +20,7 @@
import javax.ws.rs.core.Response;

import org.fcrepo.AbstractResource;
import org.fcrepo.api.rdf.HttpGraphSubjects;
import org.fcrepo.exception.InvalidChecksumException;
import org.fcrepo.serialization.SerializerUtil;
import org.fcrepo.session.InjectedSession;
Expand Down Expand Up @@ -48,18 +51,20 @@ public Response importObject(@PathParam("path")
final List<PathSegment> pathList, @QueryParam("format")
@DefaultValue("jcr/xml")
final String format, final InputStream stream) throws IOException,
RepositoryException, InvalidChecksumException {
RepositoryException, InvalidChecksumException, URISyntaxException {

final String path = toPath(pathList);
logger.debug("Deserializing at {}", path);


final HttpGraphSubjects subjects =
new HttpGraphSubjects(FedoraNodes.class, uriInfo, session);

try {
serializers.getSerializer(format)
.deserialize(session, path, stream);
session.save();
return created(
uriInfo.getAbsolutePathBuilder().path(FedoraNodes.class)
.build(path.substring(1))).build();
return created(new URI(subjects.getGraphSubject(session.getNode(path)).getURI())).build();
} finally {
session.logout();
}
Expand Down
4 changes: 2 additions & 2 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraNodes.java
Expand Up @@ -106,7 +106,7 @@ public Dataset describe(@PathParam("path")
.lastModified(date).build());
}
final HttpGraphSubjects subjects =
new HttpGraphSubjects(FedoraNodes.class, uriInfo);
new HttpGraphSubjects(FedoraNodes.class, uriInfo, session);
final Dataset propertiesDataset =
resource.getPropertiesDataset(subjects, offset, limit);
addResponseInformationToDataset(resource, propertiesDataset,
Expand Down Expand Up @@ -206,7 +206,7 @@ public Response updateSparql(@PathParam("path")
nodeService.getObject(session, path);

result.updatePropertiesDataset(new HttpGraphSubjects(
FedoraNodes.class, uriInfo), IOUtils
FedoraNodes.class, uriInfo, session), IOUtils
.toString(requestBodyStream));
final Problems problems = result.getDatasetProblems();
if (problems != null && problems.hasProblems()) {
Expand Down
Expand Up @@ -7,6 +7,8 @@

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;

import javax.jcr.RepositoryException;
Expand All @@ -25,6 +27,7 @@

import org.fcrepo.AbstractResource;
import org.fcrepo.FedoraResource;
import org.fcrepo.api.rdf.HttpGraphSubjects;
import org.fcrepo.exception.InvalidChecksumException;
import org.fcrepo.session.InjectedSession;
import org.fcrepo.utils.FedoraJcrTypes;
Expand Down Expand Up @@ -61,15 +64,13 @@ public Response ingestAndMint(@PathParam("path")
final MediaType requestContentType, final InputStream requestBodyStream,
@Context
final UriInfo uriInfo) throws RepositoryException, IOException,
InvalidChecksumException {
InvalidChecksumException, URISyntaxException {
final String pid = pidMinter.mintPid();

final String path = toPath(pathList) + "/" + pid;

logger.debug("Attempting to ingest with path: {}", path);

final Session session = getAuthenticatedSession();

try {
if (nodeService.exists(session, path)) {
return Response.status(SC_CONFLICT).entity(
Expand All @@ -84,9 +85,11 @@ public Response ingestAndMint(@PathParam("path")

session.save();
logger.debug("Finished creating {} with path: {}", mixin, path);
return created(
uriInfo.getBaseUriBuilder().path(FedoraNodes.class).build(
resource.getPath().substring(1))).entity(path)

final HttpGraphSubjects subjects =
new HttpGraphSubjects(FedoraNodes.class, uriInfo, session);

return created(new URI(subjects.getGraphSubject(resource.getNode()).getURI())).entity(path)
.build();

} finally {
Expand Down
Expand Up @@ -73,7 +73,7 @@ public Response getVersionList(@PathParam("path")
return Response.ok(
new GraphStoreStreamingOutput(resource
.getVersionDataset(new HttpGraphSubjects(
FedoraNodes.class, uriInfo)),
FedoraNodes.class, uriInfo, session)),
bestPossibleResponse.getMediaType())).build();

} finally {
Expand Down Expand Up @@ -122,7 +122,7 @@ public Dataset getVersion(@PathParam("path")
} else {

return resource.getPropertiesDataset(new HttpGraphSubjects(
FedoraNodes.class, uriInfo), 0, -1);
FedoraNodes.class, uriInfo, session), 0, -1);
}

} finally {
Expand Down
Expand Up @@ -20,6 +20,8 @@
import org.apache.jena.riot.WebContent;
import org.fcrepo.AbstractResource;
import org.fcrepo.FedoraResource;
import org.fcrepo.api.FedoraNodes;
import org.fcrepo.api.rdf.HttpGraphSubjects;
import org.fcrepo.session.InjectedSession;
import org.modeshape.common.collection.Problems;
import org.slf4j.Logger;
Expand Down Expand Up @@ -58,7 +60,7 @@ public Response updateSparql(final InputStream requestBodyStream)
final FedoraResource result =
nodeService.getObject(session, "/");

result.updatePropertiesDataset(IOUtils
result.updatePropertiesDataset(new HttpGraphSubjects(FedoraNodes.class, uriInfo, session), IOUtils
.toString(requestBodyStream));
final Problems problems = result.getDatasetProblems();
if (problems != null && problems.hasProblems()) {
Expand Down

0 comments on commit 706d838

Please sign in to comment.