Search in sources :

Example 1 with Archiver

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;
    }
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Path(java.nio.file.Path) Configuration(org.jbei.ice.storage.model.Configuration) InputStream(java.io.InputStream) IOException(java.io.IOException) Archiver(org.rauschig.jarchivelib.Archiver) URL(java.net.URL) IOException(java.io.IOException) PermissionException(org.jbei.ice.lib.access.PermissionException) AccountController(org.jbei.ice.lib.account.AccountController)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 PermissionException (org.jbei.ice.lib.access.PermissionException)1 AccountController (org.jbei.ice.lib.account.AccountController)1 Configuration (org.jbei.ice.storage.model.Configuration)1 Archiver (org.rauschig.jarchivelib.Archiver)1