Search in sources :

Example 6 with TaxonOccurrence

use of org.openforis.idm.model.TaxonOccurrence in project collect by openforis.

the class SpeciesManager method findByFamilyScientificName.

public List<TaxonOccurrence> findByFamilyScientificName(CollectTaxonomy taxonomy, String searchString, int maxResults, TaxonSearchParameters parameters) {
    List<TaxonOccurrence> result = new ArrayList<TaxonOccurrence>();
    TaxonTree taxonTree = loadTaxonTree(taxonomy);
    List<Taxon> families = taxonTree.findTaxaByScientificNameStartingWith(searchString, parameters.getHighestRank());
    result.addAll(fromTaxonomiesToTaxonOccurrences(families, parameters));
    for (Taxon familyTaxon : families) {
        List<TaxonOccurrence> descendants = taxonTree.getDescendantOccurrences(familyTaxon, parameters);
        result.addAll(descendants);
    }
    return result;
}
Also used : TaxonOccurrence(org.openforis.idm.model.TaxonOccurrence) Taxon(org.openforis.idm.model.species.Taxon) ArrayList(java.util.ArrayList) TaxonTree(org.openforis.collect.model.TaxonTree)

Example 7 with TaxonOccurrence

use of org.openforis.idm.model.TaxonOccurrence in project collect by openforis.

the class SpeciesBackupImportJobIntegrationTest method testSpeciesImport.

@Test
public void testSpeciesImport() throws Exception {
    SpeciesBackupImportJob job = importCSVFile(VALID_TEST_CSV);
    assertTrue(job.isCompleted());
    SpeciesBackupImportTask task = (SpeciesBackupImportTask) job.getTasks().get(0);
    assertTrue(task.getSkippedRows().isEmpty());
    TaxonomyDefinition taxonomyDef = survey.getReferenceDataSchema().getTaxonomyDefinition(TEST_TAXONOMY_NAME);
    assertEquals(Arrays.asList("info1", "info2"), taxonomyDef.getAttributeNames());
    {
        String code = "OLE/CAP/macrocarpa";
        TaxonOccurrence occurrence = findByCode(code);
        TaxonOccurrence expected = new TaxonOccurrence(code, "Olea capensis ssp. macrocarpa");
        expected.setInfoAttributes(Arrays.asList("info_value_1", "info_value_2"));
        expected.setTaxonRank(SUBSPECIES);
        assertEquals(expected, occurrence);
    }
    {
        String code = "ALB/ADI";
        TaxonOccurrence occurrence = findByCode(code);
        TaxonOccurrence expected = new TaxonOccurrence(code, "Albizia adianthifolia");
        expected.setInfoAttributes(Arrays.asList("info_value_3", null));
        expected.setTaxonRank(SPECIES);
        assertEquals(expected, occurrence);
    }
}
Also used : SpeciesBackupImportTask(org.openforis.collect.io.metadata.species.SpeciesBackupImportTask) TaxonOccurrence(org.openforis.idm.model.TaxonOccurrence) TaxonomyDefinition(org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition) SpeciesBackupImportJob(org.openforis.collect.io.metadata.species.SpeciesBackupImportJob) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 8 with TaxonOccurrence

use of org.openforis.idm.model.TaxonOccurrence in project collect by openforis.

the class SpeciesBackupImportJobIntegrationTest method findByCode.

protected TaxonOccurrence findByCode(String code) {
    CollectTaxonomy taxonomy = speciesManager.loadTaxonomyByName(survey, TEST_TAXONOMY_NAME);
    TaxonSearchParameters searchParameters = new TaxonSearchParameters();
    searchParameters.setHighestRank(FAMILY);
    List<TaxonOccurrence> occurrences = speciesManager.findByCode(taxonomy, code, 10, searchParameters);
    assertNotNull(occurrences);
    assertEquals(1, occurrences.size());
    TaxonOccurrence occurrence = occurrences.get(0);
    return occurrence;
}
Also used : TaxonOccurrence(org.openforis.idm.model.TaxonOccurrence) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy) TaxonSearchParameters(org.openforis.collect.manager.TaxonSearchParameters)

Example 9 with TaxonOccurrence

use of org.openforis.idm.model.TaxonOccurrence in project collect by openforis.

the class TaxonAttributeDefinition method createValueFromKeyFieldValues.

@SuppressWarnings("unchecked")
@Override
public <V extends Value> V createValueFromKeyFieldValues(List<String> keyFieldValues) {
    String code = keyFieldValues.get(0);
    String scientificName = keyFieldValues.get(1);
    return (V) new TaxonOccurrence(code, scientificName);
}
Also used : TaxonOccurrence(org.openforis.idm.model.TaxonOccurrence)

Example 10 with TaxonOccurrence

use of org.openforis.idm.model.TaxonOccurrence in project collect by openforis.

the class SpeciesManager method fromVernacularNamesToTaxonOccurrences.

private List<TaxonOccurrence> fromVernacularNamesToTaxonOccurrences(CollectTaxonomy taxonomy, List<TaxonVernacularName> vernacularNames, TaxonSearchParameters parameters) {
    List<TaxonOccurrence> result = new ArrayList<TaxonOccurrence>();
    for (TaxonVernacularName vernacularName : vernacularNames) {
        Taxon taxon = taxonDao.loadById(taxonomy, vernacularName.getTaxonSystemId());
        TaxonRank highestRank = parameters.getHighestRank();
        if (highestRank == null || highestRank == taxon.getTaxonRank() || highestRank.isHigherThan(taxon.getTaxonRank())) {
            TaxonOccurrence o = new TaxonOccurrence(taxon, vernacularName);
            if (parameters.isIncludeAncestorTaxons()) {
                loadAncestorTaxons(taxon, o);
            }
            result.add(o);
        }
    }
    return result;
}
Also used : TaxonOccurrence(org.openforis.idm.model.TaxonOccurrence) TaxonRank(org.openforis.idm.model.species.Taxon.TaxonRank) Taxon(org.openforis.idm.model.species.Taxon) ArrayList(java.util.ArrayList) TaxonVernacularName(org.openforis.idm.model.species.TaxonVernacularName)

Aggregations

TaxonOccurrence (org.openforis.idm.model.TaxonOccurrence)18 CollectTaxonomy (org.openforis.collect.model.CollectTaxonomy)8 Taxon (org.openforis.idm.model.species.Taxon)6 Secured (org.springframework.security.access.annotation.Secured)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)4 SpeciesImportProcess (org.openforis.collect.manager.speciesimport.SpeciesImportProcess)3 SpeciesImportStatus (org.openforis.collect.manager.speciesimport.SpeciesImportStatus)3 TaxonTree (org.openforis.collect.model.TaxonTree)2 List (java.util.List)1 SpeciesBackupImportJob (org.openforis.collect.io.metadata.species.SpeciesBackupImportJob)1 SpeciesBackupImportTask (org.openforis.collect.io.metadata.species.SpeciesBackupImportTask)1 TaxonSearchParameters (org.openforis.collect.manager.TaxonSearchParameters)1 CollectRecord (org.openforis.collect.model.CollectRecord)1 TaxonomyDefinition (org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition)1 TaxonAttribute (org.openforis.idm.model.TaxonAttribute)1 TaxonRank (org.openforis.idm.model.species.Taxon.TaxonRank)1 TaxonVernacularName (org.openforis.idm.model.species.TaxonVernacularName)1