use of org.openforis.idm.model.species.TaxonVernacularName in project collect by openforis.
the class SpeciesBackupImportTask method processVernacularNames.
protected void processVernacularNames(SpeciesBackupLine line, Taxon taxon) {
Map<String, List<String>> langToVernacularName = line.getLanguageToVernacularNames();
Set<String> vernacularLangCodes = langToVernacularName.keySet();
for (String langCode : vernacularLangCodes) {
List<String> vernacularNames = langToVernacularName.get(langCode);
for (String vernacularName : vernacularNames) {
TaxonVernacularName taxonVN = new TaxonVernacularName();
taxonVN.setLanguageCode(langCode);
taxonVN.setVernacularName(vernacularName);
taxonTree.addVernacularName(taxon, taxonVN);
}
}
}
use of org.openforis.idm.model.species.TaxonVernacularName 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.idm.model.species.TaxonVernacularName in project collect by openforis.
the class SpeciesManager method persistTaxonTreeNode.
protected void persistTaxonTreeNode(List<Taxon> taxonInsertBuffer, List<TaxonVernacularName> taxonVernacularNameInsertBuffer, CollectTaxonomy taxonomy, Node node) {
Taxon taxon = node.getTaxon();
taxon.setTaxonomyId(taxonomy.getId());
taxon.setStep(CONFIRMED_TAXON_STEP_NUMBER);
taxonInsertBuffer.add(taxon);
if (taxonInsertBuffer.size() > TAXON_INSERT_BUFFER_SIZE) {
flushTaxonInsertBuffer(taxonomy, taxonInsertBuffer);
}
List<TaxonVernacularName> vernacularNames = node.getVernacularNames();
for (TaxonVernacularName vernacularName : vernacularNames) {
taxonVernacularNameInsertBuffer.add(vernacularName);
if (taxonInsertBuffer.size() > TAXON_VERNACULAR_NAME_INSERT_BUFFER_SIZE) {
flushTaxonVernacularNameInsertBuffer(taxonVernacularNameInsertBuffer);
}
}
}
use of org.openforis.idm.model.species.TaxonVernacularName in project collect by openforis.
the class SpeciesManager method loadTaxonTree.
public TaxonTree loadTaxonTree(CollectTaxonomy taxonomy) {
TaxonTree tree = taxonTreeByTaxonomyIdCache.get(taxonomy.getId());
if (tree == null) {
String taxonomyName = taxonomy.getName();
TaxonomyDefinition taxonDefinition = taxonomy.getSurvey().getReferenceDataSchema().getTaxonomyDefinition(taxonomyName);
List<Taxon> taxons = taxonDao.loadTaxonsForTreeBuilding(taxonomy);
tree = new TaxonTree(taxonDefinition);
Map<Integer, Taxon> idToTaxon = new HashMap<Integer, Taxon>();
for (Taxon taxon : taxons) {
Integer systemId = taxon.getSystemId();
Integer parentId = taxon.getParentId();
Taxon parent = parentId == null ? null : idToTaxon.get(parentId);
Node newNode = tree.addNode(parent, taxon);
List<TaxonVernacularName> vernacularNames = taxonVernacularNameDao.findByTaxon(systemId);
tree.addVernacularNames(newNode, vernacularNames);
idToTaxon.put(systemId, taxon);
}
taxonTreeByTaxonomyIdCache.put(taxonomy.getId(), tree);
}
return tree;
}
use of org.openforis.idm.model.species.TaxonVernacularName in project collect by openforis.
the class SpeciesManager method includeUniqueVernacularNameIfAny.
private void includeUniqueVernacularNameIfAny(int taxonSystemId, TaxonOccurrence o) {
List<TaxonVernacularName> vernacularNames = taxonVernacularNameDao.findByTaxon(taxonSystemId);
if (vernacularNames.size() == 1) {
TaxonVernacularName vernacularName = vernacularNames.get(0);
o.setVernacularName(vernacularName.getVernacularName());
o.setLanguageCode(vernacularName.getLanguageCode());
o.setLanguageVariety(vernacularName.getLanguageVariety());
}
}
Aggregations