Search in sources :

Example 1 with TaxonTree

use of org.openforis.collect.model.TaxonTree in project collect by openforis.

the class CollectSpeciesListService method loadSpeciesListData.

@Override
public Object loadSpeciesListData(Survey survey, String taxonomyName, String attribute, String speciesCode) {
    CollectTaxonomy taxonomy = speciesManager.loadTaxonomyByName((CollectSurvey) survey, taxonomyName);
    TaxonTree taxonTree = speciesManager.loadTaxonTree(taxonomy);
    Taxon taxon = taxonTree.findTaxonByCode(speciesCode);
    if (taxon == null) {
        return null;
    }
    Node taxonNode = taxonTree.getNodeBySystemId(taxon.getSystemId());
    if (FAMILY_ATTRIBUTE.equals(attribute) || FAMILY_NAME_ATTRIBUTE.equals(attribute) || FAMILY_SCIENTIFIC_NAME_ATTRIBUTE.equals(attribute)) {
        // family name
        Node familyNode = taxonNode.getAncestor(TaxonRank.FAMILY);
        return familyNode == null ? null : familyNode.getTaxon().getScientificName();
    } else if (GENUS_ATTRIBUTE.equals(attribute)) {
        Node genusNode = taxonNode.getAncestor(TaxonRank.GENUS);
        return genusNode == null ? null : genusNode.getTaxon().getScientificName();
    } else if (SCIENTIFIC_NAME_ATTRIBUTE.equals(attribute)) {
        return taxon.getScientificName();
    } else if (CODE_ATTRIBUTE.equals(attribute)) {
        return taxon.getCode();
    } else if (Languages.exists(Standard.ISO_639_3, attribute)) {
        TaxonVernacularName vernacularName = taxonNode.getVernacularName(attribute);
        return vernacularName == null ? null : vernacularName.getVernacularName();
    } else {
        // info (extra) attribute
        TaxonomyDefinition taxonDefinition = survey.getReferenceDataSchema().getTaxonomyDefinition(taxonomyName);
        if (taxonDefinition == null) {
            throw new IllegalArgumentException("No reference data schema found for taxonomy: " + taxonomyName);
        } else {
            int attributeIndex = taxonDefinition.getAttributeNames().indexOf(attribute);
            if (attributeIndex < 0) {
                throw new IllegalArgumentException("Unsupported attribute: " + attribute);
            } else {
                return taxon.getInfoAttribute(attributeIndex);
            }
        }
    }
}
Also used : TaxonomyDefinition(org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition) 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) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy)

Example 2 with TaxonTree

use of org.openforis.collect.model.TaxonTree 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 3 with TaxonTree

use of org.openforis.collect.model.TaxonTree in project collect by openforis.

the class SpeciesManager method loadFullTaxonSummaries.

public TaxonSummaries loadFullTaxonSummaries(CollectTaxonomy taxonomy) {
    TaxonTree tree = loadTaxonTree(taxonomy);
    List<TaxonSummary> summaries = tree.toSummaries(TaxonRank.FAMILY, true);
    List<String> sortedVernacularNamesLanguageCodes = new ArrayList<String>(tree.getVernacularLanguageCodes());
    Collections.sort(sortedVernacularNamesLanguageCodes);
    List<String> infoAttributeNames = taxonomy.getSurvey().getReferenceDataSchema().getTaxonomyDefinition(taxonomy.getName()).getAttributeNames();
    return new TaxonSummaries(summaries.size(), summaries, sortedVernacularNamesLanguageCodes, infoAttributeNames);
}
Also used : TaxonSummary(org.openforis.collect.metamodel.TaxonSummary) ArrayList(java.util.ArrayList) TaxonTree(org.openforis.collect.model.TaxonTree) TaxonSummaries(org.openforis.collect.metamodel.TaxonSummaries)

Example 4 with TaxonTree

use of org.openforis.collect.model.TaxonTree 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 5 with TaxonTree

use of org.openforis.collect.model.TaxonTree in project collect by openforis.

the class SpeciesManager method loadFullTaxonSummariesOld.

public TaxonSummaries loadFullTaxonSummariesOld(CollectTaxonomy taxonomy) {
    TaxonTree tree = loadTaxonTree(taxonomy);
    List<TaxonSummary> summaries = tree.toSummaries(TaxonRank.GENUS, false);
    List<String> sortedVernacularNamesLanguageCodes = new ArrayList<String>(tree.getVernacularLanguageCodes());
    Collections.sort(sortedVernacularNamesLanguageCodes);
    List<String> infoAttributeNames = taxonomy.getSurvey().getReferenceDataSchema().getTaxonomyDefinition(taxonomy.getName()).getAttributeNames();
    return new TaxonSummaries(summaries.size(), summaries, sortedVernacularNamesLanguageCodes, infoAttributeNames);
}
Also used : TaxonSummary(org.openforis.collect.metamodel.TaxonSummary) ArrayList(java.util.ArrayList) TaxonTree(org.openforis.collect.model.TaxonTree) TaxonSummaries(org.openforis.collect.metamodel.TaxonSummaries)

Aggregations

TaxonTree (org.openforis.collect.model.TaxonTree)8 ArrayList (java.util.ArrayList)4 TaxonomyDefinition (org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition)4 Taxon (org.openforis.idm.model.species.Taxon)4 TaxonSummaries (org.openforis.collect.metamodel.TaxonSummaries)2 TaxonSummary (org.openforis.collect.metamodel.TaxonSummary)2 Node (org.openforis.collect.model.TaxonTree.Node)2 TaxonOccurrence (org.openforis.idm.model.TaxonOccurrence)2 TaxonVernacularName (org.openforis.idm.model.species.TaxonVernacularName)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ParsingException (org.openforis.collect.io.exception.ParsingException)1 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)1 CollectTaxonomy (org.openforis.collect.model.CollectTaxonomy)1 SurveyStoreException (org.openforis.collect.persistence.SurveyStoreException)1 Attribute (org.openforis.idm.metamodel.ReferenceDataSchema.ReferenceDataDefinition.Attribute)1