Search in sources :

Example 6 with ParsingException

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;
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ErrorType(org.openforis.collect.io.metadata.parsing.ParsingError.ErrorType) ParsingException(org.openforis.collect.io.exception.ParsingException) ParsingException(org.openforis.collect.io.exception.ParsingException)

Example 7 with ParsingException

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

Example 8 with ParsingException

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);
    }
}
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 9 with ParsingException

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);
    }
}
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 10 with ParsingException

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);
    }
}
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

ParsingException (org.openforis.collect.io.exception.ParsingException)11 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)9 IOException (java.io.IOException)4 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 CodeListItem (org.openforis.idm.metamodel.CodeListItem)2 Taxon (org.openforis.idm.model.species.Taxon)2 File (java.io.File)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 ErrorType (org.openforis.collect.io.metadata.parsing.ParsingError.ErrorType)1 CodeListCSVReader (org.openforis.collect.manager.codelistimport.CodeListCSVReader)1 CodeListLine (org.openforis.collect.manager.codelistimport.CodeListLine)1 TaxonTree (org.openforis.collect.model.TaxonTree)1 RecordPersistenceException (org.openforis.collect.persistence.RecordPersistenceException)1 SurveyStoreException (org.openforis.collect.persistence.SurveyStoreException)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 TaxonomyDefinition (org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition)1