use of org.openforis.collect.model.CollectTaxonomy in project collect by openforis.
the class CollectSpeciesListService method loadSpeciesListNames.
@Override
public List<String> loadSpeciesListNames(Survey survey) {
List<CollectTaxonomy> taxonomies = speciesManager.loadTaxonomiesBySurvey((CollectSurvey) survey);
List<String> result = new ArrayList<String>(taxonomies.size());
for (CollectTaxonomy taxonomy : taxonomies) {
result.add(taxonomy.getName());
}
return result;
}
use of org.openforis.collect.model.CollectTaxonomy 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);
}
}
}
}
use of org.openforis.collect.model.CollectTaxonomy 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;
}
use of org.openforis.collect.model.CollectTaxonomy in project collect by openforis.
the class SpeciesImportProcessIntegrationTest method testExport.
@Test
public void testExport() throws Exception {
SpeciesImportProcess process = importCSVFile(VALID_TEST_CSV);
SpeciesImportStatus status = process.getStatus();
assertTrue(status.isComplete());
CollectTaxonomy taxonomy = taxonomyDao.loadByName(survey, TEST_TAXONOMY_NAME);
TaxonSummaries summaries = speciesManager.loadFullTaxonSummariesOld(taxonomy);
assertNotNull(summaries);
}
use of org.openforis.collect.model.CollectTaxonomy in project collect by openforis.
the class SpeciesService method loadTaxonomiesBySurvey.
@Secured("ROLE_ENTRY")
public List<TaxonomyProxy> loadTaxonomiesBySurvey(int surveyId, boolean work) {
CollectSurvey survey = surveyManager.getOrLoadSurveyById(surveyId);
List<CollectTaxonomy> result = speciesManager.loadTaxonomiesBySurvey(survey);
return Proxies.fromList(result, TaxonomyProxy.class);
}
Aggregations