use of org.openforis.collect.metamodel.TaxonSummary 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);
}
use of org.openforis.collect.metamodel.TaxonSummary in project collect by openforis.
the class SpeciesManager method loadFullTaxonSummaries.
public TaxonSummaries loadFullTaxonSummaries(CollectTaxonomy taxonomy) {
TaxonTree tree = loadTaxonTree(taxonomy);
List<TaxonSummary> summaries = tree.toSummaries(TaxonRank.FAMILY, true);
List<String> sortedVernacularNamesLanguageCodes = new ArrayList<String>(tree.getVernacularLanguageCodes());
Collections.sort(sortedVernacularNamesLanguageCodes);
List<String> infoAttributeNames = taxonomy.getSurvey().getReferenceDataSchema().getTaxonomyDefinition(taxonomy.getName()).getAttributeNames();
return new TaxonSummaries(summaries.size(), summaries, sortedVernacularNamesLanguageCodes, infoAttributeNames);
}
use of org.openforis.collect.metamodel.TaxonSummary in project collect by openforis.
the class SpeciesExportProcess method exportToCSV.
public void exportToCSV(OutputStream out, CollectSurvey survey, int taxonomyId) {
CsvWriter writer = null;
try {
writer = new CsvWriter(out);
CollectTaxonomy taxonomy = speciesManager.loadTaxonomyById(survey, taxonomyId);
taxonomyName = taxonomy.getName();
TaxonSummaries summaries = speciesManager.loadFullTaxonSummariesOld(taxonomy);
ArrayList<String> colNames = new ArrayList<String>();
colNames.add(SpeciesFileColumn.NO.getColumnName());
colNames.add(SpeciesFileColumn.CODE.getColumnName());
colNames.add(SpeciesFileColumn.FAMILY.getColumnName());
colNames.add(SpeciesFileColumn.SCIENTIFIC_NAME.getColumnName());
colNames.add(SpeciesFileColumn.SYNONYMS.getColumnName());
List<String> vernacularNamesLangCodes = extractVernacularNameLanguageCodes(summaries);
colNames.addAll(vernacularNamesLangCodes);
List<String> infoAttributeNames = survey.getReferenceDataSchema().getTaxonomyDefinition(taxonomyName).getAttributeNames();
colNames.addAll(infoAttributeNames);
writer.writeHeaders(colNames);
List<TaxonSummary> items = summaries.getItems();
for (TaxonSummary item : items) {
writeTaxonSummary(writer, vernacularNamesLangCodes, infoAttributeNames, item);
}
} catch (Exception e) {
log.error(e);
} finally {
IOUtils.closeQuietly(writer);
}
}
use of org.openforis.collect.metamodel.TaxonSummary in project collect by openforis.
the class TaxonSummaryProxy method fromList.
public static List<TaxonSummaryProxy> fromList(List<TaxonSummary> list) {
List<TaxonSummaryProxy> proxies = new ArrayList<TaxonSummaryProxy>();
if (list != null) {
for (TaxonSummary item : list) {
TaxonSummaryProxy proxy = new TaxonSummaryProxy(item);
proxies.add(proxy);
}
}
return proxies;
}
use of org.openforis.collect.metamodel.TaxonSummary in project collect by openforis.
the class SurveyManagerIntegrationTest method publishSurveyTaxonomyTest.
@Test
public void publishSurveyTaxonomyTest() throws SurveyImportException {
insertTestTaxonomy();
CollectSurvey temporarySurvey = surveyManager.createTemporarySurveyFromPublished(survey.getUri(), adminUser);
{
CollectTaxonomy taxonomy = speciesManager.loadTaxonomyByName(temporarySurvey, "tree");
assertNotNull(taxonomy);
TaxonSummaries summaries = speciesManager.loadFullTaxonSummariesOld(taxonomy);
assertEquals(1, summaries.getTotalCount());
List<TaxonSummary> taxonSummaryList = summaries.getItems();
{
TaxonSummary taxonSummary = taxonSummaryList.get(0);
assertEquals("Albizia glaberrima", taxonSummary.getScientificName());
List<String> vernacularLanguages = taxonSummary.getVernacularLanguages();
assertEquals(Arrays.asList("swh"), vernacularLanguages);
List<String> vernacularNames = taxonSummary.getVernacularNames("swh");
assertEquals(Arrays.asList("Mgerenge", "Mchani"), vernacularNames);
}
}
}
Aggregations