Optional<String> val = Optional.absent(); if (scope == ConfigScope.GLOBAL) { val = config.getGlobal(name); } else { try { val = config.get(name); } catch (ConfigException e) { if (scope == ConfigScope.LOCAL) { val = config.getGlobal(name); config.putGlobal(name, value); } else { config.put(name, value); config.removeGlobal(name); } else { config.remove(name); config.removeSectionGlobal(name); } else { config.removeSection(name); Map<String, String> results = null; if (scope == ConfigScope.LOCAL) { results = config.getAll(); } else { results = config.getAllGlobal(); if (scope == ConfigScope.DEFAULT) {
/** * Executes the remote-list operation. * * @return {@code List<Remote>} of all remotes found in the config database, may be empty. */ @Override protected ImmutableList<Remote> _call() { ConfigDatabase config = configDatabase(); List<String> remotes = config.getAllSubsections("remote"); List<Remote> allRemotes = new ArrayList<Remote>(); for (String remoteName : remotes) { String remoteSection = "remote." + remoteName; Optional<String> remoteFetchURL = config.get(remoteSection + ".url"); Optional<String> remoteFetch = config.get(remoteSection + ".fetch"); Optional<String> remoteMapped = config.get(remoteSection + ".mapped"); Optional<String> remoteMappedBranch = config.get(remoteSection + ".mappedBranch"); Optional<String> remoteUserName = config.get(remoteSection + ".username"); Optional<String> remotePassword = config.get(remoteSection + ".password"); if (remoteFetchURL.isPresent() && remoteFetch.isPresent()) { Optional<String> remotePushURL = config.get(remoteSection + ".pushurl"); allRemotes.add(new Remote(remoteName, remoteFetchURL.get(), remotePushURL.or(remoteFetchURL.get()), remoteFetch.get(), remoteMapped.or("false").equals("true"), remoteMappedBranch.orNull(), remoteUserName.orNull(), remotePassword.orNull())); } } return ImmutableList.copyOf(allRemotes); } }
@Test public void testGetAllSection() { // Test integer and string config.put("section1.int", 1); config.put("section1.subsection.string", "2"); config.put("section1.subsection.subsub.int", 1); config.put("section1.subsection.subsub.string", "4"); config.put("section2.int", 3); assertEquals(ImmutableMap.of("int", "1"), config.getAllSection("section1")); assertEquals(ImmutableMap.of("string", "2"), config.getAllSection("section1.subsection")); assertEquals(ImmutableMap.of("int", "1", "string", "4"), config.getAllSection("section1.subsection.subsub")); }
@Override public void configure() throws RepositoryConnectionException { RepositoryConnectionException.StorageType.OBJECT.configure(config, "mongodb", "0.1"); String uri = config.get("mongodb.uri").or(config.getGlobal("mongodb.uri")) .or("mongodb://localhost:27017/"); String database = config.get("mongodb.database").or(config.getGlobal("mongodb.database")) .or("geogig"); config.put("mongodb.uri", uri); config.put("mongodb.database", database); }
@Test public void testGlobalOnly() { ConfigDatabase globalOnly = IniFileConfigDatabase.globalOnly(platform); testGlobalOnly(() -> globalOnly.get("section.key")); testGlobalOnly(() -> globalOnly.getAll()); testGlobalOnly(() -> globalOnly.get("section.key", String.class)); testGlobalOnly(() -> globalOnly.getAllSection("section")); testGlobalOnly(() -> globalOnly.getAllSubsections("section.sub")); testGlobalOnly(() -> globalOnly.put("section.key", "val")); testGlobalOnly(() -> globalOnly.remove("section.key")); testGlobalOnly(() -> globalOnly.removeSection("section")); }
@Test public void testNestedSections() { // Test integer and string config.put("section.subsection.int", 1); config.put("section.subsection.string", "2"); final int one = config.get("section.subsection.int", Integer.class).or(-1); assertEquals(one, 1); final String two = config.get("section.subsection.string").or("-1"); assertEquals(two, "2"); // Test overwriting a value that already exists config.put("section.subsection.string", "3"); final String three = config.get("section.subsection.string").or("-1"); assertEquals(three, "3"); }
private int getBulkPartitionSize() { Optional<Integer> configuredSize = configDB.get(BULK_PARTITIONING_CONFIG_KEY, Integer.class); return configuredSize.or(DEFAULT_BULK_PARTITIONING).intValue(); }
public default void putSection(String section, final Map<String, String> kvp) { checkNotNull(section); checkNotNull(kvp); kvp.forEach((k, v) -> { checkNotNull(k); checkNotNull(v); put(String.format("%s.%s", section, k), v); }); }
@Test public void testRemoveSection() { // Test integer and string config.put("section1.int", 1); config.put("section1.subsection.string", "2"); config.put("section1.subsection.subsub.int", 1); config.put("section1.subsection.subsub.string", "4"); config.put("section2.int", 3); assertTrue(config.get("section1.subsection.subsub.string").isPresent()); assertTrue(config.get("section1.subsection.subsub.int").isPresent()); config.removeSection("section1.subsection.subsub"); assertFalse(config.get("section1.subsection.subsub.string").isPresent()); assertFalse(config.get("section1.subsection.subsub.int").isPresent()); assertTrue(config.get("section1.int").isPresent()); config.removeSection("section1"); assertFalse(config.get("section1.int").isPresent()); }
@Test public void testRemove() { // Test integer and string config.put("section1.int", 1); config.put("section1.subsection.string", "2"); config.put("section1.subsection.subsub.int", 1); config.put("section1.subsection.subsub.string", "4"); config.put("section2.int", 3); assertTrue(config.get("section1.int").isPresent()); config.remove("section1.int"); assertFalse(config.get("section1.int").isPresent()); assertTrue(config.get("section1.subsection.subsub.string").isPresent()); config.remove("section1.subsection.subsub.string"); assertFalse(config.get("section1.subsection.subsub.string").isPresent()); }
@Test public void testGetAllSubsections() { // Test integer and string config.put("section1.subsection1.int", 1); config.put("section1.subsection2.string", "2"); config.put("section1.subsection1.subsub1.int", 1); config.put("section1.subsection2.subsub2.string", "2"); config.put("section2.subsection3.int", 3); config.put("section2.subsection4.string", "4"); List<String> allSubsections = config.getAllSubsections("section1"); Set<String> expected = ImmutableSet.of("subsection1", "subsection2", "subsection1.subsub1", "subsection2.subsub2"); assertEquals(expected, new HashSet<String>(allSubsections)); }
List<String> allRemotes = config.getAllSubsections("remote"); if (!allRemotes.contains(name)) { throw new RemoteException(StatusCode.REMOTE_NOT_FOUND); Optional<String> remoteFetchURL = config.get(remoteSection + ".url"); Optional<String> remoteFetch = config.get(remoteSection + ".fetch"); Optional<String> remotePushURL = Optional.absent(); Optional<String> remoteMapped = config.get(remoteSection + ".mapped"); Optional<String> remoteMappedBranch = config.get(remoteSection + ".mappedBranch"); Optional<String> remoteUserName = config.get(remoteSection + ".username"); Optional<String> remotePassword = config.get(remoteSection + ".password"); if (remoteFetchURL.isPresent() && remoteFetch.isPresent()) { remotePushURL = config.get(remoteSection + ".pushurl"); remoteMappedBranch.orNull(), remoteUserName.orNull(), remotePassword.orNull()); config.removeSection(remoteSection);
@Test public void testRemoveGlobal() { // Test integer and string config.putGlobal("section1.int", 1); config.putGlobal("section1.subsection.string", "2"); config.putGlobal("section1.subsection.subsub.int", 1); config.putGlobal("section1.subsection.subsub.string", "4"); config.putGlobal("section2.int", 3); assertTrue(config.getGlobal("section1.int").isPresent()); config.removeGlobal("section1.int"); assertFalse(config.getGlobal("section1.int").isPresent()); assertTrue(config.getGlobal("section1.subsection.subsub.string").isPresent()); config.removeGlobal("section1.subsection.subsub.string"); assertFalse(config.getGlobal("section1.subsection.subsub.string").isPresent()); }
@Test public void testRemoveSectionGlobal() { // Test integer and string config.putGlobal("section1.int", 1); config.putGlobal("section1.subsection.string", "2"); config.putGlobal("section1.subsection.subsub.int", 1); config.putGlobal("section1.subsection.subsub.string", "4"); config.putGlobal("section2.int", 3); assertTrue(config.getGlobal("section1.subsection.subsub.string").isPresent()); assertTrue(config.getGlobal("section1.subsection.subsub.int").isPresent()); config.removeSectionGlobal("section1.subsection.subsub"); assertFalse(config.getGlobal("section1.subsection.subsub.string").isPresent()); assertFalse(config.getGlobal("section1.subsection.subsub.int").isPresent()); assertTrue(config.getGlobal("section1.int").isPresent()); config.removeSectionGlobal("section1"); assertFalse(config.getGlobal("section1.int").isPresent()); } }
Map<String, String> all = db.getAllSection(section); remoteName = all.get("remote"); remoteBranch = all.get("merge"); description = all.get("description"); } else if (delete) { remoteName = db.get(remoteKey).orNull(); remoteBranch = db.get(remoteBranchKey).orNull(); description = db.get(descriptionKey).orNull(); db.remove(remoteKey); db.remove(remoteBranchKey); db.remove(descriptionKey); } else { if (!Strings.isNullOrEmpty(remoteName)) {
@Test public void testGlobal() { // Test integer and string config.putGlobal("section.int", 1); config.putGlobal("section.string", "2"); final int one = config.getGlobal("section.int", Integer.class).or(-1); assertEquals(one, 1); final String two = config.getGlobal("section.string").or("-1"); assertEquals(two, "2"); // Test overwriting a value that already exists config.putGlobal("section.string", "3"); final String three = config.getGlobal("section.string").or("-1"); assertEquals(three, "3"); }
try (ConfigDatabase config = FileRepositoryResolver .resolveConfigDatabase(platform.pwd().toURI(), context, resolveAsRootURI)) { Optional<String> ansiEnabled = config.getGlobal("ansi.enabled"); if (ansiEnabled.isPresent()) { boolean enable = Boolean.getBoolean(ansiEnabled.get());
@Test public void testPutSection() { // Test integer and string ImmutableMap<String, String> map = ImmutableMap.of(// "k1", "v1", // "subsection.string", "2", // "subsection.int", "1", // "subsection.long", "4"// ); config.putSection("section1", map); assertEquals(ImmutableMap.of("k1", "v1"), config.getAllSection("section1")); assertEquals(ImmutableMap.of("string", "2", "int", "1", "long", "4"), config.getAllSection("section1.subsection")); }
protected @Override Boolean _call() { Optional<PR> propt = command(PRFindOp.class).setId(id).call(); propt.ifPresent(pr -> { final String section = String.format("pr.%d", id); configDatabase().removeSection(section); Context context = context(); Optional<GeogigTransaction> tx = pr.tryGetTransaction(context); if (tx.isPresent()) { tx.get().abort(); } else { delete(context, pr.getHeadRef()); delete(context, pr.getOriginRef()); } }); return propt.isPresent(); }