Skip to content

Commit

Permalink
Remove repository autoversioning
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Oct 15, 2014
1 parent e81884a commit 6410b59
Show file tree
Hide file tree
Showing 19 changed files with 69 additions and 723 deletions.
Expand Up @@ -261,7 +261,6 @@ && isRdfContentType(contentType.toString())) {

try {
session.save();
versionService.nodeUpdated(resource.getNode());
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
Expand Down Expand Up @@ -304,11 +303,6 @@ public Response updateSparql(@ContentLocation final InputStream requestBodyStrea

try {
session.save();
versionService.nodeUpdated(resource().getNode());

if (resource() instanceof Datastream) {
versionService.nodeUpdated(((Datastream) resource()).getContentNode());
}
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
Expand Down Expand Up @@ -390,7 +384,6 @@ && isRdfContentType(contentTypeString)) {

try {
session.save();
versionService.nodeUpdated(result.getNode());
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
Expand Down
Expand Up @@ -125,7 +125,6 @@ public Response copyObject(@HeaderParam("Destination") final String destinationU
nodeService.copyObject(session, source, destination);

session.save();
versionService.nodeUpdated(session, destination);

return created(new URI(destinationUri)).build();
} catch (final RepositoryRuntimeException e) {
Expand Down Expand Up @@ -177,7 +176,6 @@ public Response moveObject(@HeaderParam("Destination") final String destinationU

nodeService.moveObject(session, resource().getPath(), destination);
session.save();
versionService.nodeUpdated(session, destination);
return created(new URI(destinationUri)).build();
} catch (final RepositoryRuntimeException e) {
final Throwable cause = e.getCause();
Expand Down
Expand Up @@ -42,15 +42,14 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.net.URISyntaxException;
import java.util.Collection;

import static java.util.Collections.singleton;
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;
import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
import static javax.ws.rs.core.Response.created;
import static javax.ws.rs.core.Response.noContent;
import static org.apache.commons.lang.StringUtils.isBlank;
import static org.fcrepo.http.commons.domain.RDFMediaType.JSON_LD;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3_ALT2;
Expand Down Expand Up @@ -145,14 +144,13 @@ public Response disableVersioning() {
@POST
public Response addVersion(@HeaderParam("Slug") final String slug) throws RepositoryException {
final String path = toPath(translator(), externalPath);
final Collection<String> versions = versionService.createVersion(session.getWorkspace(),
singleton(path));
final String versionIdentifier = versionService.createVersion(session, path);

if (slug != null) {
if (!isBlank(slug)) {
resource().addVersionLabel(slug);
}

final String version = (slug != null) ? slug : versions.iterator().next();
final String version = (slug != null) ? slug : versionIdentifier;

return noContent().header("Location", uriInfo.getRequestUri() + "/" + version).build();
}
Expand Down
Expand Up @@ -30,15 +30,12 @@
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.util.Collection;

import static java.util.Collections.singleton;
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;
Expand Down Expand Up @@ -102,27 +99,6 @@ private void postConstruct() {
this.label = pathListIntoVersion.split("/", 2)[0];
}

/**
* Create a new version checkpoint and tag it with the given label. If
* that label already describes another version it will silently be
* reassigned to describe this version.
*
* @return response
* @throws RepositoryException
*/
@POST
public Response addVersion() throws RepositoryException {
final Collection<String> versions = versionService.createVersion(session.getWorkspace(),
singleton(unversionedResource().getPath()));
if (label != null) {
unversionedResource().addVersionLabel(label);
}

final String version = (label != null) ? label : versions.iterator().next();
return noContent().header("Location", translator().toDomain(
externalPath) + "/fcr:versions/" + version).build();
}

/**
* Reverts the resource at the given path to the version specified by
* the label.
Expand All @@ -133,7 +109,7 @@ public Response addVersion() throws RepositoryException {
public Response revertToVersion() throws RepositoryException {
LOGGER.info("Reverting {} to version {}.", path,
label);
versionService.revertToVersion(session.getWorkspace(), unversionedResource().getPath(), label);
versionService.revertToVersion(session, unversionedResource().getPath(), label);
return noContent().build();
}

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

Expand Down
Expand Up @@ -35,7 +35,6 @@
import org.fcrepo.kernel.services.BinaryService;
import org.fcrepo.kernel.services.NodeService;
import org.fcrepo.kernel.services.ObjectService;
import org.fcrepo.kernel.services.VersionService;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -134,9 +133,6 @@ public class FedoraLdpTest {
@Mock
private BinaryService mockBinaryService;

@Mock
private VersionService mockVersionService;

@Before
public void setUp() throws Exception {
initMocks(this);
Expand All @@ -157,7 +153,6 @@ public void setUp() throws Exception {
setField(testObj, "nodeService", mockNodeService);
setField(testObj, "objectService", mockObjectService);
setField(testObj, "binaryService", mockBinaryService);
setField(testObj, "versionService", mockVersionService);

when(mockObject.getNode()).thenReturn(mockObjectNode);
when(mockObject.getEtagValue()).thenReturn("");
Expand Down Expand Up @@ -535,7 +530,6 @@ public void testPutNewObject() throws Exception {
final Response actual = testObj.createOrReplaceObjectRdf(null, null, null, null);

assertEquals(CREATED.getStatusCode(), actual.getStatus());
verify(mockVersionService).nodeUpdated(mockObjectNode);
}

@Test
Expand All @@ -551,7 +545,6 @@ public void testPutNewObjectWithRdf() throws Exception {
toInputStream("_:a <info:x> _:c ."), null, null);

assertEquals(CREATED.getStatusCode(), actual.getStatus());
verify(mockVersionService).nodeUpdated(mockObjectNode);
verify(mockObject).replaceProperties(eq(identifierConverter), any(Model.class), any(RdfStream.class));
}

Expand All @@ -567,7 +560,6 @@ public void testPutNewBinary() throws Exception {
toInputStream("xyz"), null, null);

assertEquals(CREATED.getStatusCode(), actual.getStatus());
verify(mockVersionService).nodeUpdated(mockBinaryNode);
}

@Test
Expand All @@ -585,7 +577,6 @@ public void testPutReplaceRdfObject() throws Exception {
toInputStream("_:a <info:x> _:c ."), null, null);

assertEquals(NO_CONTENT.getStatusCode(), actual.getStatus());
verify(mockVersionService).nodeUpdated(mockObject.getNode());
verify(mockObject).replaceProperties(eq(identifierConverter), any(Model.class), any(RdfStream.class));
}

Expand All @@ -595,7 +586,6 @@ public void testPatchObject() throws Exception {
final FedoraResource mockObject = setResource(FedoraObject.class);

testObj.updateSparql(toInputStream("xyz"));
verify(mockVersionService).nodeUpdated(mockObject.getNode());
}

@Test
Expand All @@ -606,8 +596,6 @@ public void testPatchBinaryDescription() throws Exception {
when(mockObject.getContentNode()).thenReturn(mockBinaryNode);

testObj.updateSparql(toInputStream("xyz"));
verify(mockVersionService).nodeUpdated(mockObject.getNode());
verify(mockVersionService).nodeUpdated(mockObject.getContentNode());
}

@Test(expected = BadRequestException.class)
Expand Down
Expand Up @@ -18,8 +18,6 @@
import static org.fcrepo.http.commons.test.util.TestHelpers.getUriInfoImpl;
import static org.fcrepo.http.commons.test.util.TestHelpers.mockSession;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy;
Expand All @@ -28,13 +26,10 @@
import static org.mockito.MockitoAnnotations.initMocks;
import static org.springframework.test.util.ReflectionTestUtils.setField;

import java.util.Collection;

import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Workspace;
import javax.jcr.nodetype.NodeType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
Expand All @@ -47,7 +42,6 @@
import org.fcrepo.kernel.services.VersionService;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Matchers;
import org.mockito.Mock;

/**
Expand Down Expand Up @@ -103,22 +97,11 @@ public void setUp() throws Exception {
new UriAwareIdentifierConverter(mockSession, UriBuilder.fromUri("http://localhost/fcrepo/{path: .*}")));
}

@Test
public void testAddVersionLabel() throws RepositoryException {
doReturn(mockResource).when(testObj).unversionedResource();

final Response response = testObj.addVersion();
verify(mockResource).addVersionLabel(anyString());
verify(mockVersions).createVersion(any(Workspace.class),
Matchers.<Collection<String>>any());
assertNotNull(response);
}

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

Expand All @@ -132,7 +115,7 @@ public void testRevertToVersionFailure() throws RepositoryException {
public void testRemoveVersion() throws RepositoryException {
doReturn(mockResource).when(testObj).unversionedResource();
final Response response = testObj.removeVersion();
verify(mockVersions).removeVersion(testObj.session.getWorkspace(), path, versionLabel);
verify(mockVersions).removeVersion(mockSession, path, versionLabel);
assertNotNull(response);
}

Expand Down

0 comments on commit 6410b59

Please sign in to comment.