Java Code Examples for org.eclipse.rdf4j.repository.config.RepositoryConfig#validate()

The following examples show how to use org.eclipse.rdf4j.repository.config.RepositoryConfig#validate() . 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: AbstractCommandTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/***
 * Add a new repository to the manager.
 *
 * @param configStream input stream of the repository configuration
 * @return ID of the repository as string
 * @throws IOException
 * @throws RDF4JException
 */
protected String addRepository(InputStream configStream) throws IOException, RDF4JException {
	RDFParser rdfParser = Rio.createParser(RDFFormat.TURTLE, SimpleValueFactory.getInstance());

	Model graph = new LinkedHashModel();
	rdfParser.setRDFHandler(new StatementCollector(graph));
	rdfParser.parse(
			new StringReader(IOUtil.readString(new InputStreamReader(configStream, StandardCharsets.UTF_8))),
			RepositoryConfigSchema.NAMESPACE);
	configStream.close();

	Resource repositoryNode = Models.subject(graph.filter(null, RDF.TYPE, RepositoryConfigSchema.REPOSITORY))
			.orElseThrow(() -> new RepositoryConfigException("could not find subject resource"));

	RepositoryConfig repoConfig = RepositoryConfig.create(graph, repositoryNode);
	repoConfig.validate();
	manager.addRepositoryConfig(repoConfig);

	String repId = Models.objectLiteral(graph.filter(repositoryNode, RepositoryConfigSchema.REPOSITORYID, null))
			.orElseThrow(() -> new RepositoryConfigException("missing repository id"))
			.stringValue();

	return repId;
}
 
Example 2
Source File: RepositoryManagerFederator.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Adds a new repository to the {@link org.eclipse.rdf4j.repository.manager.RepositoryManager}, which is a
 * federation of the given repository id's, which must also refer to repositories already managed by the
 * {@link org.eclipse.rdf4j.repository.manager.RepositoryManager}.
 *
 * @param fedID       the desired identifier for the new federation repository
 * @param description the desired description for the new federation repository
 * @param members     the identifiers of the repositories to federate, which must already exist and be managed by
 *                    the {@link org.eclipse.rdf4j.repository.manager.RepositoryManager}
 * @param readonly    whether the federation is read-only
 * @param distinct    whether the federation enforces distinct results from its members
 * @throws MalformedURLException if the {@link org.eclipse.rdf4j.repository.manager.RepositoryManager} has a
 *                               malformed location
 * @throws RDF4JException        if a problem otherwise occurs while creating the federation
 */
public void addFed(String fedID, String description, Collection<String> members, boolean readonly, boolean distinct)
		throws MalformedURLException, RDF4JException {
	if (members.contains(fedID)) {
		throw new RepositoryConfigException("A federation member may not have the same ID as the federation.");
	}
	Model graph = new LinkedHashModel();
	BNode fedRepoNode = valueFactory.createBNode();
	LOGGER.debug("Federation repository root node: {}", fedRepoNode);
	addToGraph(graph, fedRepoNode, RDF.TYPE, RepositoryConfigSchema.REPOSITORY);
	addToGraph(graph, fedRepoNode, RepositoryConfigSchema.REPOSITORYID, valueFactory.createLiteral(fedID));
	addToGraph(graph, fedRepoNode, RDFS.LABEL, valueFactory.createLiteral(description));
	addImplementation(members, graph, fedRepoNode, readonly, distinct);
	RepositoryConfig fedConfig = RepositoryConfig.create(graph, fedRepoNode);
	fedConfig.validate();
	manager.addRepositoryConfig(fedConfig);
}
 
Example 3
Source File: TestProxyRepositoryFactory.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public final void testGetRepository() throws RDF4JException, IOException {
	Model graph = Rio.parse(this.getClass().getResourceAsStream("/proxy.ttl"), RepositoryConfigSchema.NAMESPACE,
			RDFFormat.TURTLE);
	RepositoryConfig config = RepositoryConfig.create(graph,
			Models.subject(graph.getStatements(null, RDF.TYPE, RepositoryConfigSchema.REPOSITORY))
					.orElseThrow(() -> new RepositoryConfigException("missing Repository instance in config")));
	config.validate();
	assertThat(config.getID()).isEqualTo("proxy");
	assertThat(config.getTitle()).isEqualTo("Test Proxy for 'memory'");
	RepositoryImplConfig implConfig = config.getRepositoryImplConfig();
	assertThat(implConfig.getType()).isEqualTo("openrdf:ProxyRepository");
	assertThat(implConfig).isInstanceOf(ProxyRepositoryConfig.class);
	assertThat(((ProxyRepositoryConfig) implConfig).getProxiedRepositoryID()).isEqualTo("memory");

	// Factory just needs a resolver instance to proceed with construction.
	// It doesn't actually invoke the resolver until the repository is
	// accessed. Normally LocalRepositoryManager is the caller of
	// getRepository(), and will have called this setter itself.
	ProxyRepository repository = (ProxyRepository) factory.getRepository(implConfig);
	repository.setRepositoryResolver(mock(RepositoryResolver.class));
	assertThat(repository).isInstanceOf(ProxyRepository.class);
}
 
Example 4
Source File: CreateServlet.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
RepositoryConfig updateRepositoryConfig(final String configString) throws IOException, RDF4JException {
	final Model graph = new LinkedHashModel();
	final RDFParser rdfParser = Rio.createParser(RDFFormat.TURTLE, SimpleValueFactory.getInstance());
	rdfParser.setRDFHandler(new StatementCollector(graph));
	rdfParser.parse(new StringReader(configString), RepositoryConfigSchema.NAMESPACE);

	Resource res = Models.subject(graph.getStatements(null, RDF.TYPE, RepositoryConfigSchema.REPOSITORY))
			.orElseThrow(() -> new RepositoryException("could not find instance of Repository class in config"));
	final RepositoryConfig repConfig = RepositoryConfig.create(graph, res);
	repConfig.validate();
	manager.addRepositoryConfig(repConfig);
	return repConfig;
}
 
Example 5
Source File: CreateServlet.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addFederated(String repositoryId, String repositoryTitle, List<String> memberIds) {

		RepositoryConfig repoConfig = FedXRepositoryConfigBuilder.create()
				.withResolvableEndpoint(memberIds)
				.build(repositoryId, repositoryTitle);
		repoConfig.validate();
		manager.addRepositoryConfig(repoConfig);
	}
 
Example 6
Source File: SystemRepository.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Repository createDelegate() {
	RepositoryConfig repoConfig = getSystemConfig();
	if (repoConfig == null) {
		throw new RepositoryConfigException("Could not find SYSTEM configuration");
	}
	repoConfig.validate();
	RepositoryImplConfig config = repoConfig.getRepositoryImplConfig();
	RepositoryFactory factory = RepositoryRegistry.getInstance()
			.get(config.getType())
			.orElseThrow(
					() -> new RepositoryConfigException("Repository type not in classpath: " + config.getType()));
	return factory.getRepository(config);
}
 
Example 7
Source File: LocalRepositoryManager.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected Repository createRepository(String id) throws RepositoryConfigException, RepositoryException {
	Repository repository = null;

	RepositoryConfig repConfig = getRepositoryConfig(id);
	if (repConfig != null) {
		repConfig.validate();

		repository = createRepositoryStack(repConfig.getRepositoryImplConfig());
		repository.setDataDir(getRepositoryDir(id));
		repository.init();
	}

	return repository;
}
 
Example 8
Source File: HBaseRepositoryManager.java    From Halyard with Apache License 2.0 5 votes vote down vote up
@Override
protected Repository createRepository(String id) throws RepositoryConfigException, RepositoryException {
    Repository repository = null;
    RepositoryConfig repConfig = getRepositoryConfig(id);
    if (repConfig != null) {
        repConfig.validate();
        repository = createRepositoryStack(repConfig.getRepositoryImplConfig());
        repository.init();
    }
    return repository;
}
 
Example 9
Source File: RyaAccumuloSailFactoryTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
    public void testCreateFromTemplateName() throws Exception {
        LocalRepositoryManager repoman = new LocalRepositoryManager(Files.createTempDir());
        repoman.initialize();

        try(InputStream templateStream = RepositoryConfig.class.getResourceAsStream("RyaAccumuloSail.ttl")) {
            String template = IOUtils.toString(templateStream);

            final ConfigTemplate configTemplate = new ConfigTemplate(template);
            final Map<String, String> valueMap = ImmutableMap.<String, String> builder()
                    .put("Repository ID", "RyaAccumuloSail")
                    .put("Repository title", "RyaAccumuloSail Store")
                    .put("Rya Accumulo user", "root")
                    .put("Rya Accumulo password", "")
                    .put("Rya Accumulo instance", "dev")
                    .put("Rya Accumulo zookeepers", "zoo1,zoo2,zoo3")
                    .put("Rya Accumulo is mock", "true")
                    .build();

            final String configString = configTemplate.render(valueMap);

//            final Repository systemRepo = this.state.getManager().getSystemRepository();
            final Model model = new LinkedHashModel();
            final RDFParser rdfParser = Rio.createParser(RDFFormat.TURTLE);
            rdfParser.setRDFHandler(new StatementCollector(model));
            rdfParser.parse(new StringReader(configString), RepositoryConfigSchema.NAMESPACE);
            final Resource repositoryNode = Models.subject(model.filter(null, RDF.TYPE, RepositoryConfigSchema.REPOSITORY)).get();
            final RepositoryConfig repConfig = RepositoryConfig.create(model, repositoryNode);
            repConfig.validate();


            repoman.addRepositoryConfig(repConfig);

            Repository r = repoman.getRepository("RyaAccumuloSail");
            r.initialize();

        }

    }