use of org.openforis.collect.io.metadata.parsing.ParsingError 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.metadata.parsing.ParsingError in project collect by openforis.
the class CodeListImportProcess method addDifferentLabelError.
protected void addDifferentLabelError(CodeListLine line, int levelIdx, String lang) {
String level = levels.get(levelIdx);
String column = level + CodeListCSVReader.LABEL_COLUMN_SUFFIX + "_" + lang;
long lineNumber = line.getLineNumber();
ParsingError error = new ParsingError(ErrorType.INVALID_VALUE, lineNumber, column, DIFFERENT_LABEL_MESSAGE_KEY);
status.addParsingError(lineNumber, error);
}
use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class CodeListImportProcess method addMissingDefaultLanguageLabelError.
protected void addMissingDefaultLanguageLabelError(CodeListLine line, int levelIdx) {
String level = levels.get(levelIdx);
String column = level + CodeListCSVReader.LABEL_COLUMN_SUFFIX;
long lineNumber = line.getLineNumber();
ParsingError error = new ParsingError(ErrorType.EMPTY, lineNumber, column);
status.addParsingError(lineNumber, error);
}
use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class CodeListImportProcess method addEmptyCodeColumnError.
protected void addEmptyCodeColumnError(CodeListLine line, int levelIdx) {
String level = levels.get(levelIdx);
String column = level + CodeListCSVReader.CODE_COLUMN_SUFFIX;
long lineNumber = line.getLineNumber();
ParsingError error = new ParsingError(ErrorType.EMPTY, lineNumber, column);
status.addParsingError(lineNumber, error);
}
use of org.openforis.collect.io.metadata.parsing.ParsingError 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