Search in sources :

Example 6 with Table

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();
    }
}
Also used : Table(com.healthmarketscience.jackcess.Table) HashMap(java.util.HashMap) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Term(org.eol.globi.domain.Term) TermImpl(org.eol.globi.domain.TermImpl) DatabaseBuilder(com.healthmarketscience.jackcess.DatabaseBuilder) FileOutputStream(java.io.FileOutputStream) Database(com.healthmarketscience.jackcess.Database) File(java.io.File)

Example 7 with Table

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));
}
Also used : Table(com.healthmarketscience.jackcess.Table) Database(com.healthmarketscience.jackcess.Database) URI(java.net.URI) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Table (com.healthmarketscience.jackcess.Table)7 Database (com.healthmarketscience.jackcess.Database)5 File (java.io.File)4 Column (com.healthmarketscience.jackcess.Column)3 Row (com.healthmarketscience.jackcess.Row)2 HashSet (java.util.HashSet)2 KettleException (org.pentaho.di.core.exception.KettleException)2 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 DatabaseBuilder (com.healthmarketscience.jackcess.DatabaseBuilder)1 PropertyMap (com.healthmarketscience.jackcess.PropertyMap)1 Query (com.healthmarketscience.jackcess.query.Query)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 URI (java.net.URI)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HttpResponse (org.apache.http.HttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1