Search in sources :

Example 1 with LocalFile

use of ubic.gemma.model.common.description.LocalFile in project Gemma by PavlidisLab.

the class FtpArchiveFetcher method listFiles.

protected Collection<LocalFile> listFiles(String remoteFile, File newDir, Collection<LocalFile> result) throws IOException {
    if (result == null)
        result = new HashSet<>();
    for (File file : FileTools.listDirectoryFiles(newDir)) {
        if (excludePattern != null && file.getPath().endsWith(excludePattern))
            continue;
        // log.info( "\t" + file.getCanonicalPath() );
        LocalFile newFile = LocalFile.Factory.newInstance();
        newFile.setLocalURL(file.toURI().toURL());
        newFile.setRemoteURL(new File(remoteFile).toURI().toURL());
        newFile.setVersion(new SimpleDateFormat().format(new Date()));
        result.add(newFile);
    }
    // recurse into subdirectories.
    for (File file : FileTools.listSubDirectories(newDir)) {
        this.listFiles(remoteFile, file, result);
    }
    return result;
}
Also used : LocalFile(ubic.gemma.model.common.description.LocalFile) File(java.io.File) LocalFile(ubic.gemma.model.common.description.LocalFile) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) HashSet(java.util.HashSet)

Example 2 with LocalFile

use of ubic.gemma.model.common.description.LocalFile in project Gemma by PavlidisLab.

the class FtpFetcher method doTask.

protected Collection<LocalFile> doTask(FutureTask<Boolean> future, long expectedSize, String seekFileName, String outputFileName) {
    ExecutorService executor = Executors.newSingleThreadExecutor();
    executor.execute(future);
    executor.shutdown();
    try {
        File outputFile = new File(outputFileName);
        boolean ok = waitForDownload(future, expectedSize, outputFile);
        if (!ok) {
            // cancelled, probably.
            log.info("Download failed, was it cancelled?");
            return null;
        } else if (future.get()) {
            if (log.isInfoEnabled())
                log.info("Done: local file is " + outputFile);
            LocalFile file = fetchedFile(seekFileName, outputFile.getAbsolutePath());
            Collection<LocalFile> result = new HashSet<>();
            result.add(file);
            return result;
        }
    } catch (ExecutionException e) {
        throw new RuntimeException("Couldn't fetch " + seekFileName, e);
    } catch (InterruptedException e) {
        log.warn("Interrupted: Couldn't fetch " + seekFileName, e);
        return null;
    } catch (CancellationException e) {
        log.info("Cancelled");
        return null;
    }
    throw new RuntimeException("Couldn't fetch file for " + seekFileName);
}
Also used : LocalFile(ubic.gemma.model.common.description.LocalFile) Collection(java.util.Collection) LocalFile(ubic.gemma.model.common.description.LocalFile) File(java.io.File)

Example 3 with LocalFile

use of ubic.gemma.model.common.description.LocalFile in project Gemma by PavlidisLab.

the class FtpFetcher method fetch.

protected Collection<LocalFile> fetch(String identifier, String seekFile) {
    File existingFile = null;
    try {
        File newDir = mkdir(identifier);
        String outputFileName = formLocalFilePath(identifier, newDir);
        existingFile = new File(outputFileName);
        if (ftpClient == null || !ftpClient.isConnected()) {
            ftpClient = this.getNetDataSourceUtil().connect(FTP.BINARY_FILE_TYPE);
            // otherwise should have gotten an exception from connect()
            assert ftpClient != null;
        }
        long expectedSize = getExpectedSize(seekFile);
        FutureTask<Boolean> future = this.defineTask(outputFileName, seekFile);
        return this.doTask(future, expectedSize, seekFile, outputFileName);
    } catch (UnknownHostException e) {
        if (force || !allowUseExisting || existingFile == null)
            throw new RuntimeException(e);
        if (!avoidDownload)
            throw new RuntimeException(e);
        log.warn("Could not connect to " + this.getNetDataSourceUtil().getHost() + " to check size of " + seekFile + ", using existing file");
        return getExistingFile(existingFile, seekFile);
    } catch (IOException e) {
        if (force || !allowUseExisting || existingFile == null) {
            /*
                 * Printing to log here because runtime error does not deliver message when passed through
                 * java.util.concurrent.FutureTask (only throws InterruptedException and ExecutionException)
                 */
            log.error("Runtime exception thrown: " + e.getMessage() + ". \n Stack trace follows:", e);
            throw new RuntimeException("Cancelled, or couldn't fetch " + seekFile + ", make sure the file exists on the remote server and permissions are granted.", e);
        }
        if (Thread.currentThread().isInterrupted()) {
            throw new CancellationException();
        }
        log.warn("Cancelled, or couldn't fetch " + seekFile + ", make sure the file exists on the remote server.," + e + ", using existing file");
        return getExistingFile(existingFile, seekFile);
    } finally {
        try {
            if (ftpClient != null && ftpClient.isConnected())
                ftpClient.disconnect();
        } catch (IOException e) {
            // noinspection ThrowFromFinallyBlock
            throw new RuntimeException("Could not disconnect: " + e.getMessage());
        }
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) IOException(java.io.IOException) LocalFile(ubic.gemma.model.common.description.LocalFile) File(java.io.File)

Example 4 with LocalFile

use of ubic.gemma.model.common.description.LocalFile in project Gemma by PavlidisLab.

the class HttpFetcher method listFiles.

protected Collection<LocalFile> listFiles(String seekFile, String outputFileName) throws IOException {
    Collection<LocalFile> result = new HashSet<>();
    File file = new File(outputFileName);
    AbstractFetcher.log.info("Downloaded: " + file);
    LocalFile newFile = LocalFile.Factory.newInstance();
    newFile.setLocalURL(file.toURI().toURL());
    newFile.setRemoteURL(new URL(seekFile));
    newFile.setVersion(new SimpleDateFormat().format(new Date()));
    result.add(newFile);
    return result;
}
Also used : LocalFile(ubic.gemma.model.common.description.LocalFile) LocalFile(ubic.gemma.model.common.description.LocalFile) SimpleDateFormat(java.text.SimpleDateFormat) URL(java.net.URL) Date(java.util.Date) HashSet(java.util.HashSet)

Example 5 with LocalFile

use of ubic.gemma.model.common.description.LocalFile in project Gemma by PavlidisLab.

the class AbstractFetcher method fetchedFile.

/**
 * @param seekFilePath   Absolute path to the file for download
 * @param outputFilePath Absolute path to the download location.
 * @return local file
 */
protected LocalFile fetchedFile(String seekFilePath, String outputFilePath) {
    LocalFile file = LocalFile.Factory.newInstance();
    file.setVersion(new SimpleDateFormat().format(new Date()));
    try {
        file.setRemoteURL((new File(seekFilePath)).toURI().toURL());
        file.setLocalURL((new File(outputFilePath).toURI().toURL()));
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
    return file;
}
Also used : LocalFile(ubic.gemma.model.common.description.LocalFile) MalformedURLException(java.net.MalformedURLException) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) LocalFile(ubic.gemma.model.common.description.LocalFile) Date(java.util.Date)

Aggregations

LocalFile (ubic.gemma.model.common.description.LocalFile)40 File (java.io.File)17 IOException (java.io.IOException)11 MalformedURLException (java.net.MalformedURLException)4 HashSet (java.util.HashSet)4 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)4 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)4 URL (java.net.URL)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)3 Taxon (ubic.gemma.model.genome.Taxon)3 StopWatch (org.apache.commons.lang3.time.StopWatch)2 AffyPowerToolsProbesetSummarize (ubic.gemma.core.loader.expression.AffyPowerToolsProbesetSummarize)2 RawDataFetcher (ubic.gemma.core.loader.expression.geo.fetcher.RawDataFetcher)2 HttpFetcher (ubic.gemma.core.loader.util.fetcher.HttpFetcher)2 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)2 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 URISyntaxException (java.net.URISyntaxException)1