Skip to content

Commit

Permalink
Now RDF triples returned from Iterators of Nodes also returned from i…
Browse files Browse the repository at this point in the history
…teration
  • Loading branch information
ajs6f committed Oct 15, 2013
1 parent edccdc0 commit 8c427f6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
Expand Up @@ -49,7 +49,18 @@ public NodeRdfContext(final Node node, final GraphSubjects graphSubjects, final
this.node = node;
this.graphSubjects = graphSubjects;
subject = graphSubjects.getGraphSubject(node).asNode();
this.lowLevelStorageService = lowLevelStorageService;

// TODO fix GraphProperties to allow for LowLevelStorageServices to pass through it
// this is horribly ugly. LowLevelStorageServices are supposed to be managed beans.
// but the contract of GraphProperties isn't wide enough to pass one in, so rather than
// alter GraphProperties right now, I'm just spinning one on the fly.
if (lowLevelStorageService == null) {
this.lowLevelStorageService = new LowLevelStorageService();
this.lowLevelStorageService.setRepository(node.getSession()
.getRepository());
} else {
this.lowLevelStorageService = lowLevelStorageService;
}
}

/**
Expand Down
Expand Up @@ -17,13 +17,14 @@
package org.fcrepo.kernel.utils;

import static com.google.common.collect.Iterables.any;
import static com.google.common.collect.Iterators.peekingIterator;
import static com.hp.hpl.jena.graph.Triple.create;
import static com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createTypedLiteral;
import static com.hp.hpl.jena.vocabulary.RDF.nil;
import static com.hp.hpl.jena.vocabulary.RDF.type;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singleton;
import static javax.jcr.PropertyType.BINARY;
import static javax.jcr.PropertyType.BOOLEAN;
import static javax.jcr.PropertyType.DATE;
Expand Down Expand Up @@ -91,7 +92,6 @@
import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.PeekingIterator;
import com.hp.hpl.jena.datatypes.RDFDatatype;
import com.hp.hpl.jena.datatypes.xsd.XSDDateTime;
import com.hp.hpl.jena.rdf.model.Literal;
Expand Down Expand Up @@ -263,24 +263,18 @@ public Model getJcrPropertiesModel(final Iterator<Node> nodeIterator,
final Resource iteratorSubject)
throws RepositoryException {

if (!nodeIterator.hasNext()) {
return createDefaultModel();
}

final PeekingIterator<Node> iterator = peekingIterator(nodeIterator);
final Model model =
getJcrPropertiesModel();

while (iterator.hasNext()) {
final Node node = iterator.next();
addJcrPropertiesToModel(node, model);
final RdfStream results = new RdfStream();
while (nodeIterator.hasNext()) {
final Node node = nodeIterator.next();
results.concat(new PropertiesRdfContext(node, graphSubjects,
llstore).context());
if (iteratorSubject != null) {
model.add(iteratorSubject, HAS_MEMBER_OF_RESULT, graphSubjects
.getGraphSubject(node));
results.concat(singleton(create(iteratorSubject.asNode(),
HAS_MEMBER_OF_RESULT.asNode(), graphSubjects
.getGraphSubject(node).asNode())));
}
}

return model;
return results.asModel();
}

/**
Expand All @@ -296,14 +290,6 @@ public Model getJcrPropertiesModel(final Iterator<Node> nodeIterator,
public Model getJcrPropertiesModel(final Node node) throws RepositoryException {
final RdfStream namespaceContext =
new NamespaceContext(session).context();
// TODO fix GrpahProperties to allow for LowLevelStorageServices to pass through it
// this is horribly ugly. LowLevelStorageServices are supposed to be managged beans.
// but the contract of GraphProperties isn't wide enough to pass one in, so rather than
// alter GraphProperties right now, I'm just spinning one on the fly.
if (llstore == null) {
llstore = new LowLevelStorageService();
llstore.setRepository(session.getRepository());
}
return namespaceContext.concat(
new PropertiesRdfContext(node, graphSubjects, llstore)
.context()).asModel();
Expand Down
Expand Up @@ -738,16 +738,17 @@ public final void testJcrNodeIteratorAddsPredicatesForEachNode()
throws RepositoryException {
final Resource mockResource = createResource(
RESTAPI_NAMESPACE + "/search/resource");
final Node mockNode1 = mock(Node.class);
final Node mockNode2 = mock(Node.class);
final Node mockNode3 = mock(Node.class);
when(mockProperties.hasNext()).thenReturn(false);
when(mockNode1.getProperties()).thenReturn(mockProperties);
when(mockNode1.getSession()).thenReturn(mockSession);

when(mockNode2.getSession()).thenReturn(mockSession);
when(mockNode3.getSession()).thenReturn(mockSession);
when(mockNode1.getPath()).thenReturn("/path/to/first/node");
when(mockNode2.getPath()).thenReturn("/second/path/to/node");
when(mockNode3.getPath()).thenReturn("/third/path/to/node");
when(mockNode1.getPrimaryNodeType()).thenReturn(mockNodeType);
when(mockNode2.getPrimaryNodeType()).thenReturn(mockNodeType);
when(mockNode3.getPrimaryNodeType()).thenReturn(mockNodeType);
when(mockNode1.getProperties()).thenReturn(mockProperties);
when(mockNode2.getProperties()).thenReturn(mockProperties);
when(mockNode3.getProperties()).thenReturn(mockProperties);
Expand Down Expand Up @@ -942,7 +943,7 @@ private void logRDF(final Model rdf) throws IOException {
private Function<Node, ValueFactory> mockValueFactoryFunc;

@Mock
private Node mockNode;
private Node mockNode, mockNode1, mockNode2, mockNode3;

@Mock
private Node mockParent;
Expand Down

0 comments on commit 8c427f6

Please sign in to comment.