Navigation Menu

Skip to content

Commit

Permalink
Factored out an unneeded type (RdfContext) for simplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Oct 15, 2013
1 parent 8c427f6 commit b0b18ea
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 90 deletions.
Expand Up @@ -20,14 +20,15 @@
import javax.jcr.RepositoryException;

import org.fcrepo.kernel.services.LowLevelStorageService;
import org.fcrepo.kernel.utils.iterators.RdfStream;

/**
* {@link RdfContext} that holds contexts related to a specific {@link Node}.
* {@link RdfStream} that holds contexts related to a specific {@link Node}.
*
* @author ajs6f
* @date Oct 10, 2013
*/
public abstract class NodeRdfContext extends RdfContext {
public abstract class NodeRdfContext extends RdfStream {

private final Node node;

Expand Down
46 changes: 0 additions & 46 deletions fcrepo-kernel/src/main/java/org/fcrepo/kernel/rdf/RdfContext.java

This file was deleted.

Expand Up @@ -57,19 +57,19 @@ public HierarchyRdfContext(final javax.jcr.Node node,
final GraphSubjects graphSubjects, final LowLevelStorageService lowLevelStorageService) throws RepositoryException {
super(node, graphSubjects, lowLevelStorageService);
if (node.getDepth() > 0) {
context().concat(parentContext());
concat(parentContext());

}
if (node.hasNodes()) {
context().concat(childrenContext());
concat(childrenContext());
}
}

private Iterator<Triple> parentContext() throws RepositoryException {
final javax.jcr.Node parentNode = node().getParent();
final Node parentNodeSubject =
graphSubjects().getGraphSubject(parentNode).asNode();
return new PropertiesRdfContext(parentNode, graphSubjects(), lowLevelStorageService()).context()
return new PropertiesRdfContext(parentNode, graphSubjects(), lowLevelStorageService())
.concat(Iterators
.forArray(new Triple[] {
create(subject(), HAS_PARENT.asNode(),
Expand Down
Expand Up @@ -30,7 +30,7 @@
import javax.jcr.RepositoryException;
import javax.jcr.Session;

import org.fcrepo.kernel.rdf.RdfContext;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.slf4j.Logger;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableMap;
Expand All @@ -39,12 +39,13 @@
import com.hp.hpl.jena.graph.Triple;

/**
* An {@link RdfContext} that holds the namespace mappings for serializations.
* An {@link RdfStream} that holds the namespace mappings for serializations,
* as well as {@link Triple}s describing those namespaces.
*
* @author ajs6f
* @date Oct 9, 2013
*/
public class NamespaceContext extends RdfContext {
public class NamespaceContext extends RdfStream {

private static Logger LOGGER = getLogger(NamespaceContext.class);

Expand Down Expand Up @@ -89,6 +90,6 @@ public NamespaceContext(final Session session) throws RepositoryException {
createLiteral(nsURI)));
}
}
context.concat(nsTriples.build()).addNamespaces(namespaces.build());
concat(nsTriples.build()).addNamespaces(namespaces.build());
}
}
Expand Up @@ -18,7 +18,6 @@

import static com.google.common.base.Predicates.not;
import static com.google.common.collect.ImmutableSet.builder;
import static com.google.common.collect.Iterators.concat;
import static com.google.common.collect.Iterators.filter;
import static com.google.common.collect.Iterators.transform;
import static com.hp.hpl.jena.graph.NodeFactory.createLiteral;
Expand Down Expand Up @@ -110,7 +109,7 @@ private void putPropertiesIntoContext() throws RepositoryException {
node());

// this node's own properties
context().concat(triplesFromProperties(node()));
concat(triplesFromProperties(node()));

// if there's a jcr:content node, include information about it
if (node().hasNode(JCR_CONTENT)) {
Expand All @@ -120,20 +119,19 @@ private void putPropertiesIntoContext() throws RepositoryException {
final Node subject =
graphSubjects().getGraphSubject(node()).asNode();
// add triples representing parent-to-content-child relationship
context().concat(
concat(
Iterators.forArray(new Triple[] {
create(subject, HAS_CONTENT.asNode(),
contentSubject),
create(contentSubject, IS_CONTENT_OF.asNode(),
subject)}));
// add properties from content child
context()
.concat(triplesFromProperties(node().getNode(JCR_CONTENT)));
concat(triplesFromProperties(node().getNode(JCR_CONTENT)));

// add triples describing storage of content child
lowLevelStorageService().setRepository(
node().getSession().getRepository());
context().concat(
concat(
transform(lowLevelStorageService().getLowLevelCacheEntries(
contentNode).iterator(),
new Function<LowLevelCacheEntry, Triple>() {
Expand All @@ -150,7 +148,7 @@ public Triple apply(
}

if (node().getPrimaryNodeType().getName().equals(ROOT)) {
context().concat(triplesForRootNode());
concat(triplesForRootNode());
}

}
Expand Down Expand Up @@ -234,9 +232,11 @@ private Iterator<Triple> triplesFromProperties(final javax.jcr.Node n)
filter(new PropertyIterator(n.getProperties()),
not(isBinaryProperty));

return concat(new ZippingIterator<>(transform(nonBinaryProperties,
property2values), transform(nonBinaryPropertiesCopy,
property2triple)));
return Iterators.concat(new ZippingIterator<>(
transform(
nonBinaryProperties, property2values),
transform(
nonBinaryPropertiesCopy, property2triple)));

}

Expand Down
Expand Up @@ -58,7 +58,7 @@ public VersionsRdfContext(final Node node, final GraphSubjects graphSubjects,
final LowLevelStorageService lowLevelStorageService)
throws RepositoryException {
super(node, graphSubjects, lowLevelStorageService);
context().concat(versionTriples());
concat(versionTriples());
}

private Iterator<Triple> versionTriples() throws RepositoryException {
Expand All @@ -81,9 +81,8 @@ private Iterator<Triple> versionTriples() throws RepositoryException {
for (final String label : versionLabels) {
b.add(create(versionSubject, HAS_VERSION_LABEL.asNode(), createLiteral(label)));
}
context().concat(
new PropertiesRdfContext(frozenNode, graphSubjects(),
lowLevelStorageService()).context());
concat(new PropertiesRdfContext(frozenNode, graphSubjects(),
lowLevelStorageService()));

}
return b.build().iterator();
Expand Down
Expand Up @@ -16,11 +16,11 @@

package org.fcrepo.kernel.rdf.impl.mappings;

import static org.slf4j.LoggerFactory.getLogger;

import java.util.Iterator;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.AbstractIterator;
import com.google.common.base.Function;

Expand All @@ -37,30 +37,29 @@ public class ZippingIterator<F, T> extends AbstractIterator<T> {

Iterator<F> from;

Iterator<Function<F, T>> to;
Iterator<Function<F, T>> through;

private static Logger LOGGER = LoggerFactory
.getLogger(ZippingIterator.class);
private static Logger LOGGER = getLogger(ZippingIterator.class);

/**
* Default constructor.
*
* @param from
* @param to
* @param through
*/
public ZippingIterator(final Iterator<F> from,
final Iterator<Function<F, T>> to) {
final Iterator<Function<F, T>> through) {
this.from = from;
this.to = to;
this.through = through;
}

@Override
protected T computeNext() {
final boolean hasNext = (from.hasNext() && to.hasNext());
final boolean hasNext = (from.hasNext() && through.hasNext());
if (hasNext) {
LOGGER.debug("Found next element.");
final F f = from.next();
final Function<F, T> t = to.next();
final Function<F, T> t = through.next();
LOGGER.debug("Supplying from next element {} through function {}",
f, t);
return t.apply(f);
Expand Down
Expand Up @@ -248,7 +248,7 @@ public JcrRdfTools withSession(final Session session) {
* @throws RepositoryException
*/
public Model getJcrPropertiesModel() throws RepositoryException {
return new NamespaceContext(session).context().asModel();
return new NamespaceContext(session).asModel();
}

/**
Expand All @@ -267,7 +267,7 @@ public Model getJcrPropertiesModel(final Iterator<Node> nodeIterator,
while (nodeIterator.hasNext()) {
final Node node = nodeIterator.next();
results.concat(new PropertiesRdfContext(node, graphSubjects,
llstore).context());
llstore));
if (iteratorSubject != null) {
results.concat(singleton(create(iteratorSubject.asNode(),
HAS_MEMBER_OF_RESULT.asNode(), graphSubjects
Expand All @@ -288,11 +288,10 @@ public Model getJcrPropertiesModel(final Iterator<Node> nodeIterator,
* @throws RepositoryException
*/
public Model getJcrPropertiesModel(final Node node) throws RepositoryException {
final RdfStream namespaceContext =
new NamespaceContext(session).context();
final RdfStream namespaceContext = new NamespaceContext(session);
return namespaceContext.concat(
new PropertiesRdfContext(node, graphSubjects, llstore)
.context()).asModel();
new PropertiesRdfContext(node, graphSubjects, llstore))
.asModel();
}
/**
* Get a Jena RDF model for the JCR version history information for a node
Expand All @@ -304,8 +303,7 @@ public Model getJcrPropertiesModel(final Node node) throws RepositoryException {
*/
public Model getJcrVersionPropertiesModel(final Node node)
throws RepositoryException {
return new VersionsRdfContext(node, graphSubjects, llstore).context()
.asModel();
return new VersionsRdfContext(node, graphSubjects, llstore).asModel();
}

/**
Expand Down Expand Up @@ -357,7 +355,7 @@ public Model getJcrPropertiesModel(final Node node,
* @throws RepositoryException
*/
public Model getJcrNamespaceModel() throws RepositoryException {
return new NamespaceContext(session).context().asModel();
return new NamespaceContext(session).asModel();
}

/**
Expand Down
Expand Up @@ -56,8 +56,7 @@ public void testConstructor() throws RepositoryException {
when(mockSession.getWorkspace()).thenReturn(mockWorkspace);
when(mockWorkspace.getNamespaceRegistry()).thenReturn(
mockNamespaceRegistry);
assertTrue(any(new NamespaceContext(mockSession).context(),
hasTestUriAsObject));
assertTrue(any(new NamespaceContext(mockSession), hasTestUriAsObject));
}

private static Predicate<Triple> hasTestUriAsObject =
Expand Down

0 comments on commit b0b18ea

Please sign in to comment.