Search in sources :

Example 1 with RepositoryConfigException

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);
    }
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) Value(org.eclipse.rdf4j.model.Value) RepositoryConfigException(org.eclipse.rdf4j.repository.config.RepositoryConfigException)

Example 2 with RepositoryConfigException

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());
}
Also used : ContextAwareRepository(org.eclipse.rdf4j.repository.contextaware.ContextAwareRepository) RepositoryConfigException(org.eclipse.rdf4j.repository.config.RepositoryConfigException)

Example 3 with RepositoryConfigException

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);
}
Also used : TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) UnsupportedRDFormatException(org.eclipse.rdf4j.rio.UnsupportedRDFormatException) RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Model(org.eclipse.rdf4j.model.Model) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) RepositoryConfigException(org.eclipse.rdf4j.repository.config.RepositoryConfigException) File(java.io.File)

Example 4 with RepositoryConfigException

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;
}
Also used : Repository(org.eclipse.rdf4j.repository.Repository) DelegatingRepository(org.eclipse.rdf4j.repository.DelegatingRepository) RepositoryImplConfig(org.eclipse.rdf4j.repository.config.RepositoryImplConfig) DelegatingRepositoryImplConfig(org.eclipse.rdf4j.repository.config.DelegatingRepositoryImplConfig) DelegatingRepositoryImplConfig(org.eclipse.rdf4j.repository.config.DelegatingRepositoryImplConfig) RepositoryFactory(org.eclipse.rdf4j.repository.config.RepositoryFactory) FederatedServiceResolverClient(org.eclipse.rdf4j.query.algebra.evaluation.federation.FederatedServiceResolverClient) SessionManagerDependent(org.eclipse.rdf4j.http.client.SessionManagerDependent) DelegatingRepository(org.eclipse.rdf4j.repository.DelegatingRepository) RepositoryConfigException(org.eclipse.rdf4j.repository.config.RepositoryConfigException) RepositoryResolverClient(org.eclipse.rdf4j.repository.RepositoryResolverClient) HttpClientDependent(org.eclipse.rdf4j.http.client.HttpClientDependent)

Example 5 with RepositoryConfigException

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);
    }
}
Also used : ModelException(org.eclipse.rdf4j.model.util.ModelException) RepositoryConfigException(org.eclipse.rdf4j.repository.config.RepositoryConfigException)

Aggregations

RepositoryConfigException (org.eclipse.rdf4j.repository.config.RepositoryConfigException)12 IOException (java.io.IOException)4 File (java.io.File)3 RepositoryConfig (org.eclipse.rdf4j.repository.config.RepositoryConfig)3 Model (org.eclipse.rdf4j.model.Model)2 TreeModel (org.eclipse.rdf4j.model.impl.TreeModel)2 ModelException (org.eclipse.rdf4j.model.util.ModelException)2 RepositoryFactory (org.eclipse.rdf4j.repository.config.RepositoryFactory)2 RepositoryImplConfig (org.eclipse.rdf4j.repository.config.RepositoryImplConfig)2 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 URISyntaxException (java.net.URISyntaxException)1 HttpClientDependent (org.eclipse.rdf4j.http.client.HttpClientDependent)1 RDF4JProtocolSession (org.eclipse.rdf4j.http.client.RDF4JProtocolSession)1 SessionManagerDependent (org.eclipse.rdf4j.http.client.SessionManagerDependent)1 IRI (org.eclipse.rdf4j.model.IRI)1 Value (org.eclipse.rdf4j.model.Value)1 FederatedServiceResolverClient (org.eclipse.rdf4j.query.algebra.evaluation.federation.FederatedServiceResolverClient)1