use of org.openforis.collect.io.exception.ParsingException in project collect by openforis.
the class SamplingDesignImportProcess method throwDuplicateLineException.
protected void throwDuplicateLineException(SamplingDesignLine line, SamplingDesignLine duplicateLine, SamplingDesignFileColumn[] columns) throws ParsingException {
String[] colNames = new String[columns.length];
for (int i = 0; i < columns.length; i++) {
SamplingDesignFileColumn column = columns[i];
colNames[i] = column.getColumnName();
}
ParsingError error = new ParsingError(ErrorType.DUPLICATE_VALUE, line.getLineNumber(), colNames);
String duplicateLineNumber = Long.toString(duplicateLine.getLineNumber());
error.setMessageArgs(new String[] { duplicateLineNumber });
throw new ParsingException(error);
}
use of org.openforis.collect.io.exception.ParsingException in project collect by openforis.
the class SpeciesImportProcess method throwDuplicateRowParsingException.
protected void throwDuplicateRowParsingException(SpeciesLine line, SpeciesFileColumn column, Node foundNode) throws ParsingException {
ParsingError error = new ParsingError(ErrorType.DUPLICATE_VALUE, line.getLineNumber(), column.getColumnName());
error.setMessageArgs(new String[] { foundNode.getMetadata(LINE_NUMBER_TREE_NODE_METADATA).toString() });
throw new ParsingException(error);
}
use of org.openforis.collect.io.exception.ParsingException in project collect by openforis.
the class SpeciesImportProcess method createTaxonGenus.
protected Taxon createTaxonGenus(SpeciesLine line) throws ParsingException {
String genus = line.getGenus();
if (genus == null) {
ParsingError error = new ParsingError(ErrorType.INVALID_VALUE, line.getLineNumber(), SpeciesFileColumn.SCIENTIFIC_NAME.getColumnName(), INVALID_GENUS_NAME_ERROR_MESSAGE_KEY);
throw new ParsingException(error);
}
Taxon taxonFamily = createTaxonFamily(line);
String normalizedScientificName = StringUtils.join(genus, " ", GENUS_SUFFIX);
return createTaxon(line, GENUS, taxonFamily, normalizedScientificName);
}
use of org.openforis.collect.io.exception.ParsingException in project collect by openforis.
the class CSVDataImportProcess method processFile.
protected void processFile() {
long currentRowNumber = 0;
DataCSVReader reader = null;
try {
EntityDefinition parentEntityDefn = getParentEntityDefinition();
reader = new DataCSVReader(file, parentEntityDefn);
reader.init();
status.addProcessedRow(1);
status.setTotal(reader.size());
currentRowNumber = 1;
while (status.isRunning()) {
currentRowNumber++;
try {
DataLine line = reader.readNextLine();
if (line != null) {
processLine(line);
}
if (!reader.isReady()) {
// end of file reached
if (step != null) {
saveLastModifiedRecord();
}
break;
}
} catch (ParsingException e) {
status.addParsingError(currentRowNumber, e.getError());
}
}
if (status.hasErrors()) {
status.error();
} else if (status.isRunning()) {
status.complete();
}
} catch (ParsingException e) {
status.error();
status.addParsingError(1, e.getError());
} catch (Exception e) {
status.error();
status.addParsingError(currentRowNumber, new ParsingError(ErrorType.IOERROR, e.toString()));
LOG.error("Error importing CSV file", e);
} finally {
close(reader);
}
}
use of org.openforis.collect.io.exception.ParsingException in project collect by openforis.
the class CSVDataImportReader method readNextLine.
public T readNextLine() throws ParsingException {
try {
currentCSVLine = csvReader.readNextLine();
currentLine = parseCurrentLine();
return currentLine;
} catch (IOException e) {
ParsingError error = new ParsingError(ErrorType.IOERROR, e.getMessage());
throw new ParsingException(error);
}
}
Aggregations