Search in sources :

Example 1 with TaxonomyDefinition

use of org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition 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 TaxonomyDefinition

use of org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition in project collect by openforis.

the class SpeciesExportTask method extractInfoAttributeNames.

private List<String> extractInfoAttributeNames() {
    List<String> colNames = new ArrayList<String>();
    TaxonomyDefinition taxonReferenceDataSchema = survey.getReferenceDataSchema().getTaxonomyDefinition(taxonomyName);
    List<Attribute> infoAttributes = taxonReferenceDataSchema.getAttributes();
    for (Attribute infoAttribute : infoAttributes) {
        colNames.add(infoAttribute.getName());
    }
    return colNames;
}
Also used : TaxonomyDefinition(org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition) Attribute(org.openforis.idm.metamodel.ReferenceDataSchema.ReferenceDataDefinition.Attribute) ArrayList(java.util.ArrayList)

Example 3 with TaxonomyDefinition

use of org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition 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 4 with TaxonomyDefinition

use of org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition 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 TaxonomyDefinition

use of org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition 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

TaxonomyDefinition (org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition)9 TaxonTree (org.openforis.collect.model.TaxonTree)4 Taxon (org.openforis.idm.model.species.Taxon)4 Node (org.openforis.collect.model.TaxonTree.Node)3 Attribute (org.openforis.idm.metamodel.ReferenceDataSchema.ReferenceDataDefinition.Attribute)3 TaxonVernacularName (org.openforis.idm.model.species.TaxonVernacularName)3 ArrayList (java.util.ArrayList)2 CollectTaxonomy (org.openforis.collect.model.CollectTaxonomy)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)1 ParsingException (org.openforis.collect.io.exception.ParsingException)1 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)1 SpeciesBackupImportJob (org.openforis.collect.io.metadata.species.SpeciesBackupImportJob)1 SpeciesBackupImportTask (org.openforis.collect.io.metadata.species.SpeciesBackupImportTask)1 TaxonSummaries (org.openforis.collect.metamodel.TaxonSummaries)1 TaxonSummary (org.openforis.collect.metamodel.TaxonSummary)1 SurveyStoreException (org.openforis.collect.persistence.SurveyStoreException)1