Search in sources :

Example 1 with EmptyValueException

use of de.symeda.sormas.api.utils.EmptyValueException in project SORMAS-Project by hzi-braunschweig.

the class CountryImporter method importDataFromCsvLine.

@Override
protected ImportLineResult importDataFromCsvLine(String[] values, String[] entityClasses, String[] entityProperties, String[][] entityPropertyPaths, boolean firstLine) throws IOException, InvalidColumnException {
    if (values.length > entityProperties.length) {
        writeImportError(values, I18nProperties.getValidationError(Validations.importLineTooLong));
        return ImportLineResult.ERROR;
    }
    CountryDto newEntityDto = CountryDto.build();
    boolean iHasImportError = insertRowIntoData(values, entityClasses, entityPropertyPaths, false, (cellData) -> {
        try {
            if (!StringUtils.isEmpty(cellData.getValue())) {
                insertColumnEntryIntoData(newEntityDto, cellData.getValue(), cellData.getEntityPropertyPath());
            }
        } catch (ImportErrorException | InvalidColumnException e) {
            return e;
        }
        return null;
    });
    if (!iHasImportError) {
        try {
            FacadeProvider.getCountryFacade().save(newEntityDto, allowOverwrite);
            return ImportLineResult.SUCCESS;
        } catch (EmptyValueException e) {
            writeImportError(values, e.getMessage());
            return ImportLineResult.ERROR;
        } catch (ValidationRuntimeException e) {
            writeImportError(values, e.getMessage());
            return ImportLineResult.DUPLICATE;
        }
    } else {
        return ImportLineResult.ERROR;
    }
}
Also used : ImportErrorException(de.symeda.sormas.api.importexport.ImportErrorException) CountryDto(de.symeda.sormas.api.infrastructure.country.CountryDto) InvalidColumnException(de.symeda.sormas.api.importexport.InvalidColumnException) EmptyValueException(de.symeda.sormas.api.utils.EmptyValueException) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException)

Aggregations

ImportErrorException (de.symeda.sormas.api.importexport.ImportErrorException)1 InvalidColumnException (de.symeda.sormas.api.importexport.InvalidColumnException)1 CountryDto (de.symeda.sormas.api.infrastructure.country.CountryDto)1 EmptyValueException (de.symeda.sormas.api.utils.EmptyValueException)1 ValidationRuntimeException (de.symeda.sormas.api.utils.ValidationRuntimeException)1