Skip to content

Commit

Permalink
Merge pull request fcrepo#1064 from awoods/fcrepo-2074
Browse files Browse the repository at this point in the history
Allow resources that are referenced by other versioned resources to be deleted
  • Loading branch information
escowles authored Jul 7, 2016
2 parents c3eeee4 + 63fcf22 commit 4c9d8c3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import static java.util.stream.Stream.empty;
import static java.util.stream.Stream.of;
import static org.apache.commons.codec.digest.DigestUtils.shaHex;
import static org.fcrepo.kernel.api.FedoraTypes.FEDORA_LASTMODIFIED;
import static org.fcrepo.kernel.api.FedoraTypes.FEDORA_REPOSITORY_ROOT;
import static org.fcrepo.kernel.api.RdfLexicon.LAST_MODIFIED_DATE;
import static org.fcrepo.kernel.api.RdfLexicon.REPOSITORY_NAMESPACE;
import static org.fcrepo.kernel.api.RdfLexicon.isManagedNamespace;
Expand Down Expand Up @@ -157,6 +155,7 @@ public class FedoraResourceImpl extends JcrTools implements FedoraTypes, FedoraR
private static final String JCR_CHILD_VERSION_HISTORY = "jcr:childVersionHistory";
private static final String JCR_VERSIONABLE_UUID = "jcr:versionableUuid";
private static final String JCR_FROZEN_UUID = "jcr:frozenUuid";
private static final String JCR_VERSION_STORAGE = "jcr:versionStorage";

private static final PropertyConverter propertyConverter = new PropertyConverter();

Expand Down Expand Up @@ -378,7 +377,14 @@ public void delete() {
prop.setValue(newVals.toArray(new Value[newVals.size()]));
}
} catch (final RepositoryException ex) {
throw new RepositoryRuntimeException(ex);
// Ignore error from trying to update properties on versioned resources
if (ex instanceof javax.jcr.nodetype.ConstraintViolationException &&
ex.getMessage().contains(JCR_VERSION_STORAGE)) {
LOGGER.debug("Ignoring exception trying to remove property from versioned resource: {}",
ex.getMessage());
} else {
throw new RepositoryRuntimeException(ex);
}
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,45 @@ public void testVersionedChildBinaryDeleted() throws RepositoryException, Invali
}
}

@Test
public void testDeleteLinkedVersionedResources() throws RepositoryException {
final Container object1 = containerService.findOrCreate(session, "/" + getRandomPid());
final Container object2 = containerService.findOrCreate(session, "/" + getRandomPid());

// Create a link between objects 1 and 2
object2.updateProperties(subjects, "PREFIX example: <http://example.org/>\n" +
"INSERT { <> <example:link> " + "<" + createGraphSubjectNode(object1).getURI() + ">" +
" } WHERE {} ",
object2.getTriples(subjects, emptySet()));

// Create version of object2
versionService.createVersion(session, object2.getPath(), "obj2-v0");

// Verify that the objects exist
assertTrue("object1 should exist!", exists(object1));
assertTrue("object2 should exist!", exists(object2));

// This is the test: verify successful deletion of the objects
object2.delete();
session.save();

object1.delete();
session.save();

// Double-verify that the objects are gone
assertFalse("/object2 should NOT exist!", exists(object2));
assertFalse("/object1 should NOT exist!", exists(object1));
}

private boolean exists(final Container resource) {
try {
resource.getPath();
return true;
} catch (RepositoryRuntimeException e) {
return false;
}
}

@Test (expected = RepositoryRuntimeException.class)
public void testNullBaseVersion() throws RepositoryException {
final String pid = getRandomPid();
Expand Down

0 comments on commit 4c9d8c3

Please sign in to comment.