Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #548 from fcrepo4/tombstones
Add Tombstone resource when a resource is deleted, preventing the re-use of URIs until the tombstone is also removed Resolves: https://www.pivotaltracker.com/story/show/80853212
- Loading branch information
Showing
28 changed files
with
655 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraTombstones.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* Copyright 2014 DuraSpace, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.fcrepo.http.api; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import org.fcrepo.kernel.FedoraResource; | ||
import org.fcrepo.kernel.exception.RepositoryRuntimeException; | ||
import org.springframework.context.annotation.Scope; | ||
|
||
import javax.inject.Inject; | ||
import javax.jcr.RepositoryException; | ||
import javax.jcr.Session; | ||
import javax.ws.rs.DELETE; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.core.Response; | ||
|
||
import static javax.ws.rs.core.Response.noContent; | ||
|
||
/** | ||
* CRUD operations on Fedora tombstones | ||
* | ||
* @author cbeer | ||
*/ | ||
@Scope("request") | ||
@Path("/{path: .*}/fcr:tombstone") | ||
public class FedoraTombstones extends FedoraBaseResource { | ||
|
||
@Inject | ||
protected Session session; | ||
|
||
@PathParam("path") protected String externalPath; | ||
|
||
/** | ||
* Default JAX-RS entry point | ||
*/ | ||
public FedoraTombstones() { | ||
super(); | ||
} | ||
|
||
/** | ||
* Create a new FedoraNodes instance for a given path | ||
* @param externalPath | ||
*/ | ||
@VisibleForTesting | ||
public FedoraTombstones(final String externalPath) { | ||
this.externalPath = externalPath; | ||
} | ||
|
||
|
||
/** | ||
* Delete a tombstone resource (freeing the original resource to be reused) | ||
* @return | ||
*/ | ||
@DELETE | ||
public Response delete() { | ||
resource().delete(); | ||
|
||
try { | ||
session.save(); | ||
} catch (RepositoryException e) { | ||
throw new RepositoryRuntimeException(e); | ||
} | ||
|
||
return noContent().build(); | ||
} | ||
|
||
protected FedoraResource resource() { | ||
return translator().convert(translator().toDomain(externalPath)); | ||
} | ||
|
||
|
||
@Override | ||
protected Session session() { | ||
return session; | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
fcrepo-http-api/src/test/java/org/fcrepo/http/api/FedoraTombstonesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Copyright 2014 DuraSpace, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.fcrepo.http.api; | ||
|
||
import org.fcrepo.kernel.Tombstone; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
|
||
import javax.jcr.Session; | ||
import javax.ws.rs.core.Response; | ||
|
||
import static javax.ws.rs.core.Response.Status.NO_CONTENT; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.MockitoAnnotations.initMocks; | ||
import static org.springframework.test.util.ReflectionTestUtils.setField; | ||
|
||
/** | ||
* @author cabeer | ||
*/ | ||
public class FedoraTombstonesTest { | ||
|
||
@Mock | ||
private Tombstone mockResource; | ||
|
||
private String path = "/test/object"; | ||
|
||
private FedoraTombstones testObj; | ||
|
||
@Mock | ||
private Session mockSession; | ||
|
||
@Before | ||
public void setUp() { | ||
initMocks(this); | ||
testObj = spy(new FedoraTombstones(path)); | ||
setField(testObj, "session", mockSession); | ||
} | ||
|
||
@Test | ||
public void testDelete() throws Exception { | ||
final Tombstone mockResource = mock(Tombstone.class); | ||
|
||
doReturn(mockResource).when(testObj).resource(); | ||
|
||
final Response actual = testObj.delete(); | ||
assertEquals(NO_CONTENT.getStatusCode(), actual.getStatus()); | ||
verify(mockResource).delete(); | ||
verify(mockSession).save(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.