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