use of org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition 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.metamodel.ReferenceDataSchema.TaxonomyDefinition in project collect by openforis.
the class SpeciesExportTask method extractInfoAttributeNames.
private List<String> extractInfoAttributeNames() {
List<String> colNames = new ArrayList<String>();
TaxonomyDefinition taxonReferenceDataSchema = survey.getReferenceDataSchema().getTaxonomyDefinition(taxonomyName);
List<Attribute> infoAttributes = taxonReferenceDataSchema.getAttributes();
for (Attribute infoAttribute : infoAttributes) {
colNames.add(infoAttribute.getName());
}
return colNames;
}
use of org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition 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.metamodel.ReferenceDataSchema.TaxonomyDefinition 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.metamodel.ReferenceDataSchema.TaxonomyDefinition in project collect by openforis.
the class SpeciesImportProcess method createTaxon.
protected Taxon createTaxon(SpeciesLine line, TaxonRank rank, Taxon parent, String normalizedScientificName) throws ParsingException {
boolean mostSpecificRank = line.getRank() == rank;
Taxon taxon = taxonTree.findTaxonByScientificName(normalizedScientificName);
boolean newTaxon = taxon == null;
if (newTaxon) {
taxon = new Taxon();
taxon.setTaxonRank(rank);
taxon.setScientificName(normalizedScientificName);
Node node = taxonTree.addNode(parent, taxon);
node.addMetadata(LINE_NUMBER_TREE_NODE_METADATA, line.getLineNumber());
node.addMetadata(RAW_SCIENTIFIC_NAME_TREE_NODE_METADATA, line.getRawScientificName());
} else if (mostSpecificRank) {
checkDuplicateScientificName(line, parent, normalizedScientificName);
}
if (mostSpecificRank) {
String code = line.getCode();
Integer taxonId = line.getTaxonId();
checkDuplicates(line, code, taxonId);
taxon.setCode(code);
taxon.setTaxonId(taxonId);
TaxonomyDefinition taxonDefinition = survey.getReferenceDataSchema().getTaxonomyDefinition(taxonomyName);
List<Attribute> taxonAttributes = taxonDefinition.getAttributes();
for (Attribute attribute : taxonAttributes) {
String value = line.getInfoAttribute(attribute.getName());
taxon.addInfoAttribute(value);
}
taxonTree.updateNodeInfo(taxon);
processVernacularNames(line, taxon);
}
return taxon;
}
Aggregations