use of org.openforis.collect.model.TaxonTree in project collect by openforis.
the class SpeciesManager method findByFamilyCode.
public List<TaxonOccurrence> findByFamilyCode(CollectTaxonomy taxonomy, String searchString, int maxResults, TaxonSearchParameters parameters) {
List<TaxonOccurrence> result = new ArrayList<TaxonOccurrence>();
TaxonTree taxonTree = loadTaxonTree(taxonomy);
List<Taxon> families = taxonTree.findTaxaByCodeStartingWith(searchString, parameters.getHighestRank());
result.addAll(fromTaxonomiesToTaxonOccurrences(families, parameters));
for (Taxon familyTaxon : families) {
List<TaxonOccurrence> descendants = taxonTree.getDescendantOccurrences(familyTaxon, parameters);
result.addAll(descendants);
}
return result;
}
use of org.openforis.collect.model.TaxonTree in project collect by openforis.
the class SpeciesBackupImportTask method createInternalVariables.
@Override
protected void createInternalVariables() throws Throwable {
reader = new SpeciesBackupCSVReader(file);
reader.init();
List<String> infoColumnNames = reader.getInfoColumnNames();
List<ReferenceDataDefinition.Attribute> attributes = ReferenceDataDefinition.Attribute.fromNames(infoColumnNames);
TaxonomyDefinition taxonDefinition = new TaxonomyDefinition(taxonomyName);
taxonDefinition.setAttributes(attributes);
survey.getReferenceDataSchema().addTaxonomyDefinition(taxonDefinition);
taxonTree = new TaxonTree(taxonDefinition);
super.createInternalVariables();
}
use of org.openforis.collect.model.TaxonTree in project collect by openforis.
the class SpeciesImportProcess method parseTaxonCSVLines.
protected void parseTaxonCSVLines(File file) {
long currentRowNumber = 0;
try {
reader = new SpeciesCSVReader(file, csvFileOptions);
reader.init();
TaxonomyDefinition taxonomyDefinition = initializeTaxonomyDefinition();
taxonTree = new TaxonTree(taxonomyDefinition);
status.addProcessedRow(1);
currentRowNumber = 2;
while (status.isRunning()) {
try {
SpeciesLine line = reader.readNextLine();
if (line != null) {
lines.add(line);
}
if (!reader.isReady()) {
break;
}
} catch (ParsingException e) {
status.addParsingError(currentRowNumber, e.getError());
} finally {
currentRowNumber++;
}
}
status.setTotal(reader.getLinesRead() + 1);
} catch (ParsingException e) {
status.error();
status.addParsingError(1, e.getError());
} catch (Exception e) {
status.error();
status.addParsingError(currentRowNumber, new ParsingError(ErrorType.IOERROR, e.getMessage()));
LOG.error("Error importing species CSV file", e);
} finally {
IOUtils.closeQuietly(reader);
}
}
Aggregations