private void buildTable(TableBuilder.RowGroup rowGroup, TabularResultModel model) { TableBuilder.Row headerRow = rowGroup.newRow(); rowGroup.setColumnSeparator(" | "); rowGroup.newRowSeparator('-', false); Map<String, List<String>> rows = model.getContent(); if (!rows.isEmpty()) { // build table header first rows.keySet().forEach(c -> headerRow.newCenterCol(c)); // each row should have the same number of entries, so just look at the first one int rowCount = rows.values().iterator().next().size(); for (int i = 0; i < rowCount; i++) { TableBuilder.Row oneRow = rowGroup.newRow(); for (String column : rows.keySet()) { oneRow.newLeftCol(rows.get(column).get(i)); } } } }
private void buildComposite() { try { GfJsonObject content = getContent(); if (content != null) { Table resultTable = TableBuilder.newTable(); resultTable.setColumnSeparator(" : "); addHeaderInTable(resultTable, getGfJsonObject()); for (Iterator<String> it = content.keys(); it.hasNext();) { String key = it.next(); if (key.startsWith(ResultData.SECTION_DATA_ACCESSOR)) { GfJsonObject subSection = content.getJSONObject(key); buildSection(resultTable, null, subSection, 0); } else if (key.equals(CompositeResultData.SEPARATOR)) { String separatorString = content.getString(key); resultTable.newRowGroup().newRowSeparator(separatorString.charAt(0), true); } } addFooterInTable(resultTable, getGfJsonObject()); resultLines.addAll(resultTable.buildTableList()); } } catch (GfJsonException e) { resultLines .add("Error occurred while processing Command Result. Internal Error - Invalid Result."); logger.info( "Error occurred while processing Command Result. Internal Error - Invalid Result.", e); } finally { isDataBuilt = true; } }
} else if (key.equals(CompositeResultData.SEPARATOR)) { String separatorString = section.getString(key); rowGroup.newRowSeparator(separatorString.charAt(0), true); } else if (key.equals(ResultData.RESULT_HEADER) || key.equals(ResultData.RESULT_FOOTER)) {
private void buildTable(RowGroup rowGroup, GfJsonObject content) throws GfJsonException { GfJsonArray columnNames = content.names(); int numOfColumns = columnNames.size(); Row headerRow = rowGroup.newRow(); rowGroup.setColumnSeparator(" | "); rowGroup.newRowSeparator('-', false); // build Table Header first for (int i = 0; i < numOfColumns; i++) { Object object = columnNames.get(i); if (ResultData.BYTE_DATA_ACCESSOR.equals(object)) { // skip file data if any continue; } headerRow.newCenterCol(object); } // Build remaining rows by extracting data column-wise from JSON object Row[] dataRows = null; for (int i = 0; i < numOfColumns; i++) { Object object = columnNames.get(i); if (ResultData.BYTE_DATA_ACCESSOR.equals(object)) { // skip file data if any continue; } GfJsonArray accumulatedData = content.getJSONArray((String) object); dataRows = buildRows(rowGroup, dataRows, accumulatedData); } }