Search in sources :

Example 11 with Database

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);
    }
}
Also used : Table(com.healthmarketscience.jackcess.Table) HashMap(java.util.HashMap) Term(org.eol.globi.domain.Term) URI(java.net.URI) TermImpl(org.eol.globi.domain.TermImpl) DatabaseBuilder(com.healthmarketscience.jackcess.DatabaseBuilder) Database(com.healthmarketscience.jackcess.Database) File(java.io.File)

Aggregations

Database (com.healthmarketscience.jackcess.Database)11 File (java.io.File)9 Table (com.healthmarketscience.jackcess.Table)7 KettleException (org.pentaho.di.core.exception.KettleException)5 DatabaseBuilder (com.healthmarketscience.jackcess.DatabaseBuilder)3 URI (java.net.URI)3 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 MessageBox (org.eclipse.swt.widgets.MessageBox)2 Term (org.eol.globi.domain.Term)2 TermImpl (org.eol.globi.domain.TermImpl)2 Test (org.junit.Test)2 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)2 FileInputList (org.pentaho.di.core.fileinput.FileInputList)2 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 AccessInputMeta (org.pentaho.di.trans.steps.accessinput.AccessInputMeta)2 EnterSelectionDialog (org.pentaho.di.ui.core.dialog.EnterSelectionDialog)2 Column (com.healthmarketscience.jackcess.Column)1