Skip to content

Commit

Permalink
Update HTTP/JAX-RS triple injections to use interfaces to defer to the
Browse files Browse the repository at this point in the history
JAX-RS class to provide an RdfStream with the triples it wants to
inject.
  • Loading branch information
cbeer committed Oct 31, 2013
1 parent 52c0130 commit 70fb77d
Show file tree
Hide file tree
Showing 19 changed files with 252 additions and 620 deletions.
Expand Up @@ -16,12 +16,17 @@

package org.fcrepo.http.api;

import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
import static java.util.Collections.singletonMap;
import static javax.ws.rs.core.Response.ok;
import static org.fcrepo.kernel.RdfLexicon.HAS_SERIALIZATION;
import static org.fcrepo.kernel.RdfLexicon.RDFS_LABEL;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;

import javax.jcr.RepositoryException;
import javax.jcr.Session;
Expand All @@ -34,9 +39,19 @@
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;
import javax.ws.rs.core.UriInfo;

import com.google.common.collect.ImmutableSet;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.NodeFactory;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.rdf.model.Resource;
import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.http.commons.api.rdf.FedoraHttpRdfTripleProvider;
import org.fcrepo.http.commons.session.InjectedSession;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.rdf.GraphSubjects;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.fcrepo.serialization.FedoraObjectSerializer;
import org.fcrepo.serialization.SerializerUtil;
import org.slf4j.Logger;
Expand All @@ -50,7 +65,7 @@
@Component
@Scope("prototype")
@Path("/{path: .*}/fcr:export")
public class FedoraExport extends AbstractResource {
public class FedoraExport extends AbstractResource implements FedoraHttpRdfTripleProvider {

@Autowired
protected SerializerUtil serializers;
Expand Down Expand Up @@ -106,4 +121,24 @@ public void write(final OutputStream out)
}).build();

}

@Override
public RdfStream getRdfStream(final GraphSubjects graphSubjects, final FedoraResource resource, final UriInfo uriInfo) throws RepositoryException {

final ImmutableSet.Builder<Triple> tripleBuilder = new ImmutableSet.Builder<Triple>();

final Node node = graphSubjects.getGraphSubject(resource.getNode()).asNode();

// fcr:export?format=xyz
for (final String key : serializers.keySet()) {
final Map<String, String> pathMap =
singletonMap("path", resource.getPath().substring(1));
final Resource format =
createResource(uriInfo.getBaseUriBuilder().path(FedoraExport.class).queryParam("format", key).buildFromMap(pathMap).toASCIIString());
tripleBuilder.add(Triple.create(node, HAS_SERIALIZATION.asNode(), format.asNode()));
tripleBuilder.add(Triple.create(format.asNode(), RDFS_LABEL.asNode(), NodeFactory.createLiteral(key)));
}

return new RdfStream(tripleBuilder.build());
}
}
Expand Up @@ -31,6 +31,7 @@
import static org.fcrepo.http.commons.domain.RDFMediaType.RDF_XML;
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE;
import static org.fcrepo.kernel.RdfLexicon.FIRST_PAGE;
import static org.fcrepo.kernel.RdfLexicon.HAS_SEARCH_SERVICE;
import static org.fcrepo.kernel.RdfLexicon.NEXT_PAGE;
import static org.fcrepo.kernel.RdfLexicon.PAGE;
import static org.fcrepo.kernel.RdfLexicon.PAGE_OF;
Expand All @@ -54,11 +55,17 @@
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;

import com.hp.hpl.jena.graph.NodeFactory;
import com.hp.hpl.jena.graph.Triple;
import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.http.commons.api.rdf.FedoraHttpRdfTripleProvider;
import org.fcrepo.http.commons.api.rdf.HttpGraphSubjects;
import org.fcrepo.http.commons.responses.HtmlTemplate;
import org.fcrepo.http.commons.session.InjectedSession;
import org.fcrepo.jcr.FedoraJcrTypes;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.rdf.GraphSubjects;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.slf4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
Expand All @@ -79,7 +86,7 @@
@Scope("prototype")
@Path("/fcr:search")
public class FedoraFieldSearch extends AbstractResource implements
FedoraJcrTypes {
FedoraJcrTypes, FedoraHttpRdfTripleProvider {

@InjectedSession
protected Session session;
Expand Down Expand Up @@ -241,4 +248,15 @@ private Dataset getSearchDataset(final String terms,
session.logout();
}
}

@Override
public RdfStream getRdfStream(final GraphSubjects graphSubjects, final FedoraResource resource, final UriInfo uriInfo) throws RepositoryException {
final RdfStream triples = new RdfStream();

if (resource.getNode().getPrimaryNodeType().isNodeType(ROOT)) {
triples.concat(Triple.create(graphSubjects.getGraphSubject(resource.getNode()).asNode(), HAS_SEARCH_SERVICE.asNode(), NodeFactory.createURI(uriInfo.getBaseUriBuilder().path(FedoraFieldSearch.class).build().toASCIIString())));
}

return triples;
}
}
Expand Up @@ -16,6 +16,7 @@

package org.fcrepo.http.api;

import static java.util.Collections.singletonMap;
import static javax.ws.rs.core.MediaType.TEXT_HTML;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3_ALT1;
Expand All @@ -24,8 +25,10 @@
import static org.fcrepo.http.commons.domain.RDFMediaType.RDF_JSON;
import static org.fcrepo.http.commons.domain.RDFMediaType.RDF_XML;
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE;
import static org.fcrepo.kernel.RdfLexicon.HAS_FIXITY_SERVICE;

import java.util.List;
import java.util.Map;

import javax.jcr.RepositoryException;
import javax.jcr.Session;
Expand All @@ -38,10 +41,16 @@
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;

import com.hp.hpl.jena.graph.NodeFactory;
import com.hp.hpl.jena.graph.Triple;
import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.http.commons.api.rdf.FedoraHttpRdfTripleProvider;
import org.fcrepo.http.commons.api.rdf.HttpGraphSubjects;
import org.fcrepo.http.commons.session.InjectedSession;
import org.fcrepo.kernel.Datastream;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.rdf.GraphSubjects;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

Expand All @@ -57,7 +66,7 @@
@Component
@Scope("prototype")
@Path("/{path: .*}/fcr:fixity")
public class FedoraFixity extends AbstractResource {
public class FedoraFixity extends AbstractResource implements FedoraHttpRdfTripleProvider {

@InjectedSession
protected Session session;
Expand Down Expand Up @@ -97,4 +106,12 @@ public Dataset getDatastreamFixity(@PathParam("path")
session.logout();
}
}

@Override
public RdfStream getRdfStream(final GraphSubjects graphSubjects, final FedoraResource resource, final UriInfo uriInfo) throws RepositoryException {
final Map<String, String> pathMap =
singletonMap("path", resource.getPath().substring(1));

return new RdfStream(Triple.create(graphSubjects.getGraphSubject(resource.getNode()).asNode(), HAS_FIXITY_SERVICE.asNode(), NodeFactory.createURI(uriInfo.getBaseUriBuilder().path(FedoraFixity.class).buildFromMap(pathMap).toASCIIString())));
}
}
Expand Up @@ -22,6 +22,8 @@
import static org.fcrepo.jcr.FedoraJcrTypes.FEDORA_OBJECT;
import static org.fcrepo.jcr.FedoraJcrTypes.JCR_CREATED;
import static org.fcrepo.jcr.FedoraJcrTypes.JCR_LASTMODIFIED;
import static org.fcrepo.jcr.FedoraJcrTypes.ROOT;
import static org.fcrepo.kernel.RdfLexicon.HAS_SITEMAP;
import static org.modeshape.jcr.api.JcrConstants.JCR_NAME;
import static org.slf4j.LoggerFactory.getLogger;

Expand All @@ -39,12 +41,19 @@
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.UriInfo;

import com.hp.hpl.jena.graph.NodeFactory;
import com.hp.hpl.jena.graph.Triple;
import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.http.commons.api.rdf.FedoraHttpRdfTripleProvider;
import org.fcrepo.http.commons.jaxb.responses.sitemap.SitemapEntry;
import org.fcrepo.http.commons.jaxb.responses.sitemap.SitemapIndex;
import org.fcrepo.http.commons.jaxb.responses.sitemap.SitemapUrlSet;
import org.fcrepo.http.commons.session.InjectedSession;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.rdf.GraphSubjects;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.slf4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
Expand All @@ -61,7 +70,7 @@
@Component
@Scope("prototype")
@Path("/sitemap")
public class FedoraSitemap extends AbstractResource {
public class FedoraSitemap extends AbstractResource implements FedoraHttpRdfTripleProvider {

@InjectedSession
protected Session session;
Expand Down Expand Up @@ -171,4 +180,16 @@ private SitemapEntry getSitemapEntry(final Row r)
return new SitemapEntry(uriInfo.getBaseUriBuilder().path(
FedoraNodes.class).build(path.substring(1)), lastKnownDate);
}


@Override
public RdfStream getRdfStream(final GraphSubjects graphSubjects, final FedoraResource resource, final UriInfo uriInfo) throws RepositoryException {
final RdfStream triples = new RdfStream();

if (resource.getNode().getPrimaryNodeType().isNodeType(ROOT)) {
triples.concat(Triple.create(graphSubjects.getGraphSubject(resource.getNode()).asNode(), HAS_SITEMAP.asNode(), NodeFactory.createURI(uriInfo.getBaseUriBuilder().path(FedoraSitemap.class).build().toASCIIString())));
}

return triples;
}
}
Expand Up @@ -21,6 +21,8 @@
import static javax.ws.rs.core.Response.noContent;
import static javax.ws.rs.core.Response.status;
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
import static org.fcrepo.jcr.FedoraJcrTypes.ROOT;
import static org.fcrepo.kernel.RdfLexicon.HAS_TRANSACTION_SERVICE;
import static org.slf4j.LoggerFactory.getLogger;

import java.util.List;
Expand All @@ -35,12 +37,19 @@
import javax.ws.rs.core.Context;
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

import com.hp.hpl.jena.graph.NodeFactory;
import com.hp.hpl.jena.graph.Triple;
import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.http.commons.api.rdf.FedoraHttpRdfTripleProvider;
import org.fcrepo.http.commons.session.InjectedSession;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.Transaction;
import org.fcrepo.kernel.TxSession;
import org.fcrepo.kernel.rdf.GraphSubjects;
import org.fcrepo.kernel.services.TransactionService;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
Expand All @@ -52,7 +61,7 @@
@Component
@Scope("prototype")
@Path("/{path: .*}/fcr:tx")
public class FedoraTransactions extends AbstractResource {
public class FedoraTransactions extends AbstractResource implements FedoraHttpRdfTripleProvider {

private static final Logger LOGGER = getLogger(FedoraTransactions.class);

Expand Down Expand Up @@ -162,4 +171,15 @@ private Response finalizeTransaction(@PathParam("path")
}
return noContent().build();
}

@Override
public RdfStream getRdfStream(final GraphSubjects graphSubjects, final FedoraResource resource, final UriInfo uriInfo) throws RepositoryException {
final RdfStream triples = new RdfStream();

if (resource.getNode().getPrimaryNodeType().isNodeType(ROOT)) {
triples.concat(Triple.create(graphSubjects.getGraphSubject(resource.getNode()).asNode(), HAS_TRANSACTION_SERVICE.asNode(), NodeFactory.createURI(uriInfo.getBaseUriBuilder().path(FedoraTransactions.class).build().toASCIIString())));
}

return triples;
}
}
Expand Up @@ -16,6 +16,7 @@

package org.fcrepo.http.api;

import static java.util.Collections.singletonMap;
import static javax.ws.rs.core.Response.noContent;
import static javax.ws.rs.core.Response.status;
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
Expand All @@ -27,10 +28,13 @@
import static org.fcrepo.http.commons.domain.RDFMediaType.RDF_JSON;
import static org.fcrepo.http.commons.domain.RDFMediaType.RDF_XML;
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE;
import static org.fcrepo.jcr.FedoraJcrTypes.ROOT;
import static org.fcrepo.kernel.RdfLexicon.HAS_VERSION_HISTORY;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.jcr.RepositoryException;
import javax.jcr.Session;
Expand All @@ -47,11 +51,16 @@
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.core.Variant;

import com.hp.hpl.jena.graph.NodeFactory;
import com.hp.hpl.jena.graph.Triple;
import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.http.commons.api.rdf.FedoraHttpRdfTripleProvider;
import org.fcrepo.http.commons.api.rdf.HttpGraphSubjects;
import org.fcrepo.http.commons.responses.GraphStoreStreamingOutput;
import org.fcrepo.http.commons.session.InjectedSession;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.rdf.GraphSubjects;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.slf4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
Expand All @@ -66,7 +75,7 @@
@Component
@Scope("prototype")
@Path("/{path: .*}/fcr:versions")
public class FedoraVersions extends AbstractResource {
public class FedoraVersions extends AbstractResource implements FedoraHttpRdfTripleProvider {

@InjectedSession
protected Session session;
Expand Down Expand Up @@ -180,4 +189,20 @@ public Dataset getVersion(@PathParam("path")
}

}

@Override
public RdfStream getRdfStream(final GraphSubjects graphSubjects, final FedoraResource resource, final UriInfo uriInfo) throws RepositoryException {

final RdfStream triples = new RdfStream();

if (!resource.getNode().getPrimaryNodeType().isNodeType(ROOT)) {

final Map<String, String> pathMap =
singletonMap("path", resource.getPath().substring(1));
triples.concat(Triple.create(graphSubjects.getGraphSubject(resource.getNode()).asNode(), HAS_VERSION_HISTORY.asNode(), NodeFactory.createURI(uriInfo.getBaseUriBuilder().path(FedoraVersions.class).buildFromMap(pathMap).toASCIIString())));

}

return triples;
}
}

0 comments on commit 70fb77d

Please sign in to comment.