Search in sources :

Example 1 with Node

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

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

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

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

Example 5 with Node

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

the class SpeciesImportProcess method checkDuplicates.

protected void checkDuplicates(SpeciesLine line, String code, Integer taxonId) throws ParsingException {
    Node foundNode = null;
    foundNode = taxonTree.getNodeByTaxonId(taxonId);
    if (foundNode != null) {
        throwDuplicateRowParsingException(line, SpeciesFileColumn.NO, foundNode);
    }
    foundNode = taxonTree.getNodeByCode(code);
    if (foundNode != null) {
        throwDuplicateRowParsingException(line, SpeciesFileColumn.CODE, foundNode);
    }
}
Also used : Node(org.openforis.collect.model.TaxonTree.Node)

Aggregations

Node (org.openforis.collect.model.TaxonTree.Node)5 Taxon (org.openforis.idm.model.species.Taxon)4 TaxonomyDefinition (org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition)3 TaxonTree (org.openforis.collect.model.TaxonTree)2 TaxonVernacularName (org.openforis.idm.model.species.TaxonVernacularName)2 HashMap (java.util.HashMap)1 CollectTaxonomy (org.openforis.collect.model.CollectTaxonomy)1 Attribute (org.openforis.idm.metamodel.ReferenceDataSchema.ReferenceDataDefinition.Attribute)1