Search in sources :

Example 41 with ParsingError

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

Example 42 with ParsingError

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

Example 43 with ParsingError

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

Example 44 with ParsingError

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

Example 45 with ParsingError

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);
    }
}
Also used : ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) TaxonomyDefinition(org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition) ParsingException(org.openforis.collect.io.exception.ParsingException) TaxonTree(org.openforis.collect.model.TaxonTree) SurveyStoreException(org.openforis.collect.persistence.SurveyStoreException) ParsingException(org.openforis.collect.io.exception.ParsingException) IOException(java.io.IOException)

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