Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing versioning check when reverting versions of non-RDF resources #601

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.common.annotations.VisibleForTesting;
import org.fcrepo.http.commons.domain.PATCH;
import org.fcrepo.http.commons.domain.Prefer;
import org.fcrepo.kernel.FedoraBinary;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.slf4j.Logger;
Expand Down Expand Up @@ -109,7 +110,7 @@ private void postConstruct() {
public Response revertToVersion() throws RepositoryException {
LOGGER.info("Reverting {} to version {}.", path,
label);
versionService.revertToVersion(session, unversionedResource().getPath(), label);
versionService.revertToVersion(session, unversionedResourcePath(), label);
return noContent().build();
}

Expand All @@ -121,7 +122,7 @@ public Response revertToVersion() throws RepositoryException {
@DELETE
public Response removeVersion() throws RepositoryException {
LOGGER.info("Removing {} version {}.", path, label);
versionService.removeVersion(session, unversionedResource().getPath(), label);
versionService.removeVersion(session, unversionedResourcePath(), label);
return noContent().build();
}

Expand All @@ -146,13 +147,16 @@ public Response getVersion(@HeaderParam("Prefer") final Prefer prefer,
return getContent(prefer, rangeValue, rdfStream);
}

protected FedoraResource unversionedResource() {
protected String unversionedResourcePath() throws RepositoryException {

if (baseResource == null) {
baseResource = getResourceFromPath(externalPath);
if ( baseResource instanceof FedoraBinary ) {
return baseResource.getNode().getParent().getPath();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use FedoraBinary#getDescription()?

}
}

return baseResource;
return baseResource.getPath();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,29 +99,29 @@ public void setUp() throws Exception {

@Test
public void testRevertToVersion() throws RepositoryException {
doReturn(mockResource).when(testObj).unversionedResource();
doReturn(path).when(testObj).unversionedResourcePath();
final Response response = testObj.revertToVersion();
verify(mockVersions).revertToVersion(mockSession, path, versionLabel);
assertNotNull(response);
}

@Test (expected = PathNotFoundException.class)
public void testRevertToVersionFailure() throws RepositoryException {
doThrow(PathNotFoundException.class).when(testObj).unversionedResource();
doThrow(PathNotFoundException.class).when(testObj).unversionedResourcePath();
testObj.revertToVersion();
}

@Test
public void testRemoveVersion() throws RepositoryException {
doReturn(mockResource).when(testObj).unversionedResource();
doReturn(path).when(testObj).unversionedResourcePath();
final Response response = testObj.removeVersion();
verify(mockVersions).removeVersion(mockSession, path, versionLabel);
assertNotNull(response);
}

@Test (expected = PathNotFoundException.class)
public void testRemoveVersionFailure() throws RepositoryException {
doThrow(PathNotFoundException.class).when(testObj).unversionedResource();
doThrow(PathNotFoundException.class).when(testObj).unversionedResourcePath();
testObj.removeVersion();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,34 +394,47 @@ public void testVersionOperationAddsVersionableMixin() throws Exception {
}

@Test
public void testDatastreamAutoMixin() throws IOException {
public void testDatastreamAutoMixinAndRevert() throws IOException {
final String pid = getRandomUniquePid();
final String dsid = "ds1";
createObject(pid);

createDatastream(pid, "ds1", "This is some datastream content");
final String originalContent = "This is the original content";
final String versionLabel = "ver1";
createDatastream(pid, dsid, originalContent);

// datastream should not have fcr:versions endpoint
assertEquals(404, getStatus(new HttpGet(serverAddress + pid + "/ds1/fcr:versions")));
assertEquals(404, getStatus(new HttpGet(serverAddress + pid + "/" + dsid + "/fcr:versions")));

// datastream should not be versionable
final GraphStore originalObjectProperties = getContent(serverAddress + pid + "/ds1/fcr:metadata");
final GraphStore originalObjectProperties = getContent(serverAddress + pid + "/" + dsid + "/fcr:metadata");
assertFalse("Node must not have versionable mixin.",
originalObjectProperties.contains(ANY, createResource(serverAddress + pid + "/ds1").asNode(),
originalObjectProperties.contains(ANY, createResource(serverAddress + pid + "/" + dsid).asNode(),
createURI(RDF_TYPE), createURI(MIX_NAMESPACE + "versionable")));

// creating a version should succeed
final HttpPost httpPost = new HttpPost(serverAddress + pid + "/ds1/fcr:versions");
httpPost.setHeader("Slug", "label");
final HttpPost httpPost = new HttpPost(serverAddress + pid + "/" + dsid + "/fcr:versions");
httpPost.setHeader("Slug", versionLabel);
assertEquals( 204, getStatus(httpPost));

// datastream should then have versions endpoint
assertEquals( 200, getStatus(new HttpGet(serverAddress + pid + "/ds1/fcr:versions")) );
assertEquals( 200, getStatus(new HttpGet(serverAddress + pid + "/" + dsid + "/fcr:versions")) );

// datastream should then be versionable
final GraphStore updatedDSProperties = getContent(serverAddress + pid + "/ds1/fcr:metadata");
final GraphStore updatedDSProperties = getContent(serverAddress + pid + "/" + dsid + "/fcr:metadata");
assertTrue("Node must have versionable mixin.",
updatedDSProperties.contains(ANY, createResource(serverAddress + pid + "/ds1/fcr:metadata").asNode(),
createURI(RDF_TYPE), createURI(MIX_NAMESPACE + "versionable")));
updatedDSProperties.contains(ANY,
createResource(serverAddress + pid + "/" + dsid + "/fcr:metadata").asNode(),
createURI(RDF_TYPE), createURI(MIX_NAMESPACE + "versionable")));

// update the content
final String updatedContent = "This is the updated content";
execute(putDSMethod(pid,dsid,updatedContent));
assertEquals( updatedContent, EntityUtils.toString(execute(getDSMethod(pid, dsid)).getEntity()) );

// revert to the original content
revertToVersion(pid + "/" + dsid, versionLabel);
assertEquals( originalContent, EntityUtils.toString(execute(getDSMethod(pid, dsid)).getEntity()) );
}


Expand Down