Skip to content

Commit

Permalink
JSON-LD support
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed May 23, 2014
1 parent 8b51bd1 commit 512b19a
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 8 deletions.
20 changes: 20 additions & 0 deletions fcrepo-http-api/pom.xml
Expand Up @@ -156,6 +156,11 @@
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>

<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>

Expand All @@ -173,6 +178,21 @@
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
</dependency>
<dependency>
<groupId>com.github.jsonld-java</groupId>
<artifactId>jsonld-java-jena</artifactId>
<version>${jsonld.version}</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
Expand Down
Expand Up @@ -39,6 +39,7 @@
import static org.apache.http.HttpStatus.SC_PRECONDITION_FAILED;
import static org.apache.jena.riot.RDFLanguages.contentTypeToLang;
import static org.apache.jena.riot.WebContent.contentTypeSPARQLUpdate;
import static org.fcrepo.http.commons.domain.RDFMediaType.JSON_LD;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3_ALT1;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3_ALT2;
Expand Down Expand Up @@ -116,6 +117,7 @@
import org.springframework.stereotype.Component;

import com.codahale.metrics.annotation.Timed;
import com.github.jsonldjava.jena.JenaJSONLD;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.Model;
Expand All @@ -138,6 +140,10 @@ public class FedoraNodes extends AbstractResource {

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

static {
JenaJSONLD.init();
}

/**
* Retrieve the node headers
* @param pathList
Expand Down Expand Up @@ -168,7 +174,6 @@ public Response head(@PathParam("path") final List<PathSegment> pathList,
return status(OK).build();
}


/**
* Retrieve the node profile
*
Expand All @@ -184,7 +189,7 @@ public Response head(@PathParam("path") final List<PathSegment> pathList,
*/
@GET
@Produces({TURTLE, N3, N3_ALT2, RDF_XML, NTRIPLES, APPLICATION_XML, TEXT_PLAIN, TURTLE_X,
TEXT_HTML, APPLICATION_XHTML_XML})
TEXT_HTML, APPLICATION_XHTML_XML, JSON_LD})
public RdfStream describe(@PathParam("path") final List<PathSegment> pathList,
@QueryParam("offset") @DefaultValue("0") final int offset,
@QueryParam("limit") @DefaultValue("-1") final int limit,
Expand Down Expand Up @@ -403,7 +408,7 @@ public Response updateSparql(@PathParam("path")
* @throws Exception
*/
@PUT
@Consumes({TURTLE, N3, N3_ALT1, N3_ALT2, RDF_XML, NTRIPLES})
@Consumes({TURTLE, N3, N3_ALT1, N3_ALT2, RDF_XML, NTRIPLES, JSON_LD})
@Timed
public Response createOrReplaceObjectRdf(
@PathParam("path") final List<PathSegment> pathList,
Expand Down Expand Up @@ -560,7 +565,7 @@ public Response createObject(@PathParam("path")
} else {
response = noContent();
}
} else if (isRdfContentType(contentTypeString)) {
} else if (isRdfContentType(contentTypeString)) {
LOGGER.trace("Found a RDF syntax, attempting to replace triples");

final Lang lang = contentTypeToLang(contentTypeString);
Expand Down
5 changes: 5 additions & 0 deletions fcrepo-http-commons/pom.xml
Expand Up @@ -262,6 +262,11 @@
<artifactId>sesame-rio-n3</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>com.github.jsonld-java</groupId>
<artifactId>jsonld-java-sesame</artifactId>
<version>${jsonld.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Expand Up @@ -73,12 +73,16 @@ public abstract class RDFMediaType extends MediaType {

public static final MediaType NTRIPLES_TYPE = typeFromString(NTRIPLES);

public final static String JSON_LD = "application/ld+json";

public final static MediaType JSON_LD_TYPE = typeFromString(JSON_LD);

public static final List<Variant> POSSIBLE_RDF_VARIANTS = mediaTypes(
TURTLE_TYPE, N3_TYPE, N3_ALT2_TYPE, RDF_XML_TYPE, NTRIPLES_TYPE, APPLICATION_XML_TYPE, TEXT_PLAIN_TYPE,
TURTLE_X_TYPE).add().build();
TURTLE_X_TYPE, JSON_LD_TYPE).add().build();

public static final String POSSIBLE_RDF_RESPONSE_VARIANTS_STRING[] = {
TURTLE, N3, N3_ALT2, RDF_XML, NTRIPLES, TEXT_PLAIN, APPLICATION_XML, TURTLE_X };
TURTLE, N3, N3_ALT2, RDF_XML, NTRIPLES, TEXT_PLAIN, APPLICATION_XML, TURTLE_X, JSON_LD };

public static final String TSV = contentTypeTextTSV;

Expand Down
Expand Up @@ -20,6 +20,7 @@
import static javax.ws.rs.core.MediaType.APPLICATION_XML;
import static javax.ws.rs.core.MediaType.TEXT_HTML_TYPE;
import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
import static org.fcrepo.http.commons.domain.RDFMediaType.JSON_LD;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3_ALT2;
import static org.fcrepo.http.commons.domain.RDFMediaType.NTRIPLES;
Expand Down Expand Up @@ -62,7 +63,7 @@
*/
@Provider
@Component
@Produces({TURTLE, N3, N3_ALT2, RDF_XML, NTRIPLES, APPLICATION_XML, TEXT_PLAIN, TURTLE_X})
@Produces({TURTLE, N3, N3_ALT2, RDF_XML, NTRIPLES, APPLICATION_XML, TEXT_PLAIN, TURTLE_X, JSON_LD})
public class RdfStreamProvider implements MessageBodyWriter<RdfStream> {

private static final Logger LOGGER = getLogger(RdfStreamProvider.class);
Expand Down
11 changes: 11 additions & 0 deletions fcrepo-metrics/pom.xml
Expand Up @@ -32,6 +32,17 @@
<groupId>com.codahale.metrics</groupId>
<artifactId>metrics-servlets</artifactId>
<version>${metrics.version}</version>

<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -41,6 +41,7 @@
<spring.version>4.0.3.RELEASE</spring.version>
<grizzly.version>2.3.6</grizzly.version>
<jena.version>2.11.1</jena.version>
<jsonld.version>0.5-SNAPSHOT</jsonld.version>
<!-- https://github.com/github/maven-plugins/blob/master/README.md -->
<github.global.server>github</github.global.server>
<powermock.version>1.5.4</powermock.version>
Expand Down Expand Up @@ -410,7 +411,6 @@
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient-cache</artifactId>
<version>${httpclient.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
Expand Down

0 comments on commit 512b19a

Please sign in to comment.