Java源码示例:org.eclipse.rdf4j.repository.config.RepositoryConfigSchema

示例1
@Test
public void putOnNewRepoSucceeds() throws Exception {
	request.setMethod(HttpMethod.PUT.name());
	request.setContentType(RDFFormat.NTRIPLES.getDefaultMIMEType());
	request.setContent(
			("_:node1 <" + RepositoryConfigSchema.REPOSITORYID + "> \"" + repositoryId + "\" .")
					.getBytes(Charsets.UTF_8));

	when(manager.hasRepositoryConfig(repositoryId)).thenReturn(false);

	ArgumentCaptor<RepositoryConfig> config = ArgumentCaptor.forClass(RepositoryConfig.class);

	controller.handleRequest(request, response);

	verify(manager).addRepositoryConfig(config.capture());
	assertThat(config.getValue().getID()).isEqualTo(repositoryId);
}
 
示例2
@Test
public void putOnExistingRepoFails() throws Exception {
	request.setMethod(HttpMethod.PUT.name());
	request.setContentType(RDFFormat.NTRIPLES.getDefaultMIMEType());
	request.setContent(
			("_:node1 <" + RepositoryConfigSchema.REPOSITORYID + "> \"" + repositoryId + "\" .")
					.getBytes(Charsets.UTF_8));
	when(manager.hasRepositoryConfig(repositoryId)).thenReturn(true);

	try {
		controller.handleRequest(request, response);
		fail("expected exception");
	} catch (ClientHTTPException e) {
		assertThat(e.getStatusCode()).isEqualTo(409);
	}
}
 
示例3
@Test
public void postRequestModifiesConfiguration() throws Exception {
	request.setMethod(HttpMethod.POST.name());
	request.setContentType(RDFFormat.NTRIPLES.getDefaultMIMEType());
	request.setContent(
			("_:node1 <" + RepositoryConfigSchema.REPOSITORYID + "> \"" + repositoryId + "\" .")
					.getBytes(Charsets.UTF_8));

	when(manager.hasRepositoryConfig(repositoryId)).thenReturn(true);

	ArgumentCaptor<RepositoryConfig> config = ArgumentCaptor.forClass(RepositoryConfig.class);

	controller.handleRequest(request, new MockHttpServletResponse());

	verify(manager).addRepositoryConfig(config.capture());
	assertThat(config.getValue().getID()).isEqualTo(repositoryId);
}
 
示例4
/***
 * 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;
}
 
示例5
/**
 * 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);
}
 
示例6
private void addMember(Model graph, BNode sailRoot, String identifier)
		throws RDF4JException, MalformedURLException {
	LOGGER.debug("Adding member: {}", identifier);
	BNode memberNode = valueFactory.createBNode();
	addToGraph(graph, sailRoot, FederationConfig.MEMBER, memberNode);
	String memberRepoType = manager.getRepositoryConfig(identifier).getRepositoryImplConfig().getType();
	if (!(SPARQLRepositoryFactory.REPOSITORY_TYPE.equals(memberRepoType)
			|| HTTPRepositoryFactory.REPOSITORY_TYPE.equals(memberRepoType))) {
		memberRepoType = ProxyRepositoryFactory.REPOSITORY_TYPE;
	}
	addToGraph(graph, memberNode, RepositoryConfigSchema.REPOSITORYTYPE,
			valueFactory.createLiteral(memberRepoType));
	addToGraph(graph, memberNode, getLocationPredicate(memberRepoType),
			getMemberLocator(identifier, memberRepoType));
	LOGGER.debug("Added member {}: ", identifier);
}
 
示例7
@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);
}
 
示例8
@Override
public void initialize() throws RepositoryException {
	super.initialize();

	try (RepositoryConnection con = getConnection()) {
		if (con.isEmpty()) {
			logger.debug("Initializing empty {} repository", ID);

			con.begin();
			con.setNamespace("rdf", RDF.NAMESPACE);
			con.setNamespace("sys", RepositoryConfigSchema.NAMESPACE);
			con.commit();

			RepositoryConfig repConfig = new RepositoryConfig(ID, TITLE, new SystemRepositoryConfig());
			RepositoryConfigUtil.updateRepositoryConfigs(con, repConfig);

		}
	} catch (RepositoryConfigException e) {
		throw new RepositoryException(e.getMessage(), e);
	}
}
 
示例9
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;
}
 
示例10
private void addImplementation(Collection<String> members, Model graph, BNode fedRepoNode, boolean readonly,
		boolean distinct) throws RDF4JException, MalformedURLException {
	BNode implRoot = valueFactory.createBNode();
	addToGraph(graph, fedRepoNode, RepositoryConfigSchema.REPOSITORYIMPL, implRoot);
	addToGraph(graph, implRoot, RepositoryConfigSchema.REPOSITORYTYPE,
			valueFactory.createLiteral(SailRepositoryFactory.REPOSITORY_TYPE));
	addSail(members, graph, implRoot, readonly, distinct);
}
 
示例11
@Override
public void remove(RepositoryConnection conn, Resource subject, IRI predicate, Value object,
		Resource... contexts) {
	if (object != null && object.equals(RepositoryConfigSchema.REPOSITORY_CONTEXT)) {
		if (subject == null) {
			modifiedAllContextsByConnection.put(conn, true);
		} else {
			Set<Resource> removedContexts = getRemovedContexts(conn);
			removedContexts.add(subject);
		}
	}
	registerModifiedContexts(conn, contexts);
}
 
示例12
@Test
public void testGetRepositoryConfig() throws Exception {
	wireMockRule.stubFor(get(urlEqualTo("/rdf4j-server/protocol"))
			.willReturn(aResponse().withStatus(200).withBody(Protocol.VERSION)));
	wireMockRule
			.stubFor(get(urlEqualTo("/rdf4j-server/repositories/test/config"))
					.willReturn(aResponse().withStatus(200)
							.withHeader("Content-type", RDFFormat.NTRIPLES.getDefaultMIMEType())
							.withBody("_:node1 <" + RepositoryConfigSchema.REPOSITORYID + "> \"test\" . ")));

	subject.getRepositoryConfig("test");

	wireMockRule.verify(getRequestedFor(urlEqualTo("/rdf4j-server/repositories/test/config")));
}
 
示例13
@Test
public void testDefaultTableSpaceFromRepositoryId() throws Exception {
    TreeModel g = new TreeModel();
    IRI node = SimpleValueFactory.getInstance().createIRI("http://node");
    Literal id =  SimpleValueFactory.getInstance().createLiteral("testId");
    g.add(node, SailRepositorySchema.SAILIMPL, node);
    g.add(node, SailConfigSchema.DELEGATE, node);
    g.add(node, RepositoryConfigSchema.REPOSITORYIMPL, node);
    g.add(node, RepositoryConfigSchema.REPOSITORYID, id);
    HBaseSailConfig cfg = new HBaseSailConfig();
    cfg.parse(g, null);
    assertEquals(id.stringValue(), cfg.getTablespace());
}
 
示例14
@Test
public void testDefaultTableSpaceFromMissingRepositoryId() throws Exception {
    TreeModel g = new TreeModel();
    IRI node = SimpleValueFactory.getInstance().createIRI("http://node");
    g.add(node, SailRepositorySchema.SAILIMPL, node);
    g.add(node, RepositoryConfigSchema.REPOSITORYIMPL, node);
    HBaseSailConfig cfg = new HBaseSailConfig();
    cfg.parse(g, null);
    assertNull(cfg.getTablespace());
}
 
示例15
@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();

        }

    }
 
示例16
protected Resource implNode(Model model) {
	return subject(model.filter(null, RepositoryConfigSchema.REPOSITORYTYPE, null)).get();
}