Search in sources :

Example 11 with ConfigDatabase

use of org.locationtech.geogig.storage.ConfigDatabase in project GeoGig by boundlessgeo.

the class ConfigOpTest method testListLocalWithNoLocalRepository.

@Test
public void testListLocalWithNoLocalRepository() {
    ConfigDatabase database = mock(ConfigDatabase.class);
    when(database.getAll()).thenThrow(new ConfigException(StatusCode.INVALID_LOCATION));
    ConfigOp config = new ConfigOp(database);
    exception.expect(ConfigException.class);
    config.setScope(ConfigScope.LOCAL).setAction(ConfigAction.CONFIG_LIST).setName(null).setValue(null).call();
}
Also used : ConfigOp(org.locationtech.geogig.api.porcelain.ConfigOp) ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) ConfigException(org.locationtech.geogig.api.porcelain.ConfigException) Test(org.junit.Test)

Example 12 with ConfigDatabase

use of org.locationtech.geogig.storage.ConfigDatabase in project GeoGig by boundlessgeo.

the class ConfigOpTest method testGetLocalWithNoLocalRepository.

@Test
public void testGetLocalWithNoLocalRepository() {
    ConfigDatabase database = mock(ConfigDatabase.class);
    when(database.get(anyString())).thenThrow(new ConfigException(StatusCode.INVALID_LOCATION));
    ConfigOp config = new ConfigOp(database);
    exception.expect(ConfigException.class);
    config.setScope(ConfigScope.LOCAL).setAction(ConfigAction.CONFIG_GET).setName("section.key").setValue(null).call();
}
Also used : ConfigOp(org.locationtech.geogig.api.porcelain.ConfigOp) ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) ConfigException(org.locationtech.geogig.api.porcelain.ConfigException) Test(org.junit.Test)

Example 13 with ConfigDatabase

use of org.locationtech.geogig.storage.ConfigDatabase in project GeoGig by boundlessgeo.

the class CachingModuleTest method setUp.

@Before
public void setUp() throws Exception {
    odbCache = mock(Cache.class);
    indexCache = mock(Cache.class);
    final ObjectDatabaseCacheFactory odbCacheFac = mock(ObjectDatabaseCacheFactory.class);
    when(odbCacheFac.get()).thenReturn(odbCache);
    final StagingDatabaseCacheFactory indexCacheFac = mock(StagingDatabaseCacheFactory.class);
    when(indexCacheFac.get()).thenReturn(indexCache);
    File workingDirectory = tmpFolder.getRoot();
    final Platform platform = new TestPlatform(workingDirectory);
    Module module = new AbstractModule() {

        @Override
        protected void configure() {
            bind(Context.class).to(GuiceInjector.class).in(Scopes.SINGLETON);
            Multibinder.newSetBinder(binder(), Decorator.class);
            bind(DecoratorProvider.class).in(Scopes.SINGLETON);
            DataStreamSerializationFactoryV1 sfac = DataStreamSerializationFactoryV1.INSTANCE;
            bind(ObjectSerializingFactory.class).toInstance(sfac);
            bind(ObjectDatabase.class).to(HeapObjectDatabse.class).in(Scopes.SINGLETON);
            bind(StagingDatabase.class).to(HeapStagingDatabase.class).in(Scopes.SINGLETON);
            ConfigDatabase config = new IniFileConfigDatabase(platform);
            bind(ConfigDatabase.class).toInstance(config);
            bind(ObjectDatabaseCacheFactory.class).toInstance(odbCacheFac);
            bind(StagingDatabaseCacheFactory.class).toInstance(indexCacheFac);
        }
    };
    Context injector = Guice.createInjector(Modules.override(new CachingModule()).with(module)).getInstance(org.locationtech.geogig.api.Context.class);
    odb = injector.objectDatabase();
    index = injector.stagingDatabase();
    odb.open();
    index.open();
    odb.put(o1);
    odb.put(o2);
    odb.put(o3);
    index.put(s1);
    index.put(s2);
    index.put(s3);
}
Also used : ObjectSerializingFactory(org.locationtech.geogig.storage.ObjectSerializingFactory) Context(org.locationtech.geogig.api.Context) TestPlatform(org.locationtech.geogig.api.TestPlatform) Platform(org.locationtech.geogig.api.Platform) DecoratorProvider(org.locationtech.geogig.di.DecoratorProvider) IniFileConfigDatabase(org.locationtech.geogig.storage.fs.IniFileConfigDatabase) ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) HeapObjectDatabse(org.locationtech.geogig.storage.memory.HeapObjectDatabse) IniFileConfigDatabase(org.locationtech.geogig.storage.fs.IniFileConfigDatabase) AbstractModule(com.google.inject.AbstractModule) GuiceInjector(org.locationtech.geogig.di.GuiceInjector) TestPlatform(org.locationtech.geogig.api.TestPlatform) HeapStagingDatabase(org.locationtech.geogig.storage.memory.HeapStagingDatabase) Module(com.google.inject.Module) AbstractModule(com.google.inject.AbstractModule) DataStreamSerializationFactoryV1(org.locationtech.geogig.storage.datastream.DataStreamSerializationFactoryV1) File(java.io.File) Cache(com.google.common.cache.Cache) Before(org.junit.Before)

Example 14 with ConfigDatabase

use of org.locationtech.geogig.storage.ConfigDatabase in project GeoGig by boundlessgeo.

the class CacheFactory method getConfig.

@SuppressWarnings("unchecked")
private <T> T getConfig(final String keyword, final T defaultValue) {
    final String kw = configKeywordPrefix + "." + keyword;
    ConfigDatabase configDatabase = configDb.get();
    try {
        Optional<? extends Object> value = configDatabase.get(kw, defaultValue.getClass());
        if (value.isPresent()) {
            LOGGER.trace("Got cache config property {} = {}", kw, value.get());
            return (T) value.get();
        }
    } catch (ConfigException e) {
        return defaultValue;
    }
    return defaultValue;
}
Also used : ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) ConfigException(org.locationtech.geogig.api.porcelain.ConfigException)

Example 15 with ConfigDatabase

use of org.locationtech.geogig.storage.ConfigDatabase in project GeoGig by boundlessgeo.

the class RemoteAddOp method _call.

/**
     * Executes the remote-add operation.
     * 
     * @return the {@link Remote} that was added.
     */
@Override
protected Remote _call() {
    if (name == null || name.isEmpty()) {
        throw new RemoteException(StatusCode.MISSING_NAME);
    }
    if (url == null || url.isEmpty()) {
        throw new RemoteException(StatusCode.MISSING_URL);
    }
    if (branch == null || branch.isEmpty()) {
        branch = "*";
    }
    ConfigDatabase config = configDatabase();
    List<String> allRemotes = config.getAllSubsections("remote");
    if (allRemotes.contains(name)) {
        throw new RemoteException(StatusCode.REMOTE_ALREADY_EXISTS);
    }
    String configSection = "remote." + name;
    String fetch = "+" + Ref.HEADS_PREFIX + branch + ":" + Ref.REMOTES_PREFIX + name + "/" + branch;
    config.put(configSection + ".url", url);
    config.put(configSection + ".fetch", fetch);
    if (mapped) {
        config.put(configSection + ".mapped", "true");
        config.put(configSection + ".mappedBranch", branch);
    }
    if (username != null) {
        config.put(configSection + ".username", username);
    }
    if (password != null) {
        password = Remote.encryptPassword(password);
        config.put(configSection + ".password", password);
    }
    return new Remote(name, url, url, fetch, mapped, branch, username, password);
}
Also used : ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) Remote(org.locationtech.geogig.api.Remote)

Aggregations

ConfigDatabase (org.locationtech.geogig.storage.ConfigDatabase)18 File (java.io.File)6 ConfigException (org.locationtech.geogig.api.porcelain.ConfigException)6 IniFileConfigDatabase (org.locationtech.geogig.storage.fs.IniFileConfigDatabase)6 Test (org.junit.Test)4 Remote (org.locationtech.geogig.api.Remote)4 ConfigOp (org.locationtech.geogig.api.porcelain.ConfigOp)4 Hints (org.locationtech.geogig.repository.Hints)4 Platform (org.locationtech.geogig.api.Platform)3 Cache (com.google.common.cache.Cache)1 AbstractModule (com.google.inject.AbstractModule)1 Module (com.google.inject.Module)1 DB (com.mongodb.DB)1 MongoClient (com.mongodb.MongoClient)1 MongoClientURI (com.mongodb.MongoClientURI)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1