Search in sources :

Example 6 with TaxonVernacularName

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

the class SpeciesBackupImportTask method processVernacularNames.

protected void processVernacularNames(SpeciesBackupLine line, Taxon taxon) {
    Map<String, List<String>> langToVernacularName = line.getLanguageToVernacularNames();
    Set<String> vernacularLangCodes = langToVernacularName.keySet();
    for (String langCode : vernacularLangCodes) {
        List<String> vernacularNames = langToVernacularName.get(langCode);
        for (String vernacularName : vernacularNames) {
            TaxonVernacularName taxonVN = new TaxonVernacularName();
            taxonVN.setLanguageCode(langCode);
            taxonVN.setVernacularName(vernacularName);
            taxonTree.addVernacularName(taxon, taxonVN);
        }
    }
}
Also used : List(java.util.List) TaxonVernacularName(org.openforis.idm.model.species.TaxonVernacularName)

Example 7 with TaxonVernacularName

use of org.openforis.idm.model.species.TaxonVernacularName 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 8 with TaxonVernacularName

use of org.openforis.idm.model.species.TaxonVernacularName 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 9 with TaxonVernacularName

use of org.openforis.idm.model.species.TaxonVernacularName 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 10 with TaxonVernacularName

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

the class SpeciesManager method includeUniqueVernacularNameIfAny.

private void includeUniqueVernacularNameIfAny(int taxonSystemId, TaxonOccurrence o) {
    List<TaxonVernacularName> vernacularNames = taxonVernacularNameDao.findByTaxon(taxonSystemId);
    if (vernacularNames.size() == 1) {
        TaxonVernacularName vernacularName = vernacularNames.get(0);
        o.setVernacularName(vernacularName.getVernacularName());
        o.setLanguageCode(vernacularName.getLanguageCode());
        o.setLanguageVariety(vernacularName.getLanguageVariety());
    }
}
Also used : TaxonVernacularName(org.openforis.idm.model.species.TaxonVernacularName)

Aggregations

TaxonVernacularName (org.openforis.idm.model.species.TaxonVernacularName)16 Taxon (org.openforis.idm.model.species.Taxon)8 CollectTaxonomy (org.openforis.collect.model.CollectTaxonomy)5 ArrayList (java.util.ArrayList)3 TaxonomyDefinition (org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition)3 List (java.util.List)2 SelectConditionStep (org.jooq.SelectConditionStep)2 TaxonTree (org.openforis.collect.model.TaxonTree)2 Node (org.openforis.collect.model.TaxonTree.Node)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Stack (java.util.Stack)1 BatchBindStep (org.jooq.BatchBindStep)1 TableField (org.jooq.TableField)1 Test (org.junit.Test)1 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)1 TaxonSummaries (org.openforis.collect.metamodel.TaxonSummaries)1 TaxonSummary (org.openforis.collect.metamodel.TaxonSummary)1 OfcTaxonVernacularNameRecord (org.openforis.collect.persistence.jooq.tables.records.OfcTaxonVernacularNameRecord)1 TaxonOccurrence (org.openforis.idm.model.TaxonOccurrence)1