Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add ldp:contains predicates for child members of an object
  • Loading branch information
cbeer authored and Andrew Woods committed Apr 17, 2014
1 parent dce1218 commit 3555db5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 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 @@ -525,6 +526,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 @@ -576,16 +583,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 @@ -1241,6 +1245,14 @@ public void testPaging() throws Exception {
}
assertEquals("Should have two children!", 2, firstChildCount);


// count children in response graph
int firstContainsCount = 0;
for ( Iterator it = firstGraph.find(ANY,parent,CONTAINS.asNode(),ANY); it.hasNext(); firstContainsCount++ ) {
logger.debug( "Found child: {}", it.next() );
}
assertEquals("Should have two children!", 2, firstContainsCount);

// collect link headers
final Collection<String> firstLinks =
map(firstResponse.getHeaders("Link"), new Function<Header, String>() {
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 @@ -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

0 comments on commit 3555db5

Please sign in to comment.