Search in sources :

Example 1 with ParsingException

use of org.openforis.collect.io.exception.ParsingException in project collect by openforis.

the class SamplingDesignImportProcess 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 2 with ParsingException

use of org.openforis.collect.io.exception.ParsingException in project collect by openforis.

the class SpeciesImportProcess method throwDuplicateRowParsingException.

protected void throwDuplicateRowParsingException(SpeciesLine line, SpeciesFileColumn column, Node foundNode) throws ParsingException {
    ParsingError error = new ParsingError(ErrorType.DUPLICATE_VALUE, line.getLineNumber(), column.getColumnName());
    error.setMessageArgs(new String[] { foundNode.getMetadata(LINE_NUMBER_TREE_NODE_METADATA).toString() });
    throw new ParsingException(error);
}
Also used : ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) ParsingException(org.openforis.collect.io.exception.ParsingException)

Example 3 with ParsingException

use of org.openforis.collect.io.exception.ParsingException in project collect by openforis.

the class SpeciesImportProcess method createTaxonGenus.

protected Taxon createTaxonGenus(SpeciesLine line) throws ParsingException {
    String genus = line.getGenus();
    if (genus == null) {
        ParsingError error = new ParsingError(ErrorType.INVALID_VALUE, line.getLineNumber(), SpeciesFileColumn.SCIENTIFIC_NAME.getColumnName(), INVALID_GENUS_NAME_ERROR_MESSAGE_KEY);
        throw new ParsingException(error);
    }
    Taxon taxonFamily = createTaxonFamily(line);
    String normalizedScientificName = StringUtils.join(genus, " ", GENUS_SUFFIX);
    return createTaxon(line, GENUS, taxonFamily, normalizedScientificName);
}
Also used : ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) ParsingException(org.openforis.collect.io.exception.ParsingException) Taxon(org.openforis.idm.model.species.Taxon)

Example 4 with ParsingException

use of org.openforis.collect.io.exception.ParsingException in project collect by openforis.

the class CSVDataImportProcess method processFile.

protected void processFile() {
    long currentRowNumber = 0;
    DataCSVReader reader = null;
    try {
        EntityDefinition parentEntityDefn = getParentEntityDefinition();
        reader = new DataCSVReader(file, parentEntityDefn);
        reader.init();
        status.addProcessedRow(1);
        status.setTotal(reader.size());
        currentRowNumber = 1;
        while (status.isRunning()) {
            currentRowNumber++;
            try {
                DataLine line = reader.readNextLine();
                if (line != null) {
                    processLine(line);
                }
                if (!reader.isReady()) {
                    // end of file reached
                    if (step != null) {
                        saveLastModifiedRecord();
                    }
                    break;
                }
            } catch (ParsingException e) {
                status.addParsingError(currentRowNumber, e.getError());
            }
        }
        if (status.hasErrors()) {
            status.error();
        } else if (status.isRunning()) {
            status.complete();
        }
    } 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 CSV file", e);
    } finally {
        close(reader);
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) ParsingException(org.openforis.collect.io.exception.ParsingException) ParsingException(org.openforis.collect.io.exception.ParsingException) RecordPersistenceException(org.openforis.collect.persistence.RecordPersistenceException) IOException(java.io.IOException)

Example 5 with ParsingException

use of org.openforis.collect.io.exception.ParsingException in project collect by openforis.

the class CSVDataImportReader method readNextLine.

public T readNextLine() throws ParsingException {
    try {
        currentCSVLine = csvReader.readNextLine();
        currentLine = parseCurrentLine();
        return currentLine;
    } catch (IOException e) {
        ParsingError error = new ParsingError(ErrorType.IOERROR, e.getMessage());
        throw new ParsingException(error);
    }
}
Also used : 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