use of com.healthmarketscience.jackcess.Table in project eol-globi-data by jhpoelen.
the class CMECSService method buildTermMap.
private static Map<String, Term> buildTermMap() throws IOException {
LOG.info(CMECSService.class.getSimpleName() + " instantiating...");
String uri = "https://cmecscatalog.org/cmecs/documents/cmecs4.accdb";
LOG.info("CMECS data [" + uri + "] downloading ...");
HttpGet get = new HttpGet(uri);
try {
HttpResponse execute = HttpUtil.getHttpClient().execute(get);
File cmecs = File.createTempFile("cmecs", "accdb");
cmecs.deleteOnExit();
IOUtils.copy(execute.getEntity().getContent(), new FileOutputStream(cmecs));
LOG.info("CMECS data [" + uri + "] downloaded.");
Database db = new DatabaseBuilder().setFile(new File(cmecs.toURI())).setReadOnly(true).open();
Map<String, Term> aquaticSettingsTerms = new HashMap<>();
Table table = db.getTable("Aquatic Setting");
Map<String, Object> row;
while ((row = table.getNextRow()) != null) {
Integer id = (Integer) row.get("AquaticSetting_Id");
String name = (String) row.get("AquaticSettingName");
String termId = TaxonomyProvider.ID_CMECS + id;
aquaticSettingsTerms.put(name, new TermImpl(termId, name));
}
cmecs.delete();
LOG.info(CMECSService.class.getSimpleName() + " instantiated.");
return aquaticSettingsTerms;
} finally {
get.releaseConnection();
}
}
use of com.healthmarketscience.jackcess.Table in project eol-globi-data by jhpoelen.
the class StudyImporterForADWTest method readMDB.
@Test
public void readMDB() throws URISyntaxException, IOException {
URI uri = getClass().getResource("spire/econetvis.mdb").toURI();
assertThat(uri, is(notNullValue()));
Database db = DatabaseBuilder.open(new File(uri));
assertThat(db.getFileFormat(), is(Database.FileFormat.V2000));
String[] tableNames = new String[] { "attribute_types", "common_names", "entities", "habitats", "links", "localities", "metastudies", "part_mapping_new", "part_qualifiers", "studies", "study_habitat", "study_local", "taxon", "taxon_attributes" };
Set<String> expectedSet = new HashSet<String>();
Collections.addAll(expectedSet, tableNames);
Set<String> actualTableNames = db.getTableNames();
assertThat(actualTableNames.size(), is(not(0)));
assertThat("expected tables names [" + Arrays.toString(tableNames) + "] to be present", CollectionUtils.subtract(expectedSet, actualTableNames).size(), is(0));
Table studies = db.getTable("studies");
for (Map<String, Object> study : studies) {
assertNotNull(study.get("reference"));
}
List<String> expectedColumnNames = Arrays.asList("study_id", "entity1", "entity2", "link_strength", "link_type", "table_ref", "link_number");
assertColumnNames(expectedColumnNames, db.getTable("links"));
expectedColumnNames = Arrays.asList("id", "latinname", "commonname", "parent", "webinfo", "moreinfo", "numchildren", "pos", "classification", "pictures", "sounds", "specimens", "idx", "extinct", "rank");
assertColumnNames(expectedColumnNames, db.getTable("taxon"));
Table taxonTable = db.getTable("taxon");
int numberOfTaxa = 0;
while (taxonTable.getNextRow() != null) {
numberOfTaxa++;
}
assertThat(numberOfTaxa, is(198301));
Table links = db.getTable("links");
int numberOfLinks = 0;
while (links.getNextRow() != null) {
numberOfLinks++;
}
assertThat(numberOfLinks, is(18189));
}
Aggregations