Search in sources :

Example 1 with ConfigurationItem

use of org.openforis.collect.model.Configuration.ConfigurationItem 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 ConfigurationItem

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

the class ConfigurationDao method save.

public void save(Configuration config) {
    CollectDSLContext dsl = dsl();
    // delete old records
    dsl.delete(OFC_CONFIG).execute();
    // insert new records
    Set<ConfigurationItem> items = config.getProperties();
    for (ConfigurationItem item : items) {
        String value = config.get(item);
        dsl.insertInto(OFC_CONFIG).set(OFC_CONFIG.NAME, item.getKey()).set(OFC_CONFIG.VALUE, value).execute();
    }
}
Also used : ConfigurationItem(org.openforis.collect.model.Configuration.ConfigurationItem) CollectDSLContext(org.openforis.collect.persistence.jooq.CollectDSLContext)

Example 3 with ConfigurationItem

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

the class ConfigurationService method updateConfigurationItem.

public void updateConfigurationItem(String configurationItemName, String value) {
    ConfigurationItem item = ConfigurationItem.valueOf(configurationItemName);
    configurationManager.updateConfigurationItem(item, value);
}
Also used : ConfigurationItem(org.openforis.collect.model.Configuration.ConfigurationItem)

Example 4 with ConfigurationItem

use of org.openforis.collect.model.Configuration.ConfigurationItem 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

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