Skip to content

Commit

Permalink
Try to reajust dependencies and use RDFConverter from lobid-resources
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasNx committed Jul 3, 2023
1 parent 9a9ceef commit e0de892
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
10 changes: 6 additions & 4 deletions app/controllers/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,8 @@ private static Result resultFor(String id, JsonNode json, String format) {
return resultSupplier == null ? rdfSupplier.get() : resultSupplier.get();
}

private static Pair<String, String> contentAndType(JsonNode responseJson,
String responseFormat) {
static Status responseFor(JsonNode responseJson, String responseFormat)
throws JsonProcessingException {
String content = "";
String contentType = "";
switch (responseFormat) {
Expand All @@ -733,11 +733,13 @@ private static Pair<String, String> 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) {
Expand Down
30 changes: 15 additions & 15 deletions app/controllers/RdfConverter.java
Original file line number Diff line number Diff line change
@@ -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)
*
*/
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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

Expand Down

0 comments on commit e0de892

Please sign in to comment.