/** * Utility method that casts the return value of {@link #getUniqueSubject(Graph, IRI, Value, Resource[])} * to a URI, or throws a GraphUtilException if that value is not a URI. * * @return The subject of the matched statement(s). * @throws GraphUtilException * If such an exception is thrown by {@link #getUniqueSubject(Graph, IRI, Value, Resource[])} or * if its return value is not a URI. * @deprecated since 2.8.0. Use {@link Model#filter(Resource, IRI, Value, Resource...)} and * {@link Model#subjectIRI()} instead. */ @Deprecated public static IRI getUniqueSubjectURI(Graph graph, IRI pred, Value obj, Resource... contexts) throws GraphUtilException { Resource subject = getUniqueSubject(graph, pred, obj, contexts); if (subject instanceof IRI) { return (IRI)subject; } else { throw new GraphUtilException("Expected URI for subject " + subject); } }
/** * Utility method that casts the return value of {@link #getUniqueSubject(Graph, IRI, Value, Resource[])} * to a URI, or throws a GraphUtilException if that value is not a URI. * * @return The subject of the matched statement(s). * @throws GraphUtilException * If such an exception is thrown by {@link #getUniqueSubject(Graph, IRI, Value, Resource[])} or * if its return value is not a URI. * @deprecated since 2.8.0. Use {@link Model#filter(Resource, IRI, Value, Resource...)} and * {@link Model#subjectIRI()} instead. */ @Deprecated public static IRI getUniqueSubjectURI(Graph graph, IRI pred, Value obj, Resource... contexts) throws GraphUtilException { Resource subject = getUniqueSubject(graph, pred, obj, contexts); if (subject instanceof IRI) { return (IRI)subject; } else { throw new GraphUtilException("Expected URI for subject " + subject); } }
@Override public void endRDF() throws RDFHandlerException { try { Resource resultSetNode = GraphUtil.getUniqueSubject(graph, RDF.TYPE, RESULTSET); Literal booleanLit = GraphUtil.getUniqueObjectLiteral(graph, resultSetNode, BOOLEAN); if (booleanLit.equals(DAWGTestResultSetSchema.TRUE)) { value = true; } else if (booleanLit.equals(DAWGTestResultSetSchema.FALSE)) { value = false; } else { throw new RDFHandlerException("Invalid boolean value: " + booleanLit); } } catch (GraphUtilException e) { throw new RDFHandlerException(e.getMessage(), e); } } }
@Override public void endRDF() throws RDFHandlerException { try { Resource resultSetNode = GraphUtil.getUniqueSubject(graph, RDF.TYPE, RESULTSET); List<String> bindingNames = getBindingNames(resultSetNode); tqrHandler.startQueryResult(bindingNames); Iterator<Value> solIter = GraphUtil.getObjectIterator(graph, resultSetNode, SOLUTION); while (solIter.hasNext()) { Value solutionNode = solIter.next(); if (solutionNode instanceof Resource) { reportSolution((Resource)solutionNode, bindingNames); } else { throw new RDFHandlerException( "Value for " + SOLUTION + " is not a resource: " + solutionNode); } } tqrHandler.endQueryResult(); } catch (GraphUtilException e) { throw new RDFHandlerException(e.getMessage(), e); } catch (TupleQueryResultHandlerException e) { throw new RDFHandlerException(e.getMessage(), e); } }
@Override public void endRDF() throws RDFHandlerException { try { Resource resultSetNode = GraphUtil.getUniqueSubject(graph, RDF.TYPE, RESULTSET); List<String> bindingNames = getBindingNames(resultSetNode); tqrHandler.startQueryResult(bindingNames); Iterator<Value> solIter = GraphUtil.getObjectIterator(graph, resultSetNode, SOLUTION); while (solIter.hasNext()) { Value solutionNode = solIter.next(); if (solutionNode instanceof Resource) { reportSolution((Resource)solutionNode, bindingNames); } else { throw new RDFHandlerException( "Value for " + SOLUTION + " is not a resource: " + solutionNode); } } tqrHandler.endQueryResult(); } catch (GraphUtilException e) { throw new RDFHandlerException(e.getMessage(), e); } catch (TupleQueryResultHandlerException e) { throw new RDFHandlerException(e.getMessage(), e); } }
@Override public void endRDF() throws RDFHandlerException { try { Resource resultSetNode = GraphUtil.getUniqueSubject(graph, RDF.TYPE, RESULTSET); Literal booleanLit = GraphUtil.getUniqueObjectLiteral(graph, resultSetNode, BOOLEAN); if (booleanLit.equals(DAWGTestResultSetSchema.TRUE)) { value = true; } else if (booleanLit.equals(DAWGTestResultSetSchema.FALSE)) { value = false; } else { throw new RDFHandlerException("Invalid boolean value: " + booleanLit); } } catch (GraphUtilException e) { throw new RDFHandlerException(e.getMessage(), e); } } }
@Override public void endRDF() throws RDFHandlerException { try { Resource resultSetNode = GraphUtil.getUniqueSubject(graph, RDF.TYPE, RESULTSET); Literal booleanLit = GraphUtil.getUniqueObjectLiteral(graph, resultSetNode, BOOLEAN); if (booleanLit.equals(DAWGTestResultSetSchema.TRUE)) { value = true; } else if (booleanLit.equals(DAWGTestResultSetSchema.FALSE)) { value = false; } else { throw new RDFHandlerException("Invalid boolean value: " + booleanLit); } } catch (GraphUtilException e) { throw new RDFHandlerException(e.getMessage(), e); } } }
@Override public void endRDF() throws RDFHandlerException { try { Resource resultSetNode = GraphUtil.getUniqueSubject(graph, RDF.TYPE, RESULTSET); List<String> bindingNames = getBindingNames(resultSetNode); tqrHandler.startQueryResult(bindingNames); Iterator<Value> solIter = GraphUtil.getObjectIterator(graph, resultSetNode, SOLUTION); while (solIter.hasNext()) { Value solutionNode = solIter.next(); if (solutionNode instanceof Resource) { reportSolution((Resource)solutionNode, bindingNames); } else { throw new RDFHandlerException( "Value for " + SOLUTION + " is not a resource: " + solutionNode); } } tqrHandler.endQueryResult(); } catch (GraphUtilException e) { throw new RDFHandlerException(e.getMessage(), e); } catch (TupleQueryResultHandlerException e) { throw new RDFHandlerException(e.getMessage(), e); } }
private AGRepositoryConfig getConfig(Model graph) { Resource implNode = GraphUtil.getUniqueSubject(graph, vf.createIRI("http://www.openrdf.org/config/repository#repositoryType"), vf.createLiteral(AGRepositoryFactory.REPOSITORY_TYPE)); AGRepositoryFactory factory = new AGRepositoryFactory(); AGRepositoryConfig config = factory.getConfig(); config.parse(graph, implNode); return config; }
@Test @Category(TestSuites.Prepush.class) public void getRepositoryUsingManager() throws Exception { final Path confDir = Files.createTempDirectory("repomgr"); closeLater(() -> FileUtils.deleteDirectory(confDir.toFile())); RepositoryManager manager = new LocalRepositoryManager(confDir.toFile()); manager.initialize(); closeLater(manager::shutDown); Model graph = parseTurtleGraph(configFile); updateGraphForTestServer(graph); // Cleanup AGRepositoryConfig agConfig = getConfig(graph); deleteLater(agConfig.getRepositoryId(), agConfig.getCatalogId()); Resource node = GraphUtil.getUniqueSubject(graph, RDF.TYPE, RepositoryConfigSchema.REPOSITORY); String id = GraphUtil.getUniqueObjectLiteral(graph, node, RepositoryConfigSchema.REPOSITORYID).stringValue(); RepositoryConfig config = RepositoryConfig.create(graph, node); config.validate(); manager.addRepositoryConfig(config); Repository repo = manager.getRepository(id); repo.initialize(); closeLater(repo::shutDown); Assert.assertEquals(0, repo.getConnection().size()); }