use of com.healthmarketscience.jackcess.Database in project eol-globi-data by jhpoelen.
the class CMECSService method buildTermMap.
private static Map<String, Term> buildTermMap(ResourceService service) throws IOException {
LOG.info(CMECSService.class.getSimpleName() + " instantiating...");
URI uri = URI.create("https://cmecscatalog.org/cmecs/documents/cmecs4.accdb");
LOG.info("CMECS data [" + uri + "] downloading ...");
File mdbFile = null;
try {
mdbFile = File.createTempFile("cmecs", "tmp.mdb");
mdbFile.deleteOnExit();
FileUtils.copyToFile(service.retrieve(uri), mdbFile);
Database db = new DatabaseBuilder().setFile(mdbFile).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(StringUtils.lowerCase(StringUtils.strip(name)), new TermImpl(termId, name));
}
LOG.info(CMECSService.class.getSimpleName() + " instantiated.");
return aquaticSettingsTerms;
} finally {
FileUtils.deleteQuietly(mdbFile);
}
}
Aggregations