org.eclipse.rdf4j.sail.config.SailConfigException Java Examples

The following examples show how to use org.eclipse.rdf4j.sail.config.SailConfigException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LuceneSailFactory.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
	if (!SAIL_TYPE.equals(config.getType())) {
		throw new SailConfigException("Invalid Sail type: " + config.getType());
	}

	LuceneSail luceneSail = new LuceneSail();
	luceneSail.setParameter(LuceneSail.INDEX_CLASS_KEY, LuceneIndex.class.getName());

	if (config instanceof AbstractLuceneSailConfig) {
		AbstractLuceneSailConfig luceneConfig = (AbstractLuceneSailConfig) config;
		luceneSail.setParameter(LuceneSail.LUCENE_DIR_KEY, luceneConfig.getIndexDir());
		for (String key : luceneConfig.getParameterNames()) {
			luceneSail.setParameter(key, luceneConfig.getParameter(key));
		}
	}

	return luceneSail;
}
 
Example #2
Source File: SemagrowRepositoryConfig.java    From semagrow with Apache License 2.0 6 votes vote down vote up
@Override
public void parse(Model graph, Resource node) throws RepositoryConfigException {

    try {
        Optional<Resource> sailImplNode = Models.objectResource(graph.filter(node, SAILIMPL,null));

        if (sailImplNode.isPresent()) {

                sailConfig  = new SemagrowSailConfig();
                sailConfig.parse(graph, sailImplNode.get());
        }
    }
    catch (SailConfigException e) {
        throw new RepositoryConfigException(e.getMessage(), e);
    }
}
 
Example #3
Source File: SemagrowRepositoryResolver.java    From semagrow with Apache License 2.0 6 votes vote down vote up
private Model parseConfig(File file) throws SailConfigException, IOException
{
    RDFFormat format = Rio.getParserFormatForFileName(file.getAbsolutePath()).get();
    if (format==null)
        throw new SailConfigException("Unsupported file format: " + file.getAbsolutePath());
    RDFParser parser = Rio.createParser(format);
    Model model = new LinkedHashModel();
    parser.setRDFHandler(new StatementCollector(model));
    InputStream stream = new FileInputStream(file);

    try {
        parser.parse(stream, file.getAbsolutePath());
    } catch (Exception e) {
        throw new SailConfigException("Error parsing file!");
    }

    stream.close();
    return model;
}
 
Example #4
Source File: SailRepositoryConfig.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void parse(Model model, Resource repImplNode) throws RepositoryConfigException {
	try {
		Optional<Resource> sailImplNode = Models.objectResource(model.getStatements(repImplNode, SAILIMPL, null));
		if (sailImplNode.isPresent()) {
			Models.objectLiteral(model.getStatements(sailImplNode.get(), SAILTYPE, null)).ifPresent(typeLit -> {
				SailFactory factory = SailRegistry.getInstance()
						.get(typeLit.getLabel())
						.orElseThrow(() -> new RepositoryConfigException(
								"Unsupported Sail type: " + typeLit.getLabel()));

				sailImplConfig = factory.getConfig();
				sailImplConfig.parse(model, sailImplNode.get());
			});
		}
	} catch (ModelException | SailConfigException e) {
		throw new RepositoryConfigException(e.getMessage(), e);
	}
}
 
Example #5
Source File: FederationFactory.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
	if (!SAIL_TYPE.equals(config.getType())) {
		throw new SailConfigException("Invalid Sail type: " + config.getType());
	}
	assert config instanceof FederationConfig;
	FederationConfig cfg = (FederationConfig) config;
	Federation sail = new Federation();
	for (RepositoryImplConfig member : cfg.getMembers()) {
		RepositoryFactory factory = RepositoryRegistry.getInstance()
				.get(member.getType())
				.orElseThrow(() -> new SailConfigException("Unsupported repository type: " + config.getType()));
		try {
			sail.addMember(factory.getRepository(member));
		} catch (RepositoryConfigException e) {
			throw new SailConfigException(e);
		}
	}
	sail.setLocalPropertySpace(cfg.getLocalPropertySpace());
	sail.setDistinct(cfg.isDistinct());
	sail.setReadOnly(cfg.isReadOnly());
	return sail;
}
 
Example #6
Source File: SolrSailFactory.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
	if (!SAIL_TYPE.equals(config.getType())) {
		throw new SailConfigException("Invalid Sail type: " + config.getType());
	}

	LuceneSail luceneSail = new LuceneSail();
	luceneSail.setParameter(LuceneSail.INDEX_CLASS_KEY, SolrIndex.class.getName());

	if (config instanceof AbstractLuceneSailConfig) {
		AbstractLuceneSailConfig luceneConfig = (AbstractLuceneSailConfig) config;
		luceneSail.setParameter(LuceneSail.LUCENE_DIR_KEY, luceneConfig.getIndexDir());
		for (String key : luceneConfig.getParameterNames()) {
			luceneSail.setParameter(key, luceneConfig.getParameter(key));
		}
	}

	return luceneSail;
}
 
Example #7
Source File: ElasticsearchSailFactory.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
	if (!SAIL_TYPE.equals(config.getType())) {
		throw new SailConfigException("Invalid Sail type: " + config.getType());
	}

	LuceneSail luceneSail = new LuceneSail();
	luceneSail.setParameter(LuceneSail.INDEX_CLASS_KEY, ElasticsearchIndex.class.getName());

	if (config instanceof AbstractLuceneSailConfig) {
		AbstractLuceneSailConfig luceneConfig = (AbstractLuceneSailConfig) config;
		luceneSail.setParameter(LuceneSail.LUCENE_DIR_KEY, luceneConfig.getIndexDir());
		for (String key : luceneConfig.getParameterNames()) {
			luceneSail.setParameter(key, luceneConfig.getParameter(key));
		}
	}

	return luceneSail;
}
 
Example #8
Source File: FedXSailFactory.java    From CostFed with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException	{
	
	if (!SAIL_TYPE.equals(config.getType())) {
		throw new SailConfigException("Invalid Sail type: " + config.getType());
	}
	
	if (!(config instanceof FedXSailConfig)) {
		throw new SailConfigException("FedXSail config expected, was " + config.getClass().getCanonicalName());
	}	
	
	FedXSailConfig fedXSailConfig = (FedXSailConfig)config;
	String fedxConfig = fedXSailConfig.getFedxConfig();
	
	if (fedxConfig==null)
		throw new SailConfigException("FedX Sail Configuration must not be null");
	
	try	{
		return FedXFactory.initializeFederation(fedxConfig, new DefaultEndpointListProvider(Collections.<String>emptyList())).getSail();
	} catch (FedXException e) {
		throw new SailConfigException(e);
	}
}
 
Example #9
Source File: ElasticsearchStoreFactory.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Sail getSail(SailImplConfig sailImplConfig) throws SailConfigException {
	if (!SAIL_TYPE.equals(sailImplConfig.getType())) {
		throw new SailConfigException("Invalid Sail type: " + sailImplConfig.getType());
	}

	if (sailImplConfig instanceof ElasticsearchStoreConfig) {

		ElasticsearchStoreConfig config = (ElasticsearchStoreConfig) sailImplConfig;

		config.assertRequiredValuesPresent();

		ElasticsearchStore elasticsearchStore = new ElasticsearchStore(config.getHostname(), config.getPort(),
				config.getClusterName(), config.getIndex());

		EvaluationStrategyFactory evalStratFactory = config.getEvaluationStrategyFactory();
		if (evalStratFactory != null) {
			elasticsearchStore.setEvaluationStrategyFactory(evalStratFactory);
		}

		return elasticsearchStore;

	}

	return null;
}
 
Example #10
Source File: ElasticsearchStoreConfig.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void assertRequiredValuesPresent() {

		List<String> missingFields = new ArrayList<>();

		if (hostname == null) {
			missingFields.add("hostname");
		}
		if (clusterName == null) {
			missingFields.add("clusterName");
		}
		if (index == null) {
			missingFields.add("index");
		}
		if (port == -1) {
			missingFields.add("port");
		}

		if (!missingFields.isEmpty()) {
			throw new SailConfigException(
					"Required config missing for: " + missingFields.stream().reduce((a, b) -> a + " and " + b));
		}

	}
 
Example #11
Source File: LuceneSpinSailFactory.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
	if (!SAIL_TYPE.equals(config.getType())) {
		throw new SailConfigException("Invalid Sail type: " + config.getType());
	}

	LuceneSpinSail sail = new LuceneSpinSail();
	Properties params = sail.getParameters();

	// set up parameters
	params.setProperty(LuceneSail.INDEX_CLASS_KEY, LuceneSail.DEFAULT_INDEX_CLASS);

	if (config instanceof AbstractLuceneSailConfig) {
		AbstractLuceneSailConfig luceneConfig = (AbstractLuceneSailConfig) config;
		log.debug("Lucene indexDir: {}", luceneConfig.getIndexDir());
		params.setProperty(LuceneSail.LUCENE_DIR_KEY, luceneConfig.getIndexDir());
		for (String key : luceneConfig.getParameterNames()) {
			params.setProperty(key, luceneConfig.getParameter(key));
		}
	}

	return sail;
}
 
Example #12
Source File: CustomGraphQueryInferencerFactory.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
	if (!SAIL_TYPE.equals(config.getType())) {
		throw new SailConfigException("Invalid Sail type: " + config.getType());
	}
	CustomGraphQueryInferencer sail = new CustomGraphQueryInferencer();
	if (config instanceof CustomGraphQueryInferencerConfig) {
		CustomGraphQueryInferencerConfig customConfig = (CustomGraphQueryInferencerConfig) config;
		try {
			sail.setFields(customConfig.getQueryLanguage(), customConfig.getRuleQuery(),
					customConfig.getMatcherQuery());
		} catch (RDF4JException e) {
			throw new SailConfigException("Problem occured parsing rule or matcher query text.", e);
		}
	}
	return sail;
}
 
Example #13
Source File: AbstractLuceneSailConfig.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void parse(Model graph, Resource implNode) throws SailConfigException {
	super.parse(graph, implNode);

	Literal indexDirLit = Models.objectLiteral(graph.getStatements(implNode, INDEX_DIR, null))
			.orElseThrow(() -> new SailConfigException("no value found for " + INDEX_DIR));

	setIndexDir(indexDirLit.getLabel());
	for (Statement stmt : graph.getStatements(implNode, null, null)) {
		if (stmt.getPredicate().getNamespace().equals(LuceneSailConfigSchema.NAMESPACE)) {
			if (stmt.getObject() instanceof Literal) {
				String key = stmt.getPredicate().getLocalName();
				setParameter(key, stmt.getObject().stringValue());
			}
		}
	}
}
 
Example #14
Source File: MemoryStoreFactory.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
	if (!SAIL_TYPE.equals(config.getType())) {
		throw new SailConfigException("Invalid Sail type: " + config.getType());
	}

	MemoryStore memoryStore = new MemoryStore();

	if (config instanceof MemoryStoreConfig) {
		MemoryStoreConfig memConfig = (MemoryStoreConfig) config;

		memoryStore.setPersist(memConfig.getPersist());
		memoryStore.setSyncDelay(memConfig.getSyncDelay());

		if (memConfig.getIterationCacheSyncThreshold() > 0) {
			memoryStore.setIterationCacheSyncThreshold(memConfig.getIterationCacheSyncThreshold());
		}

		EvaluationStrategyFactory evalStratFactory = memConfig.getEvaluationStrategyFactory();
		if (evalStratFactory != null) {
			memoryStore.setEvaluationStrategyFactory(evalStratFactory);
		}
	}

	return memoryStore;
}
 
Example #15
Source File: DedupingInferencerFactory.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
	if (!SAIL_TYPE.equals(config.getType())) {
		throw new SailConfigException("Invalid Sail type: " + config.getType());
	}

	return new DedupingInferencer();
}
 
Example #16
Source File: FederationConfig.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void validate() throws SailConfigException {
	super.validate();
	if (members.isEmpty()) {
		throw new SailConfigException("No federation members specified");
	}
	for (RepositoryImplConfig member : members) {
		try {
			member.validate();
		} catch (RepositoryConfigException e) {
			throw new SailConfigException(e);
		}
	}
}
 
Example #17
Source File: SailRepositoryConfig.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void validate() throws RepositoryConfigException {
	super.validate();
	if (sailImplConfig == null) {
		throw new RepositoryConfigException("No Sail implementation specified for Sail repository");
	}

	try {
		sailImplConfig.validate();
	} catch (SailConfigException e) {
		throw new RepositoryConfigException(e.getMessage(), e);
	}
}
 
Example #18
Source File: ConfigurableSailRepositoryFactory.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Sail createSailStack(SailImplConfig config) throws RepositoryConfigException, SailConfigException {
	Sail sail = createSail(config);

	if (config instanceof DelegatingSailImplConfig) {
		SailImplConfig delegateConfig = ((DelegatingSailImplConfig) config).getDelegate();
		if (delegateConfig != null) {
			addDelegate(delegateConfig, sail);
		}
	}

	return sail;
}
 
Example #19
Source File: SailRepositoryFactory.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Repository getRepository(RepositoryImplConfig config) throws RepositoryConfigException {
	if (config instanceof SailRepositoryConfig) {
		SailRepositoryConfig sailRepConfig = (SailRepositoryConfig) config;

		try {
			Sail sail = createSailStack(sailRepConfig.getSailImplConfig());
			return new SailRepository(sail);
		} catch (SailConfigException e) {
			throw new RepositoryConfigException(e.getMessage(), e);
		}
	}

	throw new RepositoryConfigException("Invalid configuration class: " + config.getClass());
}
 
Example #20
Source File: SailRepositoryFactory.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Sail createSailStack(SailImplConfig config) throws RepositoryConfigException, SailConfigException {
	Sail sail = createSail(config);

	if (config instanceof DelegatingSailImplConfig) {
		SailImplConfig delegateConfig = ((DelegatingSailImplConfig) config).getDelegate();
		if (delegateConfig != null) {
			addDelegate(delegateConfig, sail);
		}
	}

	return sail;
}
 
Example #21
Source File: SailRepositoryFactory.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addDelegate(SailImplConfig config, Sail sail) throws RepositoryConfigException, SailConfigException {
	Sail delegateSail = createSailStack(config);

	try {
		((StackableSail) sail).setBaseSail(delegateSail);
	} catch (ClassCastException e) {
		throw new RepositoryConfigException(
				"Delegate configured but " + sail.getClass() + " is not a StackableSail");
	}
}
 
Example #22
Source File: HBaseSailFactory.java    From Halyard with Apache License 2.0 5 votes vote down vote up
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
    if (!SAIL_TYPE.equals(config.getType())) {
        throw new SailConfigException("Invalid Sail type: " + config.getType());
    }
    if (config instanceof HBaseSailConfig) {
        HBaseSailConfig hconfig = (HBaseSailConfig) config;
        //instantiate the sail
        HBaseSail sail = new HBaseSail(HBaseConfiguration.create(), hconfig.getTablespace(), hconfig.isCreate(), hconfig.getSplitBits(), hconfig.isPush(), hconfig.getEvaluationTimeout(), hconfig.getElasticIndexURL(), null);
        return sail;
    } else {
        throw new SailConfigException("Invalid configuration: " + config);
    }
}
 
Example #23
Source File: HBaseSailConfigTest.java    From Halyard with Apache License 2.0 5 votes vote down vote up
@Test(expected = SailConfigException.class)
public void testSplitbitsFail() throws Exception {
    TreeModel g = new TreeModel();
    g.add(SimpleValueFactory.getInstance().createIRI("http://node"), HALYARD.SPLITBITS_PROPERTY, SimpleValueFactory.getInstance().createLiteral("not a number"));
    HBaseSailConfig cfg = new HBaseSailConfig();
    cfg.parse(g, null);
}
 
Example #24
Source File: HBaseSailConfigTest.java    From Halyard with Apache License 2.0 5 votes vote down vote up
@Test(expected = SailConfigException.class)
public void testCreateTableFail() throws Exception {
    TreeModel g = new TreeModel();
    g.add(SimpleValueFactory.getInstance().createIRI("http://node"), HALYARD.CREATE_TABLE_PROPERTY, SimpleValueFactory.getInstance().createLiteral("not a boolean"));
    HBaseSailConfig cfg = new HBaseSailConfig();
    cfg.parse(g, null);
}
 
Example #25
Source File: HBaseSailConfigTest.java    From Halyard with Apache License 2.0 5 votes vote down vote up
@Test(expected = SailConfigException.class)
public void testPushStrategyFail() throws Exception {
    TreeModel g = new TreeModel();
    g.add(SimpleValueFactory.getInstance().createIRI("http://node"), HALYARD.PUSH_STRATEGY_PROPERTY, SimpleValueFactory.getInstance().createLiteral("not a boolean"));
    HBaseSailConfig cfg = new HBaseSailConfig();
    cfg.parse(g, null);
}
 
Example #26
Source File: HBaseSailConfigTest.java    From Halyard with Apache License 2.0 5 votes vote down vote up
@Test(expected = SailConfigException.class)
public void testTimeoutFail() throws Exception {
    TreeModel g = new TreeModel();
    g.add(SimpleValueFactory.getInstance().createIRI("http://node"), HALYARD.EVALUATION_TIMEOUT_PROPERTY, SimpleValueFactory.getInstance().createLiteral("not a number"));
    HBaseSailConfig cfg = new HBaseSailConfig();
    cfg.parse(g, null);
}
 
Example #27
Source File: RyaAccumuloSailConfig.java    From rya with Apache License 2.0 5 votes vote down vote up
@Override
public void parse(final Model model, final Resource implNode) throws SailConfigException {
    super.parse(model, implNode);
    System.out.println("parsing");

    try {
        final Literal userLit = GraphUtil.getOptionalObjectLiteral(model, implNode, USER);
        if (userLit != null) {
            setUser(userLit.getLabel());
        }
        final Literal pwdLit = GraphUtil.getOptionalObjectLiteral(model, implNode, PASSWORD);
        if (pwdLit != null) {
            setPassword(pwdLit.getLabel());
        }
        final Literal instLit = GraphUtil.getOptionalObjectLiteral(model, implNode, INSTANCE);
        if (instLit != null) {
            setInstance(instLit.getLabel());
        }
        final Literal zooLit = GraphUtil.getOptionalObjectLiteral(model, implNode, ZOOKEEPERS);
        if (zooLit != null) {
            setZookeepers(zooLit.getLabel());
        }
        final Literal mockLit = GraphUtil.getOptionalObjectLiteral(model, implNode, IS_MOCK);
        if (mockLit != null) {
            setMock(Boolean.parseBoolean(mockLit.getLabel()));
        }
    } catch (final GraphUtilException e) {
        throw new SailConfigException(e.getMessage(), e);
    }
}
 
Example #28
Source File: ConfigurableSailRepositoryFactory.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Repository getRepository(RepositoryImplConfig config) throws RepositoryConfigException {
	if (config instanceof ConfigurableSailRepositoryConfig) {
		ConfigurableSailRepositoryConfig sailRepConfig = (ConfigurableSailRepositoryConfig) config;

		try {
			Sail sail = createSailStack(sailRepConfig.getSailImplConfig());
			return new ConfigurableSailRepository(sail, true);
		} catch (SailConfigException e) {
			throw new RepositoryConfigException(e.getMessage(), e);
		}
	}

	throw new RepositoryConfigException("Invalid configuration class: " + config.getClass());
}
 
Example #29
Source File: CostFedRepositoryFactory.java    From CostFed with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void validate() throws RepositoryConfigException {
    super.validate();
    if (configFileName == null || !new File(configFileName).exists()) {
        throw new SailConfigException("No valid config file name specified for CostFed repository");
    }
}
 
Example #30
Source File: BaseSailConfig.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void parse(Model graph, Resource implNode) throws SailConfigException {
	super.parse(graph, implNode);

	try {

		Models.objectLiteral(graph.getStatements(implNode, EVALUATION_STRATEGY_FACTORY, null))
				.ifPresent(factoryClassName -> {
					setEvaluationStrategyFactoryClassName(factoryClassName.stringValue());
				});
	} catch (ModelException e) {
		throw new SailConfigException(e.getMessage(), e);
	}
}