Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Sonar fixes in org.fcrepo.kernel.impl.rdf.impl
  • Loading branch information
ajs6f committed Nov 13, 2014
1 parent 1e40e1a commit 1503e57
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 135 deletions.
Expand Up @@ -17,9 +17,9 @@

import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterators;
import com.hp.hpl.jena.rdf.model.Resource;

import org.fcrepo.kernel.models.FedoraResource;
import org.fcrepo.kernel.exception.RepositoryRuntimeException;
import org.fcrepo.kernel.identifiers.IdentifierConverter;
Expand All @@ -29,23 +29,32 @@

import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Value;

import java.util.Iterator;
import java.util.Set;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableSet.of;
import static javax.jcr.PropertyType.PATH;
import static javax.jcr.PropertyType.REFERENCE;
import static javax.jcr.PropertyType.WEAKREFERENCE;
import static org.fcrepo.kernel.impl.identifiers.NodeResourceConverter.nodeConverter;
import static org.fcrepo.kernel.impl.utils.FedoraTypesUtils.isBlankNode;

/**
* Embed all blank nodes in the RDF stream
*
* @author cabeer
* @author ajs6f
* @since 10/9/14
*/
public class BlankNodeRdfContext extends NodeRdfContext {

private static final Set<Integer> REFERENCE_PROPERTY_TYPES = of(REFERENCE, WEAKREFERENCE, PATH);

/**
* Default constructor.
*
Expand All @@ -59,16 +68,16 @@ public BlankNodeRdfContext(final FedoraResource resource,
super(resource, idTranslator);

concat(Iterators.concat(Iterators.transform(getBlankNodesIterator(), new Function<Node, RdfStream>() {

@Override
public RdfStream apply(final Node node) {
final FedoraResource resource = nodeConverter.convert(node);

return resource.getTriples(idTranslator, ImmutableList.of(TypeRdfContext.class,
return resource.getTriples(idTranslator, of(TypeRdfContext.class,
PropertiesRdfContext.class,
BlankNodeRdfContext.class));
}
})));

}

private Iterator<Node> getBlankNodesIterator() throws RepositoryException {
Expand All @@ -84,32 +93,25 @@ private Iterator<Node> getBlankNodesIterator() throws RepositoryException {

private static final Predicate<Property> filterReferenceProperties = new Predicate<Property>() {
@Override
public boolean apply(final Property property) {
public boolean apply(final Property p) {
checkNotNull(p);
try {
final int type = property.getType();

return type == PropertyType.REFERENCE
|| type == PropertyType.WEAKREFERENCE
|| type == PropertyType.PATH;
return REFERENCE_PROPERTY_TYPES.contains(p.getType());
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
}
};

private final Function<Value, Node> getNodesForValue = new Function<Value, Node>() {

@Override
public Node apply(final Value v) {
checkNotNull(v);
try {
final Node refNode;

if (v.getType() == PATH) {
refNode = resource().getNode().getSession().getNode(v.getString());
} else {
refNode = resource().getNode().getSession().getNodeByIdentifier(v.getString());
}

return refNode;
final Session session = resource().getNode().getSession();
return v.getType() == PATH ? session.getNode(v.getString()) :
session.getNodeByIdentifier(v.getString());
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
Expand Down
Expand Up @@ -35,6 +35,7 @@

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


private Iterator<Triple> childrenContext() {

final Iterator<FedoraResource> niceChildren = resource().getChildren();

return Iterators.concat(Iterators.transform(niceChildren, child2triples()));
}

Expand All @@ -74,23 +73,16 @@ private Function<FedoraResource, Iterator<Triple>> child2triples() {
public Iterator<Triple> apply(final FedoraResource child) {

final com.hp.hpl.jena.graph.Node childSubject;

if (child instanceof NonRdfSourceDescription) {
childSubject = translator().reverse()
.convert(((NonRdfSourceDescription) child).getDescribedResource())
.asNode();
childSubject =
translator().reverse().convert(((NonRdfSourceDescription) child).getDescribedResource())
.asNode();
} else {
childSubject = translator().reverse().convert(child).asNode();
}
LOGGER.trace("Creating triples for child node: {}", child);
final RdfStream childStream = new RdfStream();

childStream.concat(create(subject(), CONTAINS.asNode(), childSubject));

return childStream;

return new RdfStream(create(subject(), CONTAINS.asNode(), childSubject));
}
};
}

}
Expand Up @@ -22,6 +22,7 @@
import static com.hp.hpl.jena.graph.Triple.create;
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.type;
import static org.fcrepo.kernel.RdfLexicon.CONTENT_LOCATION_TYPE;
import static org.fcrepo.kernel.RdfLexicon.FIXITY_TYPE;
import static org.fcrepo.kernel.RdfLexicon.HAS_MESSAGE_DIGEST;
Expand All @@ -34,10 +35,11 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Iterator;

import javax.jcr.RepositoryException;

import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.vocabulary.RDF;

import org.fcrepo.kernel.models.FedoraResource;
import org.fcrepo.kernel.identifiers.IdentifierConverter;
import org.fcrepo.kernel.utils.FixityResult;
Expand Down Expand Up @@ -80,7 +82,7 @@ public Iterator<Triple> apply(final FixityResult blob) {
try {
b.add(create(idTranslator.reverse().convert(resource).asNode(),
HAS_FIXITY_RESULT.asNode(), resultSubject));
b.add(create(resultSubject, RDF.type.asNode(), FIXITY_TYPE.asNode()));
b.add(create(resultSubject, type.asNode(), FIXITY_TYPE.asNode()));
final String storeIdentifier = blob.getStoreIdentifier();
final com.hp.hpl.jena.graph.Node contentLocation = createResource(storeIdentifier)
.asNode();
Expand All @@ -90,21 +92,14 @@ public Iterator<Triple> apply(final FixityResult blob) {
.asNode(), createLiteral(state
.toString())));
}
final String checksum =
blob.getComputedChecksum().toString();
b.add(create(resultSubject, HAS_MESSAGE_DIGEST
.asNode(), createURI(checksum)));
final String checksum = blob.getComputedChecksum().toString();
b.add(create(resultSubject, HAS_MESSAGE_DIGEST.asNode(), createURI(checksum)));
b.add(create(resultSubject, HAS_SIZE.asNode(),
createTypedLiteral(
blob.getComputedSize())
.asNode()));
createTypedLiteral(blob.getComputedSize()).asNode()));
b.add(create(resultSubject, HAS_CONTENT_LOCATION.asNode(),
contentLocation));
b.add(create(contentLocation,
RDF.type.asNode(),
CONTENT_LOCATION_TYPE.asNode()));
b.add(create(contentLocation,
HAS_CONTENT_LOCATION_VALUE.asNode(),
b.add(create(contentLocation, type.asNode(), CONTENT_LOCATION_TYPE.asNode()));
b.add(create(contentLocation, HAS_CONTENT_LOCATION_VALUE.asNode(),
createLiteral(storeIdentifier)));

return b.build().iterator();
Expand Down
Expand Up @@ -23,19 +23,22 @@
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;

import org.fcrepo.kernel.models.NonRdfSourceDescription;
import org.fcrepo.kernel.models.FedoraResource;
import org.fcrepo.kernel.exception.RepositoryRuntimeException;
import org.fcrepo.kernel.identifiers.IdentifierConverter;
import org.fcrepo.kernel.impl.rdf.converters.ValueConverter;
import org.fcrepo.kernel.impl.rdf.impl.mappings.PropertyValueIterator;
import org.fcrepo.kernel.utils.iterators.PropertyIterator;

import org.slf4j.Logger;

import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Value;

import java.util.Iterator;

import static com.google.common.collect.Iterators.singletonIterator;
Expand All @@ -56,11 +59,14 @@

/**
* @author cabeer
* @author ajs6f
* @since 9/25/14
*/
public class LdpContainerRdfContext extends NodeRdfContext {

private static final Logger LOGGER = getLogger(ChildrenRdfContext.class);


/**
* Default constructor.
*
Expand Down Expand Up @@ -145,7 +151,14 @@ private Iterator<Triple> memberRelations(final FedoraResource container) throws

final Iterator<FedoraResource> memberNodes = container.getChildren();

return Iterators.concat(Iterators.transform(memberNodes, new Function<FedoraResource, Iterator<Triple>>() {
return Iterators.concat(Iterators.transform(memberNodes, childTriples(memberRelation,
insertedContainerProperty)));
}

private final Function<FedoraResource, Iterator<Triple>> childTriples(
final com.hp.hpl.jena.graph.Node memberRelation, final String insertedContainerProperty) {
return new Function<FedoraResource, Iterator<Triple>>() {

@Override
public Iterator<Triple> apply(final FedoraResource child) {

Expand All @@ -171,10 +184,11 @@ public Iterator<Triple> apply(final FedoraResource child) {
return emptyIterator();
}

final PropertyValueIterator values
= new PropertyValueIterator(child.getProperty(insertedContentProperty));
final PropertyValueIterator values =
new PropertyValueIterator(child.getProperty(insertedContentProperty));

return Iterators.transform(values, new Function<Value, Triple>() {

@Override
public Triple apply(final Value input) {
final RDFNode membershipResource = new ValueConverter(session(), translator())
Expand All @@ -186,7 +200,6 @@ public Triple apply(final Value input) {
throw new RepositoryRuntimeException(e);
}
}
}));
};
}

}
Expand Up @@ -15,14 +15,12 @@
*/
package org.fcrepo.kernel.impl.rdf.impl;

import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;

import org.fcrepo.kernel.models.FedoraResource;
import org.fcrepo.kernel.RdfLexicon;
import org.fcrepo.kernel.identifiers.IdentifierConverter;
import org.fcrepo.kernel.impl.rdf.converters.ValueConverter;
import org.fcrepo.kernel.impl.rdf.impl.mappings.PropertyValueIterator;
Expand All @@ -42,10 +40,12 @@
import static org.fcrepo.jcr.FedoraJcrTypes.LDP_INSERTED_CONTENT_RELATION;
import static org.fcrepo.jcr.FedoraJcrTypes.LDP_IS_MEMBER_OF_RELATION;
import static org.fcrepo.jcr.FedoraJcrTypes.LDP_MEMBER_RESOURCE;
import static org.fcrepo.kernel.RdfLexicon.MEMBER_SUBJECT;
import static org.fcrepo.kernel.impl.rdf.converters.PropertyConverter.getPropertyNameFromPredicate;

/**
* @author cabeer
* @author ajs6f
* @since 10/7/14
*/
public class LdpIsMemberOfRdfContext extends NodeRdfContext {
Expand Down Expand Up @@ -92,10 +92,10 @@ private void concatIsMemberOfRelation(final FedoraResource container) throws Rep
return;
}
} else {
insertedContainerProperty = RdfLexicon.MEMBER_SUBJECT.getURI();
insertedContainerProperty = MEMBER_SUBJECT.getURI();
}

if (insertedContainerProperty.equals(RdfLexicon.MEMBER_SUBJECT.getURI())) {
if (insertedContainerProperty.equals(MEMBER_SUBJECT.getURI())) {
concat(create(subject(), memberRelation.asNode(), membershipResource.asNode()));
} else if (container.hasType(LDP_INDIRECT_CONTAINER)) {
final String insertedContentProperty = getPropertyNameFromPredicate(resource().getNode(), createResource
Expand All @@ -117,13 +117,10 @@ public boolean apply(final RDFNode input) {
}
});

concat(Iterators.transform(insertedContentRelations, new Function<RDFNode, Triple>() {
@Override
public Triple apply(final RDFNode input) {
return create(input.asNode(), memberRelation.asNode(), membershipResource.asNode());
}
}));

while (insertedContentRelations.hasNext()) {
concat(create(insertedContentRelations.next().asNode(), memberRelation.asNode(), membershipResource
.asNode()));
}
}
}

Expand Down
Expand Up @@ -16,14 +16,12 @@
package org.fcrepo.kernel.impl.rdf.impl;

import static org.fcrepo.kernel.impl.identifiers.NodeResourceConverter.nodeToResource;
import static org.slf4j.LoggerFactory.getLogger;

import javax.jcr.Node;

import org.fcrepo.kernel.models.FedoraResource;
import org.fcrepo.kernel.identifiers.IdentifierConverter;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.slf4j.Logger;

import com.google.common.base.Converter;
import com.hp.hpl.jena.rdf.model.Resource;
Expand All @@ -42,8 +40,6 @@ public class NodeRdfContext extends RdfStream {

private final com.hp.hpl.jena.graph.Node subject;

private static final Logger LOGGER = getLogger(NodeRdfContext.class);

/**
* Default constructor.
*
Expand Down

0 comments on commit 1503e57

Please sign in to comment.