use of ubic.gemma.core.loader.util.fetcher.HttpFetcher in project Gemma by PavlidisLab.
the class HttpFetcherTest method testFetch.
/*
* Test method for 'ubic.gemma.core.loader.loaderutils.HttpFetcher.fetch(String)'
*/
public void testFetch() {
HttpFetcher hf = new HttpFetcher();
try {
hf.setForce(true);
Collection<LocalFile> results = hf.fetch("http://www.yahoo.com");
TestCase.assertNotNull(results);
TestCase.assertTrue(results.size() > 0 && results.iterator().next().getLocalURL() != null);
f = new File(results.iterator().next().getLocalURL().toURI());
TestCase.assertTrue(f.length() > 0);
} catch (Exception e) {
if (e.getCause() instanceof IOException) {
HttpFetcherTest.log.error("Got IOException, skipping test");
}
}
}
use of ubic.gemma.core.loader.util.fetcher.HttpFetcher in project Gemma by PavlidisLab.
the class NCBIGene2GOAssociationLoaderCLI method doWork.
@Override
protected Exception doWork(String[] args) {
Exception e = this.processCommandLine(args);
if (e != null) {
AbstractCLI.log.error(e);
return e;
}
TaxonService taxonService = this.getBean(TaxonService.class);
NCBIGene2GOAssociationLoader gene2GOAssLoader = new NCBIGene2GOAssociationLoader();
gene2GOAssLoader.setPersisterHelper(this.getPersisterHelper());
Collection<Taxon> taxa = taxonService.loadAll();
gene2GOAssLoader.setParser(new NCBIGene2GOAssociationParser(taxa));
HttpFetcher fetcher = new HttpFetcher();
Collection<LocalFile> files;
if (filePath != null) {
File f = new File(filePath);
if (!f.canRead()) {
return new IOException("Cannot read from " + filePath);
}
files = new HashSet<>();
LocalFile lf = LocalFile.Factory.newInstance();
try {
lf.setLocalURL(f.toURI().toURL());
} catch (MalformedURLException e1) {
return e1;
}
files.add(lf);
} else {
files = fetcher.fetch("ftp://ftp.ncbi.nih.gov/gene/DATA/" + NCBIGene2GOAssociationLoaderCLI.GENE2GO_FILE);
}
assert files.size() == 1;
LocalFile gene2Gofile = files.iterator().next();
Gene2GOAssociationService ggoserv = this.getBean(Gene2GOAssociationService.class);
AbstractCLI.log.info("Removing all old GO associations");
ggoserv.removeAll();
AbstractCLI.log.info("Done, loading new ones");
gene2GOAssLoader.load(gene2Gofile);
AbstractCLI.log.info("Don't forget to update the annotation files for platforms.");
return null;
}
Aggregations