Skip to content

Commit

Permalink
Minor code shortening
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Feb 5, 2015
1 parent 3eeb080 commit 229f6de
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
Expand Up @@ -21,8 +21,8 @@
import org.fcrepo.kernel.models.FedoraResource;
import org.fcrepo.kernel.identifiers.IdentifierConverter;
import org.fcrepo.kernel.impl.rdf.impl.mappings.PropertyValueIterator;
import org.fcrepo.kernel.impl.utils.UncheckedFunction;
import org.fcrepo.kernel.impl.utils.UncheckedPredicate;

import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
Expand All @@ -33,6 +33,7 @@
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;

import static com.google.common.collect.ImmutableList.of;
import static java.util.Arrays.asList;
import static javax.jcr.PropertyType.PATH;
Expand All @@ -41,6 +42,7 @@
import static org.fcrepo.kernel.impl.identifiers.NodeResourceConverter.nodeConverter;
import static org.fcrepo.kernel.impl.utils.FedoraTypesUtils.isBlankNode;
import static org.fcrepo.kernel.impl.utils.Streams.fromIterator;
import static org.fcrepo.kernel.impl.utils.UncheckedFunction.uncheck;

/**
* Embed all blank nodes in the RDF stream
Expand Down Expand Up @@ -84,14 +86,6 @@ private Stream<Node> getBlankNodesIterator() throws RepositoryException {
private static final Predicate<Property> filterReferenceProperties = UncheckedPredicate
.uncheck(p -> referencePropertyTypes.contains(p.getType()));

private final Function<Value, Node> getNodesForValue = UncheckedFunction.uncheck(v -> {
final Node refNode;
if (v.getType() == PATH) {
refNode = resource().getNode().getSession().getNode(v.getString());
} else {
refNode = resource().getNode().getSession().getNodeByIdentifier(v.getString());
}
return refNode;
});

private final Function<Value, Node> getNodesForValue = uncheck(v ->
v.getType() == PATH ? session().getNode(v.getString()) : session().getNodeByIdentifier(v.getString()));
}
Expand Up @@ -35,6 +35,7 @@

/**
* @author cabeer
* @author ajs6f
* @since 9/16/14
*/
public class ChildrenRdfContext extends NodeRdfContext {
Expand All @@ -61,13 +62,9 @@ public ChildrenRdfContext(final FedoraResource resource,
}

private final Function<FedoraResource, Triple> child2triples = child -> {
final FedoraResource describedThing;
if (child instanceof NonRdfSourceDescription) {
final NonRdfSourceDescription description = (NonRdfSourceDescription) child;
describedThing = description.getDescribedResource();
} else {
describedThing = child;
}
final FedoraResource describedThing =
child instanceof NonRdfSourceDescription ? ((NonRdfSourceDescription) child).getDescribedResource()
: child;
final com.hp.hpl.jena.graph.Node childSubject = translator().reverse().convert(describedThing).asNode();
LOGGER.trace("Creating triples for child node: {}", child);
return create(subject(), CONTAINS.asNode(), childSubject);
Expand Down
Expand Up @@ -15,14 +15,18 @@
*/
package org.fcrepo.kernel.impl.rdf.impl;

import static java.util.Objects.nonNull;
import static org.fcrepo.kernel.impl.identifiers.NodeResourceConverter.nodeToResource;
import static org.slf4j.LoggerFactory.getLogger;

import javax.jcr.Node;
import javax.jcr.RepositoryException;

import org.fcrepo.kernel.models.FedoraResource;
import org.fcrepo.kernel.exception.RepositoryRuntimeException;
import org.fcrepo.kernel.identifiers.IdentifierConverter;
import org.fcrepo.kernel.utils.iterators.RdfStream;

import org.slf4j.Logger;

import com.google.common.base.Converter;
Expand Down Expand Up @@ -54,6 +58,14 @@ public NodeRdfContext(final FedoraResource resource,
final IdentifierConverter<Resource, FedoraResource> idTranslator) {
super();
this.resource = resource;
try {
final Node node = resource().getNode();
if (nonNull(node)) {
session(node.getSession());
}
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
this.idTranslator = idTranslator;
this.subject = idTranslator.reverse().convert(resource).asNode();
}
Expand Down

0 comments on commit 229f6de

Please sign in to comment.