Skip to content
Permalink
Browse files

Enable transparent hierarchy support for versions, locks, import, exp…

…ort, batch, and fixity etc.

Resolves: https://www.pivotaltracker.com/story/show/71946314
  • Loading branch information...
lsitu authored and awoods committed Jul 6, 2014
1 parent ab5139c commit 4c9625e100469d12e9f3c9684ffa79bc25d987ba
Showing with 214 additions and 54 deletions.
  1. +4 −1 fcrepo-auth-roles-common/src/main/java/org/fcrepo/auth/roles/common/AccessRolesResources.java
  2. +4 −5 fcrepo-auth-roles-common/src/test/java/org/fcrepo/auth/roles/common/AccessRolesResourcesTest.java
  3. +8 −9 fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraBatch.java
  4. +9 −2 fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraExport.java
  5. +12 −5 fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraFixity.java
  6. +6 −4 fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraImport.java
  7. +23 −7 fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraLocks.java
  8. +30 −8 fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraVersions.java
  9. +6 −6 fcrepo-http-api/src/main/java/org/fcrepo/http/api/url/HttpApiResources.java
  10. +3 −3 ...o-http-api/src/main/java/org/fcrepo/http/api/versioning/VersionAwareHttpIdentifierTranslator.java
  11. +11 −0 fcrepo-http-api/src/test/java/org/fcrepo/http/api/FedoraBatchTest.java
  12. +11 −0 fcrepo-http-api/src/test/java/org/fcrepo/http/api/FedoraExportTest.java
  13. +11 −0 fcrepo-http-api/src/test/java/org/fcrepo/http/api/FedoraFixityTest.java
  14. +11 −0 fcrepo-http-api/src/test/java/org/fcrepo/http/api/FedoraImportTest.java
  15. +11 −0 fcrepo-http-api/src/test/java/org/fcrepo/http/api/FedoraLocksTest.java
  16. +11 −0 fcrepo-http-api/src/test/java/org/fcrepo/http/api/FedoraVersionsTest.java
  17. +1 −0 fcrepo-http-api/src/test/java/org/fcrepo/http/api/versioning/VersionAwareHttpGraphSubjectsTest.java
  18. +7 −2 fcrepo-http-commons/src/main/java/org/fcrepo/http/commons/api/rdf/HttpIdentifierTranslator.java
  19. +7 −0 fcrepo-http-commons/src/test/java/org/fcrepo/http/commons/api/rdf/HttpIdentifierTranslatorTest.java
  20. +9 −2 fcrepo-kernel-api/src/main/java/org/fcrepo/kernel/FedoraResource.java
  21. +6 −0 fcrepo-kernel-api/src/main/java/org/fcrepo/kernel/rdf/IdentifierTranslator.java
  22. +8 −0 fcrepo-kernel/src/main/java/org/fcrepo/kernel/FedoraResourceImpl.java
  23. +5 −0 fcrepo-kernel/src/main/java/org/fcrepo/kernel/rdf/impl/DefaultIdentifierTranslator.java
@@ -56,8 +56,11 @@ public Model createModelForResource(final FedoraResource resource,

if (resource.getNode().isNodeType(
FedoraJcrTypes.FEDORA_RESOURCE)) {
if (resource.getPath(graphSubjects) == null) {
throw new RepositoryException("resource.getPath(graphSubjects) is Null: " + resource.getPath());
}
final Map<String, String> pathMap =
singletonMap("path", resource.getPath().substring(1));
singletonMap("path", resource.getPath(graphSubjects).substring(1));
final Resource acl = model.createResource(uriInfo.getBaseUriBuilder().path(
AccessRoles.class).buildFromMap(pathMap).toASCIIString());
model.add(s, RdfLexicon.HAS_ACCESS_ROLES_SERVICE, acl);
@@ -27,10 +27,10 @@
import javax.jcr.RepositoryException;
import javax.ws.rs.core.UriInfo;

import org.fcrepo.http.commons.api.rdf.HttpIdentifierTranslator;
import org.fcrepo.jcr.FedoraJcrTypes;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.RdfLexicon;
import org.fcrepo.kernel.rdf.IdentifierTranslator;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Matchers;
@@ -48,7 +48,7 @@
public class AccessRolesResourcesTest {

@Mock
private IdentifierTranslator graphSubjects;
private HttpIdentifierTranslator graphSubjects;

@Mock
private FedoraResource fedoraResource;
@@ -99,12 +99,11 @@ public void testCreateModelForNonFedoraResource()

@Test
public void testCreateModelForResource() throws RepositoryException {

when(resourceNode.isNodeType(eq(FedoraJcrTypes.FEDORA_RESOURCE)))
.thenReturn(true);

when(fedoraResource.getPath()).thenReturn("/" + pathString);

when(resourceNode.getPath()).thenReturn("/" + pathString);
when(fedoraResource.getPath(graphSubjects)).thenReturn("/" + pathString);
final Model model =
resources.createModelForResource(fedoraResource, uriInfo,
graphSubjects);
@@ -16,6 +16,7 @@
package org.fcrepo.http.api;

import static com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
import static com.sun.jersey.api.Responses.notAcceptable;
import static java.nio.charset.StandardCharsets.UTF_8;
import static javax.ws.rs.core.MediaType.MULTIPART_FORM_DATA;
@@ -151,10 +152,14 @@ public Response batchModify(@PathParam("path") final List<PathSegment> pathList,
throws RepositoryException, InvalidChecksumException, IOException, URISyntaxException {

final String path = toPath(pathList);
final HttpIdentifierTranslator subjects =
new HttpIdentifierTranslator(session, FedoraNodes.class, uriInfo);
final String jcrPath = getJCRPath(createResource(uriInfo.getBaseUri() + path), subjects);
LOGGER.trace("GET: Using auto hierarchy path {} to retrieve resource.", jcrPath);

// TODO: this is ugly, but it works.
final PathFactory pathFactory = new ExecutionContext().getValueFactories().getPathFactory();
final org.modeshape.jcr.value.Path jcrPath = pathFactory.create(path);
final org.modeshape.jcr.value.Path jcrPathObj = pathFactory.create(jcrPath);

try {

@@ -222,14 +227,11 @@ public Response batchModify(@PathParam("path") final List<PathSegment> pathList,
pathName = partName;
}

final String objPath = pathFactory.create(jcrPath, pathName).getCanonicalPath().getString();
final String objPath = pathFactory.create(jcrPathObj, pathName).getCanonicalPath().getString();

switch (realContentDisposition) {
case INLINE:

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

final FedoraResource resource;

if (nodeService.exists(session, objPath)) {
@@ -293,10 +295,7 @@ public Response batchModify(@PathParam("path") final List<PathSegment> pathList,
versionService.nodeUpdated(resource.getNode());
}

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

return created(new URI(subjects.getSubject(path).getURI())).build();
return created(new URI(subjects.getSubject(path).getURI())).build();

} finally {
session.logout();
@@ -15,6 +15,7 @@
*/
package org.fcrepo.http.api;

import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
import static javax.ws.rs.core.Response.ok;
import static org.slf4j.LoggerFactory.getLogger;

@@ -35,6 +36,7 @@
import javax.ws.rs.core.StreamingOutput;

import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.http.commons.api.rdf.HttpIdentifierTranslator;
import org.fcrepo.http.commons.session.InjectedSession;
import org.fcrepo.serialization.FedoraObjectSerializer;
import org.fcrepo.serialization.SerializerUtil;
@@ -68,15 +70,20 @@
* @param pathList
* @param format
* @return object in the given format
* @throws RepositoryException
*/
@GET
public Response exportObject(
@PathParam("path") final List<PathSegment> pathList,
@QueryParam("format") @DefaultValue("jcr/xml") final String format) {
@QueryParam("format") @DefaultValue("jcr/xml") final String format) throws RepositoryException {

final String path = toPath(pathList);

LOGGER.debug("Requested object serialization for {} using serialization format {}", path, format);
final HttpIdentifierTranslator subjects =
new HttpIdentifierTranslator(session, FedoraNodes.class, uriInfo);
final String jcrPath = getJCRPath(createResource(uriInfo.getBaseUri() + path), subjects);
LOGGER.trace("GET: Using auto hierarchy path {} to retrieve resource.", jcrPath);

final FedoraObjectSerializer serializer =
serializers.getSerializer(format);
@@ -92,7 +99,7 @@ public void write(final OutputStream out)
LOGGER.debug("Selecting from serializer map: {}", serializers);
LOGGER.debug("Retrieved serializer for format: {}", format);
serializer.serialize(objectService.getObject(
session, path), out);
session, jcrPath), out);
LOGGER.debug("Successfully serialized object: {}", path);
} catch (final RepositoryException e) {
throw new WebApplicationException(e);
@@ -25,6 +25,8 @@
import static org.fcrepo.http.commons.domain.RDFMediaType.RDF_XML;
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE;
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE_X;
import static org.slf4j.LoggerFactory.getLogger;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;

import java.util.List;

@@ -44,6 +46,7 @@
import org.fcrepo.http.commons.session.InjectedSession;
import org.fcrepo.kernel.Datastream;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.slf4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@@ -60,6 +63,8 @@
@Path("/{path: .*}/fcr:fixity")
public class FedoraFixity extends AbstractResource {

private static final Logger LOGGER = getLogger(FedoraFixity.class);

@InjectedSession
protected Session session;

@@ -86,12 +91,14 @@ public RdfStream getDatastreamFixity(@PathParam("path")
final UriInfo uriInfo) throws RepositoryException {

final String path = toPath(pathList);
LOGGER.trace("Getting datastream fixity profile path {}", path);
final HttpIdentifierTranslator subjects =
new HttpIdentifierTranslator(session, FedoraNodes.class, uriInfo);
final String jcrPath = getJCRPath(createResource(uriInfo.getBaseUri() + path), subjects);
LOGGER.trace("GET: Using auto hierarchy path {} to retrieve resource.", jcrPath);

final Datastream ds = datastreamService.getDatastream(session, path);

return datastreamService.getFixityResultsModel(
new HttpIdentifierTranslator(session, FedoraNodes.class, uriInfo), ds)
.session(session);
final Datastream ds = datastreamService.getDatastream(session, jcrPath);
return datastreamService.getFixityResultsModel(subjects, ds).session(session);

}
}
@@ -15,6 +15,7 @@
*/
package org.fcrepo.http.api;

import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
import static javax.ws.rs.core.Response.created;
import static javax.ws.rs.core.Response.Status.CONFLICT;
import static javax.ws.rs.core.Response.status;
@@ -91,13 +92,14 @@ public Response importObject(@PathParam("path") final List<PathSegment> pathList

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

final String jcrPath = getJCRPath(createResource(uriInfo.getBaseUri() + path), subjects);
LOGGER.trace("GET: Using auto hierarchy path {} to retrieve resource.", jcrPath);
try {
serializers.getSerializer(format)
.deserialize(session, path, stream);
.deserialize(session, jcrPath, stream);
session.save();
return created(new URI(subjects.getSubject(path).getURI())).build();
} catch ( ItemExistsException ex ) {
return created(new URI(subjects.getSubject(jcrPath).getURI())).build();
} catch ( final ItemExistsException ex ) {
return status(CONFLICT).entity("Item already exists").build();
} finally {
session.logout();
@@ -49,6 +49,7 @@
import static com.hp.hpl.jena.graph.NodeFactory.createLiteral;
import static com.hp.hpl.jena.graph.NodeFactory.createURI;
import static com.hp.hpl.jena.graph.Triple.create;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
import static javax.ws.rs.core.MediaType.APPLICATION_XHTML_XML;
import static javax.ws.rs.core.MediaType.APPLICATION_XML;
import static javax.ws.rs.core.MediaType.TEXT_HTML;
@@ -89,8 +90,13 @@
public RdfStream getLock(@PathParam("path") final List<PathSegment> pathList) throws RepositoryException {

final String path = toPath(pathList);
final Node node = session.getNode(path);
final Lock lock = lockService.getLock(session, path);
LOGGER.trace("Getting lock profile for: {}", path);
final HttpIdentifierTranslator subjects =
new HttpIdentifierTranslator(session, FedoraNodes.class, uriInfo);
final String jcrPath = getJCRPath(createResource(uriInfo.getBaseUri() + path), subjects);
LOGGER.trace("GET: Using auto hierarchy path {} to retrieve resource.", jcrPath);
final Node node = session.getNode(jcrPath);
final Lock lock = lockService.getLock(session, jcrPath);
return getLockRdfStream(node, lock);
}

@@ -108,11 +114,16 @@ public Response createLock(@PathParam("path") final List<PathSegment> pathList,
throws RepositoryException, URISyntaxException {
try {
final String path = toPath(pathList);
final Node node = session.getNode(path);
final Lock lock = lockService.acquireLock(session, path, isDeep);
LOGGER.trace("Creating lock for: {}", path);
final HttpIdentifierTranslator subjects =
new HttpIdentifierTranslator(session, FedoraNodes.class, uriInfo);
final String jcrPath = getJCRPath(createResource(uriInfo.getBaseUri() + path), subjects);
LOGGER.trace("GET: Using auto hierarchy path {} to retrieve resource.", jcrPath);
final Node node = session.getNode(jcrPath);
final Lock lock = lockService.acquireLock(session, jcrPath, isDeep);
session.save();
final String location = getTranslator().getSubject(node.getPath()).getURI();
LOGGER.debug("Locked {} with lock token {}.", path, lock.getLockToken());
LOGGER.debug("Locked {} with lock token {}.", jcrPath, lock.getLockToken());
return created(new URI(location)).entity(location).header("Lock-Token", lock.getLockToken()).build();
} finally {
session.logout();
@@ -130,9 +141,14 @@ public Response deleteLock(@PathParam("path") final List<PathSegment> pathList)
throws RepositoryException, URISyntaxException {
try {
final String path = toPath(pathList);
lockService.releaseLock(session, path);
LOGGER.trace("Deleting lock for: {}", path);
final HttpIdentifierTranslator subjects =
new HttpIdentifierTranslator(session, FedoraNodes.class, uriInfo);
final String jcrPath = getJCRPath(createResource(uriInfo.getBaseUri() + path), subjects);
LOGGER.trace("GET: Using auto hierarchy path {} to retrieve resource.", jcrPath);
lockService.releaseLock(session, jcrPath);
session.save();
LOGGER.debug("Unlocked {}.", path);
LOGGER.debug("Unlocked {}.", jcrPath);
return noContent().build();
} finally {
session.logout();
@@ -54,6 +54,7 @@
import java.util.Collections;
import java.util.List;

import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
import static javax.ws.rs.core.MediaType.APPLICATION_XHTML_XML;
import static javax.ws.rs.core.MediaType.APPLICATION_XML;
import static javax.ws.rs.core.MediaType.TEXT_HTML;
@@ -107,14 +108,18 @@ public RdfStream getVersionList(@PathParam("path") final List<PathSegment> pathL
@Context final UriInfo uriInfo) throws RepositoryException {
final String path = toPath(pathList);

LOGGER.trace("Getting versions list for: {}", path);
LOGGER.info("Getting versions list for: {}", path);
final HttpIdentifierTranslator subjects =
new HttpIdentifierTranslator(session, FedoraNodes.class, uriInfo);
final String jcrPath = getJCRPath(createResource(uriInfo.getBaseUri() + path), subjects);
LOGGER.info("GET: Using auto hierarchy path {} to retrieve resource.", jcrPath);

final FedoraResource resource = nodeService.getObject(session, path);
final FedoraResource resource = nodeService.getObject(session, jcrPath);

try {
return resource.getVersionTriples(nodeTranslator()).session(session).topic(
nodeTranslator().getSubject(resource.getNode().getPath()).asNode());
} catch ( UnsupportedRepositoryOperationException ex ) {
} catch ( final UnsupportedRepositoryOperationException ex ) {
throw new WebApplicationException( status(NOT_FOUND).entity("This resource is not versioned").build() );
}
}
@@ -153,8 +158,12 @@ public Response revertToVersion(@PathParam("path") final List<PathSegment> pathL
final String path = toPath(pathList);
LOGGER.info("Reverting {} to version {}.", path,
label);
final HttpIdentifierTranslator subjects =
new HttpIdentifierTranslator(session, FedoraNodes.class, uriInfo);
final String jcrPath = getJCRPath(createResource(uriInfo.getBaseUri() + path), subjects);
LOGGER.info("GET: Using auto hierarchy path {} to retrieve resource.", jcrPath);
try {
versionService.revertToVersion(session.getWorkspace(), path, label);
versionService.revertToVersion(session.getWorkspace(), jcrPath, label);
return noContent().build();
} finally {
session.logout();
@@ -174,10 +183,14 @@ public Response removeVersion(@PathParam("path") final List<PathSegment> pathLis
@PathParam("label") final String label) throws RepositoryException {
final String path = toPath(pathList);
LOGGER.info("Removing {} version {}.", path, label);
final HttpIdentifierTranslator subjects =
new HttpIdentifierTranslator(session, FedoraNodes.class, uriInfo);
final String jcrPath = getJCRPath(createResource(uriInfo.getBaseUri() + path), subjects);
LOGGER.info("GET: Using auto hierarchy path {} to retrieve resource.", jcrPath);
try {
versionService.removeVersion(session.getWorkspace(), path, label);
versionService.removeVersion(session.getWorkspace(), jcrPath, label);
return noContent().build();
} catch ( VersionException ex ) {
} catch ( final VersionException ex ) {
return status(BAD_REQUEST).entity(ex.getMessage()).build();
} finally {
session.logout();
@@ -196,10 +209,15 @@ public Response addVersion(@PathParam("path")

private Response addVersion(final String path, final String label) throws RepositoryException {
try {
LOGGER.info("Adding {} version {}.", path, label);
final HttpIdentifierTranslator subjects =
new HttpIdentifierTranslator(session, FedoraNodes.class, uriInfo);
final String jcrPath = getJCRPath(createResource(uriInfo.getBaseUri() + path), subjects);
LOGGER.info("GET: Using auto hierarchy path {} to retrieve resource.", jcrPath);
final FedoraResource resource =
nodeService.getObject(session, path);
nodeService.getObject(session, jcrPath);
versionService.createVersion(session.getWorkspace(),
Collections.singleton(path));
Collections.singleton(jcrPath));
if (label != null) {
resource.addVersionLabel(label);
}
@@ -235,6 +253,10 @@ public RdfStream getVersion(@PathParam("path")
final String path = toPath(pathList);
LOGGER.trace("Getting version profile for: {} at version: {}", path,
label);
final HttpIdentifierTranslator subjects =
new HttpIdentifierTranslator(session, this.getClass(), uriInfo);
final String jcrPath = getJCRPath(createResource(uriInfo.getBaseUri() + path), subjects);
LOGGER.trace("GET: Using auto hierarchy path {} to retrieve resource.", jcrPath);
final Node node = nodeTranslator().getNodeFromGraphSubjectForVersionNode(uriInfo.getRequestUri().toString());
if (node == null) {
throw new WebApplicationException(status(NOT_FOUND).build());
Oops, something went wrong.

0 comments on commit 4c9625e

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