Search in sources :

Example 6 with TaxonTree

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;
}
Also used : TaxonOccurrence(org.openforis.idm.model.TaxonOccurrence) Taxon(org.openforis.idm.model.species.Taxon) ArrayList(java.util.ArrayList) TaxonTree(org.openforis.collect.model.TaxonTree)

Example 7 with TaxonTree

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();
}
Also used : Attribute(org.openforis.idm.metamodel.ReferenceDataSchema.ReferenceDataDefinition.Attribute) TaxonomyDefinition(org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition) TaxonTree(org.openforis.collect.model.TaxonTree)

Example 8 with TaxonTree

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);
    }
}
Also used : ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) TaxonomyDefinition(org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition) ParsingException(org.openforis.collect.io.exception.ParsingException) TaxonTree(org.openforis.collect.model.TaxonTree) SurveyStoreException(org.openforis.collect.persistence.SurveyStoreException) ParsingException(org.openforis.collect.io.exception.ParsingException) IOException(java.io.IOException)

Aggregations

TaxonTree (org.openforis.collect.model.TaxonTree)8 ArrayList (java.util.ArrayList)4 TaxonomyDefinition (org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition)4 Taxon (org.openforis.idm.model.species.Taxon)4 TaxonSummaries (org.openforis.collect.metamodel.TaxonSummaries)2 TaxonSummary (org.openforis.collect.metamodel.TaxonSummary)2 Node (org.openforis.collect.model.TaxonTree.Node)2 TaxonOccurrence (org.openforis.idm.model.TaxonOccurrence)2 TaxonVernacularName (org.openforis.idm.model.species.TaxonVernacularName)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ParsingException (org.openforis.collect.io.exception.ParsingException)1 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)1 CollectTaxonomy (org.openforis.collect.model.CollectTaxonomy)1 SurveyStoreException (org.openforis.collect.persistence.SurveyStoreException)1 Attribute (org.openforis.idm.metamodel.ReferenceDataSchema.ReferenceDataDefinition.Attribute)1