Search in sources :

Example 21 with Taxon

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

the class SpeciesDaoIntegrationTest method testCRUD.

// Disabled because SQLite does not provide Unicode case support by default
// TODO implement it
// @Test
// public void testFindUnicode() throws Exception {
// testFindVernacularName("Орех", 100, 1);
// }
// 
// @Test
// public void testFindUnicodeCaseInsensitive() throws Exception {
// testFindVernacularName("орех", 100, 1);
// }
@Test
public void testCRUD() throws Exception {
    // Create taxonomy
    CollectTaxonomy taxonomy1 = testInsertAndLoadTaxonomy("it_bamboo");
    testUpdateAndLoadTaxonomy(taxonomy1, "it_trees");
    // Create taxa
    Stack<Taxon> taxa = new Stack<Taxon>();
    taxa.push(testInsertAndLoadTaxon(taxonomy1, -1, "JUG", "Juglandaceaex", FAMILY, 9, null));
    taxa.push(testInsertAndLoadTaxon(taxonomy1, -2, "JUG2", "sJuglans sp.", GENUS, 0, null));
    taxa.push(testUpdateAndLoadTaxon(taxonomy1, taxa.pop(), "Juglans sp.", GENUS, 9, taxa.get(0)));
    taxa.push(testInsertAndLoadTaxon(taxonomy1, -4, "JUG3", "Juglans regia", SPECIES, 9, taxa.get(1)));
    // Create vernacular names
    Stack<TaxonVernacularName> names = new Stack<TaxonVernacularName>();
    names.push(testInsertAndLoadVernacularName(taxa.get(0), "Walnut family", "eng", "", 9));
    names.push(testInsertAndLoadVernacularName(taxa.get(0), "Walnuts", "en", "Cockney", 0));
    names.push(testUpdateAndLoadVernacularName(names.pop(), taxa.get(1), "Walnut", "eng", "", 9));
    names.push(testInsertAndLoadVernacularName(taxa.get(1), "Noce", "ita", "", 9));
    names.push(testInsertAndLoadVernacularName(taxa.get(2), "Persian walnut", "eng", "", 9));
    names.push(testInsertAndLoadVernacularName(taxa.get(2), "English walnut", "eng", "", 9));
    names.push(testInsertAndLoadVernacularName(taxa.get(2), "Noce bianco", "ita", "", 9));
    names.push(testInsertAndLoadVernacularName(taxa.get(2), "Орех грецкий", "rus", "", 9));
    // Remove names
    while (!names.isEmpty()) {
        testDeleteAndLoadVernacularName(names.pop());
    }
    // Remove taxa
    while (!taxa.isEmpty()) {
        testDeleteAndLoadTaxon(taxa.pop());
    }
    // Remove taxonomy
    testDeleteAndLoadTaxonomy(taxonomy1);
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) TaxonVernacularName(org.openforis.idm.model.species.TaxonVernacularName) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy) Stack(java.util.Stack) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 22 with Taxon

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

the class SpeciesDaoIntegrationTest method testFindScientificName.

private void testFindScientificName(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.findByScientificName(taxonomy1, FAMILY, match, maxResults);
    assertEquals(expectedResults, results.size());
    match = match.toUpperCase();
    for (Taxon taxon : results) {
        String name = taxon.getScientificName();
        name = name.toUpperCase();
        assertTrue(name.startsWith(match));
    }
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy)

Example 23 with Taxon

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

the class SpeciesManager method fromVernacularNamesToTaxonOccurrences.

private List<TaxonOccurrence> fromVernacularNamesToTaxonOccurrences(CollectTaxonomy taxonomy, List<TaxonVernacularName> vernacularNames, TaxonSearchParameters parameters) {
    List<TaxonOccurrence> result = new ArrayList<TaxonOccurrence>();
    for (TaxonVernacularName vernacularName : vernacularNames) {
        Taxon taxon = taxonDao.loadById(taxonomy, vernacularName.getTaxonSystemId());
        TaxonRank highestRank = parameters.getHighestRank();
        if (highestRank == null || highestRank == taxon.getTaxonRank() || highestRank.isHigherThan(taxon.getTaxonRank())) {
            TaxonOccurrence o = new TaxonOccurrence(taxon, vernacularName);
            if (parameters.isIncludeAncestorTaxons()) {
                loadAncestorTaxons(taxon, o);
            }
            result.add(o);
        }
    }
    return result;
}
Also used : TaxonOccurrence(org.openforis.idm.model.TaxonOccurrence) TaxonRank(org.openforis.idm.model.species.Taxon.TaxonRank) Taxon(org.openforis.idm.model.species.Taxon) ArrayList(java.util.ArrayList) TaxonVernacularName(org.openforis.idm.model.species.TaxonVernacularName)

Example 24 with Taxon

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

the class SpeciesManager method findByFamilyCode.

public List<TaxonOccurrence> findByFamilyCode(CollectTaxonomy taxonomy, String searchString, int maxResults, TaxonSearchParameters parameters) {
    List<TaxonOccurrence> result = new ArrayList<TaxonOccurrence>();
    TaxonTree taxonTree = loadTaxonTree(taxonomy);
    List<Taxon> families = taxonTree.findTaxaByCodeStartingWith(searchString, parameters.getHighestRank());
    result.addAll(fromTaxonomiesToTaxonOccurrences(families, parameters));
    for (Taxon familyTaxon : families) {
        List<TaxonOccurrence> descendants = taxonTree.getDescendantOccurrences(familyTaxon, parameters);
        result.addAll(descendants);
    }
    return result;
}
Also used : TaxonOccurrence(org.openforis.idm.model.TaxonOccurrence) Taxon(org.openforis.idm.model.species.Taxon) ArrayList(java.util.ArrayList) TaxonTree(org.openforis.collect.model.TaxonTree)

Example 25 with Taxon

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

the class SpeciesBackupImportTask method processLine.

protected void processLine(SpeciesBackupLine line) throws ParsingException {
    Taxon taxon = new Taxon();
    taxon.setSystemId(line.getId());
    taxon.setParentId(line.getParentId());
    taxon.setTaxonRank(line.getRank());
    taxon.setTaxonId(line.getNo());
    taxon.setCode(line.getCode());
    taxon.setScientificName(line.getScientificName());
    List<Attribute> taxonAttributes = survey.getReferenceDataSchema().getTaxonomyDefinition(taxonomyName).getAttributes();
    for (Attribute taxonAttribute : taxonAttributes) {
        taxon.addInfoAttribute(line.getInfoAttribute(taxonAttribute.getName()));
    }
    Taxon parent = findParentTaxon(line);
    taxonTree.addNode(parent, taxon);
    processVernacularNames(line, taxon);
}
Also used : Attribute(org.openforis.idm.metamodel.ReferenceDataSchema.ReferenceDataDefinition.Attribute) Taxon(org.openforis.idm.model.species.Taxon)

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