Search in sources :

Example 1 with RequestParseException

use of cern.modesti.request.upload.exception.RequestParseException in project modesti by jlsalmon.

the class RequestParserFactory method parseRequest.

/**
 * Parse the given Excel sheet as a {@link Request} instance.
 *
 * @param stream the Excel sheet input stream
 * @return the result of the parse operation
 */
public RequestParseResult parseRequest(InputStream stream) {
    Sheet sheet = getSheet(stream);
    Row header = sheet.getRow(0);
    String pluginId = header.getCell(0).getStringCellValue().trim();
    RequestParser parser = getPluginRequestParser(pluginId);
    if (parser == null) {
        throw new UnsupportedRequestException("No parser found for domain " + pluginId);
    }
    RequestParseResult result = parser.parseRequest(sheet);
    if (result.getRequest().getPoints().isEmpty()) {
        throw new RequestParseException("Sheet contains no data points");
    }
    return result;
}
Also used : RequestParseException(cern.modesti.request.upload.exception.RequestParseException) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) UnsupportedRequestException(cern.modesti.plugin.UnsupportedRequestException)

Aggregations

UnsupportedRequestException (cern.modesti.plugin.UnsupportedRequestException)1 RequestParseException (cern.modesti.request.upload.exception.RequestParseException)1 Row (org.apache.poi.ss.usermodel.Row)1 Sheet (org.apache.poi.ss.usermodel.Sheet)1