Search in sources :

Example 1 with Taxon

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

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

the class TaxonTree method taxaToNodes.

private List<Node> taxaToNodes(List<Taxon> list) {
    List<Node> result = new ArrayList<Node>(list.size());
    for (Taxon taxon : list) {
        Node node = getNodeBySystemId(taxon.getSystemId());
        result.add(node);
    }
    return result;
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) ArrayList(java.util.ArrayList)

Example 3 with Taxon

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

the class SpeciesImportProcessIntegrationTest method findTaxonByCode.

protected Taxon findTaxonByCode(String code) {
    CollectTaxonomy taxonomy = taxonomyDao.loadByName(survey, TEST_TAXONOMY_NAME);
    List<Taxon> results = taxonDao.findByCode(taxonomy, FAMILY, code, 10);
    assertNotNull(results);
    assertEquals(1, results.size());
    Taxon taxon = results.get(0);
    return taxon;
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy)

Example 4 with Taxon

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

the class SpeciesDaoIntegrationTest method testDeleteTaxonByTaxonomy.

@Test
public void testDeleteTaxonByTaxonomy() {
    CollectSurvey survey = createAndStoreSurvey();
    // Create taxonomy
    CollectTaxonomy t = new CollectTaxonomy();
    t.setSurvey(survey);
    t.setName("it_trees");
    taxonomyDao.insert(t);
    CollectTaxonomy t2 = new CollectTaxonomy();
    t2.setSurvey(survey);
    t2.setName("it_bamboos");
    taxonomyDao.insert(t2);
    Taxon family1 = testInsertAndLoadTaxon(t, -1, "JUGLANDACAE", "Juglandaceae", FAMILY, 9, null);
    Taxon genus1 = testInsertAndLoadTaxon(t, -2, "JUG", "Juglans sp.", GENUS, 9, family1);
    testInsertAndLoadTaxon(t, -3, "JUG/REG", "Juglans regia", SPECIES, 9, genus1);
    Taxon family2 = testInsertAndLoadTaxon(t2, -1, "JUGLANDACAE", "Juglandaceae", FAMILY, 9, null);
    Taxon genus2 = testInsertAndLoadTaxon(t2, -2, "JUG", "Juglans sp.", GENUS, 9, family2);
    testInsertAndLoadTaxon(t2, -3, "JUG/REG", "Juglans regia", SPECIES, 9, genus2);
    // verify taxon records present
    List<Taxon> results = taxonDao.findByCode(t, FAMILY, "%", 10);
    assertEquals(3, results.size());
    taxonDao.deleteByTaxonomy(t);
    // verify all taxon records deleted for taxonomy 1
    List<Taxon> results2 = taxonDao.findByCode(t, FAMILY, "%", 10);
    assertTrue(results2 == null || results2.size() == 0);
    // verify all taxon records NOT deleted for taxonomy 2
    List<Taxon> results3 = taxonDao.findByCode(t2, FAMILY, "%", 10);
    assertEquals(3, results3.size());
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) CollectSurvey(org.openforis.collect.model.CollectSurvey) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 5 with Taxon

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

the class SpeciesDaoIntegrationTest method testInsertAndLoadTaxon.

private Taxon testInsertAndLoadTaxon(CollectTaxonomy taxonomy, int taxonId, String code, String scientificName, TaxonRank rank, int step, Taxon parent) {
    Integer parentId = parent == null ? null : parent.getSystemId();
    // Insert
    Taxon t = new Taxon();
    t.setTaxonId(taxonId);
    t.setCode(code);
    t.setScientificName(scientificName);
    t.setTaxonRank(rank);
    t.setStep(step);
    t.setTaxonomyId(taxonomy.getId());
    t.setParentId(parentId);
    taxonDao.insert(t);
    // Confirm saved
    t = taxonDao.loadById((CollectTaxonomy) taxonomy, t.getSystemId());
    assertNotNull(t);
    assertEquals((Integer) taxonId, t.getTaxonId());
    assertEquals(scientificName, t.getScientificName());
    assertEquals(rank, t.getTaxonRank());
    assertEquals(taxonomy.getId(), t.getTaxonomyId());
    assertEquals(step, t.getStep());
    assertEquals(parentId, t.getParentId());
    return t;
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy)

Aggregations

Taxon (org.openforis.idm.model.species.Taxon)29 CollectTaxonomy (org.openforis.collect.model.CollectTaxonomy)13 TaxonVernacularName (org.openforis.idm.model.species.TaxonVernacularName)8 ArrayList (java.util.ArrayList)6 TaxonOccurrence (org.openforis.idm.model.TaxonOccurrence)6 Test (org.junit.Test)4 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)4 TaxonTree (org.openforis.collect.model.TaxonTree)4 Node (org.openforis.collect.model.TaxonTree.Node)4 TaxonomyDefinition (org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition)4 ParsingException (org.openforis.collect.io.exception.ParsingException)2 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)2 SpeciesImportProcess (org.openforis.collect.manager.speciesimport.SpeciesImportProcess)2 SpeciesImportStatus (org.openforis.collect.manager.speciesimport.SpeciesImportStatus)2 Attribute (org.openforis.idm.metamodel.ReferenceDataSchema.ReferenceDataDefinition.Attribute)2 TaxonRank (org.openforis.idm.model.species.Taxon.TaxonRank)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Stack (java.util.Stack)1