Skip to content

Commit

Permalink
Updating REST API to include children by default for HTML view
Browse files Browse the repository at this point in the history
  • Loading branch information
escowles committed Oct 24, 2014
1 parent 9be09b8 commit 619b3dd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
21 changes: 19 additions & 2 deletions fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraLdp.java
Expand Up @@ -63,6 +63,7 @@
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLDecoder;
import java.text.ParseException;

import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
import static javax.ws.rs.core.MediaType.APPLICATION_XHTML_XML;
Expand All @@ -87,6 +88,7 @@
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE_X;
import static org.fcrepo.jcr.FedoraJcrTypes.FEDORA_DATASTREAM;
import static org.fcrepo.jcr.FedoraJcrTypes.FEDORA_OBJECT;
import static org.fcrepo.kernel.RdfLexicon.EMBED_CONTAINS;
import static org.fcrepo.kernel.RdfLexicon.LDP_NAMESPACE;
import static org.fcrepo.kernel.impl.services.TransactionServiceImpl.getCurrentTransactionId;
import static org.slf4j.LoggerFactory.getLogger;
Expand Down Expand Up @@ -171,8 +173,7 @@ public Response options() {
*/
@GET
@Produces({TURTLE + ";qs=10", JSON_LD + ";qs=8",
N3, N3_ALT2, RDF_XML, NTRIPLES, APPLICATION_XML, TEXT_PLAIN, TURTLE_X,
TEXT_HTML, APPLICATION_XHTML_XML, "*/*"})
N3, N3_ALT2, RDF_XML, NTRIPLES, APPLICATION_XML, TEXT_PLAIN, TURTLE_X, "*/*"})
public Response describe(@HeaderParam("Range") final String rangeValue) throws IOException {
checkCacheControlHeaders(request, servletResponse, resource(), session);

Expand All @@ -185,6 +186,22 @@ public Response describe(@HeaderParam("Range") final String rangeValue) throws I

}

/**
* Retrieve the HTML version of the node profile
*
* @return triples for the specified node
* @throws RepositoryException
*/
@GET
@Produces({TEXT_HTML, APPLICATION_XHTML_XML})
public Response describeHTML(@HeaderParam("Range") final String rangeValue) throws IOException, ParseException {
// if no prefer header is set, include child resources so they can be used for conditional link building
if ( prefer == null ) {
prefer = new Prefer("return=representation; include=\"" + EMBED_CONTAINS + "\"");
}
return describe(rangeValue);
}

/**
* Deletes an object.
*
Expand Down
6 changes: 3 additions & 3 deletions fcrepo-http-api/src/main/resources/views/common-metadata.vsl
Expand Up @@ -11,10 +11,10 @@
<dd>
<ol id="childList">
#foreach($quad in $helpers.getObjects($rdf, $topic, $rdfLexicon.CONTAINS))
#if ($helpers.isRdfResource($rdf, $quad.getObject()) )
<li><a href="$quad.getObject().getURI()">$esc.html($helpers.getObjectTitle($rdf, $quad.getObject()))</a></li>
#else
#if ($helpers.isBinary($rdf, $quad.getObject()) )
<li><a href="${quad.getObject().getURI()}/fcr:metadata">$esc.html($helpers.getObjectTitle($rdf, $quad.getObject()))</a></li>
#else
<li><a href="$quad.getObject().getURI()">$esc.html($helpers.getObjectTitle($rdf, $quad.getObject()))</a></li>
#end
#end
</ol>
Expand Down
Expand Up @@ -17,18 +17,17 @@

import static com.google.common.base.Strings.isNullOrEmpty;
import static com.hp.hpl.jena.graph.Node.ANY;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
import static com.hp.hpl.jena.graph.NodeFactory.createLiteral;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createProperty;
import static org.fcrepo.jcr.FedoraJcrTypes.FCR_METADATA;
import static org.fcrepo.kernel.RdfLexicon.DC_TITLE;
import static org.fcrepo.kernel.RdfLexicon.HAS_MIXIN_TYPE;
import static org.fcrepo.kernel.RdfLexicon.HAS_VERSION_LABEL;
import static org.fcrepo.kernel.RdfLexicon.LAST_MODIFIED_DATE;
import static org.fcrepo.kernel.RdfLexicon.RDFS_LABEL;
import static org.fcrepo.kernel.RdfLexicon.HAS_VERSION;
import static org.fcrepo.kernel.RdfLexicon.HAS_CONTENT;
import static org.fcrepo.kernel.RdfLexicon.RDF_NAMESPACE;
import static org.fcrepo.kernel.RdfLexicon.DC_NAMESPACE;
import static org.fcrepo.kernel.RdfLexicon.LDP_NAMESPACE;
import static org.slf4j.LoggerFactory.getLogger;

import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -67,6 +66,7 @@
public class ViewHelpers {

private static final Logger LOGGER = getLogger(ViewHelpers.class);
private static final Node FEDORA_BINARY = createLiteral("fedora:binary");

private static ViewHelpers instance = null;

Expand Down Expand Up @@ -423,13 +423,10 @@ public String getPrefixPreamble(final PrefixMapping mapping) {
}

/**
* Determines whether the subject is kind of RDF resource
* Determines whether the subject is a binary (non-RDF resource)
*/
public boolean isRdfResource(final Graph graph, final Node subject ) {
final Iterator<Triple> it = graph.find(subject,
createResource(RDF_NAMESPACE + "type").asNode(),
createResource(LDP_NAMESPACE + "RDFSource").asNode());
return it.hasNext();
public boolean isBinary(final Graph graph, final Node subject ) {
return graph.find(subject, HAS_MIXIN_TYPE.asNode(), FEDORA_BINARY).hasNext();
}

/**
Expand Down
Expand Up @@ -26,6 +26,7 @@
import static org.fcrepo.http.commons.test.util.TestHelpers.getUriInfoImpl;
import static org.fcrepo.kernel.RdfLexicon.CREATED_BY;
import static org.fcrepo.kernel.RdfLexicon.DC_TITLE;
import static org.fcrepo.kernel.RdfLexicon.HAS_MIXIN_TYPE;
import static org.fcrepo.kernel.RdfLexicon.HAS_PRIMARY_TYPE;
import static org.fcrepo.kernel.RdfLexicon.HAS_VERSION_LABEL;
import static org.fcrepo.kernel.RdfLexicon.DC_NAMESPACE;
Expand All @@ -35,8 +36,6 @@
import static org.fcrepo.kernel.RdfLexicon.RDFS_LABEL;
import static org.fcrepo.kernel.RdfLexicon.REPOSITORY_NAMESPACE;
import static org.fcrepo.kernel.RdfLexicon.WRITABLE;
import static org.fcrepo.kernel.RdfLexicon.RDF_NAMESPACE;
import static org.fcrepo.kernel.RdfLexicon.LDP_NAMESPACE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -189,16 +188,10 @@ public void testIsNotFrozenNode() {
}

@Test
public void testRdfResource() {
final String ns = "http://any/namespace#";
final String type = "anyType";
public void testIsBinary() {
final Graph mem = createDefaultModel().getGraph();
mem.add(new Triple(createURI("a/b"),
createResource(RDF_NAMESPACE + "type").asNode(),
createResource(LDP_NAMESPACE + "RDFSource").asNode()));

assertTrue("Node is a " + type + " node.",
testObj.isRdfResource(mem, createURI("a/b")));
mem.add(new Triple(createURI("a/b"), HAS_MIXIN_TYPE.asNode(), createLiteral("fedora:binary")));
assertTrue(testObj.isBinary(mem, createURI("a/b")));
}

@Test
Expand Down

0 comments on commit 619b3dd

Please sign in to comment.