Search in sources :

Example 6 with QueryEvaluationException

use of org.eclipse.rdf4j.query.QueryEvaluationException in project rdf4j by eclipse.

the class HTTPRepositoryConnection method getNamespaces.

public RepositoryResult<Namespace> getNamespaces() throws RepositoryException {
    try {
        List<Namespace> namespaceList = new ArrayList<Namespace>();
        TupleQueryResult namespaces = client.getNamespaces();
        try {
            while (namespaces.hasNext()) {
                BindingSet bindingSet = namespaces.next();
                Value prefix = bindingSet.getValue("prefix");
                Value namespace = bindingSet.getValue("namespace");
                if (prefix instanceof Literal && namespace instanceof Literal) {
                    String prefixStr = ((Literal) prefix).getLabel();
                    String namespaceStr = ((Literal) namespace).getLabel();
                    namespaceList.add(new SimpleNamespace(prefixStr, namespaceStr));
                }
            }
        } finally {
            namespaces.close();
        }
        return createRepositoryResult(namespaceList);
    } catch (QueryEvaluationException e) {
        throw new RepositoryException(e);
    } catch (IOException e) {
        throw new RepositoryException(e);
    }
}
Also used : BindingSet(org.eclipse.rdf4j.query.BindingSet) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) Literal(org.eclipse.rdf4j.model.Literal) ArrayList(java.util.ArrayList) Value(org.eclipse.rdf4j.model.Value) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) IOException(java.io.IOException) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult) Namespace(org.eclipse.rdf4j.model.Namespace) SimpleNamespace(org.eclipse.rdf4j.model.impl.SimpleNamespace) SimpleNamespace(org.eclipse.rdf4j.model.impl.SimpleNamespace)

Example 7 with QueryEvaluationException

use of org.eclipse.rdf4j.query.QueryEvaluationException in project rdf4j by eclipse.

the class RemoteRepositoryManager method getRepositoryConfig.

@Override
public RepositoryConfig getRepositoryConfig(String id) throws RepositoryException {
    Model model = new LinkedHashModel();
    try (RDF4JProtocolSession httpClient = getSesameClient().createRDF4JProtocolSession(serverURL)) {
        httpClient.setUsernameAndPassword(username, password);
        httpClient.setRepository(Protocol.getRepositoryLocation(serverURL, SystemRepository.ID));
        httpClient.getStatements(null, null, null, true, new StatementCollector(model));
    } catch (IOException | QueryEvaluationException | UnauthorizedException ue) {
        throw new RepositoryException(ue);
    }
    return RepositoryConfigUtil.getRepositoryConfig(model, id);
}
Also used : QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) UnauthorizedException(org.eclipse.rdf4j.http.protocol.UnauthorizedException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) RDF4JProtocolSession(org.eclipse.rdf4j.http.client.RDF4JProtocolSession) IOException(java.io.IOException)

Example 8 with QueryEvaluationException

use of org.eclipse.rdf4j.query.QueryEvaluationException in project rdf4j by eclipse.

the class RemoteRepositoryManager method getAllRepositoryInfos.

@Override
public Collection<RepositoryInfo> getAllRepositoryInfos(boolean skipSystemRepo) throws RepositoryException {
    List<RepositoryInfo> result = new ArrayList<RepositoryInfo>();
    try (RDF4JProtocolSession httpClient = getSesameClient().createRDF4JProtocolSession(serverURL)) {
        httpClient.setUsernameAndPassword(username, password);
        TupleQueryResult responseFromServer = httpClient.getRepositoryList();
        while (responseFromServer.hasNext()) {
            BindingSet bindingSet = responseFromServer.next();
            RepositoryInfo repInfo = new RepositoryInfo();
            String id = Literals.getLabel(bindingSet.getValue("id"), null);
            if (skipSystemRepo && id.equals(SystemRepository.ID)) {
                continue;
            }
            Value uri = bindingSet.getValue("uri");
            String description = Literals.getLabel(bindingSet.getValue("title"), null);
            boolean readable = Literals.getBooleanValue(bindingSet.getValue("readable"), false);
            boolean writable = Literals.getBooleanValue(bindingSet.getValue("writable"), false);
            if (uri instanceof IRI) {
                try {
                    repInfo.setLocation(new URL(uri.toString()));
                } catch (MalformedURLException e) {
                    logger.warn("Server reported malformed repository URL: {}", uri);
                }
            }
            repInfo.setId(id);
            repInfo.setDescription(description);
            repInfo.setReadable(readable);
            repInfo.setWritable(writable);
            result.add(repInfo);
        }
    } catch (IOException ioe) {
        logger.warn("Unable to retrieve list of repositories", ioe);
        throw new RepositoryException(ioe);
    } catch (QueryEvaluationException qee) {
        logger.warn("Unable to retrieve list of repositories", qee);
        throw new RepositoryException(qee);
    } catch (UnauthorizedException ue) {
        logger.warn("Not authorized to retrieve list of repositories", ue);
        throw new RepositoryException(ue);
    } catch (RepositoryException re) {
        logger.warn("Unable to retrieve list of repositories", re);
        throw re;
    }
    return result;
}
Also used : BindingSet(org.eclipse.rdf4j.query.BindingSet) IRI(org.eclipse.rdf4j.model.IRI) MalformedURLException(java.net.MalformedURLException) ArrayList(java.util.ArrayList) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) IOException(java.io.IOException) URL(java.net.URL) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) Value(org.eclipse.rdf4j.model.Value) UnauthorizedException(org.eclipse.rdf4j.http.protocol.UnauthorizedException) RDF4JProtocolSession(org.eclipse.rdf4j.http.client.RDF4JProtocolSession) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult)

Example 9 with QueryEvaluationException

use of org.eclipse.rdf4j.query.QueryEvaluationException in project rdf4j by eclipse.

the class RemoteRepositoryManager method addRepositoryConfig.

@Override
public void addRepositoryConfig(RepositoryConfig config) throws RepositoryException, RepositoryConfigException {
    try (RDF4JProtocolSession httpClient = getSesameClient().createRDF4JProtocolSession(serverURL)) {
        String baseURI = Protocol.getRepositoryLocation(serverURL, config.getID());
        Resource ctx = SimpleValueFactory.getInstance().createIRI(baseURI + "#" + config.getID());
        httpClient.setUsernameAndPassword(username, password);
        httpClient.setRepository(Protocol.getRepositoryLocation(serverURL, SystemRepository.ID));
        Model model = new LinkedHashModel();
        config.export(model, ctx);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Rio.write(model, baos, httpClient.getPreferredRDFFormat());
        removeRepository(config.getID());
        try (InputStream contents = new ByteArrayInputStream(baos.toByteArray())) {
            httpClient.upload(contents, baseURI, httpClient.getPreferredRDFFormat(), false, true, ctx);
        }
    } catch (IOException | QueryEvaluationException | UnauthorizedException ue) {
        throw new RepositoryException(ue);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Resource(org.eclipse.rdf4j.model.Resource) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) ByteArrayInputStream(java.io.ByteArrayInputStream) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) UnauthorizedException(org.eclipse.rdf4j.http.protocol.UnauthorizedException) RDF4JProtocolSession(org.eclipse.rdf4j.http.client.RDF4JProtocolSession) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel)

Example 10 with QueryEvaluationException

use of org.eclipse.rdf4j.query.QueryEvaluationException in project rdf4j by eclipse.

the class HTTPRepositoryConnection method getContextIDs.

public RepositoryResult<Resource> getContextIDs() throws RepositoryException {
    try {
        List<Resource> contextList = new ArrayList<Resource>();
        TupleQueryResult contextIDs = client.getContextIDs();
        try {
            while (contextIDs.hasNext()) {
                BindingSet bindingSet = contextIDs.next();
                Value context = bindingSet.getValue("contextID");
                if (context instanceof Resource) {
                    contextList.add((Resource) context);
                }
            }
        } finally {
            contextIDs.close();
        }
        return createRepositoryResult(contextList);
    } catch (QueryEvaluationException e) {
        throw new RepositoryException(e);
    } catch (IOException e) {
        throw new RepositoryException(e);
    }
}
Also used : BindingSet(org.eclipse.rdf4j.query.BindingSet) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) Resource(org.eclipse.rdf4j.model.Resource) ArrayList(java.util.ArrayList) Value(org.eclipse.rdf4j.model.Value) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) IOException(java.io.IOException) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult)

Aggregations

QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)16 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)15 IOException (java.io.IOException)9 MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)9 TupleQueryResult (org.eclipse.rdf4j.query.TupleQueryResult)9 BindingSet (org.eclipse.rdf4j.query.BindingSet)6 TupleQuery (org.eclipse.rdf4j.query.TupleQuery)5 RDF4JProtocolSession (org.eclipse.rdf4j.http.client.RDF4JProtocolSession)4 Value (org.eclipse.rdf4j.model.Value)4 ArrayList (java.util.ArrayList)3 ExceptionConvertingIteration (org.eclipse.rdf4j.common.iteration.ExceptionConvertingIteration)3 UnauthorizedException (org.eclipse.rdf4j.http.protocol.UnauthorizedException)3 Resource (org.eclipse.rdf4j.model.Resource)3 Binding (org.eclipse.rdf4j.query.Binding)3 UnsupportedQueryLanguageException (org.eclipse.rdf4j.query.UnsupportedQueryLanguageException)3 UpdateExecutionException (org.eclipse.rdf4j.query.UpdateExecutionException)3 UnknownTransactionStateException (org.eclipse.rdf4j.repository.UnknownTransactionStateException)3 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)3 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)3 Model (org.eclipse.rdf4j.model.Model)2