Skip to content

Commit

Permalink
Delete linked-to resource response
Browse files Browse the repository at this point in the history
- works against running fcrepo4, but fails in IT

Resolves: https://www.pivotaltracker.com/story/show/69702570
  • Loading branch information
escowles authored and Andrew Woods committed Apr 18, 2014
1 parent a766c91 commit 9183bc1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
15 changes: 15 additions & 0 deletions fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraNodes.java
Expand Up @@ -123,6 +123,9 @@
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.Model;

import org.modeshape.jcr.cache.NodeKey;
import org.modeshape.jcr.cache.ReferentialIntegrityException;

/**
* CRUD operations on Fedora Nodes
*/
Expand Down Expand Up @@ -676,6 +679,18 @@ public Response deleteObject(@PathParam("path")
nodeService.deleteObject(session, path);
session.save();
return noContent().build();
} catch (javax.jcr.ReferentialIntegrityException riex) {
StringBuffer msg = new StringBuffer("Unable to delete node because it is linked to "
+ "by other nodes: ");

// lookup paths of linking nodes
Throwable inner = riex.getCause();
if ( inner instanceof ReferentialIntegrityException) {
for ( NodeKey node : ((ReferentialIntegrityException)inner).getReferrers() ) {
msg.append( " " + session.getNodeByIdentifier(node.getIdentifier()).getPath() );
}
}
return status(SC_PRECONDITION_FAILED).entity(msg.toString()).build();
} finally {
session.logout();
}
Expand Down
Expand Up @@ -867,9 +867,9 @@ public void testDescribeSize() throws Exception {


assertEquals(CREATED.getStatusCode(),
getStatus(postObjMethod(sizeNode)));
getStatus(postObjMethod(sizeNode)));
assertEquals(CREATED.getStatusCode(), getStatus(postDSMethod(sizeNode,
"asdf", "1234")));
"asdf", "1234")));

graphStore = getGraphStore(new HttpGet(serverAddress + ""));
logger.trace("For testDescribeSize() new size retrieved repository graph:\n"
Expand Down Expand Up @@ -918,9 +918,9 @@ public void testDescribeCount() throws Exception {
(String) iterator.next().getObject().getLiteralValue();

logger.debug("Old size was: " + oldSize + " and new size was: " +
newSize);
newSize);
assertTrue("No increment in count occurred when we expected one!",
Integer.parseInt(oldSize) < Integer.parseInt(newSize));
Integer.parseInt(oldSize) < Integer.parseInt(newSize));
}

/**
Expand Down Expand Up @@ -1367,7 +1367,29 @@ public String apply(final Header h) {
for ( String link : nextLinks ) {
assertFalse("Should not have next page header!", link.contains("rel=\"next\""));
}
assertFalse("Should not have next page triple!", nextGraph.contains(ANY, ANY, NEXT_PAGE.asNode(), ANY));
assertFalse("Should not have next pagiple!", nextGraph.contains(ANY, ANY, NEXT_PAGE.asNode(), ANY));
}

@Test
@Ignore("Works in real life")
public void testLinkedDeletion() throws Exception {
createObject("linked-from");
createObject("linked-to");

String sparql = "insert data { <" + serverAddress + "linked-from> "
+ "<http://fedora.info/definitions/v4/rels-ext#isMemberOfCollection> "
+ "<" + serverAddress + "linked-to> . }";
HttpPatch patch = new HttpPatch(serverAddress + "linked-from");
patch.addHeader("Content-Type", "application/sparql-update");
final BasicHttpEntity e = new BasicHttpEntity();
e.setContent(new ByteArrayInputStream(sparql.getBytes()));
assertEquals("Couldn't link resources!", 204, getStatus(patch));

HttpDelete delete = new HttpDelete(serverAddress + "linked-to");
assertEquals("Deleting linked-to should error!", 412, getStatus(delete));

HttpGet get = new HttpGet(serverAddress + "linked-from");
assertEquals("Linked to should still exist!", 200, getStatus(get));
}

}

0 comments on commit 9183bc1

Please sign in to comment.