use of org.openforis.collect.model.CollectTaxonomy 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.collect.model.CollectTaxonomy 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;
}
use of org.openforis.collect.model.CollectTaxonomy 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));
}
}
use of org.openforis.collect.model.CollectTaxonomy in project collect by openforis.
the class SpeciesBackupImportTask method persistTaxa.
private void persistTaxa() throws SurveyStoreException {
CollectTaxonomy taxonomy = loadTaxonomy();
if (taxonomy == null) {
if (overwriteAll) {
// create and store taxonomy taxonomy
taxonomy = new CollectTaxonomy();
taxonomy.setName(taxonomyName);
taxonomy.setSurvey(survey);
speciesManager.save(taxonomy);
} else {
throw new RuntimeException("Cannot insert new taxonomy: overwriteAll parameter not specified");
}
}
// taxonomy definition changed
saveSurvey();
speciesManager.insertTaxons(taxonomy, taxonTree, overwriteAll);
}
use of org.openforis.collect.model.CollectTaxonomy in project collect by openforis.
the class SpeciesManager method loadTaxonSummaries.
public TaxonSummaries loadTaxonSummaries(CollectSurvey survey, int taxonomyId, int offset, int maxRecords) {
CollectTaxonomy taxonomy = loadTaxonomyById(survey, taxonomyId);
String taxonomyName = taxonomy.getName();
int totalCount = taxonDao.countTaxons(taxonomy);
Set<String> vernacularNamesLanguageCodes = new HashSet<String>();
List<TaxonSummary> items = new ArrayList<TaxonSummary>();
TaxonomyDefinition taxonDefinition = survey.getReferenceDataSchema().getTaxonomyDefinition(taxonomyName);
if (totalCount > 0) {
List<Taxon> taxons = taxonDao.loadTaxons(taxonomy, offset, maxRecords);
for (Taxon taxon : taxons) {
List<TaxonVernacularName> vernacularNames = taxonVernacularNameDao.findByTaxon(taxon.getSystemId());
TaxonSummary summary = new TaxonSummary(taxonDefinition, taxon, vernacularNames, null);
List<String> itemVernLangCodes = summary.getVernacularLanguages();
vernacularNamesLanguageCodes.addAll(itemVernLangCodes);
items.add(summary);
}
}
List<String> sortedVernacularNamesLanguageCodes = new ArrayList<String>(vernacularNamesLanguageCodes);
Collections.sort(sortedVernacularNamesLanguageCodes);
List<String> infoAttributeNames = taxonDefinition.getAttributeNames();
return new TaxonSummaries(totalCount, items, sortedVernacularNamesLanguageCodes, infoAttributeNames);
}
Aggregations