Skip to content

Commit

Permalink
Handle errors for trying to list version of unversioned node
Browse files Browse the repository at this point in the history
  • Loading branch information
escowles authored and Andrew Woods committed May 21, 2014
1 parent e37a086 commit 8af7da1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Expand Up @@ -33,8 +33,9 @@

import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.version.VersionException;
import javax.jcr.Session;
import javax.jcr.UnsupportedRepositoryOperationException;
import javax.jcr.version.VersionException;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
Expand Down Expand Up @@ -101,20 +102,21 @@ public class FedoraVersions extends ContentExposingResource {
@HtmlTemplate(value = "fcr:versions")
@Produces({TURTLE, N3, N3_ALT2, RDF_XML, NTRIPLES, APPLICATION_XML, TEXT_PLAIN, TURTLE_X,
TEXT_HTML, APPLICATION_XHTML_XML})
public RdfStream getVersionList(@PathParam("path")
final List<PathSegment> pathList,
@Context
final Request request,
@Context
final UriInfo uriInfo) throws RepositoryException {
public RdfStream getVersionList(@PathParam("path") final List<PathSegment> pathList,
@Context final Request request,
@Context final UriInfo uriInfo) throws RepositoryException {
final String path = toPath(pathList);

LOGGER.trace("Getting versions list for: {}", path);

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

return resource.getVersionTriples(nodeTranslator()).session(session).topic(
nodeTranslator().getSubject(resource.getNode().getPath()).asNode());
try {
return resource.getVersionTriples(nodeTranslator()).session(session).topic(
nodeTranslator().getSubject(resource.getNode().getPath()).asNode());
} catch ( UnsupportedRepositoryOperationException ex ) {
throw new WebApplicationException( status(NOT_FOUND).entity("This resource is not versioned").build() );
}
}

/**
Expand Down
Expand Up @@ -75,6 +75,16 @@ public void testGetObjectVersionProfile() throws Exception {
results.contains(Node.ANY, subject.asNode(), HAS_VERSION.asNode(), Node.ANY));
}

@Test
public void testGetUnversionedObjectVersionProfile() throws Exception {
final String pid = getRandomUniquePid();

createObject(pid);

final HttpGet getVersion = new HttpGet(serverAddress + pid + "/fcr:versions");
assertEquals(404, getStatus(getVersion));
}

@Test
public void testAddAndRetrieveVersion() throws Exception {
final String pid = getRandomUniquePid();
Expand Down Expand Up @@ -388,7 +398,7 @@ public void testRemoveCurrentVersion() throws Exception {
addMixin(objId, MIX_NAMESPACE + "versionable");
postObjectVersion(objId, versionLabel);

// removing a non-existent version should 404
// removing the current version should 400
final HttpDelete delete = new HttpDelete(serverAddress + objId + "/fcr:versions/" + versionLabel);
assertEquals(BAD_REQUEST.getStatusCode(), getStatus(delete));
}
Expand Down

0 comments on commit 8af7da1

Please sign in to comment.