use of org.openforis.collect.io.exception.ParsingException in project collect by openforis.
the class LineParser method newLineInstance.
protected T newLineInstance() throws ParsingException {
ParameterizedType type = (ParameterizedType) this.getClass().getGenericSuperclass();
Type[] actualTypeArguments = type.getActualTypeArguments();
@SuppressWarnings("unchecked") Class<T> lineType = (Class<T>) actualTypeArguments[0];
T line;
try {
line = lineType.newInstance();
} catch (Exception e) {
throw new ParsingException(e);
}
return line;
}
use of org.openforis.collect.io.exception.ParsingException in project collect by openforis.
the class SamplingDesignImportTask 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 CodeListImportTask method parseCSVLines.
private void parseCSVLines() {
long currentRowNumber = 0;
try {
CollectSurvey survey = (CollectSurvey) codeList.getSurvey();
List<String> languages = survey.getLanguages();
String defaultLanguage = survey.getDefaultLanguage();
File file = OpenForisIOUtils.copyToTempFile(inputStream);
reader = new CodeListCSVReader(file, csvFileOptions, languages, defaultLanguage);
reader.init();
levels = reader.getLevels();
addProcessedRow(1);
currentRowNumber = 2;
while (isRunning()) {
try {
CodeListLine line = reader.readNextLine();
if (line != null) {
CodeListItem currentParentItem = null;
List<String> levelCodes = line.getLevelCodes();
for (int levelIdx = 0; levelIdx < levelCodes.size(); levelIdx++) {
boolean lastLevel = levelIdx == levelCodes.size() - 1;
CodeListItem item = processLevel(currentParentItem, line, levelIdx, lastLevel);
currentParentItem = item;
}
addProcessedRow(currentRowNumber);
}
if (!reader.isReady()) {
break;
}
} catch (ParsingException e) {
addParsingError(currentRowNumber, e.getError());
} finally {
currentRowNumber++;
}
}
} catch (ParsingException e) {
changeStatus(Status.FAILED);
addParsingError(1, e.getError());
} catch (Exception e) {
changeStatus(Status.FAILED);
addParsingError(currentRowNumber, new ParsingError(ErrorType.IOERROR, e.toString()));
LOG.error("Error importing code list CSV file", e);
} finally {
IOUtils.closeQuietly(reader);
}
}
use of org.openforis.collect.io.exception.ParsingException in project collect by openforis.
the class CodeListImportProcess method parseCSVLines.
protected void parseCSVLines() {
long currentRowNumber = 0;
try {
CollectSurvey survey = (CollectSurvey) codeList.getSurvey();
List<String> languages = survey.getLanguages();
String defaultLanguage = survey.getDefaultLanguage();
reader = new CodeListCSVReader(file, csvFileOptions, languages, defaultLanguage);
reader.init();
levels = reader.getLevels();
status.addProcessedRow(1);
currentRowNumber = 2;
while (status.isRunning()) {
try {
CodeListLine line = reader.readNextLine();
if (line != null) {
CodeListItem currentParentItem = null;
List<String> levelCodes = line.getLevelCodes();
for (int levelIdx = 0; levelIdx < levelCodes.size(); levelIdx++) {
boolean lastLevel = levelIdx == levelCodes.size() - 1;
CodeListItem item = processLevel(currentParentItem, line, levelIdx, lastLevel);
currentParentItem = item;
}
status.addProcessedRow(currentRowNumber);
}
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.toString()));
LOG.error("Error importing species CSV file", e);
} finally {
IOUtils.closeQuietly(reader);
}
}
use of org.openforis.collect.io.exception.ParsingException 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