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;
}
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);
}
}
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;
}
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);
}
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;
}
Aggregations