Skip to content

Commit

Permalink
Defined ordering for node type selections
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Dec 15, 2013
1 parent cfcae2e commit bb0fb04
Showing 1 changed file with 33 additions and 10 deletions.
Expand Up @@ -18,7 +18,6 @@

import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.RDFNode;
Expand All @@ -38,17 +37,19 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static com.google.common.collect.Collections2.transform;
import static com.google.common.collect.Maps.transformValues;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
import static java.util.Arrays.asList;
import static java.util.Collections.sort;
import static org.apache.http.HttpStatus.SC_BAD_REQUEST;
import static org.fcrepo.kernel.rdf.SerializationUtils.getDatasetSubject;
import static org.fcrepo.kernel.rdf.SerializationUtils.unifyDatasetModel;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;
import static org.modeshape.jcr.api.JcrConstants.JCR_DATA;
import static org.slf4j.LoggerFactory.getLogger;

/**
Expand All @@ -65,6 +66,14 @@ public class LDPathTransform implements Transformation {

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

private static final Comparator<NodeType> nodeTypeComp = new Comparator<NodeType>() {

@Override
public int compare(final NodeType o1, final NodeType o2) {
return o1.getName().compareTo(o2.getName());

}
};

/**
* Construct a new Transform from the InputStream
Expand All @@ -88,22 +97,36 @@ public static LDPathTransform getNodeTypeTransform(final Node node,

LOGGER.debug("Found program node: {}", programNode.getPath());



final NodeType primaryNodeType = node.getPrimaryNodeType();

final NodeType[] supertypes = primaryNodeType.getSupertypes();
final List<NodeType> supertypes =
asList(primaryNodeType.getSupertypes());
sort(supertypes, nodeTypeComp);

final List<NodeType> mixinTypes = asList(node.getMixinNodeTypes());
sort(mixinTypes, nodeTypeComp);

final ImmutableList.Builder<NodeType> nodeTypesB =
new ImmutableList.Builder<NodeType>().addAll(mixinTypes).add(
primaryNodeType).addAll(supertypes);

for (final NodeType mixin : mixinTypes) {
final List<NodeType> mixinSupers = asList(mixin.getDeclaredSupertypes());
sort(mixinSupers, nodeTypeComp);
nodeTypesB.addAll(mixinSupers);
}

final Set<NodeType> nodeTypes =
new ImmutableSet.Builder<NodeType>().addAll(
asList(node.getMixinNodeTypes())).add(primaryNodeType)
.addAll(asList(supertypes)).build();
final List<NodeType> nodeTypes = nodeTypesB.build();

LOGGER.debug("Discovered node types: {}", nodeTypes);

for (final NodeType nodeType : nodeTypes) {
if (programNode.hasNode(nodeType.toString())) {
return new LDPathTransform(programNode.getNode(nodeType.toString())
.getNode("jcr:content")
.getProperty("jcr:data")
.getNode(JCR_CONTENT)
.getProperty(JCR_DATA)
.getBinary().getStream());
}
}
Expand Down

0 comments on commit bb0fb04

Please sign in to comment.