use of org.eclipse.rdf4j.repository.config.RepositoryConfigException in project rdf4j by eclipse.
the class ContextAwareConfig method parse.
@Override
public void parse(Model model, Resource resource) throws RepositoryConfigException {
super.parse(model, resource);
try {
Models.objectLiteral(model.filter(resource, INCLUDE_INFERRED, null)).ifPresent(lit -> setIncludeInferred(lit.booleanValue()));
Models.objectLiteral(model.filter(resource, MAX_QUERY_TIME, null)).ifPresent(lit -> setMaxQueryTime(lit.intValue()));
Models.objectLiteral(model.filter(resource, QUERY_LANGUAGE, null)).ifPresent(lit -> setQueryLanguage(QueryLanguage.valueOf(lit.getLabel())));
Models.objectIRI(model.filter(resource, QUERY_LANGUAGE, null)).ifPresent(iri -> setBaseURI(iri.stringValue()));
Set<Value> objects = model.filter(resource, READ_CONTEXT, null).objects();
setReadContexts(objects.toArray(new IRI[objects.size()]));
objects = model.filter(resource, ADD_CONTEXT, null).objects();
setAddContexts(objects.toArray(new IRI[objects.size()]));
objects = model.filter(resource, REMOVE_CONTEXT, null).objects();
setRemoveContexts(objects.toArray(new IRI[objects.size()]));
objects = model.filter(resource, ARCHIVE_CONTEXT, null).objects();
setArchiveContexts(objects.toArray(new IRI[objects.size()]));
Models.objectIRI(model.filter(resource, INSERT_CONTEXT, null)).ifPresent(iri -> setInsertContext(iri));
} catch (ArrayStoreException e) {
throw new RepositoryConfigException(e);
}
}
use of org.eclipse.rdf4j.repository.config.RepositoryConfigException in project rdf4j by eclipse.
the class ContextAwareFactory method getRepository.
public Repository getRepository(RepositoryImplConfig configuration) throws RepositoryConfigException {
if (configuration instanceof ContextAwareConfig) {
ContextAwareConfig config = (ContextAwareConfig) configuration;
ContextAwareRepository repo = new ContextAwareRepository();
repo.setIncludeInferred(config.isIncludeInferred());
repo.setMaxQueryTime(config.getMaxQueryTime());
repo.setQueryLanguage(config.getQueryLanguage());
repo.setBaseURI(config.getBaseURI());
repo.setReadContexts(config.getReadContexts());
repo.setAddContexts(config.getAddContexts());
repo.setRemoveContexts(config.getRemoveContexts());
repo.setArchiveContexts(config.getArchiveContexts());
repo.setInsertContext(config.getInsertContext());
return repo;
}
throw new RepositoryConfigException("Invalid configuration class: " + configuration.getClass());
}
use of org.eclipse.rdf4j.repository.config.RepositoryConfigException in project rdf4j by eclipse.
the class LocalRepositoryManager method addRepositoryConfig.
private synchronized void addRepositoryConfig(RepositoryConfig config, boolean updateSystem) {
File dataDir = getRepositoryDir(config.getID());
if (!dataDir.exists()) {
dataDir.mkdirs();
}
if (!dataDir.isDirectory()) {
throw new RepositoryConfigException("Could not create directory: " + dataDir);
}
File configFile = new File(dataDir, CFG_FILE);
if (!upgraded && !configFile.exists()) {
upgraded = true;
upgrade();
}
Model model = new TreeModel();
String ns = configFile.toURI().toString() + "#";
config.export(model, SimpleValueFactory.getInstance().createIRI(ns, config.getID()));
File part = new File(configFile.getParentFile(), configFile.getName() + ".part");
try (OutputStream output = new FileOutputStream(part)) {
Rio.write(model, output, configFile.toURI().toString(), CONFIG_FORMAT, CFG_CONFIG);
} catch (IOException | RDFHandlerException | UnsupportedRDFormatException | URISyntaxException e) {
throw new RepositoryConfigException(e);
}
if (updateSystem) {
super.addRepositoryConfig(config);
}
part.renameTo(configFile);
}
use of org.eclipse.rdf4j.repository.config.RepositoryConfigException in project rdf4j by eclipse.
the class LocalRepositoryManager method createRepositoryStack.
/**
* Creates the stack of Repository objects for the repository represented by the specified
* {@link org.eclipse.rdf4j.repository.config.RepositoryImplConfig}. Uses a
* {@link org.eclipse.rdf4j.repository.config.RepositoryFactory} to create the repository and initialize
* it.
*
* @param config
* The node representing the to-be-created repository in the configuration.
* @return The created repository, or <tt>null</tt> if no such repository exists.
* @throws RepositoryConfigException
* If no repository could be created due to invalid or incomplete configuration data.
*/
private Repository createRepositoryStack(RepositoryImplConfig config) throws RepositoryConfigException {
RepositoryFactory factory = RepositoryRegistry.getInstance().get(config.getType()).orElseThrow(() -> new RepositoryConfigException("Unsupported repository type: " + config.getType()));
Repository repository = factory.getRepository(config);
if (repository instanceof RepositoryResolverClient) {
((RepositoryResolverClient) repository).setRepositoryResolver(this);
}
if (repository instanceof FederatedServiceResolverClient) {
((FederatedServiceResolverClient) repository).setFederatedServiceResolver(getFederatedServiceResolver());
}
if (repository instanceof SessionManagerDependent) {
((SessionManagerDependent) repository).setHttpClientSessionManager(client);
} else if (repository instanceof HttpClientDependent) {
((HttpClientDependent) repository).setHttpClient(getHttpClient());
}
if (config instanceof DelegatingRepositoryImplConfig) {
RepositoryImplConfig delegateConfig = ((DelegatingRepositoryImplConfig) config).getDelegate();
Repository delegate = createRepositoryStack(delegateConfig);
try {
((DelegatingRepository) repository).setDelegate(delegate);
} catch (ClassCastException e) {
throw new RepositoryConfigException("Delegate specified for repository that is not a DelegatingRepository: " + delegate.getClass(), e);
}
}
return repository;
}
use of org.eclipse.rdf4j.repository.config.RepositoryConfigException in project rdf4j by eclipse.
the class HTTPRepositoryConfig method parse.
@Override
public void parse(Model model, Resource implNode) throws RepositoryConfigException {
super.parse(model, implNode);
try {
Models.objectIRI(model.filter(implNode, REPOSITORYURL, null)).ifPresent(iri -> setURL(iri.stringValue()));
Models.objectLiteral(model.filter(implNode, USERNAME, null)).ifPresent(username -> setUsername(username.getLabel()));
Models.objectLiteral(model.filter(implNode, PASSWORD, null)).ifPresent(password -> setPassword(password.getLabel()));
} catch (ModelException e) {
throw new RepositoryConfigException(e.getMessage(), e);
}
}
Aggregations