Skip to content

Commit

Permalink
FedoraRepositoryNamespaces now streams RDF
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Nov 24, 2013
1 parent 449420b commit daac99d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
Expand Up @@ -45,6 +45,7 @@
import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.http.commons.responses.HtmlTemplate;
import org.fcrepo.http.commons.session.InjectedSession;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -82,7 +83,7 @@ public Response updateNamespaces(final InputStream requestBodyStream)

try {
final Dataset dataset =
nodeService.getNamespaceRegistryGraph(session);
nodeService.getNamespaceRegistryDataset(session);
parseExecute(IOUtils.toString(requestBodyStream), dataset);
session.save();
return status(SC_NO_CONTENT).build();
Expand All @@ -101,14 +102,7 @@ public Response updateNamespaces(final InputStream requestBodyStream)
@Produces({TURTLE, N3, N3_ALT1, N3_ALT2, RDF_XML, RDF_JSON, NTRIPLES,
TEXT_HTML})
@HtmlTemplate("jcr:namespaces")
public Dataset getNamespaces() throws RepositoryException, IOException {

try {
final Dataset dataset =
nodeService.getNamespaceRegistryGraph(session);
return dataset;
} finally {
session.logout();
}
public RdfStream getNamespaces() throws RepositoryException, IOException {
return nodeService.getNamespaceRegistryStream(session).session(session);
}
}
Expand Up @@ -33,6 +33,7 @@

import org.fcrepo.http.api.repository.FedoraRepositoryNamespaces;
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 All @@ -51,6 +52,8 @@ public class FedoraRepositoryNamespacesTest {
@Mock
private Dataset mockDataset;

private RdfStream testRdfStream = new RdfStream();

private Session mockSession;

@Before
Expand All @@ -66,17 +69,17 @@ public void setUp() throws RepositoryException, URISyntaxException,

@Test
public void testGetNamespaces() throws RepositoryException, IOException {
when(mockNodeService.getNamespaceRegistryGraph(mockSession))
.thenReturn(mockDataset);
assertEquals(mockDataset, testObj.getNamespaces());
when(mockNodeService.getNamespaceRegistryStream(mockSession))
.thenReturn(testRdfStream);
assertEquals(testRdfStream, testObj.getNamespaces());
}

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

final Model model = createDefaultModel();
final Dataset mockDataset = DatasetFactory.create(model);
when(mockNodeService.getNamespaceRegistryGraph(mockSession))
when(mockNodeService.getNamespaceRegistryDataset(mockSession))
.thenReturn(mockDataset);

testObj.updateNamespaces(new ByteArrayInputStream(
Expand Down
Expand Up @@ -184,7 +184,7 @@ public String apply(final String p) {
* @return
* @throws RepositoryException
*/
public Dataset getNamespaceRegistryGraph(final Session session)
public Dataset getNamespaceRegistryDataset(final Session session)
throws RepositoryException {

final Model model =
Expand All @@ -199,6 +199,21 @@ public Dataset getNamespaceRegistryGraph(final Session session)

}

/**
* Serialize the JCR namespace information as an {@link RdfStream}
*
* @param session
* @return
* @throws RepositoryException
*/
public RdfStream getNamespaceRegistryStream(final Session session)
throws RepositoryException {

return JcrRdfTools.withContext(null, session).getNamespaceTriples();

}


/**
* Perform a full-text search on the whole repository and return the
* information as an RDF Dataset
Expand Down
Expand Up @@ -81,7 +81,7 @@ public void testGetNamespaceRegistryGraph() throws Exception {
final Session session = repository.login();

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

final NamespaceRegistry namespaceRegistry =
session.getWorkspace().getNamespaceRegistry();
Expand All @@ -107,7 +107,7 @@ public void testUpdateNamespaceRegistryGraph() throws Exception {
final Session session = repository.login();

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

Expand Down

0 comments on commit daac99d

Please sign in to comment.