Search in sources :

Example 11 with TaxonVernacularName

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

the class SpeciesImportProcess method processVernacularNames.

protected void processVernacularNames(SpeciesLine 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 : ArrayList(java.util.ArrayList) List(java.util.List) TaxonVernacularName(org.openforis.idm.model.species.TaxonVernacularName)

Example 12 with TaxonVernacularName

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

the class TaxonVernacularNameDao method findByVernacularName.

public List<TaxonVernacularName> findByVernacularName(int taxonomyId, String searchString, String[] qualifierValues, int maxResults) {
    TaxonVernacularNameDSLContext dsl = dsl();
    // find containing
    searchString = "%" + searchString.toLowerCase(Locale.ENGLISH) + "%";
    SelectConditionStep selectConditionStep = dsl.select(OFC_TAXON_VERNACULAR_NAME.fields()).from(OFC_TAXON_VERNACULAR_NAME).join(OFC_TAXON).on(OFC_TAXON.ID.equal(OFC_TAXON_VERNACULAR_NAME.TAXON_ID)).where(OFC_TAXON.TAXONOMY_ID.equal(taxonomyId).and(DSL.lower(OFC_TAXON_VERNACULAR_NAME.VERNACULAR_NAME).like(searchString)));
    if (qualifierValues != null) {
        for (int i = 0; i < qualifierValues.length; i++) {
            String value = qualifierValues[i];
            if (value != null) {
                TableField field = QUALIFIER_FIELDS[i];
                selectConditionStep.and(field.equal(value));
            }
        }
    }
    selectConditionStep.limit(maxResults);
    Result<?> result = selectConditionStep.fetch();
    List<TaxonVernacularName> entities = dsl.fromResult(result);
    return entities;
}
Also used : SelectConditionStep(org.jooq.SelectConditionStep) TaxonVernacularName(org.openforis.idm.model.species.TaxonVernacularName) TableField(org.jooq.TableField)

Example 13 with TaxonVernacularName

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

the class TaxonVernacularNameDao method findByTaxon.

public List<TaxonVernacularName> findByTaxon(int taxonId) {
    TaxonVernacularNameDSLContext dsl = dsl();
    SelectConditionStep selectConditionStep = dsl.select(OFC_TAXON_VERNACULAR_NAME.fields()).from(OFC_TAXON_VERNACULAR_NAME).where(OFC_TAXON_VERNACULAR_NAME.TAXON_ID.equal(taxonId));
    Result<?> result = selectConditionStep.fetch();
    List<TaxonVernacularName> entities = dsl.fromResult(result);
    return entities;
}
Also used : SelectConditionStep(org.jooq.SelectConditionStep) TaxonVernacularName(org.openforis.idm.model.species.TaxonVernacularName)

Example 14 with TaxonVernacularName

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

the class SurveyManagerIntegrationTest method insertTestTaxonomy.

private void insertTestTaxonomy() {
    CollectTaxonomy taxonomy = new CollectTaxonomy();
    taxonomy.setName("tree");
    taxonomy.setSurvey(survey);
    speciesManager.save(taxonomy);
    Taxon taxon = new Taxon();
    taxon.setTaxonomyId(taxonomy.getId());
    taxon.setCode("ALB/GLA");
    taxon.setScientificName("Albizia glaberrima");
    taxon.setTaxonRank(TaxonRank.GENUS);
    speciesManager.save(taxon);
    {
        TaxonVernacularName vernacularName = new TaxonVernacularName();
        vernacularName.setTaxonSystemId(taxon.getSystemId());
        vernacularName.setVernacularName("Mgerenge");
        vernacularName.setLanguageCode("swh");
        speciesManager.save(vernacularName);
    }
    {
        TaxonVernacularName vernacularName = new TaxonVernacularName();
        vernacularName.setTaxonSystemId(taxon.getSystemId());
        vernacularName.setVernacularName("Mchani");
        vernacularName.setLanguageCode("swh");
        speciesManager.save(vernacularName);
    }
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) TaxonVernacularName(org.openforis.idm.model.species.TaxonVernacularName) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy)

Example 15 with TaxonVernacularName

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

the class SpeciesDaoIntegrationTest method testCRUD.

// Disabled because SQLite does not provide Unicode case support by default
// TODO implement it
// @Test
// public void testFindUnicode() throws Exception {
// testFindVernacularName("Орех", 100, 1);
// }
// 
// @Test
// public void testFindUnicodeCaseInsensitive() throws Exception {
// testFindVernacularName("орех", 100, 1);
// }
@Test
public void testCRUD() throws Exception {
    // Create taxonomy
    CollectTaxonomy taxonomy1 = testInsertAndLoadTaxonomy("it_bamboo");
    testUpdateAndLoadTaxonomy(taxonomy1, "it_trees");
    // Create taxa
    Stack<Taxon> taxa = new Stack<Taxon>();
    taxa.push(testInsertAndLoadTaxon(taxonomy1, -1, "JUG", "Juglandaceaex", FAMILY, 9, null));
    taxa.push(testInsertAndLoadTaxon(taxonomy1, -2, "JUG2", "sJuglans sp.", GENUS, 0, null));
    taxa.push(testUpdateAndLoadTaxon(taxonomy1, taxa.pop(), "Juglans sp.", GENUS, 9, taxa.get(0)));
    taxa.push(testInsertAndLoadTaxon(taxonomy1, -4, "JUG3", "Juglans regia", SPECIES, 9, taxa.get(1)));
    // Create vernacular names
    Stack<TaxonVernacularName> names = new Stack<TaxonVernacularName>();
    names.push(testInsertAndLoadVernacularName(taxa.get(0), "Walnut family", "eng", "", 9));
    names.push(testInsertAndLoadVernacularName(taxa.get(0), "Walnuts", "en", "Cockney", 0));
    names.push(testUpdateAndLoadVernacularName(names.pop(), taxa.get(1), "Walnut", "eng", "", 9));
    names.push(testInsertAndLoadVernacularName(taxa.get(1), "Noce", "ita", "", 9));
    names.push(testInsertAndLoadVernacularName(taxa.get(2), "Persian walnut", "eng", "", 9));
    names.push(testInsertAndLoadVernacularName(taxa.get(2), "English walnut", "eng", "", 9));
    names.push(testInsertAndLoadVernacularName(taxa.get(2), "Noce bianco", "ita", "", 9));
    names.push(testInsertAndLoadVernacularName(taxa.get(2), "Орех грецкий", "rus", "", 9));
    // Remove names
    while (!names.isEmpty()) {
        testDeleteAndLoadVernacularName(names.pop());
    }
    // Remove taxa
    while (!taxa.isEmpty()) {
        testDeleteAndLoadTaxon(taxa.pop());
    }
    // Remove taxonomy
    testDeleteAndLoadTaxonomy(taxonomy1);
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) TaxonVernacularName(org.openforis.idm.model.species.TaxonVernacularName) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy) Stack(java.util.Stack) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

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