Search in sources :

Example 6 with RDF4JProtocolSession

use of org.eclipse.rdf4j.http.client.RDF4JProtocolSession 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 7 with RDF4JProtocolSession

use of org.eclipse.rdf4j.http.client.RDF4JProtocolSession in project rdf4j by eclipse.

the class RemoteRepositoryManager method removeRepository.

@Override
public boolean removeRepository(String repositoryID) throws RepositoryException, RepositoryConfigException {
    boolean existingRepo = hasRepositoryConfig(repositoryID);
    if (existingRepo) {
        try (RDF4JProtocolSession httpClient = getSesameClient().createRDF4JProtocolSession(serverURL)) {
            httpClient.setUsernameAndPassword(username, password);
            httpClient.deleteRepository(repositoryID);
        } catch (IOException e) {
            logger.warn("error while deleting remote repository", e);
            throw new RepositoryConfigException(e);
        }
    }
    return existingRepo;
}
Also used : RDF4JProtocolSession(org.eclipse.rdf4j.http.client.RDF4JProtocolSession) IOException(java.io.IOException) RepositoryConfigException(org.eclipse.rdf4j.repository.config.RepositoryConfigException)

Aggregations

RDF4JProtocolSession (org.eclipse.rdf4j.http.client.RDF4JProtocolSession)7 IOException (java.io.IOException)6 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)5 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)4 UnauthorizedException (org.eclipse.rdf4j.http.protocol.UnauthorizedException)3 Model (org.eclipse.rdf4j.model.Model)2 Value (org.eclipse.rdf4j.model.Value)2 LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)2 BindingSet (org.eclipse.rdf4j.query.BindingSet)2 TupleQueryResult (org.eclipse.rdf4j.query.TupleQueryResult)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 IRI (org.eclipse.rdf4j.model.IRI)1 Resource (org.eclipse.rdf4j.model.Resource)1 RepositoryConfigException (org.eclipse.rdf4j.repository.config.RepositoryConfigException)1 StatementCollector (org.eclipse.rdf4j.rio.helpers.StatementCollector)1