use of com.github.noraui.exception.data.EmptyDataFileContentException in project NoraUi by NoraUi.
the class RestDataProvider method initColumns.
private void initColumns() throws EmptyDataFileContentException {
final String url = this.norauiWebServicesApi + scenarioName + "/columns";
log.debug("initColumns with this url [{}]", url);
try {
String httpResponse = httpService.get(url);
if (!"".equals(httpResponse)) {
columns = new Gson().fromJson(httpResponse, DataModel.class).getColumns();
if (columns != null && !columns.isEmpty()) {
resultColumnName = Messages.getMessage(ResultColumnNames.RESULT_COLUMN_NAME);
columns.add(resultColumnName);
} else {
log.warn("No column could be returned at {}", url);
throw new EmptyDataFileContentException(Messages.getMessage(EmptyDataFileContentException.EMPTY_DATA_FILE_CONTENT_ERROR_MESSAGE));
}
} else {
log.warn("No column could be returned at {}", url);
throw new EmptyDataFileContentException(Messages.getMessage(EmptyDataFileContentException.EMPTY_DATA_FILE_CONTENT_ERROR_MESSAGE));
}
} catch (TechnicalException | NumberFormatException | HttpServiceException e) {
log.error("initColumns error", e);
}
}
use of com.github.noraui.exception.data.EmptyDataFileContentException 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.EmptyDataFileContentException 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