Search in sources :

Example 6 with Taxon

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

the class SpeciesDaoIntegrationTest method testFindVernacularName.

private void testFindVernacularName(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);
    Taxon species1 = testInsertAndLoadTaxon(taxonomy1, -3, "JUG/REG", "Juglans regia", SPECIES, 9, genus1);
    testInsertAndLoadVernacularName(family1, "Walnut family", "eng", "", 9);
    testInsertAndLoadVernacularName(genus1, "Walnut", "eng", "", 0);
    testInsertAndLoadVernacularName(genus1, "Noce", "ita", "", 9);
    testInsertAndLoadVernacularName(species1, "Noce bianco", "ita", "", 9);
    testInsertAndLoadVernacularName(species1, "Persian walnut", "eng", "", 9);
    testInsertAndLoadVernacularName(species1, "Орех грецкий", "rus", "", 9);
    List<TaxonVernacularName> results = taxonVernacularNameDao.findByVernacularName(taxonomy1.getId(), match, maxResults);
    assertEquals(expectedResults, results.size());
    match = match.toUpperCase();
    for (TaxonVernacularName tvn : results) {
        String name = tvn.getVernacularName();
        name = name.toUpperCase();
        assertTrue(name.contains(match));
    }
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) TaxonVernacularName(org.openforis.idm.model.species.TaxonVernacularName) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy)

Example 7 with Taxon

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

the class SpeciesBackupImportTask method findParentTaxon.

private Taxon findParentTaxon(SpeciesBackupLine line) throws ParsingException {
    Node parentNode = line.getParentId() == null ? null : taxonTree.getNodeBySystemId(line.getParentId());
    Taxon parent = parentNode == null ? null : parentNode.getTaxon();
    return parent;
}
Also used : Node(org.openforis.collect.model.TaxonTree.Node) Taxon(org.openforis.idm.model.species.Taxon)

Example 8 with Taxon

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

the class SpeciesManager method loadTaxonSummaries.

public TaxonSummaries loadTaxonSummaries(CollectSurvey survey, int taxonomyId, int offset, int maxRecords) {
    CollectTaxonomy taxonomy = loadTaxonomyById(survey, taxonomyId);
    String taxonomyName = taxonomy.getName();
    int totalCount = taxonDao.countTaxons(taxonomy);
    Set<String> vernacularNamesLanguageCodes = new HashSet<String>();
    List<TaxonSummary> items = new ArrayList<TaxonSummary>();
    TaxonomyDefinition taxonDefinition = survey.getReferenceDataSchema().getTaxonomyDefinition(taxonomyName);
    if (totalCount > 0) {
        List<Taxon> taxons = taxonDao.loadTaxons(taxonomy, offset, maxRecords);
        for (Taxon taxon : taxons) {
            List<TaxonVernacularName> vernacularNames = taxonVernacularNameDao.findByTaxon(taxon.getSystemId());
            TaxonSummary summary = new TaxonSummary(taxonDefinition, taxon, vernacularNames, null);
            List<String> itemVernLangCodes = summary.getVernacularLanguages();
            vernacularNamesLanguageCodes.addAll(itemVernLangCodes);
            items.add(summary);
        }
    }
    List<String> sortedVernacularNamesLanguageCodes = new ArrayList<String>(vernacularNamesLanguageCodes);
    Collections.sort(sortedVernacularNamesLanguageCodes);
    List<String> infoAttributeNames = taxonDefinition.getAttributeNames();
    return new TaxonSummaries(totalCount, items, sortedVernacularNamesLanguageCodes, infoAttributeNames);
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) ArrayList(java.util.ArrayList) TaxonSummaries(org.openforis.collect.metamodel.TaxonSummaries) TaxonomyDefinition(org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition) TaxonSummary(org.openforis.collect.metamodel.TaxonSummary) TaxonVernacularName(org.openforis.idm.model.species.TaxonVernacularName) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy) HashSet(java.util.HashSet)

Example 9 with Taxon

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

the class SpeciesManager method persistTaxonTreeNode.

protected void persistTaxonTreeNode(List<Taxon> taxonInsertBuffer, List<TaxonVernacularName> taxonVernacularNameInsertBuffer, CollectTaxonomy taxonomy, Node node) {
    Taxon taxon = node.getTaxon();
    taxon.setTaxonomyId(taxonomy.getId());
    taxon.setStep(CONFIRMED_TAXON_STEP_NUMBER);
    taxonInsertBuffer.add(taxon);
    if (taxonInsertBuffer.size() > TAXON_INSERT_BUFFER_SIZE) {
        flushTaxonInsertBuffer(taxonomy, taxonInsertBuffer);
    }
    List<TaxonVernacularName> vernacularNames = node.getVernacularNames();
    for (TaxonVernacularName vernacularName : vernacularNames) {
        taxonVernacularNameInsertBuffer.add(vernacularName);
        if (taxonInsertBuffer.size() > TAXON_VERNACULAR_NAME_INSERT_BUFFER_SIZE) {
            flushTaxonVernacularNameInsertBuffer(taxonVernacularNameInsertBuffer);
        }
    }
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) TaxonVernacularName(org.openforis.idm.model.species.TaxonVernacularName)

Example 10 with Taxon

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

the class SpeciesManager method fromTaxonomiesToTaxonOccurrences.

private List<TaxonOccurrence> fromTaxonomiesToTaxonOccurrences(List<Taxon> list, TaxonSearchParameters parameters) {
    List<TaxonOccurrence> result = new ArrayList<TaxonOccurrence>(list.size());
    for (Taxon taxon : list) {
        TaxonOccurrence o = new TaxonOccurrence(taxon);
        o.setTaxonRank(taxon.getTaxonRank());
        if (parameters.isIncludeUniqueVernacularName()) {
            includeUniqueVernacularNameIfAny(taxon.getSystemId(), o);
        }
        if (parameters.isIncludeAncestorTaxons()) {
            loadAncestorTaxons(taxon, o);
        }
        result.add(o);
    }
    return result;
}
Also used : TaxonOccurrence(org.openforis.idm.model.TaxonOccurrence) Taxon(org.openforis.idm.model.species.Taxon) ArrayList(java.util.ArrayList)

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