use of org.globalbioticinteractions.dataset.DatasetRegistryException in project eol-globi-data by jhpoelen.
the class CacheLocalReadonly method getContentProvenance.
public static ContentProvenance getContentProvenance(URI resourceURI, String cachePath, String namespace) {
AtomicReference<ContentProvenance> meta = new AtomicReference<>(null);
File accessFile;
try {
File cacheDirForNamespace = CacheUtil.findCacheDirForNamespace(cachePath, namespace);
String hashCandidate = getHashCandidate(resourceURI, cacheDirForNamespace.toURI());
accessFile = ProvenanceLog.findProvenanceLogFile(namespace, cachePath);
if (accessFile.exists()) {
try (InputStream is = new FileInputStream(accessFile)) {
ProvenanceLog.parseProvenanceStream(is, new ProvenanceLog.ProvenanceEntryListener() {
@Override
public void onValues(String[] values) {
if (values.length > 3) {
URI sourceURI = URI.create(values[1]);
String sha256 = values[2];
String accessedAt = StringUtils.trim(values[3]);
if (StringUtils.isNotBlank(sha256)) {
ContentProvenance provenance = getProvenance(resourceURI, hashCandidate, sourceURI, sha256, accessedAt, cacheDirForNamespace, namespace);
if (provenance != null) {
meta.set(provenance);
}
}
}
}
});
}
}
} catch (IOException | DatasetRegistryException e) {
LOG.error("unexpected exception on getting meta for [" + resourceURI + "]", e);
}
return meta.get();
}
use of org.globalbioticinteractions.dataset.DatasetRegistryException in project eol-globi-data by jhpoelen.
the class DatasetImporterFactoryImplIT method defaultTSVImporterCached.
@Test
public void defaultTSVImporterCached() throws StudyImporterException, DatasetRegistryException, IOException {
final DatasetRegistry datasetRegistry = new DatasetRegistryWithCache(new DatasetRegistryGitHubArchive(inStream -> inStream), dataset -> CacheUtil.cacheFor(dataset.getNamespace(), "target/datasets", inStream -> inStream));
DatasetImporter importer = getTemplateImporter(datasetRegistry, "globalbioticinteractions/template-dataset");
DatasetImporterForTSV importerTSV = (DatasetImporterForTSV) importer;
assertThat(importerTSV.getBaseUrl(), startsWith("https://github.com/globalbioticinteractions/template-dataset/"));
assertThat(importerTSV.getDataset().retrieve(URI.create("globi.json")), is(notNullValue()));
}
use of org.globalbioticinteractions.dataset.DatasetRegistryException in project eol-globi-data by jhpoelen.
the class DatasetImporterForRegistry method importData.
private void importData(String namespace) throws StudyImporterException {
try {
LOG.info("[" + namespace + "] checking status...");
Dataset dataset = new DatasetFactory(getRegistry()).datasetFor(namespace);
if (datasetFilter.test(dataset)) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
LOG.info("[" + namespace + "] is active, importing...");
getNodeFactory().getOrCreateDataset(dataset);
importData(dataset);
stopWatch.stop();
LOG.info("[" + namespace + "] imported in " + stopWatch.getTime(TimeUnit.SECONDS) + "s");
} else {
LOG.info("[" + namespace + "] is deprecated, not importing.");
}
} catch (StudyImporterException | DatasetRegistryException ex) {
String msg = "failed to import data from repo [" + namespace + "]";
LOG.error(msg, ex);
throw new StudyImporterException(msg, ex);
}
}
Aggregations