use of org.openforis.idm.model.species.Taxon in project collect by openforis.
the class SpeciesImportProcess method createTaxonGenus.
protected Taxon createTaxonGenus(SpeciesLine line) throws ParsingException {
String genus = line.getGenus();
if (genus == null) {
ParsingError error = new ParsingError(ErrorType.INVALID_VALUE, line.getLineNumber(), SpeciesFileColumn.SCIENTIFIC_NAME.getColumnName(), INVALID_GENUS_NAME_ERROR_MESSAGE_KEY);
throw new ParsingException(error);
}
Taxon taxonFamily = createTaxonFamily(line);
String normalizedScientificName = StringUtils.join(genus, " ", GENUS_SUFFIX);
return createTaxon(line, GENUS, taxonFamily, normalizedScientificName);
}
use of org.openforis.idm.model.species.Taxon in project collect by openforis.
the class TaxonDao method insert.
/**
* Inserts the items in batch.
*/
public void insert(CollectTaxonomy taxonomy, List<Taxon> items) {
if (items != null && !items.isEmpty()) {
TaxonDSLContext dsl = dsl(taxonomy);
int id = dsl.nextId(OFC_TAXON.ID, OFC_TAXON_ID_SEQ);
int maxId = id;
Insert<OfcTaxonRecord> query = dsl.createInsertStatement();
BatchBindStep batch = dsl.batch(query);
for (Taxon item : items) {
if (item.getSystemId() == null) {
item.setSystemId(id++);
}
Object[] values = dsl.extractValues(item);
batch.bind(values);
maxId = Math.max(maxId, item.getSystemId());
}
batch.execute();
dsl.restartSequence(OFC_TAXON_ID_SEQ, maxId + 1);
}
}
use of org.openforis.idm.model.species.Taxon in project collect by openforis.
the class SpeciesBackupImportJobIntegrationTest 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 SurveyManagerIntegrationTest method insertTestTaxonomy.
private void insertTestTaxonomy() {
CollectTaxonomy taxonomy = new CollectTaxonomy();
taxonomy.setName("tree");
taxonomy.setSurvey(survey);
speciesManager.save(taxonomy);
Taxon taxon = new Taxon();
taxon.setTaxonomyId(taxonomy.getId());
taxon.setCode("ALB/GLA");
taxon.setScientificName("Albizia glaberrima");
taxon.setTaxonRank(TaxonRank.GENUS);
speciesManager.save(taxon);
{
TaxonVernacularName vernacularName = new TaxonVernacularName();
vernacularName.setTaxonSystemId(taxon.getSystemId());
vernacularName.setVernacularName("Mgerenge");
vernacularName.setLanguageCode("swh");
speciesManager.save(vernacularName);
}
{
TaxonVernacularName vernacularName = new TaxonVernacularName();
vernacularName.setTaxonSystemId(taxon.getSystemId());
vernacularName.setVernacularName("Mchani");
vernacularName.setLanguageCode("swh");
speciesManager.save(vernacularName);
}
}
use of org.openforis.idm.model.species.Taxon in project collect by openforis.
the class SpeciesDaoIntegrationTest method testFindCode.
private void testFindCode(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);
testInsertAndLoadTaxon(taxonomy1, -3, "JUG/REG", "Juglans regia", SPECIES, 9, genus1);
List<Taxon> results = taxonDao.findByCode(taxonomy1, FAMILY, match, maxResults);
assertEquals(expectedResults, results.size());
match = match.toUpperCase();
for (Taxon taxon : results) {
String code = taxon.getCode();
code = (code == null) ? "" : code.toUpperCase();
assertTrue(code.startsWith(match));
}
}
Aggregations