use of org.openforis.idm.model.species.TaxonVernacularName 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.TaxonVernacularName in project collect by openforis.
the class TaxonVernacularNameDao method insert.
public void insert(List<TaxonVernacularName> items) {
if (items != null && !items.isEmpty()) {
TaxonVernacularNameDSLContext dsl = dsl();
int id = dsl.nextId(OFC_TAXON_VERNACULAR_NAME.ID, OFC_TAXON_VERNACULAR_NAME_ID_SEQ);
int maxId = id;
Insert<OfcTaxonVernacularNameRecord> query = dsl.createInsertStatement();
BatchBindStep batch = dsl.batch(query);
for (TaxonVernacularName item : items) {
if (item.getId() == null) {
item.setId(id++);
}
Object[] values = dsl.extractValues(item);
batch.bind(values);
maxId = Math.max(maxId, item.getId());
}
batch.execute();
dsl.restartSequence(OFC_TAXON_VERNACULAR_NAME_ID_SEQ, maxId + 1);
}
}
use of org.openforis.idm.model.species.TaxonVernacularName in project collect by openforis.
the class TaxonTree method includeUniqueVernacularNameIfAny.
private void includeUniqueVernacularNameIfAny(Node node, TaxonOccurrence o) {
List<TaxonVernacularName> vernacularNames = node.getVernacularNames();
if (vernacularNames.size() == 1) {
TaxonVernacularName vernacularName = vernacularNames.get(0);
o.setVernacularName(vernacularName.getVernacularName());
o.setLanguageCode(vernacularName.getLanguageCode());
o.setLanguageVariety(vernacularName.getLanguageVariety());
}
}
use of org.openforis.idm.model.species.TaxonVernacularName in project collect by openforis.
the class SpeciesDaoIntegrationTest method testInsertAndLoadVernacularName.
private TaxonVernacularName testInsertAndLoadVernacularName(Taxon taxon1, String name, String lang, String variety, int step) {
// Insert
TaxonVernacularName tvn = new TaxonVernacularName();
tvn.setVernacularName(name);
tvn.setLanguageCode(lang);
tvn.setLanguageVariety(variety);
tvn.setTaxonSystemId(taxon1.getSystemId());
tvn.setStep(step);
taxonVernacularNameDao.insert(tvn);
// Confirm saved
tvn = taxonVernacularNameDao.loadById(tvn.getId());
assertNotNull(tvn);
assertEquals(taxon1.getSystemId(), tvn.getTaxonSystemId());
assertEquals(name, tvn.getVernacularName());
assertEquals(lang, tvn.getLanguageCode());
assertEquals(variety, tvn.getLanguageVariety());
assertEquals(step, tvn.getStep());
return tvn;
}
use of org.openforis.idm.model.species.TaxonVernacularName in project collect by openforis.
the class SpeciesDaoIntegrationTest method testFindVernacularName.
private void testFindVernacularName(String match, int maxResults, int expectedResults) {
// Create taxonomy
CollectTaxonomy taxonomy1 = testInsertAndLoadTaxonomy("it_bamboo");
testUpdateAndLoadTaxonomy(taxonomy1, "it_trees");
Taxon family1 = testInsertAndLoadTaxon(taxonomy1, -1, "JUGLANDACAE", "Juglandaceae", FAMILY, 9, null);
Taxon genus1 = testInsertAndLoadTaxon(taxonomy1, -2, "JUG", "Juglans sp.", GENUS, 9, family1);
Taxon species1 = testInsertAndLoadTaxon(taxonomy1, -3, "JUG/REG", "Juglans regia", SPECIES, 9, genus1);
testInsertAndLoadVernacularName(family1, "Walnut family", "eng", "", 9);
testInsertAndLoadVernacularName(genus1, "Walnut", "eng", "", 0);
testInsertAndLoadVernacularName(genus1, "Noce", "ita", "", 9);
testInsertAndLoadVernacularName(species1, "Noce bianco", "ita", "", 9);
testInsertAndLoadVernacularName(species1, "Persian walnut", "eng", "", 9);
testInsertAndLoadVernacularName(species1, "Орех грецкий", "rus", "", 9);
List<TaxonVernacularName> results = taxonVernacularNameDao.findByVernacularName(taxonomy1.getId(), match, maxResults);
assertEquals(expectedResults, results.size());
match = match.toUpperCase();
for (TaxonVernacularName tvn : results) {
String name = tvn.getVernacularName();
name = name.toUpperCase();
assertTrue(name.contains(match));
}
}
Aggregations