Skip to content

Commit

Permalink
Filtering references that aren't inbound to the node in question
Browse files Browse the repository at this point in the history
  • Loading branch information
escowles committed Aug 25, 2015
1 parent 59defcb commit dec0838
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
Expand Up @@ -1100,9 +1100,11 @@ public void testGetObjectReferences() throws IOException {
public void testGetObjectReferencesIndirect() throws Exception {
final String uuid = getRandomUniqueId();
final String pid1 = uuid + "/parent";
final String pid2 = uuid + "/child";
final String pid2 = uuid + "/child1";
final String pid3 = uuid + "/child2";
createObjectAndClose(pid1);
createObjectAndClose(pid2);
createObjectAndClose(pid3);

final String memberRelation = "http://pcdm.org/models#hasMember";

Expand All @@ -1116,13 +1118,9 @@ public void testGetObjectReferencesIndirect() throws Exception {
createContainer.setEntity(new StringEntity(membersRDF));
assertEquals(CREATED.getStatusCode(), getStatus(createContainer));

// create a proxy in the indirect container
final HttpPost createProxy = new HttpPost(serverAddress + pid1 + "/members");
createProxy.addHeader("Content-Type", "text/turtle");
final String proxyRDF = "<> <http://www.openarchives.org/ore/terms/proxyFor> <" + serverAddress + pid2 + ">;"
+ " <http://www.openarchives.org/ore/terms/proxyIn> <" + serverAddress + pid1 + "> .";
createProxy.setEntity(new StringEntity(proxyRDF));
assertEquals(CREATED.getStatusCode(), getStatus(createProxy));
// create proxies for the children in the indirect container
createProxy(pid1, pid2);
createProxy(pid1, pid3);

// retrieve the parent and verify the outbound triples exist
final HttpGet getParent = new HttpGet(serverAddress + pid1);
Expand All @@ -1132,6 +1130,10 @@ public void testGetObjectReferencesIndirect() throws Exception {
createURI(serverAddress + pid1),
createURI(memberRelation),
createURI(serverAddress + pid2)));
assertTrue(parentGraph.contains(Node.ANY,
createURI(serverAddress + pid1),
createURI(memberRelation),
createURI(serverAddress + pid3)));
}

// retrieve the members container and verify the LDP triples exist
Expand Down Expand Up @@ -1170,8 +1172,21 @@ public void testGetObjectReferencesIndirect() throws Exception {
createURI(serverAddress + pid1),
createURI(memberRelation),
createURI(serverAddress + pid2)));

assertFalse("Should not contain inbound references to the other child", memberGraph.contains(Node.ANY,
createURI(serverAddress + pid1),
createURI(memberRelation),
createURI(serverAddress + pid3)));
}
}
private void createProxy(final String parent, final String child) throws Exception {
final HttpPost createProxy = new HttpPost(serverAddress + parent + "/members");
createProxy.addHeader("Content-Type", "text/turtle");
final String proxyRDF = "<> <http://www.openarchives.org/ore/terms/proxyFor> <" + serverAddress + child + ">;"
+ " <http://www.openarchives.org/ore/terms/proxyIn> <" + serverAddress + parent + "> .";
createProxy.setEntity(new StringEntity(proxyRDF));
assertEquals(CREATED.getStatusCode(), getStatus(createProxy));
}

@Test
public void testGetObjectGraphLacksUUID() throws Exception {
Expand Down
Expand Up @@ -39,6 +39,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;

/**
* Accumulate inbound references to a given resource
Expand Down Expand Up @@ -68,6 +69,10 @@ public ReferencesRdfContext(final FedoraResource resource,
putReferencesIntoContext(resource.getNode());
}

private final Predicate<Triple> INBOUND = t -> {
return t.getObject().getURI().equals(translator().reverse().convert(resource()).getURI());
};

@SuppressWarnings("unchecked")
private void putReferencesIntoContext(final Node node) throws RepositoryException {
Iterator<Property> references = node.getReferences();
Expand All @@ -78,7 +83,7 @@ private void putReferencesIntoContext(final Node node) throws RepositoryExceptio
references = node.getReferences();
weakReferences = node.getWeakReferences();
allReferences = Iterators.concat(references, weakReferences);
concat(flatMap(flatMap( allReferences, potentialProxies), triplesForValue));
concat(Iterators.filter(flatMap(flatMap( allReferences, potentialProxies), triplesForValue), INBOUND::test));
}

/* References from LDP indirect containers are generated dynamically by LdpContainerRdfContext, so they won't
Expand Down

0 comments on commit dec0838

Please sign in to comment.