Skip to content

Commit

Permalink
Simple cleanup using Java 8 types and syntax for RDF generating code
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Jul 30, 2015
1 parent 54c729b commit 8a2e747
Show file tree
Hide file tree
Showing 22 changed files with 356 additions and 682 deletions.
Expand Up @@ -82,7 +82,7 @@
import org.fcrepo.kernel.api.services.policy.StoragePolicyDecisionPoint;
import org.fcrepo.kernel.api.utils.iterators.RdfStream;
import org.fcrepo.kernel.modeshape.rdf.impl.AclRdfContext;
import org.fcrepo.kernel.modeshape.rdf.impl.BlankNodeRdfContext;
import org.fcrepo.kernel.modeshape.rdf.impl.SkolemNodeRdfContext;
import org.fcrepo.kernel.modeshape.rdf.impl.ChildrenRdfContext;
import org.fcrepo.kernel.modeshape.rdf.impl.ContentRdfContext;
import org.fcrepo.kernel.modeshape.rdf.impl.HashRdfContext;
Expand Down Expand Up @@ -253,7 +253,7 @@ protected RdfStream getResourceTriples() {

// Embed all hash and blank nodes
rdfStream.concat(filter(getTriples(HashRdfContext.class), tripleFilter::test));
rdfStream.concat(filter(getTriples(BlankNodeRdfContext.class), tripleFilter::test));
rdfStream.concat(filter(getTriples(SkolemNodeRdfContext.class), tripleFilter::test));

// Include inbound references to this object
if (ldpPreferences.prefersReferences()) {
Expand All @@ -268,7 +268,7 @@ protected RdfStream getResourceTriples() {
rdfStream.concat(filter(concat(transform(children, child ->
child.getTriples(translator(),
ImmutableList.of(
TypeRdfContext.class, PropertiesRdfContext.class, BlankNodeRdfContext.class)))),
TypeRdfContext.class, PropertiesRdfContext.class, SkolemNodeRdfContext.class)))),
tripleFilter::test));

}
Expand Down
Expand Up @@ -19,12 +19,12 @@
import javax.jcr.Property;
import javax.jcr.Value;

import org.fcrepo.kernel.api.utils.UncheckedFunction;

import java.util.Iterator;
import java.util.function.Function;
import java.util.function.Predicate;

import org.fcrepo.kernel.api.utils.UncheckedFunction;

import static com.google.common.collect.Iterators.forArray;
import static com.google.common.collect.Iterators.singletonIterator;
import static javax.jcr.PropertyType.BINARY;
Expand All @@ -42,11 +42,11 @@ private JcrPropertyFunctions() {
}

/**
* Constructs an {@link java.util.Iterator} of {@link javax.jcr.Value}s from any
* {@link javax.jcr.Property}, multi-valued or not.
* Constructs an {@link java.util.Iterator} of {@link javax.jcr.Value}s from any {@link javax.jcr.Property},
* multi- or single-valued.
*/
public static Function<Property, Iterator<Value>> property2values = UncheckedFunction.uncheck(
p -> p.isMultiple() ? forArray(p.getValues()) : singletonIterator(p.getValue()));
(final Property p) -> p.isMultiple() ? forArray(p.getValues()) : singletonIterator(p.getValue()));

/**
* Check if a JCR property is a binary jcr:data property
Expand Down
Expand Up @@ -45,7 +45,7 @@
*/
public class RdfStream extends ForwardingIterator<Triple> {

private Map<String, String> namespaces = new HashMap<>();
private final Map<String, String> namespaces = new HashMap<>();

protected Iterator<Triple> triples;

Expand All @@ -57,7 +57,7 @@ public class RdfStream extends ForwardingIterator<Triple> {

/**
* Constructor that begins the stream with proffered triples.
*
*
* @param triples the triples
* @param <Tr> extends {@link Triple}
* @param <T> extends {@link Iterable}
Expand All @@ -69,7 +69,7 @@ public <Tr extends Triple, T extends Iterator<Tr>> RdfStream(final T triples) {

/**
* Constructor that begins the stream with proffered triples.
*
*
* @param triples the triples
* @param <Tr> extends {@link Triple}
* @param <T> extends {@link Iterable}
Expand All @@ -80,7 +80,7 @@ public <Tr extends Triple, T extends Iterable<Tr>> RdfStream(final T triples) {

/**
* Constructor that begins the stream with proffered triples.
*
*
* @param triples the triples
* @param <Tr> extends {@link Triple}
* @param <T> extends {@link Collection}
Expand All @@ -92,7 +92,7 @@ public <Tr extends Triple, T extends Collection<Tr>> RdfStream(

/**
* Constructor that begins the stream with proffered triples.
*
*
* @param triples the triples
* @param <T> extends {@link Triple}
*/
Expand All @@ -103,7 +103,7 @@ public <T extends Triple> RdfStream(final T... triples) {

/**
* Constructor that begins the stream with proffered statements.
*
*
* @param statements the statements
* @param <T> extends {@link Statement}
*/
Expand All @@ -115,7 +115,7 @@ public <T extends Statement> RdfStream(final T... statements) {

/**
* Constructor that begins the stream with proffered triple.
*
*
* @param triple the triple
* @param <T> extends {@link Triple}
*/
Expand All @@ -132,7 +132,7 @@ public RdfStream() {

/**
* Returns the proffered {@link Triple}s with the context of this RdfStream.
*
*
* @param stream the stream
* @param <Tr> extends {@link Triple}
* @param <T> extends {@link Iterator}
Expand All @@ -144,7 +144,7 @@ public <Tr extends Triple, T extends Iterator<Tr>> RdfStream withThisContext(fin

/**
* Returns the proffered {@link Triple}s with the context of this RdfStream.
*
*
* @param stream the stream
* @param <Tr> extends {@link Triple}
* @param <T> extends {@link Iterator}
Expand Down Expand Up @@ -194,7 +194,7 @@ public RdfStream concat(final Collection<? extends Triple> newTriples) {

/**
* As {@link Iterators#limit(Iterator, int)} while maintaining context.
*
*
* @param limit the limit
* @return RDFStream
*/
Expand All @@ -204,7 +204,7 @@ public RdfStream limit(final Integer limit) {

/**
* As {@link Iterators#advance(Iterator, int)} while maintaining context.
*
*
* @param skipNum the skip number
* @return RDFStream
*/
Expand All @@ -215,7 +215,7 @@ public RdfStream skip(final Integer skipNum) {

/**
* As {@link Iterators#filter(Iterator, Predicate)} while maintaining context.
*
*
* @param predicate the predicate
* @return RdfStream
*/
Expand All @@ -225,7 +225,7 @@ public RdfStream filter(final Predicate<? super Triple> predicate) {

/**
* As {@link Iterators#transform(Iterator, Function)}.
*
*
* @param f the parameter f
* @param <ToType> extends {@link Iterator}
* @return Iterator
Expand All @@ -236,7 +236,7 @@ public <ToType> Iterator<ToType> transform(final Function<? super Triple, ToType

/**
* RdfStream
*
*
* @param prefix the prefix
* @param uri the uri
* @return This object for continued use.
Expand Down Expand Up @@ -264,7 +264,7 @@ public Session session() {

/**
* Sets the JCR context of this stream
*
*
* @param session The {@link Session} in context
* @return the JCR context of this stream
*/
Expand All @@ -282,7 +282,7 @@ public Node topic() {

/**
* Sets the topic of this stream
*
*
* @param topic The {@link Node} topic in context
* @return the stream
*/
Expand All @@ -293,7 +293,7 @@ public RdfStream topic(final Node topic) {

/**
* WARNING! This method exhausts the RdfStream on which it is called!
*
*
* @return A {@link Model} containing the prefix mappings and triples in this stream of RDF
*/
public Model asModel() {
Expand Down Expand Up @@ -359,6 +359,11 @@ public Triple apply(final T prototriple) {
};
}

protected static <From, To> Iterator<To> flatMap(final Iterator<From> i,
final java.util.function.Function<From, Iterator<To>> f) {
return Iterators.concat(Iterators.transform(i, f::apply));
}

/*
* We ignore duplicated triples for equality. (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
Expand Down
Expand Up @@ -43,20 +43,13 @@ public AclRdfContext(final FedoraResource resource,
final IdentifierConverter<Resource, FedoraResource> idTranslator) throws RepositoryException {
super(resource, idTranslator);

// include writable status
concatWritable();
}

private void concatWritable() throws RepositoryException {
boolean writable = false;
try {
resource().getNode().getSession().checkPermission( resource().getPath(), "add_node,set_property,remove" );
writable = true;
} catch ( AccessControlException ex ) {
} catch ( final AccessControlException ex ) {
writable = false;
}

concat(create(subject(), WRITABLE.asNode(), createLiteral(String.valueOf(writable), XSDboolean)));
}

}

This file was deleted.

0 comments on commit 8a2e747

Please sign in to comment.