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;
}
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);
}
}
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();
}
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);
}
}
Aggregations