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