All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.swak.excel.validation.BizRowDataValidator Maven / Gradle / Ivy

package com.swak.excel.validation;


import com.swak.common.exception.ExcelException;
import com.swak.common.validation.ValidationResult;
import com.swak.excel.enums.ExcelErrCode;

import java.util.List;
import java.util.Map;

public interface BizRowDataValidator {

    ValidationResult validate(List dataList);

    default boolean validate(List dataList, Map cellMap) {
        ValidationResult validResult = validate(dataList);
        int rowIndex = validResult.getRowIndex();
        if (!validResult.isSuccess()) {
            ValidationResult.ErrorMessage errorMessage = validResult.getErrorMessages().get(0);
            Integer columnIndex = cellMap.get(errorMessage.getPropertyName());
            if (columnIndex != null) {
                throw new ExcelException(ExcelErrCode.BIZ_ROW_COL_ERROR, new Object[]{errorMessage.getPropertyName(),
                        (rowIndex + 1), (columnIndex + 1), errorMessage.getMessage()});
            } else {
                throw new ExcelException(ExcelErrCode.BIZ_ROW_ERROR, new Object[]{errorMessage.getPropertyName(),
                        (rowIndex + 1), errorMessage.getMessage()});
            }
        }
        return true;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy