use of com.github.noraui.exception.data.WrongDataFileFormatException in project NoraUi by NoraUi.
the class CsvDataProvider method initColumns.
private void initColumns() throws EmptyDataFileContentException, WrongDataFileFormatException, IOException {
columns = new ArrayList<>();
final CSVReader reader = openInputData();
final String[] headers = reader.readNext();
for (final String header : headers) {
if (!"".equals(header)) {
columns.add(header);
}
}
reader.close();
if (columns.size() < 2) {
throw new EmptyDataFileContentException(Messages.getMessage(EmptyDataFileContentException.EMPTY_DATA_FILE_CONTENT_ERROR_MESSAGE));
}
resultColumnName = columns.get(columns.size() - 1);
if (!isResultColumnNameAuthorized(resultColumnName)) {
throw new WrongDataFileFormatException(String.format(Messages.getMessage(WrongDataFileFormatException.WRONG_RESULT_COLUMN_NAME_ERROR_MESSAGE), ResultColumnNames.getAuthorizedNames()));
}
}
use of com.github.noraui.exception.data.WrongDataFileFormatException in project NoraUi by NoraUi.
the class ExcelDataProvider method initColumns.
/**
* @throws EmptyDataFileContentException
* if data is empty
* @throws WrongDataFileFormatException
* if data is wrong
*/
protected void initColumns() throws EmptyDataFileContentException, WrongDataFileFormatException {
columns = new ArrayList<>();
final Sheet sheet = workbook.getSheetAt(0);
final Row row = sheet.getRow(0);
Cell cell;
for (int i = 0; (cell = row.getCell(i)) != null; i++) {
columns.add(cell.getStringCellValue());
}
if (columns.size() < 2) {
throw new EmptyDataFileContentException(Messages.getMessage(EmptyDataFileContentException.EMPTY_DATA_FILE_CONTENT_ERROR_MESSAGE));
}
resultColumnName = columns.get(columns.size() - 1);
if (!isResultColumnNameAuthorized(resultColumnName)) {
throw new WrongDataFileFormatException(String.format(Messages.getMessage(WrongDataFileFormatException.WRONG_RESULT_COLUMN_NAME_ERROR_MESSAGE), ResultColumnNames.getAuthorizedNames()));
}
}
Aggregations