Skip to content

Commit

Permalink
Merge pull request #165 from futures/FixityHttpIteration
Browse files Browse the repository at this point in the history
FedoraFixity now streaming results

Resolves: https://www.pivotaltracker.com/story/show/61166322
  • Loading branch information
Andrew Woods committed Nov 22, 2013
2 parents 83af13b + 14f035c commit ee3c9ff
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 45 deletions.
29 changes: 12 additions & 17 deletions fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraFixity.java
Expand Up @@ -42,11 +42,11 @@
import org.fcrepo.http.commons.api.rdf.HttpGraphSubjects;
import org.fcrepo.http.commons.session.InjectedSession;
import org.fcrepo.kernel.Datastream;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.codahale.metrics.annotation.Timed;
import com.hp.hpl.jena.query.Dataset;

/**
* Run a fixity check on a path
Expand Down Expand Up @@ -77,24 +77,19 @@ public class FedoraFixity extends AbstractResource {
@Timed
@Produces({TURTLE, N3, N3_ALT1, N3_ALT2, RDF_XML, RDF_JSON, NTRIPLES,
TEXT_HTML})
public Dataset getDatastreamFixity(@PathParam("path")
final List<PathSegment> pathList,
@Context
final Request request,
@Context
final UriInfo uriInfo) throws RepositoryException {
public RdfStream getDatastreamFixity(@PathParam("path")
final List<PathSegment> pathList,
@Context
final Request request,
@Context
final UriInfo uriInfo) throws RepositoryException {

try {
final String path = toPath(pathList);
final String path = toPath(pathList);

final Datastream ds =
datastreamService.getDatastream(session, path);
final Datastream ds = datastreamService.getDatastream(session, path);

return datastreamService.getFixityResultsModel(new HttpGraphSubjects(
session, FedoraNodes.class, uriInfo), ds);

return datastreamService.getFixityResultsModel(
new HttpGraphSubjects(session, FedoraNodes.class, uriInfo),
ds);
} finally {
session.logout();
}
}
}
Expand Up @@ -18,7 +18,6 @@

import static com.google.common.base.Throwables.propagate;
import static com.google.common.collect.ImmutableSet.builder;
import static com.hp.hpl.jena.graph.NodeFactory.createAnon;
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.create;
Expand All @@ -31,6 +30,7 @@
import static org.fcrepo.kernel.RdfLexicon.HAS_LOCATION;
import static org.fcrepo.kernel.RdfLexicon.IS_FIXITY_RESULT_OF;

import java.util.Calendar;
import java.util.Iterator;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
Expand Down Expand Up @@ -72,9 +72,9 @@ public FixityRdfContext(final Node node, final GraphSubjects graphSubjects,

@Override
public Iterator<Triple> apply(final FixityResult blob) {
// fixity results are just blank nodes
final com.hp.hpl.jena.graph.Node resultSubject =
createAnon();
createURI(subject().getURI() + "/fixity/"
+ Calendar.getInstance().getTimeInMillis());
final ImmutableSet.Builder<Triple> b = builder();
try {
b.add(create(resultSubject, IS_FIXITY_RESULT_OF
Expand Down
Expand Up @@ -37,12 +37,12 @@

import org.fcrepo.kernel.Datastream;
import org.fcrepo.kernel.exception.InvalidChecksumException;
import org.fcrepo.kernel.rdf.GraphProperties;
import org.fcrepo.kernel.rdf.GraphSubjects;
import org.fcrepo.kernel.rdf.JcrRdfTools;
import org.fcrepo.kernel.services.policy.StoragePolicyDecisionPoint;
import org.fcrepo.kernel.utils.FixityResult;
import org.fcrepo.kernel.utils.LowLevelCacheEntry;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand All @@ -51,10 +51,6 @@
import com.codahale.metrics.Timer;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.sparql.util.Context;
import com.hp.hpl.jena.update.GraphStoreFactory;

/**
* Service for creating and retrieving Datastreams without using the JCR API.
Expand Down Expand Up @@ -186,25 +182,16 @@ public Datastream asDatastream(final Node node) throws RepositoryException {
* @return
* @throws RepositoryException
*/
public Dataset getFixityResultsModel(final GraphSubjects subjects,
public RdfStream getFixityResultsModel(final GraphSubjects subjects,
final Datastream datastream) throws RepositoryException {

final Collection<FixityResult> blobs =
runFixityAndFixProblems(datastream);

final Model model =
JcrRdfTools
.withContext(subjects, datastream.getNode().getSession())
.getJcrTriples(datastream.getNode(), blobs).asModel();

final Dataset dataset = GraphStoreFactory.create(model).toDataset();

final String uri =
subjects.getGraphSubject(datastream.getNode()).getURI();
final Context context = dataset.getContext();
context.set(GraphProperties.URI_SYMBOL, uri);

return dataset;
return JcrRdfTools.withContext(subjects,
datastream.getNode().getSession()).getJcrTriples(
datastream.getNode(), blobs).topic(
subjects.getGraphSubject(datastream.getNode()).asNode());
}

/**
Expand Down
Expand Up @@ -66,8 +66,6 @@
import org.powermock.modules.junit4.PowerMockRunner;

import com.google.common.base.Function;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.sparql.util.Symbol;

@RunWith(PowerMockRunner.class)
@PowerMockIgnore({"org.slf4j.*", "org.apache.xerces.*", "javax.xml.*",
Expand Down Expand Up @@ -198,18 +196,17 @@ public void testGetFixityResultsModel() throws Exception {
when(
llStore.transformLowLevelCacheEntries(eq(mockContent),
Matchers.<Function<LowLevelCacheEntry,FixityResult>> any())).thenReturn(mockCollection);

when(
mockJcrRdfTools.getJcrTriples(eq(mockNode), Matchers
.<Iterable<FixityResult>> any())).thenReturn(new RdfStream());

when(mockSubjects.getGraphSubject(mockNode)).thenReturn(
createResource("abc"));
final Dataset fixityResultsModel =
final RdfStream fixityResults =
testObj.getFixityResultsModel(mockSubjects, mockDatastream);

assertTrue(fixityResultsModel.getContext().isDefined(
Symbol.create("uri")));
assertEquals("Got wrong topic of fixity results!",
createResource("abc").asNode(), fixityResults.topic());
}

@Test
Expand Down

0 comments on commit ee3c9ff

Please sign in to comment.