Skip to content
Permalink
Browse files

fix up bnode handling (e.g. for fixity results)

  • Loading branch information...
cbeer committed Jul 4, 2013
1 parent 103ed4c commit 00822be15cd17c85e584bfbd1e40adc014874138
@@ -30,10 +30,17 @@
<h2>Triples for other nodes</h2>
#foreach($subject in $model.listSubjects())
#if( $subject != $topic )
#if ( $subject.getURI() )
<div class="well" resource="$subject.getURI()">
<h3><a href="$subject.getURI()">$esc.html($helpers.getObjectTitle($rdf, $subject.asNode()))</a></h3>
#triples($subject.asNode())
</div>
#else
<div class="well" resource="$subject.getId()">
<h3>$esc.html($helpers.getObjectTitle($rdf, $subject.asNode()))</h3>
#triples($subject.asNode())
</div>
#end
#end
#end
</div>
@@ -97,7 +97,14 @@ public String getObjectTitle(final DatasetGraph dataset,
}
}

return subject.getURI();
if (subject.isURI()) {
return subject.getURI();
} else if (subject.isBlank()) {
return subject.getBlankNodeLabel();
} else {
return subject.toString();
}

}

/**
@@ -99,6 +99,20 @@ public void shouldUseTheObjectUriIfATitleIsNotAvailable() {

}

@Test
public void shouldUsetheBNodeIdIfItIsABNode() {
final DatasetGraph mem = DatasetGraphFactory.createMem();
final Node anon = NodeFactory.createAnon();
assertEquals(anon.getBlankNodeLabel(), testObj.getObjectTitle(mem, anon));
}

@Test
public void shouldJustUseTheStringIfItIsALiteral() {
final DatasetGraph mem = DatasetGraphFactory.createMem();
final Node lit = NodeFactory.createLiteral("xyz");
assertEquals("\"xyz\"", testObj.getObjectTitle(mem, lit));
}

@Test
public void shouldConvertRdfObjectsToStrings() {

@@ -31,6 +31,7 @@
import javax.jcr.RepositoryException;
import javax.jcr.Session;

import com.hp.hpl.jena.sparql.util.Symbol;
import org.fcrepo.Datastream;
import org.fcrepo.binary.PolicyDecisionPoint;
import org.fcrepo.exception.InvalidChecksumException;
@@ -172,22 +173,29 @@ public Datastream asDatastream(final Node node)

/**
* Get the fixity results for the datastream as a RDF Dataset
* @param factory
* @param subjects
* @param datastream
* @return
* @throws RepositoryException
*/
public Dataset getFixityResultsModel(final GraphSubjects factory,
public Dataset getFixityResultsModel(final GraphSubjects subjects,
final Datastream datastream)
throws RepositoryException {


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


final Model model = JcrRdfTools.getFixityResultsModel(factory, datastream.getNode(), blobs);
final Model model = JcrRdfTools.getFixityResultsModel(subjects, datastream.getNode(), blobs);

return GraphStoreFactory.create(model).toDataset();

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

String uri = JcrRdfTools.getGraphSubject(subjects, datastream.getNode()).getURI();
com.hp.hpl.jena.sparql.util.Context context = dataset.getContext();
context.set(Symbol.create("uri"),uri);

return dataset;
}

/**
@@ -265,7 +273,6 @@ public boolean apply(org.fcrepo.utils.FixityResult input) {
* against the given checksum and size.
*
* @param resource
* @param digest
* @param dsChecksum -the checksum and algorithm represented as a URI
* @param dsSize
* @return
@@ -38,6 +38,9 @@
import javax.jcr.Session;
import javax.jcr.nodetype.NodeType;

import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.sparql.util.Symbol;
import org.fcrepo.Datastream;
import org.fcrepo.binary.PolicyDecisionPoint;
import org.fcrepo.rdf.GraphSubjects;
@@ -185,7 +188,11 @@ public void testGetFixityResultsModel() throws RepositoryException, URISyntaxExc
Model mockModel = mock(Model.class);
when(JcrRdfTools.getFixityResultsModel(eq(mockSubjects), eq(mockNode), any(Collection.class))).thenReturn(mockModel);

testObj.getFixityResultsModel(mockSubjects, mockDatastream);

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

assertTrue(fixityResultsModel.getContext().isDefined(Symbol.create("uri")));
}


0 comments on commit 00822be

Please sign in to comment.
You can’t perform that action at this time.