Search in sources :

Example 1 with DataTableColumn

use of io.irontest.models.DataTableColumn in project irontest by zheng-wang.

the class UtilsDAO method getTestcaseDataTable.

/**
 * @param testcaseId
 * @param fetchFirstRowOnly if true, only the first data table row (if exists) will be fetched; if false, all rows will be fetched.
 * @return
 */
@Transaction
public DataTable getTestcaseDataTable(long testcaseId, boolean fetchFirstRowOnly) {
    DataTable dataTable = new DataTable();
    List<DataTableColumn> columns = dataTableColumnDAO().findByTestcaseId(testcaseId);
    // populate the data table rows Java model column by column
    List<LinkedHashMap<String, Object>> rows = new ArrayList<>();
    for (DataTableColumn column : columns) {
        List<DataTableCell> columnCells = dataTableCellDAO().findByColumnId(column.getId());
        for (DataTableCell columnCell : columnCells) {
            short rowSequence = columnCell.getRowSequence();
            if (rows.size() < rowSequence) {
                rows.add(new LinkedHashMap<String, Object>());
            }
            Object cellObject;
            if (columnCell.getValue() != null) {
                cellObject = columnCell.getValue();
            } else {
                cellObject = endpointDAO().findById(columnCell.getEndpointId());
            }
            rows.get(rowSequence - 1).put(column.getName(), cellObject);
            if (fetchFirstRowOnly && rows.size() == 1) {
                break;
            }
        }
    }
    if (columns.size() > 0) {
        dataTable = new DataTable();
        dataTable.setColumns(columns);
        dataTable.setRows(rows);
    }
    return dataTable;
}
Also used : DataTableCell(io.irontest.models.DataTableCell) DataTable(io.irontest.models.DataTable) DataTableColumn(io.irontest.models.DataTableColumn) ArrayList(java.util.ArrayList) CreateSqlObject(org.skife.jdbi.v2.sqlobject.CreateSqlObject) LinkedHashMap(java.util.LinkedHashMap) Transaction(org.skife.jdbi.v2.sqlobject.Transaction)

Example 2 with DataTableColumn

use of io.irontest.models.DataTableColumn in project irontest by zheng-wang.

the class DataTableColumnMapper method map.

public DataTableColumn map(int index, ResultSet rs, StatementContext ctx) throws SQLException {
    DataTableColumn result = new DataTableColumn();
    result.setId(rs.getLong("id"));
    result.setName(rs.getString("name"));
    result.setType(DataTableColumnType.getByText(rs.getString("type")));
    return result;
}
Also used : DataTableColumn(io.irontest.models.DataTableColumn)

Aggregations

DataTableColumn (io.irontest.models.DataTableColumn)2 DataTable (io.irontest.models.DataTable)1 DataTableCell (io.irontest.models.DataTableCell)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 CreateSqlObject (org.skife.jdbi.v2.sqlobject.CreateSqlObject)1 Transaction (org.skife.jdbi.v2.sqlobject.Transaction)1