use of org.jbei.ice.storage.model.Configuration in project ice by JBEI.
the class ConfigurationController method autoUpdateSetting.
// update the setting automatically. Currently works only for blast installations
public Setting autoUpdateSetting(String userId, Setting setting) {
AccountController accountController = new AccountController();
if (!accountController.isAdministrator(userId))
throw new PermissionException("Cannot auto update system setting without admin privileges");
Configuration configuration = dao.get(setting.getKey());
if (configuration == null) {
Logger.error("Could not retrieve setting " + setting.getKey());
return null;
}
String osName = System.getProperty("os.name").replaceAll("\\s+", "").toLowerCase();
String blast = "ncbi-blast-2.6.0+-x64-" + osName + ".tar.gz";
Path path = Paths.get(dao.get(ConfigurationKey.TEMPORARY_DIRECTORY).getValue(), blast);
Path dest = Paths.get(dao.get(ConfigurationKey.DATA_DIRECTORY).getValue());
if (!Files.exists(dest)) {
Logger.error("Cannot access access dir : " + dest.toString());
return null;
}
try (InputStream is = (new URL(BLAST_FTP_DIR + blast)).openStream()) {
Files.copy(is, path.toAbsolutePath(), StandardCopyOption.REPLACE_EXISTING);
Archiver archiver = ArchiverFactory.createArchiver("tar", "gz");
archiver.extract(path.toFile(), dest.toFile());
Path valuePath = Paths.get(dest.toString(), "ncbi-blast-2.6.0+", "bin");
configuration.setValue(valuePath.toString());
Files.list(valuePath).forEach(dirPath -> {
try {
Files.setPosixFilePermissions(dirPath, PosixFilePermissions.fromString("rwxrwxrwx"));
} catch (IOException e) {
Logger.error(e);
}
});
return dao.update(configuration).toDataTransferObject();
} catch (Exception e) {
Logger.error(e);
return null;
}
}
use of org.jbei.ice.storage.model.Configuration in project ice by JBEI.
the class ConfigurationController method retrieveSystemSettings.
public ArrayList<Setting> retrieveSystemSettings(String userId) {
ArrayList<Setting> settings = new ArrayList<>();
if (!new AccountController().isAdministrator(userId))
return settings;
for (ConfigurationKey key : ConfigurationKey.values()) {
Configuration configuration = dao.get(key);
Setting setting;
if (configuration == null)
setting = new Setting(key.name(), "");
else
setting = new Setting(configuration.getKey(), configuration.getValue());
settings.add(setting);
}
return settings;
}
use of org.jbei.ice.storage.model.Configuration in project ice by JBEI.
the class ConfigurationController method setPropertyValue.
public Configuration setPropertyValue(ConfigurationKey key, String value) {
Configuration configuration = dao.get(key);
if (configuration == null) {
configuration = new Configuration();
configuration.setKey(key.name());
configuration.setValue(value);
return dao.create(configuration);
}
configuration.setValue(value);
return dao.update(configuration);
}
use of org.jbei.ice.storage.model.Configuration in project ice by JBEI.
the class ConfigurationDAOTest method testSave.
@Test
public void testSave() throws Exception {
Configuration config = new Configuration();
config.setKey("foo");
config.setValue("bar");
config = dao.create(config);
Assert.assertNotNull(config);
Assert.assertTrue(config.getId() > 0);
}
use of org.jbei.ice.storage.model.Configuration in project ice by JBEI.
the class ConfigurationDAOTest method testGet.
@Test
public void testGet() throws Exception {
Configuration config = new Configuration();
config.setKey(ConfigurationKey.NEW_REGISTRATION_ALLOWED.name());
config.setValue("true");
config = dao.create(config);
Assert.assertNotNull(config);
Assert.assertTrue(config.getId() > 0);
config = dao.get(ConfigurationKey.NEW_REGISTRATION_ALLOWED);
Assert.assertNotNull(config);
Assert.assertEquals("true", config.getValue());
config = dao.get(ConfigurationKey.NEW_REGISTRATION_ALLOWED.name());
Assert.assertNotNull(config);
Assert.assertEquals("true", config.getValue());
}
Aggregations