Skip to content

Commit

Permalink
Add ldp:contains predicates for child members of an object
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Apr 16, 2014
1 parent e86870c commit 175e88a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 16 deletions.
Expand Up @@ -44,6 +44,7 @@
import static org.apache.http.impl.client.cache.CacheConfig.DEFAULT;
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE;
import static org.fcrepo.jcr.FedoraJcrTypes.ROOT;
import static org.fcrepo.kernel.RdfLexicon.CONTAINS;
import static org.fcrepo.kernel.RdfLexicon.DC_NAMESPACE;
import static org.fcrepo.kernel.RdfLexicon.DC_TITLE;
import static org.fcrepo.kernel.RdfLexicon.FIRST_PAGE;
Expand Down Expand Up @@ -515,6 +516,12 @@ public void testGetObjectGraphMinimal() throws Exception {
+ pid + "> <" + HAS_CHILD + ">",
DOTALL).matcher(content).find());

assertFalse("Didn't expect contained member resources",
compile(
"<"
+ serverAddress
+ pid + "> <" + CONTAINS + ">",
DOTALL).matcher(content).find());
}

@Test
Expand Down Expand Up @@ -566,16 +573,13 @@ public void testGetObjectOmitContainment() throws Exception {
+ pid + "> <" + HAS_CHILD + ">",
DOTALL).matcher(content).find());

int count = 0;

final Matcher matcher = compile("<http://fedora.info/definitions/v4/repository#uuid>",
DOTALL).matcher(content);

while (matcher.find()) {
count++;
}
assertFalse("Didn't expect contained member resources",
compile(
"<"
+ serverAddress
+ pid + "> <" + CONTAINS + ">",
DOTALL).matcher(content).find());

assertEquals("Didn't expect to find inlined resources", 1, count);
}

@Test
Expand Down
Expand Up @@ -169,8 +169,6 @@ public final class RdfLexicon {
createProperty(LDP_NAMESPACE + "firstPage");
public static final Property NEXT_PAGE =
createProperty(LDP_NAMESPACE + "nextPage");
public static final Property MEMBERS_INLINED =
createProperty(LDP_NAMESPACE + "membersInlined");
public static final Resource CONTAINER =
createResource(LDP_NAMESPACE + "Container");
public static final Resource DIRECT_CONTAINER =
Expand All @@ -179,12 +177,12 @@ public final class RdfLexicon {
createProperty(LDP_NAMESPACE + "membershipResource");
public static final Property HAS_MEMBER_RELATION =
createProperty(LDP_NAMESPACE + "hasMemberRelation");
public static final Property INLINED_RESOURCE =
createProperty(LDP_NAMESPACE + "inlinedResource");
public static final Property CONTAINS =
createProperty(LDP_NAMESPACE + "contains");

public static final Set<Property> ldpProperties = of(PAGE, PAGE_OF,
FIRST_PAGE, NEXT_PAGE, MEMBERS_INLINED, MEMBERSHIP_RESOURCE,
HAS_MEMBER_RELATION, INLINED_RESOURCE);
FIRST_PAGE, NEXT_PAGE, MEMBERSHIP_RESOURCE,
HAS_MEMBER_RELATION, CONTAINS);
public static final Set<Resource> ldpResources = of(CONTAINER,
DIRECT_CONTAINER);

Expand Down
Expand Up @@ -31,7 +31,7 @@ public HierarchyRdfContextOptions() {
this.limit = -1;
this.offset = -1;
membership = true;
containment = false;
containment = true;
}

/**
Expand Down
Expand Up @@ -21,6 +21,7 @@
import static com.hp.hpl.jena.graph.Triple.create;
import static com.hp.hpl.jena.vocabulary.RDF.type;
import static org.fcrepo.kernel.RdfLexicon.CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.CONTAINS;
import static org.fcrepo.kernel.RdfLexicon.DIRECT_CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.HAS_CHILD;
import static org.fcrepo.kernel.RdfLexicon.HAS_PARENT;
Expand Down Expand Up @@ -168,6 +169,7 @@ public Iterator<Triple> apply(final javax.jcr.Node child) {
childStream.concat(
new PropertiesRdfContext(child, graphSubjects(), lowLevelStorageService())
);
childStream.concat(create(subject(), CONTAINS.asNode(), childSubject));
}

return childStream;
Expand Down
Expand Up @@ -20,6 +20,7 @@
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
import static com.hp.hpl.jena.vocabulary.RDF.type;
import static org.fcrepo.kernel.RdfLexicon.CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.CONTAINS;
import static org.fcrepo.kernel.RdfLexicon.DIRECT_CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.HAS_CHILD;
import static org.fcrepo.kernel.RdfLexicon.HAS_PARENT;
Expand Down Expand Up @@ -103,6 +104,9 @@ public void shouldIncludeChildNodeInformation() throws RepositoryException,
final Model actual = getResults();
logRdf("Retrieved RDF for shouldIncludeChildNodeInformation() as follows: ",
actual);

assertEquals("Didn't find enough contains!", 5, Iterators.size(actual
.listObjectsOfProperty(CONTAINS)));
assertEquals("Didn't find enough children!", 5, Iterators.size(actual
.listObjectsOfProperty(HAS_CHILD)));
assertEquals("Found too many parents!", 1, Iterators.size(actual
Expand Down
Expand Up @@ -331,6 +331,8 @@ public void shouldIncludeFullChildNodeInformationInsideWindow()
when(mockNode.hasNodes()).thenReturn(true);
HierarchyRdfContextOptions options = new HierarchyRdfContextOptions(2, 0);

options.containment = false;

final Model actual =
testObj.getTreeTriples(mockNode, options).asModel();
assertEquals(2, Iterators.size(actual
Expand Down

0 comments on commit 175e88a

Please sign in to comment.