Search in sources :

Example 16 with Taxon

use of org.openforis.idm.model.species.Taxon in project collect by openforis.

the class SpeciesImportProcess method createTaxonGenus.

protected Taxon createTaxonGenus(SpeciesLine line) throws ParsingException {
    String genus = line.getGenus();
    if (genus == null) {
        ParsingError error = new ParsingError(ErrorType.INVALID_VALUE, line.getLineNumber(), SpeciesFileColumn.SCIENTIFIC_NAME.getColumnName(), INVALID_GENUS_NAME_ERROR_MESSAGE_KEY);
        throw new ParsingException(error);
    }
    Taxon taxonFamily = createTaxonFamily(line);
    String normalizedScientificName = StringUtils.join(genus, " ", GENUS_SUFFIX);
    return createTaxon(line, GENUS, taxonFamily, normalizedScientificName);
}
Also used : ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) ParsingException(org.openforis.collect.io.exception.ParsingException) Taxon(org.openforis.idm.model.species.Taxon)

Example 17 with Taxon

use of org.openforis.idm.model.species.Taxon in project collect by openforis.

the class TaxonDao method insert.

/**
 * Inserts the items in batch.
 */
public void insert(CollectTaxonomy taxonomy, List<Taxon> items) {
    if (items != null && !items.isEmpty()) {
        TaxonDSLContext dsl = dsl(taxonomy);
        int id = dsl.nextId(OFC_TAXON.ID, OFC_TAXON_ID_SEQ);
        int maxId = id;
        Insert<OfcTaxonRecord> query = dsl.createInsertStatement();
        BatchBindStep batch = dsl.batch(query);
        for (Taxon item : items) {
            if (item.getSystemId() == null) {
                item.setSystemId(id++);
            }
            Object[] values = dsl.extractValues(item);
            batch.bind(values);
            maxId = Math.max(maxId, item.getSystemId());
        }
        batch.execute();
        dsl.restartSequence(OFC_TAXON_ID_SEQ, maxId + 1);
    }
}
Also used : BatchBindStep(org.jooq.BatchBindStep) Taxon(org.openforis.idm.model.species.Taxon) OfcTaxonRecord(org.openforis.collect.persistence.jooq.tables.records.OfcTaxonRecord)

Example 18 with Taxon

use of org.openforis.idm.model.species.Taxon in project collect by openforis.

the class SpeciesBackupImportJobIntegrationTest method findTaxonByCode.

protected Taxon findTaxonByCode(String code) {
    CollectTaxonomy taxonomy = taxonomyDao.loadByName(survey, TEST_TAXONOMY_NAME);
    List<Taxon> results = taxonDao.findByCode(taxonomy, FAMILY, code, 10);
    assertNotNull(results);
    assertEquals(1, results.size());
    Taxon taxon = results.get(0);
    return taxon;
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy)

Example 19 with Taxon

use of org.openforis.idm.model.species.Taxon in project collect by openforis.

the class SurveyManagerIntegrationTest method insertTestTaxonomy.

private void insertTestTaxonomy() {
    CollectTaxonomy taxonomy = new CollectTaxonomy();
    taxonomy.setName("tree");
    taxonomy.setSurvey(survey);
    speciesManager.save(taxonomy);
    Taxon taxon = new Taxon();
    taxon.setTaxonomyId(taxonomy.getId());
    taxon.setCode("ALB/GLA");
    taxon.setScientificName("Albizia glaberrima");
    taxon.setTaxonRank(TaxonRank.GENUS);
    speciesManager.save(taxon);
    {
        TaxonVernacularName vernacularName = new TaxonVernacularName();
        vernacularName.setTaxonSystemId(taxon.getSystemId());
        vernacularName.setVernacularName("Mgerenge");
        vernacularName.setLanguageCode("swh");
        speciesManager.save(vernacularName);
    }
    {
        TaxonVernacularName vernacularName = new TaxonVernacularName();
        vernacularName.setTaxonSystemId(taxon.getSystemId());
        vernacularName.setVernacularName("Mchani");
        vernacularName.setLanguageCode("swh");
        speciesManager.save(vernacularName);
    }
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) TaxonVernacularName(org.openforis.idm.model.species.TaxonVernacularName) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy)

Example 20 with Taxon

use of org.openforis.idm.model.species.Taxon in project collect by openforis.

the class SpeciesDaoIntegrationTest method testFindCode.

private void testFindCode(String match, int maxResults, int expectedResults) {
    // Create taxonomy
    CollectTaxonomy taxonomy1 = testInsertAndLoadTaxonomy("it_bamboo");
    testUpdateAndLoadTaxonomy(taxonomy1, "it_trees");
    Taxon family1 = testInsertAndLoadTaxon(taxonomy1, -1, "JUGLANDACAE", "Juglandaceae", FAMILY, 9, null);
    Taxon genus1 = testInsertAndLoadTaxon(taxonomy1, -2, "JUG", "Juglans sp.", GENUS, 9, family1);
    testInsertAndLoadTaxon(taxonomy1, -3, "JUG/REG", "Juglans regia", SPECIES, 9, genus1);
    List<Taxon> results = taxonDao.findByCode(taxonomy1, FAMILY, match, maxResults);
    assertEquals(expectedResults, results.size());
    match = match.toUpperCase();
    for (Taxon taxon : results) {
        String code = taxon.getCode();
        code = (code == null) ? "" : code.toUpperCase();
        assertTrue(code.startsWith(match));
    }
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy)

Aggregations

Taxon (org.openforis.idm.model.species.Taxon)29 CollectTaxonomy (org.openforis.collect.model.CollectTaxonomy)13 TaxonVernacularName (org.openforis.idm.model.species.TaxonVernacularName)8 ArrayList (java.util.ArrayList)6 TaxonOccurrence (org.openforis.idm.model.TaxonOccurrence)6 Test (org.junit.Test)4 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)4 TaxonTree (org.openforis.collect.model.TaxonTree)4 Node (org.openforis.collect.model.TaxonTree.Node)4 TaxonomyDefinition (org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition)4 ParsingException (org.openforis.collect.io.exception.ParsingException)2 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)2 SpeciesImportProcess (org.openforis.collect.manager.speciesimport.SpeciesImportProcess)2 SpeciesImportStatus (org.openforis.collect.manager.speciesimport.SpeciesImportStatus)2 Attribute (org.openforis.idm.metamodel.ReferenceDataSchema.ReferenceDataDefinition.Attribute)2 TaxonRank (org.openforis.idm.model.species.Taxon.TaxonRank)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Stack (java.util.Stack)1