Skip to content

Commit

Permalink
Use datasets (with the HtmlProvider) consistenty.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed May 23, 2013
1 parent 65be930 commit 994585d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 32 deletions.
@@ -1,6 +1,7 @@

package org.fcrepo.api;

import static javax.ws.rs.core.MediaType.TEXT_HTML;
import static org.fcrepo.http.RDFMediaType.N3;
import static org.fcrepo.http.RDFMediaType.N3_ALT1;
import static org.fcrepo.http.RDFMediaType.N3_ALT2;
Expand All @@ -24,18 +25,17 @@
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.core.Variant;

import com.hp.hpl.jena.query.Dataset;
import org.fcrepo.AbstractResource;
import org.fcrepo.api.rdf.HttpGraphSubjects;
import org.fcrepo.http.RDFMediaType;
import org.fcrepo.responses.GraphStoreStreamingOutput;
import org.fcrepo.utils.FedoraJcrTypes;
import org.slf4j.Logger;
import org.springframework.stereotype.Component;

import com.codahale.metrics.annotation.Timed;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.update.GraphStore;

/**
* @author Frank Asseg
Expand All @@ -50,8 +50,8 @@ public class FedoraFieldSearch extends AbstractResource implements

@GET
@Timed
@Produces({N3, N3_ALT1, N3_ALT2, TURTLE, RDF_XML, RDF_JSON, NTRIPLES})
public GraphStoreStreamingOutput searchSubmitRdf(@QueryParam("q")
@Produces({N3, N3_ALT1, N3_ALT2, TURTLE, RDF_XML, RDF_JSON, NTRIPLES, TEXT_HTML})
public Dataset searchSubmitRdf(@QueryParam("q")
final String terms, @QueryParam("offset")
@DefaultValue("0")
final long offset, @QueryParam("limit")
Expand Down Expand Up @@ -80,13 +80,12 @@ public GraphStoreStreamingOutput searchSubmitRdf(@QueryParam("q")
ResourceFactory.createResource(uriInfo.getRequestUri()
.toASCIIString());

final GraphStore graphStore =
final Dataset dataset =
nodeService.searchRepository(new HttpGraphSubjects(
FedoraNodes.class, uriInfo), searchResult, session,
terms, limit, offset);

return new GraphStoreStreamingOutput(graphStore,
bestPossibleResponse.getMediaType());
return dataset;

} finally {
session.logout();
Expand Down
@@ -1,5 +1,6 @@
package org.fcrepo.api;

import static javax.ws.rs.core.MediaType.TEXT_HTML;
import static org.fcrepo.http.RDFMediaType.N3;
import static org.fcrepo.http.RDFMediaType.N3_ALT1;
import static org.fcrepo.http.RDFMediaType.N3_ALT2;
Expand Down Expand Up @@ -40,7 +41,7 @@ public class FedoraFixity extends AbstractResource {

@GET
@Timed
@Produces({N3, N3_ALT1, N3_ALT2, TURTLE, RDF_XML, RDF_JSON, NTRIPLES})
@Produces({N3, N3_ALT1, N3_ALT2, TURTLE, RDF_XML, RDF_JSON, NTRIPLES, TEXT_HTML})
public Dataset getDatastreamFixity(@PathParam("path") List<PathSegment> pathList,
@Context final Request request,
@Context final UriInfo uriInfo) throws RepositoryException {
Expand Down
Expand Up @@ -24,7 +24,6 @@
import javax.ws.rs.core.Response;

import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.update.GraphStore;
import com.hp.hpl.jena.update.UpdateAction;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpStatus;
Expand Down Expand Up @@ -61,9 +60,9 @@ public Response updateNamespaces(final InputStream requestBodyStream)
final Session session = getAuthenticatedSession();
try {

final GraphStore graph = nodeService.getNamespaceRegistryGraph(session);
final Dataset dataset = nodeService.getNamespaceRegistryGraph(session);

UpdateAction.parseExecute(IOUtils.toString(requestBodyStream), graph);
UpdateAction.parseExecute(IOUtils.toString(requestBodyStream), dataset);

session.save();

Expand All @@ -88,9 +87,9 @@ public Dataset getNamespaces() throws RepositoryException,
final Session session = getAuthenticatedSession();
try {

final GraphStore graph = nodeService.getNamespaceRegistryGraph(session);
final Dataset dataset = nodeService.getNamespaceRegistryGraph(session);

return graph.toDataset();
return dataset;
} finally {
session.logout();
}
Expand Down
Expand Up @@ -19,8 +19,7 @@
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.core.Variant;

import com.hp.hpl.jena.update.GraphStore;
import com.hp.hpl.jena.update.GraphStoreFactory;
import com.hp.hpl.jena.query.DatasetFactory;
import org.fcrepo.rdf.GraphSubjects;
import org.fcrepo.services.NodeService;
import org.fcrepo.test.util.TestHelpers;
Expand Down Expand Up @@ -63,7 +62,7 @@ public void testFieldSearch() throws RepositoryException, URISyntaxException {
new Variant(MediaType.valueOf("application/n-triples"), null,
null));

when(mockNodeService.searchRepository(any(GraphSubjects.class), eq(ResourceFactory.createResource("http://localhost/fcrepo/path/to/query/endpoint")), eq(mockSession), eq("ZZZ"), eq(0), eq(0L))).thenReturn(GraphStoreFactory.create());
when(mockNodeService.searchRepository(any(GraphSubjects.class), eq(ResourceFactory.createResource("http://localhost/fcrepo/path/to/query/endpoint")), eq(mockSession), eq("ZZZ"), eq(0), eq(0L))).thenReturn(DatasetFactory.create());

testObj.searchSubmitRdf("ZZZ", 0, 0, mockRequest, uriInfo);

Expand Down
Expand Up @@ -14,10 +14,9 @@
import javax.jcr.Session;

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.rdf.model.ModelFactory;
import com.hp.hpl.jena.update.GraphStore;
import com.hp.hpl.jena.update.GraphStoreFactory;
import org.fcrepo.api.repository.FedoraRepositoryNamespaces;
import org.fcrepo.services.NodeService;
import org.fcrepo.test.util.TestHelpers;
Expand Down Expand Up @@ -51,21 +50,19 @@ public void tearDown() {
@Test
public void testGetNamespaces() throws RepositoryException, IOException {

GraphStore mockGraphStore = mock(GraphStore.class);
Dataset mockDataset = mock(Dataset.class);
when(mockGraphStore.toDataset()).thenReturn(mockDataset);

when(mockNodeService.getNamespaceRegistryGraph(mockSession)).thenReturn(mockGraphStore);
when(mockNodeService.getNamespaceRegistryGraph(mockSession)).thenReturn(mockDataset);
assertEquals(mockDataset, testObj.getNamespaces());
}

@Test
public void testUpdateNamespaces() throws RepositoryException, IOException {

final Model model = ModelFactory.createDefaultModel();
GraphStore mockGraphStore = GraphStoreFactory.create(model);
Dataset mockDataset = DatasetFactory.create(model);

when(mockNodeService.getNamespaceRegistryGraph(mockSession)).thenReturn(mockGraphStore);
when(mockNodeService.getNamespaceRegistryGraph(mockSession)).thenReturn(mockDataset);

testObj.updateNamespaces(new ByteArrayInputStream("INSERT { <http://example.com/this> <http://example.com/is> \"abc\"} WHERE { }".getBytes()));

Expand Down
Expand Up @@ -20,6 +20,8 @@
import javax.jcr.query.QueryManager;
import javax.jcr.query.QueryResult;

import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.query.DatasetFactory;
import org.fcrepo.rdf.GraphSubjects;
import org.fcrepo.utils.FedoraJcrTypes;
import org.fcrepo.utils.FedoraTypesUtils;
Expand Down Expand Up @@ -112,18 +114,18 @@ public void setRepository(final Repository repository) {
repo = repository;
}

public GraphStore getNamespaceRegistryGraph(final Session session) throws RepositoryException {
public Dataset getNamespaceRegistryGraph(final Session session) throws RepositoryException {

final Model model = JcrRdfTools.getJcrNamespaceModel(session);

model.register(new NamespaceChangedStatementListener(session));

final GraphStore graphStore = GraphStoreFactory.create(model);
final Dataset dataset = DatasetFactory.create(model);

return graphStore;
return dataset;

}
public GraphStore searchRepository(final GraphSubjects subjectFactory,
public Dataset searchRepository(final GraphSubjects subjectFactory,
final Resource searchSubject, final Session session,
final String terms, final int limit, final long offset)
throws RepositoryException {
Expand Down Expand Up @@ -187,9 +189,9 @@ public GraphStore searchRepository(final GraphSubjects subjectFactory,
.createTypedLiteral(true));
}

final GraphStore graphStore = GraphStoreFactory.create(model);
final Dataset dataset = DatasetFactory.create(model);

return graphStore;
return dataset;

}
}
Expand Up @@ -12,6 +12,7 @@
import javax.jcr.Session;

import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.update.GraphStore;
import com.hp.hpl.jena.update.UpdateAction;
Expand Down Expand Up @@ -59,7 +60,7 @@ public void testGetAllObjectsDatastreamSize() throws Exception {
public void testGetNamespaceRegistryGraph() throws Exception {
Session session = repository.login();

final GraphStore registryGraph = objectService.getNamespaceRegistryGraph(session);
final Dataset registryGraph = objectService.getNamespaceRegistryGraph(session);

final NamespaceRegistry namespaceRegistry = session.getWorkspace().getNamespaceRegistry();

Expand All @@ -70,7 +71,7 @@ public void testGetNamespaceRegistryGraph() throws Exception {
continue;
}
final String uri = namespaceRegistry.getURI(s);
assertTrue("expected to find JCR namespaces " + s + " in graph", registryGraph.contains(Node.ANY, ResourceFactory.createResource(uri).asNode(), ResourceFactory.createProperty(JcrRdfTools.HAS_NAMESPACE_PREDICATE).asNode(), ResourceFactory.createPlainLiteral(s).asNode()));
assertTrue("expected to find JCR namespaces " + s + " in graph", registryGraph.asDatasetGraph().contains(Node.ANY, ResourceFactory.createResource(uri).asNode(), ResourceFactory.createProperty(JcrRdfTools.HAS_NAMESPACE_PREDICATE).asNode(), ResourceFactory.createPlainLiteral(s).asNode()));
}
session.logout();
}
Expand All @@ -79,7 +80,7 @@ public void testGetNamespaceRegistryGraph() throws Exception {
public void testUpdateNamespaceRegistryGraph() throws Exception {
Session session = repository.login();

final GraphStore registryGraph = objectService.getNamespaceRegistryGraph(session);
final Dataset registryGraph = objectService.getNamespaceRegistryGraph(session);
final NamespaceRegistry namespaceRegistry = session.getWorkspace().getNamespaceRegistry();

UpdateAction.parseExecute("INSERT { <info:abc> <" + JcrRdfTools.HAS_NAMESPACE_PREDICATE + "> \"abc\" } WHERE { }", registryGraph);
Expand Down

0 comments on commit 994585d

Please sign in to comment.