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;
}
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();
}
}
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);
}
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);
}
}
Aggregations