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

The following examples show how to use org.eclipse.rdf4j.repository.config.RepositoryConfig#export() . 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: LocalRepositoryManagerIntegrationTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
@Deprecated
public void testAddToSystemRepository() {
	RepositoryConfig config = subject.getRepositoryConfig(TEST_REPO);
	subject.addRepositoryConfig(new RepositoryConfig(SystemRepository.ID, new SystemRepositoryConfig()));
	subject.shutDown();
	subject = new LocalRepositoryManager(datadir);
	subject.initialize();
	try (RepositoryConnection con = subject.getSystemRepository().getConnection()) {
		Model model = new TreeModel();
		config.setID("changed");
		config.export(model, con.getValueFactory().createBNode());
		con.begin();
		con.add(model, con.getValueFactory().createBNode());
		con.commit();
	}
	assertTrue(subject.hasRepositoryConfig("changed"));
}
 
Example 2
Source File: LocalRepositoryManagerIntegrationTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
@Deprecated
public void testModifySystemRepository() {
	RepositoryConfig config = subject.getRepositoryConfig(TEST_REPO);
	subject.addRepositoryConfig(new RepositoryConfig(SystemRepository.ID, new SystemRepositoryConfig()));
	subject.shutDown();
	subject = new LocalRepositoryManager(datadir);
	subject.initialize();
	try (RepositoryConnection con = subject.getSystemRepository().getConnection()) {
		Model model = new TreeModel();
		config.setTitle("Changed");
		config.export(model, con.getValueFactory().createBNode());
		Resource ctx = RepositoryConfigUtil.getContext(con, config.getID());
		con.begin();
		con.clear(ctx);
		con.add(model, ctx == null ? con.getValueFactory().createBNode() : ctx);
		con.commit();
	}
	assertEquals("Changed", subject.getRepositoryConfig(TEST_REPO).getTitle());
}
 
Example 3
Source File: LocalRepositoryManagerIntegrationTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
@Deprecated
public void testRemoveFromSystemRepository() {
	RepositoryConfig config = subject.getRepositoryConfig(TEST_REPO);
	subject.addRepositoryConfig(new RepositoryConfig(SystemRepository.ID, new SystemRepositoryConfig()));
	subject.shutDown();
	subject = new LocalRepositoryManager(datadir);
	subject.initialize();
	try (RepositoryConnection con = subject.getSystemRepository().getConnection()) {
		Model model = new TreeModel();
		config.setID("changed");
		config.export(model, con.getValueFactory().createBNode());
		con.begin();
		con.add(model, con.getValueFactory().createBNode());
		con.commit();
	}
	assertTrue(subject.hasRepositoryConfig("changed"));
	try (RepositoryConnection con = subject.getSystemRepository().getConnection()) {
		con.begin();
		con.clear(RepositoryConfigUtil.getContext(con, config.getID()));
		con.commit();
	}
	assertFalse(subject.hasRepositoryConfig(config.getID()));
}
 
Example 4
Source File: ConfigController.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private ModelAndView handleQuery(HttpServletRequest request, HttpServletResponse response)
		throws ClientHTTPException {

	RDFWriterFactory rdfWriterFactory = ProtocolUtil.getAcceptableService(request, response,
			RDFWriterRegistry.getInstance());
	String repId = RepositoryInterceptor.getRepositoryID(request);
	RepositoryConfig repositoryConfig = repositoryManager.getRepositoryConfig(repId);

	Model configData = modelFactory.createEmptyModel();
	String baseURI = request.getRequestURL().toString();
	Resource ctx = SimpleValueFactory.getInstance().createIRI(baseURI + "#" + repositoryConfig.getID());

	repositoryConfig.export(configData, ctx);
	Map<String, Object> model = new HashMap<>();
	model.put(ConfigView.FORMAT_KEY, rdfWriterFactory.getRDFFormat());
	model.put(ConfigView.CONFIG_DATA_KEY, configData);
	model.put(ConfigView.HEADERS_ONLY, METHOD_HEAD.equals(request.getMethod()));
	return new ModelAndView(ConfigView.getInstance(), model);
}
 
Example 5
Source File: RepositoryManager.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Checks on whether the given repository is referred to by a
 * {@link org.eclipse.rdf4j.repository.sail.ProxyRepository} configuration.
 *
 * @param repositoryID id to check
 * @return true if there is no existing proxy reference to the given id, false otherwise
 * @throws RepositoryException
 */
public boolean isSafeToRemove(String repositoryID) throws RepositoryException {
	SimpleValueFactory vf = SimpleValueFactory.getInstance();
	for (String id : getRepositoryIDs()) {
		RepositoryConfig config = getRepositoryConfig(id);
		Model model = new LinkedHashModel();
		config.export(model, vf.createBNode());
		if (model.contains(null, PROXIED_ID, vf.createLiteral(repositoryID))) {
			return false;
		}
	}
	return true;
}
 
Example 6
Source File: RemoteRepositoryManager.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void addRepositoryConfig(RepositoryConfig config) throws RepositoryException, RepositoryConfigException {
	try (RDF4JProtocolSession protocolSession = getSharedHttpClientSessionManager()
			.createRDF4JProtocolSession(serverURL)) {
		protocolSession.setUsernameAndPassword(username, password);

		int serverProtocolVersion = Integer.parseInt(protocolSession.getServerProtocol());
		if (serverProtocolVersion < 9) { // explicit PUT create operation was introduced in Protocol version 9
			String baseURI = Protocol.getRepositoryLocation(serverURL, config.getID());
			Resource ctx = SimpleValueFactory.getInstance().createIRI(baseURI + "#" + config.getID());
			protocolSession.setRepository(Protocol.getRepositoryLocation(serverURL, SystemRepository.ID));
			Model model = getModelFactory().createEmptyModel();
			config.export(model, ctx);
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			Rio.write(model, baos, protocolSession.getPreferredRDFFormat());
			removeRepository(config.getID());
			try (InputStream contents = new ByteArrayInputStream(baos.toByteArray())) {
				protocolSession.upload(contents, baseURI, protocolSession.getPreferredRDFFormat(), false, true,
						ctx);
			}
		} else {
			if (hasRepositoryConfig(config.getID())) {
				protocolSession.updateRepository(config);
			} else {
				protocolSession.createRepository(config);
			}
		}
	} catch (IOException | QueryEvaluationException | UnauthorizedException | NumberFormatException e) {
		throw new RepositoryException(e);
	}
}