Search in sources :

Example 11 with Taxon

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

the class SpeciesManager method loadAncestorTaxons.

private void loadAncestorTaxons(Taxon taxon, TaxonOccurrence o) {
    Taxon currentTaxon = taxon;
    while (currentTaxon.getParentId() != null) {
        Taxon parentTaxon = taxonDao.loadById((CollectTaxonomy) currentTaxon.getTaxonomy(), currentTaxon.getParentId());
        TaxonOccurrence parentTaxonOccurrence = new TaxonOccurrence(parentTaxon);
        o.addAncestorTaxon(parentTaxonOccurrence);
        currentTaxon = parentTaxon;
    }
}
Also used : TaxonOccurrence(org.openforis.idm.model.TaxonOccurrence) Taxon(org.openforis.idm.model.species.Taxon)

Example 12 with Taxon

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

the class SpeciesManager method findByFamilyScientificName.

public List<TaxonOccurrence> findByFamilyScientificName(CollectTaxonomy taxonomy, String searchString, int maxResults, TaxonSearchParameters parameters) {
    List<TaxonOccurrence> result = new ArrayList<TaxonOccurrence>();
    TaxonTree taxonTree = loadTaxonTree(taxonomy);
    List<Taxon> families = taxonTree.findTaxaByScientificNameStartingWith(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 13 with Taxon

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

the class SpeciesManager method loadTaxonTree.

public TaxonTree loadTaxonTree(CollectTaxonomy taxonomy) {
    TaxonTree tree = taxonTreeByTaxonomyIdCache.get(taxonomy.getId());
    if (tree == null) {
        String taxonomyName = taxonomy.getName();
        TaxonomyDefinition taxonDefinition = taxonomy.getSurvey().getReferenceDataSchema().getTaxonomyDefinition(taxonomyName);
        List<Taxon> taxons = taxonDao.loadTaxonsForTreeBuilding(taxonomy);
        tree = new TaxonTree(taxonDefinition);
        Map<Integer, Taxon> idToTaxon = new HashMap<Integer, Taxon>();
        for (Taxon taxon : taxons) {
            Integer systemId = taxon.getSystemId();
            Integer parentId = taxon.getParentId();
            Taxon parent = parentId == null ? null : idToTaxon.get(parentId);
            Node newNode = tree.addNode(parent, taxon);
            List<TaxonVernacularName> vernacularNames = taxonVernacularNameDao.findByTaxon(systemId);
            tree.addVernacularNames(newNode, vernacularNames);
            idToTaxon.put(systemId, taxon);
        }
        taxonTreeByTaxonomyIdCache.put(taxonomy.getId(), tree);
    }
    return tree;
}
Also used : TaxonomyDefinition(org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition) HashMap(java.util.HashMap) Taxon(org.openforis.idm.model.species.Taxon) Node(org.openforis.collect.model.TaxonTree.Node) TaxonTree(org.openforis.collect.model.TaxonTree) TaxonVernacularName(org.openforis.idm.model.species.TaxonVernacularName)

Example 14 with Taxon

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

the class SpeciesImportProcess method findParentTaxon.

private Taxon findParentTaxon(SpeciesLine line) throws ParsingException {
    TaxonRank rank = line.getRank();
    TaxonRank parentRank = rank.getParent();
    String scientificName;
    switch(parentRank) {
        case FAMILY:
            scientificName = line.getFamilyName();
            break;
        case GENUS:
            scientificName = line.getGenus();
            break;
        case SPECIES:
            scientificName = line.getSpeciesName();
            break;
        default:
            throw new RuntimeException("Unsupported rank");
    }
    Taxon result = taxonTree.findTaxonByScientificName(scientificName);
    return result;
}
Also used : TaxonRank(org.openforis.idm.model.species.Taxon.TaxonRank) Taxon(org.openforis.idm.model.species.Taxon)

Example 15 with Taxon

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

the class SpeciesImportProcess method createTaxon.

protected Taxon createTaxon(SpeciesLine line, TaxonRank rank, Taxon parent, String normalizedScientificName) throws ParsingException {
    boolean mostSpecificRank = line.getRank() == rank;
    Taxon taxon = taxonTree.findTaxonByScientificName(normalizedScientificName);
    boolean newTaxon = taxon == null;
    if (newTaxon) {
        taxon = new Taxon();
        taxon.setTaxonRank(rank);
        taxon.setScientificName(normalizedScientificName);
        Node node = taxonTree.addNode(parent, taxon);
        node.addMetadata(LINE_NUMBER_TREE_NODE_METADATA, line.getLineNumber());
        node.addMetadata(RAW_SCIENTIFIC_NAME_TREE_NODE_METADATA, line.getRawScientificName());
    } else if (mostSpecificRank) {
        checkDuplicateScientificName(line, parent, normalizedScientificName);
    }
    if (mostSpecificRank) {
        String code = line.getCode();
        Integer taxonId = line.getTaxonId();
        checkDuplicates(line, code, taxonId);
        taxon.setCode(code);
        taxon.setTaxonId(taxonId);
        TaxonomyDefinition taxonDefinition = survey.getReferenceDataSchema().getTaxonomyDefinition(taxonomyName);
        List<Attribute> taxonAttributes = taxonDefinition.getAttributes();
        for (Attribute attribute : taxonAttributes) {
            String value = line.getInfoAttribute(attribute.getName());
            taxon.addInfoAttribute(value);
        }
        taxonTree.updateNodeInfo(taxon);
        processVernacularNames(line, taxon);
    }
    return taxon;
}
Also used : TaxonomyDefinition(org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition) Attribute(org.openforis.idm.metamodel.ReferenceDataSchema.ReferenceDataDefinition.Attribute) Taxon(org.openforis.idm.model.species.Taxon) Node(org.openforis.collect.model.TaxonTree.Node)

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