Search in sources :

Example 1 with Configuration

use of org.openforis.collect.model.Configuration in project collect by openforis.

the class ConfigurationDao method load.

public Configuration load() {
    Configuration c = new Configuration();
    CollectDSLContext dsl = dsl();
    Result<OfcConfigRecord> result = dsl.selectFrom(OFC_CONFIG).fetch();
    for (OfcConfigRecord record : result) {
        String key = record.getValue(OFC_CONFIG.NAME);
        String value = record.getValue(OFC_CONFIG.VALUE);
        ConfigurationItem configurationItem = ConfigurationItem.fromKey(key);
        c.put(configurationItem, value);
    }
    return c;
}
Also used : ConfigurationItem(org.openforis.collect.model.Configuration.ConfigurationItem) Configuration(org.openforis.collect.model.Configuration) CollectDSLContext(org.openforis.collect.persistence.jooq.CollectDSLContext) OfcConfigRecord(org.openforis.collect.persistence.jooq.tables.records.OfcConfigRecord)

Example 2 with Configuration

use of org.openforis.collect.model.Configuration in project collect by openforis.

the class BaseStorageManager method initStorageDirectory.

protected boolean initStorageDirectory(ConfigurationItem configurationItem, boolean createIfNotExists) {
    Configuration configuration = configurationManager.getConfiguration();
    String customStoragePath = configuration.get(configurationItem);
    if (StringUtils.isBlank(customStoragePath)) {
        storageDirectory = getDefaultStorageDirectory();
    } else {
        storageDirectory = new File(customStoragePath);
    }
    boolean result = storageDirectory.exists();
    if (!result) {
        if (createIfNotExists) {
            result = storageDirectory.mkdirs();
        }
    }
    if (LOG.isInfoEnabled()) {
        if (result) {
            LOG.info(String.format("Using %s directory: %s", configurationItem.getLabel(), storageDirectory.getAbsolutePath()));
        } else {
            LOG.info(String.format("%s directory %s does not exist or it's not accessible", configurationItem.getLabel(), storageDirectory.getAbsolutePath()));
        }
    }
    return result;
}
Also used : Configuration(org.openforis.collect.model.Configuration) File(java.io.File)

Example 3 with Configuration

use of org.openforis.collect.model.Configuration in project collect by openforis.

the class ConfigurationDaoIntegrationTest method testCRUD.

@Test
public void testCRUD() throws Exception {
    // SAVE NEW
    Configuration config = new Configuration();
    config.setUploadPath("/home/test/uploadPathTest");
    config.setIndexPath("/home/test/indexPathTest");
    configurationDao.save(config);
    // RELOAD
    Configuration reloaded = configurationDao.load();
    assertNotNull(reloaded);
    Set<ConfigurationItem> items = reloaded.getProperties();
    assertEquals(2, items.size());
    for (ConfigurationItem item : items) {
        String oldValue = config.get(item);
        assertNotNull(oldValue);
        String newValue = reloaded.get(item);
        assertEquals(oldValue, newValue);
    }
}
Also used : ConfigurationItem(org.openforis.collect.model.Configuration.ConfigurationItem) Configuration(org.openforis.collect.model.Configuration) CollectTest(org.openforis.collect.CollectTest) Test(org.junit.Test)

Aggregations

Configuration (org.openforis.collect.model.Configuration)3 ConfigurationItem (org.openforis.collect.model.Configuration.ConfigurationItem)2 File (java.io.File)1 Test (org.junit.Test)1 CollectTest (org.openforis.collect.CollectTest)1 CollectDSLContext (org.openforis.collect.persistence.jooq.CollectDSLContext)1 OfcConfigRecord (org.openforis.collect.persistence.jooq.tables.records.OfcConfigRecord)1