Skip to content

Commit

Permalink
Moving iterated generation of versioning-related triples through to t…
Browse files Browse the repository at this point in the history
…he domain models
  • Loading branch information
ajs6f committed Oct 25, 2013
1 parent 6a22fd7 commit ce5f246
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 32 deletions.
Expand Up @@ -44,6 +44,7 @@
import org.fcrepo.http.commons.test.util.TestHelpers;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.services.NodeService;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
Expand Down Expand Up @@ -89,7 +90,7 @@ public void testGetVersionList() throws RepositoryException {
when(mockNodes.getObject(any(Session.class), anyString())).thenReturn(
mockResource);
when(mockResource.getVersionDataset(any(HttpGraphSubjects.class)))
.thenReturn(mockDataset);
.thenReturn(new RdfStream());
when(mockVariant.getMediaType()).thenReturn(
new MediaType("text", "turtle"));

Expand Down
Expand Up @@ -27,9 +27,11 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.StreamingOutput;

import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.slf4j.Logger;

import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.query.DatasetFactory;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.update.GraphStore;

Expand Down Expand Up @@ -70,6 +72,19 @@ public GraphStoreStreamingOutput(final Dataset dataset,
contentTypeToLang(mediaType.toString()).getName().toUpperCase();
}

/**
* Construct the StreamingOutput machinery to serialize
* an RdfStream to the mime type given
* @param dataset
* @param mediaType
*/
public GraphStoreStreamingOutput(final RdfStream stream,
final MediaType mediaType) {
this.dataset = DatasetFactory.create(stream.asModel());
format =
contentTypeToLang(mediaType.toString()).getName().toUpperCase();
}

@Override
public void write(final OutputStream out) throws IOException,
WebApplicationException {
Expand Down
17 changes: 4 additions & 13 deletions fcrepo-kernel/src/main/java/org/fcrepo/kernel/FedoraResource.java
Expand Up @@ -43,11 +43,11 @@
import org.fcrepo.kernel.rdf.GraphSubjects;
import org.fcrepo.kernel.rdf.impl.JcrGraphProperties;
import org.fcrepo.kernel.utils.JcrRdfTools;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.modeshape.jcr.api.JcrTools;
import org.slf4j.Logger;

import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.query.DatasetFactory;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.update.UpdateRequest;

Expand Down Expand Up @@ -263,19 +263,10 @@ public Dataset getPropertiesDataset(final GraphSubjects subjects)
* @return
* @throws RepositoryException
*/
public Dataset getVersionDataset(final GraphSubjects subjects)
public RdfStream getVersionDataset(final GraphSubjects subjects)
throws RepositoryException {
final Model model =
JcrRdfTools.withContext(subjects, node.getSession())
.getJcrVersionPropertiesModel(node).asModel();

final Dataset dataset = DatasetFactory.create(model);

final String uri = subjects.getGraphSubject(node).getURI();
final com.hp.hpl.jena.sparql.util.Context context = dataset.getContext();
context.set(URI_SYMBOL,uri);

return dataset;
return JcrRdfTools.withContext(subjects, node.getSession())
.getJcrVersionPropertiesModel(node);
}

/**
Expand Down
Expand Up @@ -19,7 +19,9 @@
import static com.hp.hpl.jena.graph.Node.ANY;
import static com.hp.hpl.jena.graph.NodeFactory.createLiteral;
import static com.hp.hpl.jena.graph.NodeFactory.createURI;
import static com.hp.hpl.jena.graph.Triple.createMatch;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createPlainLiteral;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createProperty;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createTypedLiteral;
import static java.util.Arrays.asList;
import static javax.jcr.PropertyType.LONG;
Expand Down Expand Up @@ -58,8 +60,13 @@
import org.springframework.test.context.ContextConfiguration;

import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.sparql.core.DatasetGraph;
import com.hp.hpl.jena.sparql.util.Symbol;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
Expand Down Expand Up @@ -353,26 +360,24 @@ public void testGetObjectVersionGraph() throws RepositoryException {

session.save();

final Dataset graphStore = object.getVersionDataset(subjects);
final Model graphStore = object.getVersionDataset(subjects).asModel();

logger.info(graphStore.toString());

// go querying for the version URI
Node s = createURI(RESTAPI_NAMESPACE + "/testObjectVersionGraph");
Node p = createURI(REPOSITORY_NAMESPACE + "hasVersion");
final ExtendedIterator<Triple> triples =
graphStore.asDatasetGraph().getDefaultGraph().find(
createMatch(s, p, ANY));
Resource s = createResource(RESTAPI_NAMESPACE + "/testObjectVersionGraph");
Property p = createProperty(REPOSITORY_NAMESPACE + "hasVersion");
final ExtendedIterator<Statement> triples = graphStore.listStatements(s, p, (RDFNode)null);

final List<Triple> list = triples.toList();
final List<Statement> list = triples.toList();
assertEquals(1, list.size());

// make sure it matches the label
s = list.get(0).getMatchObject();
p = createURI(REPOSITORY_NAMESPACE + "hasVersionLabel");
final Node o = createLiteral("v0.0.1");
s = list.get(0).getObject().asResource();
p = createProperty(REPOSITORY_NAMESPACE + "hasVersionLabel");
final Literal o = createPlainLiteral("v0.0.1");

assertTrue(graphStore.asDatasetGraph().contains(ANY, s, p, o));
assertTrue(graphStore.contains(s, p, o));

}

Expand Down
Expand Up @@ -277,11 +277,8 @@ public void testGetVersionDataset() throws Exception {
final RdfStream versionsStream = new RdfStream();
when(mockJcrRdfTools.getJcrVersionPropertiesModel(any(Node.class)))
.thenReturn(versionsStream);
final Dataset dataset = testObj.getVersionDataset(mockSubjects);

assertEquals(versionsStream, RdfStream.fromModel(dataset.getDefaultModel()));
assertEquals(RESTAPI_NAMESPACE + "xyz", dataset.getContext().get(
Symbol.create("uri")));
final RdfStream result = testObj.getVersionDataset(mockSubjects);
assertEquals(versionsStream, result);
}

@Test
Expand Down

0 comments on commit ce5f246

Please sign in to comment.