Skip to content

Commit

Permalink
change signature of graph subjects to accept a session on method invo…
Browse files Browse the repository at this point in the history
…cation, not constructor
  • Loading branch information
cbeer committed Jul 12, 2013
1 parent ce228cb commit d86fdba
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 46 deletions.
Expand Up @@ -120,7 +120,7 @@ public Response create(
checksumURI);

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

return created(
new URI(subjects.getGraphSubject(
Expand Down Expand Up @@ -188,8 +188,7 @@ public Response modifyContent(

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

return created(
new URI(subjects.getGraphSubject(
Expand Down
Expand Up @@ -132,7 +132,7 @@ public Response modifyDatastreams(@PathParam("path")
session.save();

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

return created(
new URI(subjects.getGraphSubject(session.getNode(path))
Expand Down
Expand Up @@ -164,7 +164,7 @@ private Dataset getSearchDataset(final String terms, final long offset,

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

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

return datastreamService.getFixityResultsModel(
new HttpGraphSubjects(FedoraNodes.class, uriInfo, session),
new HttpGraphSubjects(FedoraNodes.class, uriInfo),
ds);
} finally {
session.logout();
Expand Down
Expand Up @@ -102,10 +102,10 @@ public Dataset getNextPid(@PathParam("path")

final Collection<String> identifiers =
transform(create(closed(1, numPids), integers()), pidMinter
.makePid());
.makePid());

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

for (final String identifier : identifiers) {

Expand All @@ -116,7 +116,7 @@ public Dataset getNextPid(@PathParam("path")
absPath = path + "/" + identifier;
}

final Resource s = subjects.getGraphSubject(absPath);
final Resource s = subjects.getGraphSubject(session, absPath);

model.add(pidsResult, HAS_MEMBER_OF_RESULT, s);
}
Expand Down
Expand Up @@ -92,7 +92,7 @@ public Response importObject(@PathParam("path")
logger.debug("Deserializing at {}", path);

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

try {
serializers.getSerializer(format)
Expand Down
4 changes: 2 additions & 2 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraNodes.java
Expand Up @@ -147,7 +147,7 @@ public Dataset describe(@PathParam("path")
.lastModified(date).build());
}
final HttpGraphSubjects subjects =
new HttpGraphSubjects(FedoraNodes.class, uriInfo, session);
new HttpGraphSubjects(FedoraNodes.class, uriInfo);
final Dataset propertiesDataset =
resource.getPropertiesDataset(subjects, offset, limit);
addResponseInformationToDataset(resource, propertiesDataset,
Expand Down Expand Up @@ -252,7 +252,7 @@ public Response updateSparql(@PathParam("path")
nodeService.getObject(session, path);

Dataset properties = result.updatePropertiesDataset(new HttpGraphSubjects(
FedoraNodes.class, uriInfo, session), IOUtils
FedoraNodes.class, uriInfo), IOUtils
.toString(requestBodyStream));
Model problems = properties.getNamedModel(PROBLEMS_MODEL_NAME);
if (problems.size() > 0) {
Expand Down
Expand Up @@ -119,7 +119,7 @@ public Response ingestAndMint(
logger.debug("Finished creating {} with path: {}", mixin, path);

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

return created(
new URI(subjects.getGraphSubject(resource.getNode())
Expand Down
Expand Up @@ -103,7 +103,7 @@ public Response getVersionList(@PathParam("path")
return Response.ok(
new GraphStoreStreamingOutput(resource
.getVersionDataset(new HttpGraphSubjects(
FedoraNodes.class, uriInfo, session)),
FedoraNodes.class, uriInfo)),
bestPossibleResponse.getMediaType())).build();

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

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

} finally {
Expand Down
Expand Up @@ -82,7 +82,7 @@ public Response updateSparql(final InputStream requestBodyStream)
nodeService.getObject(session, "/");

Dataset dataset = result.updatePropertiesDataset(new HttpGraphSubjects(
FedoraNodes.class, uriInfo, session), IOUtils
FedoraNodes.class, uriInfo), IOUtils
.toString(requestBodyStream));
if (dataset.containsNamedModel(GraphProperties.PROBLEMS_MODEL_NAME)) {
Model problems = dataset.getNamedModel(GraphProperties.PROBLEMS_MODEL_NAME);
Expand Down
Expand Up @@ -53,8 +53,6 @@ public class HttpGraphSubjects implements GraphSubjects {

private final int pathIx;

private final Session session;

/**
* Build HTTP graph subjects relative to the given JAX-RS resource, using the UriInfo provided.
*
Expand All @@ -63,10 +61,8 @@ public class HttpGraphSubjects implements GraphSubjects {
*
* @param relativeTo
* @param uris
* @param session
*/
public HttpGraphSubjects(final Class<?> relativeTo, final UriInfo uris,
final Session session) {
public HttpGraphSubjects(final Class<?> relativeTo, final UriInfo uris) {
this.nodesBuilder = uris.getBaseUriBuilder().path(relativeTo);
String basePath = nodesBuilder.build("").toString();
if (!basePath.endsWith("/")) {
Expand All @@ -76,21 +72,10 @@ public HttpGraphSubjects(final Class<?> relativeTo, final UriInfo uris,
this.pathIx = basePath.length() - 1;
LOGGER.debug("Resolving graph subjects to a base URI of \"{}\"",
basePath);
this.session = session;
}

/**
* Build HTTP graphs to resources relative to the given JAX-RS resource
* @param relativeTo
* @param uris
*/
public HttpGraphSubjects(final Class<?> relativeTo, final UriInfo uris) {
this(relativeTo, uris, null);

}

@Override
public Resource getGraphSubject(final String absPath)
public Resource getGraphSubject(final Session session, final String absPath)
throws RepositoryException {
final URI result =
nodesBuilder.buildFromMap(getPathMap(session, absPath));
Expand All @@ -100,7 +85,7 @@ public Resource getGraphSubject(final String absPath)

@Override
public Resource getGraphSubject(final Node node) throws RepositoryException {
final URI result = nodesBuilder.buildFromMap(getPathMap(session, node));
final URI result = nodesBuilder.buildFromMap(getPathMap(node));
LOGGER.debug("Translated node {} into RDF subject {}", node, result);
return ResourceFactory.createResource(result.toString());
}
Expand Down Expand Up @@ -176,12 +161,12 @@ public boolean isFedoraGraphSubject(final Resource subject) {
return subject.isURIResource() && subject.getURI().startsWith(basePath);
}

private static Map<String, String> getPathMap(final Session session,
final Node node) throws RepositoryException {
return getPathMap(session, node.getPath());
private Map<String, String> getPathMap(final Node node)
throws RepositoryException {
return getPathMap(node.getSession(), node.getPath());
}

private static Map<String, String> getPathMap(final Session session,
private Map<String, String> getPathMap(final Session session,
final String absPath) throws RepositoryException {
// the path param value doesn't start with a slash
String path = absPath.substring(1);
Expand Down
Expand Up @@ -63,8 +63,7 @@ public void setUp() {
initMocks(this);
final UriInfo uris = getUriInfoImpl(testPath);
testObj =
new HttpGraphSubjects(MockNodeController.class, uris,
mockSession);
new HttpGraphSubjects(MockNodeController.class, uris);
}

@Test
Expand Down
Expand Up @@ -54,9 +54,11 @@ Node getNodeFromGraphSubject(final Session session, final Resource subject)
/**
* Get the RDF resource for an absolute path
*
*
* @param session
* @param absPath the absolute path to the JCR node
* @return an RDF URI resource
* @throws RepositoryException
*/
Resource getGraphSubject(String absPath) throws RepositoryException;
Resource getGraphSubject(final Session session, final String absPath) throws RepositoryException;
}
Expand Up @@ -39,7 +39,7 @@ public class DefaultGraphSubjects implements GraphSubjects {


@Override
public Resource getGraphSubject(String absPath) throws RepositoryException {
public Resource getGraphSubject(final Session session, final String absPath) throws RepositoryException {
if (absPath.endsWith(JcrConstants.JCR_CONTENT)) {
return ResourceFactory
.createResource("info:fedora" +
Expand All @@ -51,12 +51,12 @@ public Resource getGraphSubject(String absPath) throws RepositoryException {
}

@Override
public Resource getGraphSubject(Node node) throws RepositoryException {
return getGraphSubject(node.getPath());
public Resource getGraphSubject(final Node node) throws RepositoryException {
return getGraphSubject(node.getSession(), node.getPath());
}

@Override
public Node getNodeFromGraphSubject(Session session, Resource subject)
public Node getNodeFromGraphSubject(final Session session, final Resource subject)
throws RepositoryException {
if (!isFedoraGraphSubject(subject)) {
return null;
Expand All @@ -76,7 +76,7 @@ public Node getNodeFromGraphSubject(Session session, Resource subject)
}

@Override
public boolean isFedoraGraphSubject(Resource subject) {
public boolean isFedoraGraphSubject(final Resource subject) {
checkArgument(subject != null, "null cannot be a Fedora object!");
assert(subject != null);

Expand Down

0 comments on commit d86fdba

Please sign in to comment.