Search in sources :

Example 1 with TaxonVernacularName

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

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

the class TaxonVernacularNameDao method insert.

public void insert(List<TaxonVernacularName> items) {
    if (items != null && !items.isEmpty()) {
        TaxonVernacularNameDSLContext dsl = dsl();
        int id = dsl.nextId(OFC_TAXON_VERNACULAR_NAME.ID, OFC_TAXON_VERNACULAR_NAME_ID_SEQ);
        int maxId = id;
        Insert<OfcTaxonVernacularNameRecord> query = dsl.createInsertStatement();
        BatchBindStep batch = dsl.batch(query);
        for (TaxonVernacularName item : items) {
            if (item.getId() == null) {
                item.setId(id++);
            }
            Object[] values = dsl.extractValues(item);
            batch.bind(values);
            maxId = Math.max(maxId, item.getId());
        }
        batch.execute();
        dsl.restartSequence(OFC_TAXON_VERNACULAR_NAME_ID_SEQ, maxId + 1);
    }
}
Also used : BatchBindStep(org.jooq.BatchBindStep) TaxonVernacularName(org.openforis.idm.model.species.TaxonVernacularName) OfcTaxonVernacularNameRecord(org.openforis.collect.persistence.jooq.tables.records.OfcTaxonVernacularNameRecord)

Example 3 with TaxonVernacularName

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

the class TaxonTree method includeUniqueVernacularNameIfAny.

private void includeUniqueVernacularNameIfAny(Node node, TaxonOccurrence o) {
    List<TaxonVernacularName> vernacularNames = node.getVernacularNames();
    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)

Example 4 with TaxonVernacularName

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

the class SpeciesDaoIntegrationTest method testInsertAndLoadVernacularName.

private TaxonVernacularName testInsertAndLoadVernacularName(Taxon taxon1, String name, String lang, String variety, int step) {
    // Insert
    TaxonVernacularName tvn = new TaxonVernacularName();
    tvn.setVernacularName(name);
    tvn.setLanguageCode(lang);
    tvn.setLanguageVariety(variety);
    tvn.setTaxonSystemId(taxon1.getSystemId());
    tvn.setStep(step);
    taxonVernacularNameDao.insert(tvn);
    // Confirm saved
    tvn = taxonVernacularNameDao.loadById(tvn.getId());
    assertNotNull(tvn);
    assertEquals(taxon1.getSystemId(), tvn.getTaxonSystemId());
    assertEquals(name, tvn.getVernacularName());
    assertEquals(lang, tvn.getLanguageCode());
    assertEquals(variety, tvn.getLanguageVariety());
    assertEquals(step, tvn.getStep());
    return tvn;
}
Also used : TaxonVernacularName(org.openforis.idm.model.species.TaxonVernacularName)

Example 5 with TaxonVernacularName

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

the class SpeciesDaoIntegrationTest method testFindVernacularName.

private void testFindVernacularName(String match, int maxResults, int expectedResults) {
    // Create taxonomy
    CollectTaxonomy taxonomy1 = testInsertAndLoadTaxonomy("it_bamboo");
    testUpdateAndLoadTaxonomy(taxonomy1, "it_trees");
    Taxon family1 = testInsertAndLoadTaxon(taxonomy1, -1, "JUGLANDACAE", "Juglandaceae", FAMILY, 9, null);
    Taxon genus1 = testInsertAndLoadTaxon(taxonomy1, -2, "JUG", "Juglans sp.", GENUS, 9, family1);
    Taxon species1 = testInsertAndLoadTaxon(taxonomy1, -3, "JUG/REG", "Juglans regia", SPECIES, 9, genus1);
    testInsertAndLoadVernacularName(family1, "Walnut family", "eng", "", 9);
    testInsertAndLoadVernacularName(genus1, "Walnut", "eng", "", 0);
    testInsertAndLoadVernacularName(genus1, "Noce", "ita", "", 9);
    testInsertAndLoadVernacularName(species1, "Noce bianco", "ita", "", 9);
    testInsertAndLoadVernacularName(species1, "Persian walnut", "eng", "", 9);
    testInsertAndLoadVernacularName(species1, "Орех грецкий", "rus", "", 9);
    List<TaxonVernacularName> results = taxonVernacularNameDao.findByVernacularName(taxonomy1.getId(), match, maxResults);
    assertEquals(expectedResults, results.size());
    match = match.toUpperCase();
    for (TaxonVernacularName tvn : results) {
        String name = tvn.getVernacularName();
        name = name.toUpperCase();
        assertTrue(name.contains(match));
    }
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) TaxonVernacularName(org.openforis.idm.model.species.TaxonVernacularName) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy)

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