Search in sources :

Example 1 with EmptyDataFileContentException

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);
    }
}
Also used : HttpServiceException(com.github.noraui.exception.HttpServiceException) TechnicalException(com.github.noraui.exception.TechnicalException) Gson(com.google.gson.Gson) EmptyDataFileContentException(com.github.noraui.exception.data.EmptyDataFileContentException)

Example 2 with EmptyDataFileContentException

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()));
    }
}
Also used : CSVReader(com.opencsv.CSVReader) WrongDataFileFormatException(com.github.noraui.exception.data.WrongDataFileFormatException) EmptyDataFileContentException(com.github.noraui.exception.data.EmptyDataFileContentException)

Example 3 with EmptyDataFileContentException

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()));
    }
}
Also used : WrongDataFileFormatException(com.github.noraui.exception.data.WrongDataFileFormatException) EmptyDataFileContentException(com.github.noraui.exception.data.EmptyDataFileContentException) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell)

Aggregations

EmptyDataFileContentException (com.github.noraui.exception.data.EmptyDataFileContentException)3 WrongDataFileFormatException (com.github.noraui.exception.data.WrongDataFileFormatException)2 HttpServiceException (com.github.noraui.exception.HttpServiceException)1 TechnicalException (com.github.noraui.exception.TechnicalException)1 Gson (com.google.gson.Gson)1 CSVReader (com.opencsv.CSVReader)1 Cell (org.apache.poi.ss.usermodel.Cell)1 Row (org.apache.poi.ss.usermodel.Row)1 Sheet (org.apache.poi.ss.usermodel.Sheet)1