use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class CodeListImportProcessIntegrationTest method testDuplicateValues.
@Test
public void testDuplicateValues() throws Exception {
CodeList codeList = survey.createCodeList();
codeList.setName(TEST_CODE_LIST_NAME);
survey.addCodeList(codeList);
CodeListImportProcess process = importCSVFile(INVALID_TEST_CSV, codeList);
CodeListImportStatus status = process.getStatus();
assertTrue(status.isError());
List<ParsingError> errors = status.getErrors();
// different label
assertTrue(containsError(errors, 4, "region_label_en"));
assertTrue(containsError(errors, 4, "district_code"));
assertTrue(containsError(errors, 7, "district_code"));
}
use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class SpeciesImportProcessIntegrationTest method testErrorHandling.
@Test
public void testErrorHandling() throws Exception {
SpeciesImportProcess process = importCSVFile(INVALID_TEST_CSV);
SpeciesImportStatus status = process.getStatus();
List<ParsingError> errors = status.getErrors();
assertEquals(7, errors.size());
assertTrue(status.isRowProcessed(1));
assertTrue(status.isRowProcessed(2));
assertTrue(status.isRowProcessed(4));
assertTrue(status.isRowProcessed(5));
assertFalse(status.isRowProcessed(3));
assertFalse(status.isRowProcessed(6));
assertFalse(status.isRowProcessed(7));
assertFalse(status.isRowProcessed(8));
assertFalse(status.isRowProcessed(9));
assertFalse(status.isRowProcessed(10));
assertFalse(status.isRowProcessed(11));
// unexisting row
assertFalse(status.isRowProcessed(12));
assertTrue(containsError(errors, 3, SpeciesFileColumn.CODE, ErrorType.EMPTY));
assertTrue(containsError(errors, 6, SpeciesFileColumn.CODE, ErrorType.DUPLICATE_VALUE));
assertTrue(containsError(errors, 7, SpeciesFileColumn.FAMILY, ErrorType.EMPTY));
assertTrue(containsError(errors, 8, SpeciesFileColumn.NO, ErrorType.DUPLICATE_VALUE));
assertTrue(containsError(errors, 9, SpeciesFileColumn.SCIENTIFIC_NAME, ErrorType.DUPLICATE_VALUE));
assertTrue(containsError(errors, 10, SpeciesFileColumn.SCIENTIFIC_NAME, ErrorType.DUPLICATE_VALUE));
assertTrue(containsError(errors, 11, "swh", ErrorType.INVALID_VALUE));
}
use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class CodeListImportTask method addDuplicateCodeError.
private void addDuplicateCodeError(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.DUPLICATE_VALUE, lineNumber, column);
addParsingError(lineNumber, error);
}
use of org.openforis.collect.io.metadata.parsing.ParsingError 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.metadata.parsing.ParsingError in project collect by openforis.
the class CodeListImportTask method addEmptyCodeColumnError.
private 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);
addParsingError(lineNumber, error);
}
Aggregations