Skip to content

Commit

Permalink
hack in datastream location information to rdf response
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed May 15, 2013
1 parent dc2f6fd commit 0dbb83a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
27 changes: 24 additions & 3 deletions fcrepo-kernel/src/main/java/org/fcrepo/utils/JcrRdfTools.java
@@ -1,6 +1,5 @@
package org.fcrepo.utils;

import com.google.common.base.Predicate;
import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import com.hp.hpl.jena.datatypes.RDFDatatype;
Expand All @@ -10,20 +9,21 @@
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import org.fcrepo.services.LowLevelStorageService;
import org.modeshape.jcr.api.JcrConstants;
import org.modeshape.jcr.api.NamespaceRegistry;
import org.slf4j.Logger;

import javax.jcr.*;
import javax.jcr.PropertyIterator;
import javax.jcr.version.Version;
import javax.jcr.version.VersionHistory;
import javax.jcr.version.VersionIterator;


import java.util.Set;

import static com.google.common.base.Preconditions.checkArgument;
import static org.fcrepo.utils.FedoraJcrTypes.FCR_CONTENT;
import static org.fcrepo.utils.FedoraJcrTypes.FEDORA_OBJECT;
import static org.slf4j.LoggerFactory.getLogger;

public abstract class JcrRdfTools {
Expand Down Expand Up @@ -152,9 +152,30 @@ public static Model getJcrPropertiesModel(final Node node) throws RepositoryExce

addJcrTreePropertiesToModel(node, model);

if (node.hasNode(JcrConstants.JCR_CONTENT)) {
addJcrContentLocationInformationToModel(node, model);
}

return model;
}

private static void addJcrContentLocationInformationToModel(final Node node, final Model model) throws RepositoryException {
final Node contentNode = node.getNode(JcrConstants.JCR_CONTENT);
final Resource contentNodeSubject = getGraphSubject(contentNode);

// TODO: get this from somewhere else.
LowLevelStorageService llstore = new LowLevelStorageService();
llstore.setRepository(node.getSession().getRepository());

final Set<LowLevelCacheEntry> cacheEntries = llstore.getLowLevelCacheEntries(node);

for (LowLevelCacheEntry e : cacheEntries) {
model.add(contentNodeSubject, model.createProperty("info:fedora/fedora-system:def/internal#hasLocation"), e.getExternalIdentifier());
}


}

/**
* Add the properties of a Node's parent and immediate children (as well as the jcr:content of children) to the given
* RDF model
Expand Down
Expand Up @@ -157,6 +157,12 @@ public void testDatastreamGraph() throws IOException, RepositoryException, Inval
o = Node.createLiteral("22", ModelFactory.createDefaultModel().createTypedLiteral(22L).getDatatype());
assertTrue(object.getGraphStore().getDefaultGraph().contains(s, p, o));

// location

p = Node.createURI("info:fedora/fedora-system:def/internal#hasLocation");
o = Node.ANY;

assertTrue(object.getGraphStore().getDefaultGraph().contains(s, p, o));


session.logout();
Expand Down

0 comments on commit 0dbb83a

Please sign in to comment.