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);
}
}
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);
}
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;
}
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);
}
}
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);
}
}
Aggregations