Skip to content

Commit

Permalink
GH-4622 preserve blank node IDs with shacl validation reports from re…
Browse files Browse the repository at this point in the history
…mote repository
  • Loading branch information
hmottestad committed Oct 3, 2023
1 parent 078af89 commit 7cfebab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@

import org.eclipse.rdf4j.common.annotation.InternalUseOnly;
import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
import org.eclipse.rdf4j.rio.ParserConfig;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.rio.Rio;
import org.eclipse.rdf4j.rio.helpers.BasicParserSettings;
import org.eclipse.rdf4j.rio.helpers.ParseErrorLogger;

@InternalUseOnly
class RemoteValidation {
Expand All @@ -37,7 +41,9 @@ class RemoteValidation {
Model asModel() {
if (model == null) {
try {
model = Rio.parse(stringReader, baseUri, format);
ParserConfig parserConfig = new ParserConfig().set(BasicParserSettings.PRESERVE_BNODE_IDS, true);
model = Rio.parse(stringReader, baseUri, format, parserConfig, SimpleValueFactory.getInstance(),
new ParseErrorLogger());
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,14 @@ public ModelAndView resolveException(HttpServletRequest request, HttpServletResp

StringWriter stringWriter = new StringWriter();

// We choose NQUADS because we want to support streaming in the future, and because there could be a use for
// different graphs in the future
Rio.write(validationReportModel, stringWriter, RDFFormat.NQUADS);
// We choose RDFJSON because this format doesn't rename blank nodes.
Rio.write(validationReportModel, stringWriter, RDFFormat.RDFJSON);

statusCode = HttpServletResponse.SC_CONFLICT;
errMsg = stringWriter.toString();

Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/shacl-validation-report+n-quads");
headers.put("Content-Type", "application/shacl-validation-report+rdf+json");
model.put(SimpleResponseView.CUSTOM_HEADERS_KEY, headers);
}

Expand Down

0 comments on commit 7cfebab

Please sign in to comment.