Search in sources :

Example 6 with TaxonomyDefinition

use of org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition in project collect by openforis.

the class SpeciesImportProcess method initializeTaxonomyDefinition.

private TaxonomyDefinition initializeTaxonomyDefinition() {
    List<String> infoColumnNames = reader.getInfoColumnNames();
    TaxonomyDefinition taxonomyDefinition = new TaxonomyDefinition(taxonomyName);
    taxonomyDefinition.setAttributes(ReferenceDataDefinition.Attribute.fromNames(infoColumnNames));
    ReferenceDataSchema referenceDataSchema = survey.getReferenceDataSchema();
    referenceDataSchema.addTaxonomyDefinition(taxonomyDefinition);
    return taxonomyDefinition;
}
Also used : ReferenceDataSchema(org.openforis.idm.metamodel.ReferenceDataSchema) TaxonomyDefinition(org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition)

Example 7 with TaxonomyDefinition

use of org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition in project collect by openforis.

the class SpeciesBackupImportJobIntegrationTest method testSpeciesImport.

@Test
public void testSpeciesImport() throws Exception {
    SpeciesBackupImportJob job = importCSVFile(VALID_TEST_CSV);
    assertTrue(job.isCompleted());
    SpeciesBackupImportTask task = (SpeciesBackupImportTask) job.getTasks().get(0);
    assertTrue(task.getSkippedRows().isEmpty());
    TaxonomyDefinition taxonomyDef = survey.getReferenceDataSchema().getTaxonomyDefinition(TEST_TAXONOMY_NAME);
    assertEquals(Arrays.asList("info1", "info2"), taxonomyDef.getAttributeNames());
    {
        String code = "OLE/CAP/macrocarpa";
        TaxonOccurrence occurrence = findByCode(code);
        TaxonOccurrence expected = new TaxonOccurrence(code, "Olea capensis ssp. macrocarpa");
        expected.setInfoAttributes(Arrays.asList("info_value_1", "info_value_2"));
        expected.setTaxonRank(SUBSPECIES);
        assertEquals(expected, occurrence);
    }
    {
        String code = "ALB/ADI";
        TaxonOccurrence occurrence = findByCode(code);
        TaxonOccurrence expected = new TaxonOccurrence(code, "Albizia adianthifolia");
        expected.setInfoAttributes(Arrays.asList("info_value_3", null));
        expected.setTaxonRank(SPECIES);
        assertEquals(expected, occurrence);
    }
}
Also used : SpeciesBackupImportTask(org.openforis.collect.io.metadata.species.SpeciesBackupImportTask) TaxonOccurrence(org.openforis.idm.model.TaxonOccurrence) TaxonomyDefinition(org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition) SpeciesBackupImportJob(org.openforis.collect.io.metadata.species.SpeciesBackupImportJob) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 8 with TaxonomyDefinition

use of org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition 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 9 with TaxonomyDefinition

use of org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition 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

TaxonomyDefinition (org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition)9 TaxonTree (org.openforis.collect.model.TaxonTree)4 Taxon (org.openforis.idm.model.species.Taxon)4 Node (org.openforis.collect.model.TaxonTree.Node)3 Attribute (org.openforis.idm.metamodel.ReferenceDataSchema.ReferenceDataDefinition.Attribute)3 TaxonVernacularName (org.openforis.idm.model.species.TaxonVernacularName)3 ArrayList (java.util.ArrayList)2 CollectTaxonomy (org.openforis.collect.model.CollectTaxonomy)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)1 ParsingException (org.openforis.collect.io.exception.ParsingException)1 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)1 SpeciesBackupImportJob (org.openforis.collect.io.metadata.species.SpeciesBackupImportJob)1 SpeciesBackupImportTask (org.openforis.collect.io.metadata.species.SpeciesBackupImportTask)1 TaxonSummaries (org.openforis.collect.metamodel.TaxonSummaries)1 TaxonSummary (org.openforis.collect.metamodel.TaxonSummary)1 SurveyStoreException (org.openforis.collect.persistence.SurveyStoreException)1