diff --git a/app/controllers/Application.java b/app/controllers/Application.java index d60729b5..f0366cb4 100644 --- a/app/controllers/Application.java +++ b/app/controllers/Application.java @@ -712,8 +712,8 @@ private static Result resultFor(String id, JsonNode json, String format) { return resultSupplier == null ? rdfSupplier.get() : resultSupplier.get(); } - private static Pair contentAndType(JsonNode responseJson, - String responseFormat) { + static Status responseFor(JsonNode responseJson, String responseFormat) + throws JsonProcessingException { String content = ""; String contentType = ""; switch (responseFormat) { @@ -733,11 +733,13 @@ private static Pair contentAndType(JsonNode responseJson, break; } default: { - content = prettyJsonOk(responseJson); + content = new ObjectMapper().writerWithDefaultPrettyPrinter() + .writeValueAsString(responseJson); contentType = Accept.Format.JSON_LD.types[0]; } } - return Pair.of(content, contentType + "; charset=utf-8"); + return content.isEmpty() ? internalServerError("No content") + : ok(content).as(contentType + "; charset=utf-8"); } private static String prettyJsonOk(JsonNode jsonNode) { diff --git a/app/controllers/RdfConverter.java b/app/controllers/RdfConverter.java index d9589ae0..6dfd43f7 100644 --- a/app/controllers/RdfConverter.java +++ b/app/controllers/RdfConverter.java @@ -1,21 +1,19 @@ /* Copyright 2017 Fabian Steeg, hbz. Licensed under the EPL 2.0 */ -package controllers; +package controllers.resources; +import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; import java.io.StringWriter; - -import com.github.jsonldjava.core.JsonLdError; -import com.github.jsonldjava.core.JsonLdProcessor; -import com.github.jsonldjava.jena.JenaTripleCallback; -import com.github.jsonldjava.utils.JsonUtils; -import com.hp.hpl.jena.rdf.model.Model; +import org.apache.jena.rdf.model.Model; +import org.apache.jena.rdf.model.ModelFactory; import play.Logger; /** * Helper class for converting JsonLd to RDF. - * + * * @author Fabian Steeg (fsteeg) * */ @@ -47,29 +45,31 @@ public String getName() { */ public static String toRdf(final String jsonLd, final RdfFormat format) { try { - final Object jsonObject = JsonUtils.fromString(jsonLd); - final JenaTripleCallback callback = new JenaTripleCallback(); - final Model model = (Model) JsonLdProcessor.toRDF(jsonObject, callback); + //convert json-ld string into InputStream as is required by the read() function. + final InputStream targetStream = new ByteArrayInputStream(jsonLd.getBytes()); + final Model model = ModelFactory.createDefaultModel() ; + + model.read(targetStream, "", "JSON-LD"); model.setNsPrefix("bf", "http://id.loc.gov/ontologies/bibframe/"); model.setNsPrefix("bibo", "http://purl.org/ontology/bibo/"); model.setNsPrefix("dc", "http://purl.org/dc/elements/1.1/"); model.setNsPrefix("dcterms", "http://purl.org/dc/terms/"); - model.setNsPrefix("gndo", "http://d-nb.info/standards/elementset/gnd#"); + model.setNsPrefix("gndo", "https://d-nb.info/standards/elementset/gnd#"); model.setNsPrefix("lv", "http://purl.org/lobid/lv#"); model.setNsPrefix("mo", "http://purl.org/ontology/mo/"); - model.setNsPrefix("org", "http://www.w3.org/ns/org#"); model.setNsPrefix("owl", "http://www.w3.org/2002/07/owl#"); model.setNsPrefix("rdau", "http://rdaregistry.info/Elements/u/"); model.setNsPrefix("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); model.setNsPrefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#"); - model.setNsPrefix("schema", "https://schema.org/"); + model.setNsPrefix("schema", "http://schema.org/"); model.setNsPrefix("skos", "http://www.w3.org/2004/02/skos/core#"); model.setNsPrefix("wdrs", "http://www.w3.org/2007/05/powder-s#"); model.setNsPrefix("xsd", "http://www.w3.org/2001/XMLSchema#"); + final StringWriter writer = new StringWriter(); model.write(writer, format.getName()); return writer.toString(); - } catch (IOException | JsonLdError e) { + } catch ( Exception e) { Logger.error(e.getMessage(), e); } return null; diff --git a/build.sbt b/build.sbt index e5a0889f..069e12a1 100644 --- a/build.sbt +++ b/build.sbt @@ -15,9 +15,8 @@ libraryDependencies ++= Seq( // otherwise javaWs won't work exclude ("io.netty", "netty"), "com.fasterxml.jackson.core" % "jackson-annotations" % "2.15.1", - "com.github.jsonld-java" % "jsonld-java" % "0.4.1", - "com.github.jsonld-java" % "jsonld-java-jena" % "0.4.1" exclude("org.slf4j", "slf4j-log4j12"), - "org.apache.jena" % "jena-arq" % "2.9.3", + "com.github.jsonld-java" % "jsonld-java" % "0.13.4", + "org.apache.jena" % "jena-arq" % "3.17.0", "org.metafacture" % "metamorph" % "5.7.0-rc1", "org.metafacture" % "metafacture-elasticsearch" % "5.7.0-rc1", "org.metafacture" % "metamorph-test" % "5.7.0-rc1", @@ -38,7 +37,6 @@ libraryDependencies ++= Seq( // force play to use these versions (ignoring transitive dependencies) dependencyOverrides += "com.fasterxml.jackson.core" % "jackson-databind" % "2.6.2" dependencyOverrides += "com.fasterxml.jackson.core" % "jackson-core" % "2.6.2" -dependencyOverrides += "org.apache.jena" % "jena-core" % "2.11.1" resolvers += Resolver.mavenLocal