use of org.rauschig.jarchivelib.Archiver 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;
}
}
Aggregations