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