Search in sources :

Example 26 with RepositoryException

use of org.eclipse.rdf4j.repository.RepositoryException in project rdf4j by eclipse.

the class HTTPRepositoryConnection method rollback.

public void rollback() throws RepositoryException {
    if (this.getRepository().useCompatibleMode()) {
        txn.clear();
        active = false;
        return;
    }
    flushTransactionState(Action.ROLLBACK);
    try {
        client.rollbackTransaction();
        active = false;
    } catch (RDF4JException e) {
        throw new RepositoryException(e);
    } catch (IllegalStateException e) {
        throw new RepositoryException(e);
    } catch (IOException e) {
        throw new RepositoryException(e);
    }
}
Also used : RDF4JException(org.eclipse.rdf4j.RDF4JException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) IOException(java.io.IOException)

Example 27 with RepositoryException

use of org.eclipse.rdf4j.repository.RepositoryException in project rdf4j by eclipse.

the class HTTPRepositoryConnection method clearNamespaces.

public void clearNamespaces() throws RepositoryException {
    if (this.getRepository().useCompatibleMode()) {
        boolean localTransaction = startLocalTransaction();
        txn.add(new ClearNamespacesOperation());
        conditionalCommit(localTransaction);
        return;
    }
    try {
        client.clearNamespaces();
    } catch (IOException e) {
        throw new RepositoryException(e);
    }
}
Also used : ClearNamespacesOperation(org.eclipse.rdf4j.http.protocol.transaction.operations.ClearNamespacesOperation) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) IOException(java.io.IOException)

Example 28 with RepositoryException

use of org.eclipse.rdf4j.repository.RepositoryException 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 29 with RepositoryException

use of org.eclipse.rdf4j.repository.RepositoryException 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 30 with RepositoryException

use of org.eclipse.rdf4j.repository.RepositoryException 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)

Aggregations

RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)67 IOException (java.io.IOException)24 MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)20 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)15 RDF4JException (org.eclipse.rdf4j.RDF4JException)13 HttpResponse (org.apache.http.HttpResponse)11 TupleQueryResult (org.eclipse.rdf4j.query.TupleQueryResult)10 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)8 HttpGet (org.apache.http.client.methods.HttpGet)7 Resource (org.eclipse.rdf4j.model.Resource)7 Statement (org.eclipse.rdf4j.model.Statement)6 ArrayList (java.util.ArrayList)5 HttpPut (org.apache.http.client.methods.HttpPut)5 RDF4JProtocolSession (org.eclipse.rdf4j.http.client.RDF4JProtocolSession)5 UnauthorizedException (org.eclipse.rdf4j.http.protocol.UnauthorizedException)5 BindingSet (org.eclipse.rdf4j.query.BindingSet)5 TupleQuery (org.eclipse.rdf4j.query.TupleQuery)5 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4