Skip to content

Commit

Permalink
Change MalformedRdfException to a RuntimeException
Browse files Browse the repository at this point in the history
- Fail on POST/PUT with out-of-domain RDF

Resolves: https://jira.duraspace.org/browse/FCREPO-1417
  • Loading branch information
whikloj authored and Andrew Woods committed May 27, 2015
1 parent 957f997 commit c5a9b37
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 27 deletions.
Expand Up @@ -19,6 +19,7 @@
import org.fcrepo.kernel.impl.rdf.impl.DefaultIdentifierTranslator;
import org.fcrepo.kernel.impl.rdf.impl.PropertiesRdfContext;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.fcrepo.kernel.exception.RepositoryRuntimeException;
import org.junit.Test;

import javax.jcr.PathNotFoundException;
Expand Down Expand Up @@ -56,7 +57,7 @@ protected String getFederationRoot() {
return getReadWriteFederationRoot();
}

@Test(expected = RepositoryException.class)
@Test(expected = RepositoryRuntimeException.class)
public void testWriteProperty() throws RepositoryException {
final Session session = repo.login();

Expand All @@ -82,7 +83,7 @@ public void testWriteProperty() throws RepositoryException {
session.logout();
}

@Test(expected = RepositoryException.class)
@Test(expected = RepositoryRuntimeException.class)
public void testRemoveProperty() throws RepositoryException {
final Session session = repo.login();

Expand Down
Expand Up @@ -89,13 +89,15 @@ public boolean apply(final Triple t) {
"Discovered a Fedora-relevant subject in triple: {}.",
t);
} else {
LOGGER.debug("Ignoring triple: {}.", t);
LOGGER.error("subject ({}) is not in repository domain.", t.getSubject().toString());
throw new MalformedRdfException(String.format(
"RDF Stream contains subject(s) (%s) not in the domain of this repository.", t.getSubject()));
}
return result;
}

};
// we knock out non-Fedora RDF
// we fail on non-Fedora RDF
this.stream =
stream.withThisContext(stream.filter(isFedoraSubjectTriple));

Expand Down
Expand Up @@ -57,6 +57,7 @@
import javax.jcr.version.VersionManager;

import org.fcrepo.kernel.exception.RepositoryRuntimeException;
import org.fcrepo.kernel.exception.MalformedRdfException;
import org.fcrepo.kernel.models.FedoraResource;
import org.fcrepo.kernel.identifiers.IdentifierConverter;
import org.fcrepo.kernel.impl.rdf.JcrRdfTools;
Expand Down Expand Up @@ -266,7 +267,7 @@ public void testIsNotNew() {
testObj.isNew());
}

@Test
@Test(expected = MalformedRdfException.class)
public void testReplacePropertiesDataset() throws Exception {

final DefaultIdentifierTranslator defaultGraphSubjects = new DefaultIdentifierTranslator(mockSession);
Expand All @@ -276,33 +277,20 @@ public void testReplacePropertiesDataset() throws Exception {

final Model propertiesModel = createDefaultModel();
propertiesModel.add(propertiesModel.createResource("a"),
propertiesModel.createProperty("b"),
"c");


propertiesModel.add(propertiesModel.createResource("i"),
propertiesModel.createProperty("j"),
"k");
propertiesModel.createProperty("b"),
"c");

propertiesModel.add(propertiesModel.createResource("x"),
propertiesModel.createProperty("y"),
"z");
final RdfStream propertiesStream = RdfStream.fromModel(propertiesModel);

final Model replacementModel = createDefaultModel();

replacementModel.add(replacementModel.createResource("a"),
replacementModel.createProperty("b"),
"n");


replacementModel.add(replacementModel.createResource("i"),
replacementModel.createProperty("j"),
"k");
replacementModel.createProperty("b"),
"n");

testObj.replaceProperties(defaultGraphSubjects,
replacementModel,
propertiesStream);
replacementModel,
propertiesStream);
}

@Test
Expand Down
Expand Up @@ -15,16 +15,14 @@
*/
package org.fcrepo.kernel.exception;

import javax.jcr.RepositoryException;

/**
* Indicates that RDF was presented for persistence to the repository,
* but could not be persisted for some reportable reason.
*
* @author ajs6f
* @since Oct 24, 2013
*/
public class MalformedRdfException extends RepositoryException {
public class MalformedRdfException extends RepositoryRuntimeException {

private static final long serialVersionUID = 1L;

Expand Down

0 comments on commit c5a9b37

Please sign in to comment.