Search in sources :

Example 36 with ParsingError

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"));
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) CodeListImportStatus(org.openforis.collect.manager.codelistimport.CodeListImportStatus) CodeListImportProcess(org.openforis.collect.manager.codelistimport.CodeListImportProcess) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 37 with ParsingError

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));
}
Also used : ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) SpeciesImportProcess(org.openforis.collect.manager.speciesimport.SpeciesImportProcess) SpeciesImportStatus(org.openforis.collect.manager.speciesimport.SpeciesImportStatus) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 38 with ParsingError

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);
}
Also used : ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError)

Example 39 with ParsingError

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);
    }
}
Also used : CodeListCSVReader(org.openforis.collect.manager.codelistimport.CodeListCSVReader) ParsingException(org.openforis.collect.io.exception.ParsingException) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) ParsingException(org.openforis.collect.io.exception.ParsingException) CollectSurvey(org.openforis.collect.model.CollectSurvey) CodeListLine(org.openforis.collect.manager.codelistimport.CodeListLine) CodeListItem(org.openforis.idm.metamodel.CodeListItem) File(java.io.File)

Example 40 with ParsingError

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);
}
Also used : ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError)

Aggregations

ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)46 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)19 Test (org.junit.Test)17 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)17 CollectRecord (org.openforis.collect.model.CollectRecord)12 ParsingException (org.openforis.collect.io.exception.ParsingException)9 Entity (org.openforis.idm.model.Entity)9 CollectSurvey (org.openforis.collect.model.CollectSurvey)5 RealAttribute (org.openforis.idm.model.RealAttribute)5 DataParsingError (org.openforis.collect.io.data.CSVDataImportJob.DataParsingError)4 RealValue (org.openforis.idm.model.RealValue)4 IOException (java.io.IOException)3 NodeChangeSet (org.openforis.collect.model.NodeChangeSet)3 Survey (org.openforis.idm.metamodel.Survey)3 ArrayList (java.util.ArrayList)2 SpeciesImportProcess (org.openforis.collect.manager.speciesimport.SpeciesImportProcess)2 SpeciesImportStatus (org.openforis.collect.manager.speciesimport.SpeciesImportStatus)2 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)2 CodeListItem (org.openforis.idm.metamodel.CodeListItem)2 SpatialReferenceSystem (org.openforis.idm.metamodel.SpatialReferenceSystem)2