Skip to content

Commit

Permalink
Throw exception on statement addition and deletions with non-repo sub…
Browse files Browse the repository at this point in the history
  • Loading branch information
whikloj authored and Andrew Woods committed Mar 13, 2015
1 parent b947785 commit 2e5265c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Expand Up @@ -93,7 +93,9 @@ public void addedStatement(final Statement input) {

// if it's not about a node, ignore it.
if (!idTranslator.inDomain(subject) && !subject.isAnon()) {
return;
LOGGER.error("subject ({}) is not in repository domain.", subject);
throw new MalformedRdfException(String.format(
"Update RDF contains subject(s) (%s) not in the domain of this repository.", subject));
}

final Statement s = jcrRdfTools.skolemize(idTranslator, input);
Expand Down Expand Up @@ -132,7 +134,9 @@ public void removedStatement(final Statement s) {

// if it's not about a node, we don't care.
if (!idTranslator.inDomain(subject)) {
return;
LOGGER.error("subject ({}) is not in repository domain.", subject);
throw new MalformedRdfException(String.format(
"Update RDF contains subject(s) (%s) not in the domain of this repository.", subject));
}

final FedoraResource resource = idTranslator.convert(subject);
Expand Down
Expand Up @@ -97,13 +97,8 @@ public void testObjectGraph() throws Exception {
.matcher(model.toString()).find());

object.updateProperties(subjects, "PREFIX dc: <http://purl.org/dc/elements/1.1/>\n" +
"INSERT { <http://example/egbook> dc:title " +
"\"This is an example of an update that will be " +
"ignored\" } WHERE {}", object.getTriples(subjects, PropertiesRdfContext.class));

object.updateProperties(subjects, "PREFIX dc: <http://purl.org/dc/elements/1.1/>\n" +
"INSERT { <" + graphSubject + "> dc:title " +
"\"This is an example title\" } WHERE {}", object.getTriples(subjects, PropertiesRdfContext.class));
"INSERT { <" + graphSubject + "> dc:title " +
"\"This is an example title\" } WHERE {}", object.getTriples(subjects, PropertiesRdfContext.class));


final Value[] values = object.getNode().getProperty("dc:title").getValues();
Expand Down Expand Up @@ -236,4 +231,15 @@ public void testReplaceObjectGraphWithErrors() {
assertTrue(e.getMessage().contains("/relative-url"));
assertTrue(e.getMessage().contains("/another-relative-url"));
}

@Test(expected = MalformedRdfException.class)
public void testUpdatingObjectGraphWithOutOfDomainSubjects() throws AccessDeniedException, MalformedRdfException {
final Container object =
containerService.findOrCreate(session, "/graphObject");

object.updateProperties(subjects, "PREFIX dc: <http://purl.org/dc/elements/1.1/>\n" +
"INSERT { <http://example/egbook> dc:title " + "\"This is an example of an update that will be " +
"ignored\" } WHERE {}", object.getTriples(subjects, PropertiesRdfContext.class));
}

}

0 comments on commit 2e5265c

Please sign in to comment.