Skip to content

Commit

Permalink
Cleaning compiler warnings and other nonfunctional changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Dec 16, 2014
1 parent 38d5939 commit ed42a0f
Show file tree
Hide file tree
Showing 30 changed files with 484 additions and 422 deletions.
Expand Up @@ -71,6 +71,7 @@
* A set of helpful tools for converting JCR properties to RDF
*
* @author Chris Beer
* @author ajs6f
* @since May 10, 2013
*/
public class JcrRdfTools {
Expand All @@ -93,7 +94,7 @@ public class JcrRdfTools {
private final IdentifierConverter<Resource, FedoraResource> idTranslator;
private final ValueConverter valueConverter;

private Session session;
private final Session session;
private final NodePropertiesTools nodePropertiesTools = new NodePropertiesTools();

@VisibleForTesting
Expand Down Expand Up @@ -413,7 +414,7 @@ private Resource getSkolemizedResource(final IdentifierConverter<Resource, Fedor
return skolemizedBnodeMap.get(id);
}

private String skolemizedId() {
return "/.well-known/genid/" + randomUUID().toString();
private static String skolemizedId() {
return "/.well-known/genid/" + randomUUID();
}
}
Expand Up @@ -196,6 +196,7 @@ public RdfLiteralJcrValueBuilder(final String literal) {
}
}

@Override
public String toString() {
final StringBuilder b = new StringBuilder();

Expand Down Expand Up @@ -225,9 +226,8 @@ public String value() {
public RDFDatatype datatype() {
if (hasDatatypeUri()) {
return new BaseDatatype(datatypeUri);
} else {
return null;
}
return null;
}

public String lang() {
Expand Down
Expand Up @@ -19,26 +19,29 @@
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;
import com.hp.hpl.jena.graph.NodeFactory;
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;
import static com.hp.hpl.jena.graph.NodeFactory.createURI;
import static com.hp.hpl.jena.graph.Triple.create;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
import static java.util.Collections.emptyIterator;
Expand All @@ -56,6 +59,7 @@

/**
* @author cabeer
* @author ajs6f
* @since 9/25/14
*/
public class LdpContainerRdfContext extends NodeRdfContext {
Expand All @@ -73,26 +77,27 @@ public LdpContainerRdfContext(final FedoraResource resource,
throws RepositoryException {
super(resource, idTranslator);
final Iterator<Property> properties = Iterators.filter(new PropertyIterator(resource.getNode().getReferences
(LDP_MEMBER_RESOURCE)), new Predicate<Property>() {


@Override
public boolean apply(final Property input) {
try {
final Node container = input.getParent();
return container.isNodeType(LDP_DIRECT_CONTAINER) || container.isNodeType(LDP_INDIRECT_CONTAINER);
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
}
});
(LDP_MEMBER_RESOURCE)), isContainer );

if (properties.hasNext()) {
LOGGER.trace("Found membership containers for {}", resource);
concat(membershipContext(properties));
}
}

private static Predicate<Property> isContainer = new Predicate<Property>() {

@Override
public boolean apply(final Property property) {
try {
final Node container = property.getParent();
return container.isNodeType(LDP_DIRECT_CONTAINER) || container.isNodeType(LDP_INDIRECT_CONTAINER);
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
}
};

private Iterator<Triple> membershipContext(final Iterator<Property> properties) {
return Iterators.concat(Iterators.transform(properties, nodes2triples()));
}
Expand All @@ -101,12 +106,11 @@ private Function<Property, Iterator<Triple>> nodes2triples() {
return new Function<Property,Iterator<Triple>>() {

@Override
public Iterator<Triple> apply(final Property input) {
public Iterator<Triple> apply(final Property property) {
try {
final FedoraResource resource = nodeConverter.convert(input.getParent());

final FedoraResource resource = nodeConverter.convert(property.getParent());
return memberRelations(resource);
} catch (RepositoryException e) {
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
}
Expand All @@ -124,7 +128,7 @@ private Iterator<Triple> memberRelations(final FedoraResource container) throws

if (container.hasProperty(LDP_HAS_MEMBER_RELATION)) {
final Property property = container.getProperty(LDP_HAS_MEMBER_RELATION);
memberRelation = NodeFactory.createURI(property.getString());
memberRelation = createURI(property.getString());
} else if (container.hasType(LDP_BASIC_CONTAINER)) {
memberRelation = LDP_MEMBER.asNode();
} else {
Expand Down Expand Up @@ -162,33 +166,30 @@ public Iterator<Triple> apply(final FedoraResource child) {
if (insertedContainerProperty.equals(MEMBER_SUBJECT.getURI())) {

return singletonIterator(create(subject(), memberRelation, childSubject));
} else {
}
final String insertedContentProperty = getPropertyNameFromPredicate(resource().getNode(),
createResource(insertedContainerProperty),
null);

final String insertedContentProperty = getPropertyNameFromPredicate(resource().getNode(),
createResource(insertedContainerProperty),
null);
if (!child.hasProperty(insertedContentProperty)) {
return emptyIterator();
}

if (!child.hasProperty(insertedContentProperty)) {
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())
.convert(input);
return create(subject(), memberRelation, membershipResource.asNode());
}
});
}
return Iterators.transform(values, new Function<Value, Triple>() {
@Override
public Triple apply(final Value input) {
final RDFNode membershipResource = new ValueConverter(session(), translator())
.convert(input);
return create(subject(), memberRelation, membershipResource.asNode());
}
});
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
}
}));
}

}
Expand Up @@ -15,13 +15,18 @@
*/
package org.fcrepo.kernel.impl.rdf.impl.mappings;

import static com.google.common.collect.Iterators.singletonIterator;

import com.google.common.collect.AbstractIterator;
import com.google.common.collect.Iterators;

import org.fcrepo.kernel.exception.RepositoryRuntimeException;
import org.fcrepo.kernel.utils.iterators.PropertyIterator;

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

import java.util.Iterator;

/**
Expand All @@ -30,26 +35,36 @@
* @author cabeer
*/
public class PropertyValueIterator extends AbstractIterator<Value> {
private Iterator<Property> properties;
private final Iterator<Property> properties;
private Iterator<Value> currentValues;

/**
* Iterate through a single property's values
* Iterate through multiple properties' values
* @param properties
*/
public PropertyValueIterator(final Property properties) {
this(Iterators.singletonIterator(properties));
public PropertyValueIterator(final PropertyIterator properties) {
this.properties = properties;
this.currentValues = null;
}

/**
* Iterate through multiple property's values
* Iterate through multiple properties' values
* @param properties
*/
public PropertyValueIterator(final Iterator<Property> properties) {
this.properties = properties;
this.currentValues = null;
}

/**
* Iterate through a property's values
* @param properties
*/
public PropertyValueIterator(final Property property) {
this.properties = singletonIterator(property);
this.currentValues = null;
}

@Override
protected Value computeNext() {
try {
Expand All @@ -62,10 +77,9 @@ protected Value computeNext() {
if (property.isMultiple()) {
currentValues = Iterators.forArray(property.getValues());
return currentValues.next();
} else {
currentValues = null;
return property.getValue();
}
currentValues = null;
return property.getValue();
}

return endOfData();
Expand Down
Expand Up @@ -31,6 +31,7 @@

/**
* @author bbpennel
* @author ajs6f
* @since Feb 20, 2014
*/
public abstract class AbstractService {
Expand Down Expand Up @@ -63,8 +64,8 @@ protected Node findNode(final Session session, final String path) {
}
}

private void tagHierarchyWithPairtreeMixin(final Node baseNode,
final Node createdNode) throws RepositoryException {
private static void tagHierarchyWithPairtreeMixin(final Node baseNode, final Node createdNode)
throws RepositoryException {
Node parent = createdNode.getParent();

while (parent.isNew() && !parent.equals(baseNode)) {
Expand Down
Expand Up @@ -37,6 +37,7 @@

/**
* @author cabeer
* @author ajs6f
* @since 10/10/14
*/
@Component
Expand Down Expand Up @@ -84,7 +85,7 @@ public FedoraBinary find(final Session session, final String path) {
}
}

private void initializeNewDatastreamProperties(final Node node) {
private static void initializeNewDatastreamProperties(final Node node) {
try {

if (node.canAddMixin(FEDORA_RESOURCE)) {
Expand Down Expand Up @@ -117,7 +118,7 @@ public FedoraBinary cast(final Node node) {
return new FedoraBinaryImpl(node);
}

private void assertIsType(final Node node) {
private static void assertIsType(final Node node) {
if (!FedoraBinaryImpl.hasMixin(node)) {
throw new ResourceTypeException(node + " can not be used as a binary");
}
Expand Down
Expand Up @@ -17,6 +17,7 @@

import static org.fcrepo.kernel.FedoraJcrTypes.FEDORA_CONTAINER;
import static org.fcrepo.kernel.FedoraJcrTypes.FEDORA_RESOURCE;
import static org.fcrepo.kernel.impl.ContainerImpl.hasMixin;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;
import static org.modeshape.jcr.api.JcrConstants.NT_FOLDER;
import static org.slf4j.LoggerFactory.getLogger;
Expand All @@ -30,13 +31,15 @@
import org.fcrepo.kernel.exception.ResourceTypeException;
import org.fcrepo.kernel.impl.ContainerImpl;
import org.fcrepo.kernel.services.ContainerService;

import org.slf4j.Logger;
import org.springframework.stereotype.Component;

/**
* Service for creating and retrieving FedoraObjects without using the JCR API.
*
* @author cbeer
* @author ajs6f
* @since Feb 11, 2013
*/
@Component
Expand Down Expand Up @@ -81,7 +84,7 @@ public Container find(final Session session, final String path) {
return cast(node);
}

private void initializeNewObjectProperties(final Node node) {
private static void initializeNewObjectProperties(final Node node) {
try {
LOGGER.debug("Setting object properties on node {}...", node.getPath());

Expand All @@ -105,8 +108,8 @@ public Container cast(final Node node) {
return new ContainerImpl(node);
}

private void assertIsType(final Node node) {
if (!ContainerImpl.hasMixin(node)) {
private static void assertIsType(final Node node) {
if (!hasMixin(node)) {
throw new ResourceTypeException(node + " can not be used as a object");
}
}
Expand Down
Expand Up @@ -37,10 +37,10 @@
import org.springframework.stereotype.Component;

/**
* Service for managing access to Fedora 'nodes' (either datastreams or objects,
* we don't care.)
* Service for managing access to Fedora 'nodes' (either datastreams or objects, we don't care.)
*
* @author Chris Beer
* @author ajs6f
* @since May 9, 2013
*/
@Component
Expand Down Expand Up @@ -122,7 +122,7 @@ public void moveObject(final Session session, final String source, final String
}
}

private void createTombstone(final Node parent, final String path) throws RepositoryException {
private static void createTombstone(final Node parent, final String path) throws RepositoryException {
final FedoraResourceImpl fedoraResource = new FedoraResourceImpl(parent);
final Node n = fedoraResource.findOrCreateChild(parent, path, FEDORA_TOMBSTONE);
LOGGER.info("Created tombstone at {} ", n.getPath());
Expand Down

0 comments on commit ed42a0f

Please sign in to comment.