Java Code Examples for org.eclipse.rdf4j.rio.Rio#write()
The following examples show how to use
org.eclipse.rdf4j.rio.Rio#write() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomTurtleParserTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testLiteralWithNewlines() throws Exception { String namespace = "http://www.foo.com/bar#"; String okLiteralString = "Literal \n without \n new line at the beginning. \n "; String errLiteralString = "\n Literal \n with \n new line at the beginning. \n "; IRI mySubject = vf.createIRI(namespace, "Subject"); IRI myPredicate = vf.createIRI(namespace, "Predicate"); Literal myOkObject = vf.createLiteral(okLiteralString); Literal myErrObject = vf.createLiteral(errLiteralString); StringWriter out = new StringWriter(); Model model = new LinkedHashModel(); model.add(mySubject, myPredicate, myOkObject); model.add(mySubject, myPredicate, myErrObject); Rio.write(model, out, RDFFormat.TURTLE); String str = out.toString(); System.err.println(str); assertTrue("okLiteralString not found", str.contains(okLiteralString)); assertTrue("errLiteralString not found", str.contains(errLiteralString)); }
Example 2
Source File: PropertyShape.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
String describe(SailRepositoryConnection connection, Resource resource) { GraphQuery graphQuery = connection.prepareGraphQuery("describe ?a where {BIND(?resource as ?a)}"); graphQuery.setBinding("resource", resource); try (Stream<Statement> stream = graphQuery.evaluate().stream()) { LinkedHashModel statements = stream.collect(Collectors.toCollection(LinkedHashModel::new)); statements.setNamespace(SHACL.PREFIX, SHACL.NAMESPACE); WriterConfig config = new WriterConfig(); config.set(BasicWriterSettings.PRETTY_PRINT, true); config.set(BasicWriterSettings.INLINE_BLANK_NODES, true); StringWriter stringWriter = new StringWriter(); Rio.write(statements, stringWriter, RDFFormat.TURTLE, config); return stringWriter.toString(); } }
Example 3
Source File: RDFXMLParserCustomTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testParseCommentAtStart() throws Exception { // Example from: // http://www.w3.org/TR/rdf-syntax-grammar/#section-Syntax-parsetype-Collection StringBuilder string = new StringBuilder(); string.append("<!-- Test comment for parser to ignore -->\n"); string.append("<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" "); string.append(" xmlns:ex=\"http://example.org/stuff/1.0/\"> \n"); string.append(" <rdf:Description rdf:about=\"http://example.org/basket\"> \n"); string.append(" <ex:hasFruit>\n"); string.append(" Mango\n"); string.append(" </ex:hasFruit>\n"); string.append(" </rdf:Description>\n"); string.append("</rdf:RDF>"); Model parse = Rio.parse(new StringReader(string.toString()), "", RDFFormat.RDFXML); Rio.write(parse, System.out, RDFFormat.NTRIPLES); assertEquals(1, parse.size()); }
Example 4
Source File: RdfDescriptionSaver.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
@Override public void commit() throws RdfProcessingFailedException { try { inputStream.close(); FileWriter newFileWriter = new FileWriter(descriptionFile, false); //false for overwrite file (true=concat) Rio.write(model, newFileWriter, RDFFormat.RDFXML); newFileWriter.flush(); newFileWriter.close(); importStatus.setStatus("Description saved"); } catch (IOException e) { throw new RdfProcessingFailedException(e); } }
Example 5
Source File: RdfConverter.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) throws IOException { final Model model = Rio.parse( new FileReader("/home/martijnm/Desktop/emdates_places_opole.ttl"), "http://example.com", RDFFormat.TURTLE ); Rio.write(model, new FileWriter("/home/martijnm/Desktop/emdates_places_opole.nq"), RDFFormat.NQUADS); }
Example 6
Source File: ArrangedWriterTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testWriteRepeatedInlineBlankNode() { Model model = new ModelBuilder().subject(exNs + "subject") .add(vf.createIRI(exNs, "rel1"), bnode1) .add(vf.createIRI(exNs, "rel2"), bnode1) .add(vf.createIRI(exNs, "rel3"), bnode2) .subject(bnode1) .add(RDFS.LABEL, "the bnode1") .subject(bnode2) .add(RDFS.LABEL, "the bnode2") .build(); model.setNamespace(RDFS.NS); model.setNamespace("ex", exNs); StringWriter stringWriter = new StringWriter(); BufferedWriter writer = new BufferedWriter(stringWriter); WriterConfig config = new WriterConfig(); config.set(BasicWriterSettings.INLINE_BLANK_NODES, true); Rio.write(model, writer, RDFFormat.TURTLE, config); String sep = System.lineSeparator(); String expectedResult = "@prefix ex: <http://example.org/> ." + sep + "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> ." + sep + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> ." + sep + sep + "ex:subject ex:rel1 _:bnode1 ." + sep + sep + "_:bnode1 rdfs:label \"the bnode1\" ." + sep + sep + "ex:subject ex:rel2 _:bnode1;" + sep + " ex:rel3 [" + sep + " rdfs:label \"the bnode2\"" + sep + " ] ." + sep; assertEquals(expectedResult, stringWriter.toString()); }
Example 7
Source File: SimpleOntology.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Override public OutputStream asRdfXml(OutputStream outputStream) throws MobiOntologyException { try { RDFHandler rdfWriter = new BufferedGroupingRDFHandler(Rio.createWriter(RDFFormat.RDFXML, outputStream)); org.eclipse.rdf4j.model.Model sesameModel = asSesameModel(); Rio.write(sesameModel, rdfWriter); } catch (RDFHandlerException e) { throw new MobiOntologyException("Error while writing Ontology."); } return outputStream; }
Example 8
Source File: DescriptionView.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
private void createDescriptionNode(Description description, RDFFormat parseFormat, Interpreter interpreter) { try { Model model = Rio.parse(IOUtils.toInputStream(description.getRawContent()), "", parseFormat); ByteArrayOutputStream out = new ByteArrayOutputStream(); Rio.write(model, out, RDFFormat.JSONLD); ObjectMapper mapper = new ObjectMapper(); content = mapper.readTree(out.toString()); } catch (Exception e) { // catch all e.g. org.xml.sax.SAXParseException rawContent = description.getRawContent(); error = new ErrorView(e, interpreter); } }
Example 9
Source File: AbstractShaclTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void printCurrentState(SailRepository shaclRepository) { if (!fullLogging) { return; } try (SailRepositoryConnection connection = shaclRepository.getConnection()) { if (connection.isEmpty()) { System.out.println("### CURRENT REPOSITORY STATE ###"); System.out.println(" EMPTY!"); System.out.println("################################################\n"); } else { try (Stream<Statement> stream = connection.getStatements(null, null, null, false).stream()) { LinkedHashModel model = stream.collect(Collectors.toCollection(LinkedHashModel::new)); model.setNamespace("ex", "http://example.com/ns#"); model.setNamespace(FOAF.PREFIX, FOAF.NAMESPACE); model.setNamespace(XMLSchema.PREFIX, XMLSchema.NAMESPACE); model.setNamespace(RDF.PREFIX, RDF.NAMESPACE); model.setNamespace(RDFS.PREFIX, RDFS.NAMESPACE); WriterConfig writerConfig = new WriterConfig(); writerConfig.set(BasicWriterSettings.PRETTY_PRINT, true); writerConfig.set(BasicWriterSettings.INLINE_BLANK_NODES, true); System.out.println("### CURRENT REPOSITORY STATE ###"); Rio.write(model, System.out, RDFFormat.TURTLE, writerConfig); System.out.println("################################################\n"); } } } }
Example 10
Source File: ValidationReportTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void simpleFirstTest() throws IOException { SailRepository shaclSail = Utils.getInitializedShaclRepository("shacl.ttl", false); try (SailRepositoryConnection connection = shaclSail.getConnection()) { connection.begin(); connection.add(RDFS.RESOURCE, RDF.TYPE, RDFS.RESOURCE); connection.add(RDFS.RESOURCE, RDFS.LABEL, connection.getValueFactory().createLiteral("a")); connection.add(RDFS.CLASS, RDF.TYPE, RDFS.RESOURCE); connection.add(RDF.SUBJECT, RDF.TYPE, RDFS.RESOURCE); connection.commit(); fail(); } catch (RepositoryException e) { ShaclSailValidationException cause = (ShaclSailValidationException) e.getCause(); Model actual = cause.validationReportAsModel(); actual.setNamespace(RDF.PREFIX, RDF.NAMESPACE); actual.setNamespace(RDFS.PREFIX, RDFS.NAMESPACE); actual.setNamespace("ex", "http://example.com/ns#"); Rio.write(actual, System.out, RDFFormat.TURTLE); Model expected = Rio.parse(new StringReader("" + "@prefix ex: <http://example.com/ns#> .\n" + "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n" + "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n" + "@prefix sh: <http://www.w3.org/ns/shacl#> .\n" + "\n" + "_:node1d1gi0h02x12 a sh:ValidationReport;\n" + " sh:conforms false;\n" + " sh:result _:node1d1gi0h02x13 .\n" + "\n" + "_:node1d1gi0h02x13 a sh:ValidationResult;\n" + " sh:focusNode rdf:subject;\n" + " sh:resultPath rdfs:label;\n" + " sh:sourceConstraintComponent sh:MinCountConstraintComponent;\n" + " sh:sourceShape ex:PersonShapeProperty .\n" + "\n" + "_:node1d1gi0h02x12 sh:result _:node1d1gi0h02x14 .\n" + "\n" + "_:node1d1gi0h02x14 a sh:ValidationResult;\n" + " sh:focusNode rdfs:Class;\n" + " sh:resultPath rdfs:label;\n" + " sh:sourceConstraintComponent sh:MinCountConstraintComponent;\n" + " sh:sourceShape ex:PersonShapeProperty ." + ""), "", RDFFormat.TURTLE); assertTrue(Models.isomorphic(expected, actual)); } }
Example 11
Source File: RdfConverter.java From timbuctoo with GNU General Public License v3.0 | 4 votes |
public static void main(String[] args) throws Exception { InputStream resourceAsStream = new FileInputStream(args[0]); Model model = Rio.parse(resourceAsStream, "", RDFFormat.NQUADS); Rio.write(model, new FileOutputStream(args[1]), RDFFormat.TURTLE); }
Example 12
Source File: ArrangedWriterTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void write(Model model, OutputStream writer) { RDFWriter rdfWriter = writerFactory.getWriter(writer); // "pretty print" forces ArrangedWriter to handle namespaces rdfWriter.getWriterConfig().set(BasicWriterSettings.PRETTY_PRINT, true); Rio.write(model, rdfWriter); }
Example 13
Source File: ValidationReportTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void nestedLogicalOrSupport() throws IOException { SailRepository shaclSail = Utils.getInitializedShaclRepository("test-cases/or/datatype/shacl.ttl", false); try (SailRepositoryConnection connection = shaclSail.getConnection()) { connection.begin(); connection.prepareUpdate(IOUtils.toString(ValidationReportTest.class.getClassLoader() .getResourceAsStream("test-cases/or/datatype/invalid/case1/query1.rq"), StandardCharsets.UTF_8)) .execute(); connection.commit(); fail(); } catch (RepositoryException e) { ShaclSailValidationException cause = (ShaclSailValidationException) e.getCause(); Model actual = cause.validationReportAsModel(); actual.setNamespace(RDF.PREFIX, RDF.NAMESPACE); actual.setNamespace(RDFS.PREFIX, RDFS.NAMESPACE); actual.setNamespace("ex", "http://example.com/ns#"); WriterConfig writerConfig = new WriterConfig(); writerConfig.set(BasicWriterSettings.INLINE_BLANK_NODES, true); writerConfig.set(BasicWriterSettings.PRETTY_PRINT, true); Rio.write(actual, System.out, RDFFormat.TURTLE, writerConfig); Model expected = Rio.parse(new StringReader("" + "@prefix ex: <http://example.com/ns#> .\n" + "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n" + "@prefix sh: <http://www.w3.org/ns/shacl#> .\n" + "\n" + "[] a sh:ValidationReport;\n" + " sh:conforms false;\n" + " sh:result [ a sh:ValidationResult;\n" + " sh:detail [ a sh:ValidationResult;\n" + " sh:detail [ a sh:ValidationResult;\n" + " sh:focusNode ex:validPerson1;\n" + " sh:resultPath ex:age;\n" + " sh:sourceConstraintComponent sh:DatatypeConstraintComponent;\n" + " sh:sourceShape ex:personShapeAgeLong\n" + " ];\n" + " sh:focusNode ex:validPerson1;\n" + " sh:resultPath ex:age;\n" + " sh:sourceConstraintComponent sh:DatatypeConstraintComponent;\n" + " sh:sourceShape ex:personShapeAgeInteger\n" + " ];\n" + " sh:focusNode ex:validPerson1;\n" + " sh:resultPath ex:age;\n" + " sh:sourceConstraintComponent sh:OrConstraintComponent;\n" + " sh:sourceShape ex:personShapeOr\n" + " ] ." + ""), "", RDFFormat.TURTLE); assertTrue(Models.isomorphic(expected, actual)); } }
Example 14
Source File: ValidationReportTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void withoutPathTest() throws IOException { SailRepository shaclSail = Utils.getInitializedShaclRepository("shaclValidateTarget.ttl", false); try (SailRepositoryConnection connection = shaclSail.getConnection()) { connection.begin(); connection.add(vf.createIRI("http://example.com/ns#", "node1"), RDF.TYPE, vf.createIRI("http://example.com/ns#", "SecondTarget")); connection.commit(); fail(); } catch (RepositoryException e) { ShaclSailValidationException cause = (ShaclSailValidationException) e.getCause(); Model actual = cause.validationReportAsModel(); actual.setNamespace(RDF.PREFIX, RDF.NAMESPACE); actual.setNamespace(RDFS.PREFIX, RDFS.NAMESPACE); actual.setNamespace("ex", "http://example.com/ns#"); Rio.write(actual, System.out, RDFFormat.TURTLE); Model expected = Rio.parse(new StringReader("" + "@prefix ex: <http://example.com/ns#> .\n" + "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n" + "@prefix sh: <http://www.w3.org/ns/shacl#> .\n" + "\n" + "_:node1e4dsta0ax19 a sh:ValidationReport;\n" + " sh:conforms false;\n" + " sh:result _:node1e4dsta0ax20 .\n" + "\n" + "_:node1e4dsta0ax20 a sh:ValidationResult;\n" + " sh:focusNode ex:node1;\n" + " sh:sourceConstraintComponent sh:ClassConstraintComponent;\n" + " sh:sourceShape ex:PersonShape ." + ""), "", RDFFormat.TURTLE); assertTrue(Models.isomorphic(expected, actual)); } }
Example 15
Source File: SerializableTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void testMaxCount2Snapshot() throws IOException, InterruptedException { SailRepository repo = Utils.getInitializedShaclRepository("shaclMax.ttl", false); multithreadedMaxCount2Violation(IsolationLevels.SNAPSHOT, repo); try (SailRepositoryConnection connection = repo.getConnection()) { connection.begin(); ValidationReport revalidate = ((ShaclSailConnection) connection.getSailConnection()).revalidate(); Rio.write(revalidate.asModel(), System.out, RDFFormat.TURTLE); assertTrue(revalidate.conforms()); connection.commit(); } repo.shutDown(); }
Example 16
Source File: SerializableTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void testMaxCount2Serializable() throws IOException, InterruptedException { SailRepository repo = Utils.getInitializedShaclRepository("shaclMax.ttl", false); multithreadedMaxCount2Violation(IsolationLevels.SERIALIZABLE, repo); try (SailRepositoryConnection connection = repo.getConnection()) { connection.begin(); ValidationReport revalidate = ((ShaclSailConnection) connection.getSailConnection()).revalidate(); Rio.write(revalidate.asModel(), System.out, RDFFormat.TURTLE); assertTrue(revalidate.conforms()); connection.commit(); } repo.shutDown(); }
Example 17
Source File: SerializableTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void testMaxCountSerializable() throws IOException, InterruptedException { SailRepository repo = Utils.getInitializedShaclRepository("shaclMax.ttl", false); multithreadedMaxCountViolation(IsolationLevels.SERIALIZABLE, repo); try (SailRepositoryConnection connection = repo.getConnection()) { connection.begin(); ValidationReport revalidate = ((ShaclSailConnection) connection.getSailConnection()).revalidate(); Rio.write(revalidate.asModel(), System.out, RDFFormat.TURTLE); assertTrue(revalidate.conforms()); connection.commit(); } repo.shutDown(); }
Example 18
Source File: SerializableTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void testMaxCountSnapshot() throws IOException, InterruptedException { for (int i = 0; i < 10; i++) { SailRepository repo = Utils.getInitializedShaclRepository("shaclMax.ttl", false); Sail sail = repo.getSail(); // ((ShaclSail) sail).setGlobalLogValidationExecution(true); multithreadedMaxCountViolation(IsolationLevels.SNAPSHOT, repo); try (SailRepositoryConnection connection = repo.getConnection()) { connection.begin(); ValidationReport revalidate = ((ShaclSailConnection) connection.getSailConnection()).revalidate(); Rio.write(revalidate.asModel(), System.out, RDFFormat.TURTLE); assertTrue(revalidate.conforms()); connection.commit(); } repo.shutDown(); } }
Example 19
Source File: OntologyRecordServiceTest.java From mobi with GNU Affero General Public License v3.0 | 4 votes |
@Before public void setUp() throws Exception { recordService = new SimpleOntologyRecordService(); deleteActivity = deleteActivityFactory.createNew(VALUE_FACTORY.createIRI("http://test.org/activity/delete")); WriterConfig config = new WriterConfig(); config.set(JSONLDSettings.JSONLD_MODE, JSONLDMode.FLATTEN); importedOntologyIRI = VALUE_FACTORY.createIRI("http://test.org/ontology/IRI"); InputStream testOntology = getClass().getResourceAsStream("/test-ontology.ttl"); ontologyModel = MODEL_FACTORY.createModel(Values.mobiModel(Rio.parse(testOntology, "", RDFFormat.TURTLE))); ontologyJsonLd = new ByteArrayOutputStream(); Rio.write(Values.sesameModel(ontologyModel), ontologyJsonLd, RDFFormat.JSONLD, config); user = userFactory.createNew(VALUE_FACTORY.createIRI("http://test.org/user")); headCommit = commitFactory.createNew(commitIRI); branch = branchFactory.createNew(branchIRI); branch.setHead(headCommit); branch.setProperty(VALUE_FACTORY.createLiteral("Test Record"), VALUE_FACTORY.createIRI(_Thing.title_IRI)); Model deletions = MODEL_FACTORY.createModel(); deletions.add(VALUE_FACTORY.createIRI("http://test.com#sub"), VALUE_FACTORY.createIRI(_Thing.description_IRI), VALUE_FACTORY.createLiteral("Description")); difference = new Difference.Builder() .additions(MODEL_FACTORY.createModel()) .deletions(deletions) .build(); tag = tagFactory.createNew(tagIRI); tag.setVersionedDistribution(Collections.singleton(distributionFactory.createNew(distributionIRI))); testRecord = recordFactory.createNew(testIRI); testRecord.setProperty(VALUE_FACTORY.createLiteral("Test Record"), VALUE_FACTORY.createIRI(_Thing.title_IRI)); testRecord.setCatalog(catalogFactory.createNew(catalogId)); testRecord.setBranch(Collections.singleton(branch)); testRecord.setVersion(Collections.singleton(tag)); testRecord.setLatestVersion(tag); testRecord.setBranch(Collections.singleton(branch)); testRecord.setMasterBranch(branchFactory.createNew(masterBranchIRI)); testRecord.setOntologyIRI(testIRI); MockitoAnnotations.initMocks(this); when(ontologyId1.getOntologyIRI()).thenReturn(Optional.empty()); when(ontologyId1.getOntologyIdentifier()).thenReturn(importedOntologyIRI); when(ontologyId2.getOntologyIRI()).thenReturn(Optional.of(importedOntologyIRI)); when(ontologyManager.ontologyIriExists(any(IRI.class))).thenReturn(false); when(ontologyManager.createOntologyId(any(Model.class))).thenReturn(ontologyId1); when(versioningManager.commit(any(IRI.class), any(IRI.class), any(IRI.class), eq(user), anyString(), any(Model.class), any(Model.class))).thenReturn(commitIRI); when(utilsService.optObject(any(IRI.class), any(OrmFactory.class), eq(connection))).thenReturn(Optional.of(testRecord)); when(utilsService.getBranch(eq(testRecord), eq(branchIRI), any(OrmFactory.class), eq(connection))).thenReturn(branch); when(utilsService.getHeadCommitIRI(eq(branch))).thenReturn(commitIRI); doReturn(Stream.of(commitIRI).collect(Collectors.toList())) .when(utilsService).getCommitChain(eq(commitIRI), eq(false), any(RepositoryConnection.class)); when(utilsService.getExpectedObject(eq(commitIRI), any(OrmFactory.class), eq(connection))).thenReturn(headCommit); when(utilsService.getRevisionChanges(eq(commitIRI), eq(connection))).thenReturn(difference); when(provUtils.startDeleteActivity(any(User.class), any(IRI.class))).thenReturn(deleteActivity); doNothing().when(mergeRequestManager).deleteMergeRequestsWithRecordId(eq(testIRI), any(RepositoryConnection.class)); doNothing().when(ontologyCache).clearCache(any(Resource.class)); doNothing().when(ontologyCache).clearCacheImports(any(Resource.class)); when(xacmlPolicyManager.addPolicy(any(XACMLPolicy.class))).thenReturn(recordPolicyIRI); when(connection.getStatements(eq(null), eq(VALUE_FACTORY.createIRI(Policy.relatedResource_IRI)), any(IRI.class))).thenReturn(results); when(results.hasNext()).thenReturn(true); when(results.next()).thenReturn(statement); when(statement.getSubject()).thenReturn(recordPolicyIRI); when(configProvider.getRepository()).thenReturn(repository); when(repository.getConnection()).thenReturn(connection); when(connection.prepareTupleQuery(anyString())).thenReturn(tupleQuery); when(tupleQuery.evaluate()).thenReturn(tupleQueryResult); when(tupleQueryResult.hasNext()).thenReturn(true, false); when(tupleQueryResult.next()).thenReturn(bindingSet); when(bindingSet.getBinding(anyString())).thenReturn(Optional.of(binding)); when(binding.getValue()).thenReturn(VALUE_FACTORY.createLiteral("urn:record"), VALUE_FACTORY.createLiteral("urn:master"), VALUE_FACTORY.createLiteral("urn:user")); when(sesameTransformer.mobiModel(any(org.eclipse.rdf4j.model.Model.class))).thenAnswer(i -> Values.mobiModel(i.getArgumentAt(0, org.eclipse.rdf4j.model.Model.class))); injectOrmFactoryReferencesIntoService(recordService); recordService.setOntologyManager(ontologyManager); recordService.setUtilsService(utilsService); recordService.setVf(VALUE_FACTORY); recordService.setModelFactory(MODEL_FACTORY); recordService.setProvUtils(provUtils); recordService.setOntologyCache(ontologyCache); recordService.setVersioningManager(versioningManager); recordService.setMergeRequestManager(mergeRequestManager); recordService.setPolicyManager(xacmlPolicyManager); recordService.setEngineManager(engineManager); recordService.setCatalogConfigProvider(configProvider); recordService.setSesameTransformer(sesameTransformer); }
Example 20
Source File: ProtocolExceptionResolver.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception exception) { logger.debug("ProtocolExceptionResolver.resolveException() called"); Map<String, Object> model = new HashMap<>(); int statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; String errMsg = exception.getMessage(); if (exception instanceof HTTPException) { HTTPException httpExc = (HTTPException) exception; statusCode = httpExc.getStatusCode(); if (exception instanceof ClientHTTPException) { logger.info("Client sent bad request ( " + statusCode + ")", exception); } else { logger.error("Error while handling request (" + statusCode + ")", exception); } } else { logger.error("Error while handling request", exception); } int depth = 10; Throwable temp = exception; while (!(temp instanceof ValidationException)) { if (depth-- == 0) { break; } if (temp == null) { break; } temp = temp.getCause(); } if (temp instanceof ValidationException) { // This is currently just a simple fix that causes the validation report to be printed. // This should not be the final solution. Model validationReportModel = ((ValidationException) temp).validationReportAsModel(); 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); statusCode = HttpServletResponse.SC_CONFLICT; errMsg = stringWriter.toString(); Map<String, String> headers = new HashMap<>(); headers.put("Content-Type", "application/shacl-validation-report+n-quads"); model.put(SimpleResponseView.CUSTOM_HEADERS_KEY, headers); } model.put(SimpleResponseView.SC_KEY, statusCode); model.put(SimpleResponseView.CONTENT_KEY, errMsg); return new ModelAndView(SimpleResponseView.getInstance(), model); }