private void buildCommandOutput() { commandOutputIndex = 0; commandOutput = new ArrayList<>(); TableBuilder.Table resultTable = TableBuilder.newTable(); addSpacedRowInTable(resultTable, result.getHeader()); int index = 0; int sectionSize = result.getContent().size(); for (AbstractResultModel section : result.getContent().values()) { index++; if (section instanceof DataResultModel) { buildData(resultTable, (DataResultModel) section); } else if (section instanceof TabularResultModel) { buildTabularCommandOutput(resultTable, (TabularResultModel) section); } else if (section instanceof InfoResultModel) { buildInfoOrErrorCommandOutput(resultTable, (InfoResultModel) section); } else { throw new IllegalArgumentException( "Unable to process output for " + section.getClass().getName()); } // only add the spacer in between the sections. if (index < sectionSize) { addSpacedRowInTable(resultTable, LINE_SEPARATOR); } } addSpacedRowInTable(resultTable, result.getFooter()); commandOutput.addAll(resultTable.buildTableList()); }
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; } }
private void buildData() { try { if (ResultData.TYPE_COMPOSITE.equals(resultData.getType())) { buildComposite(); } else { GfJsonObject content = getContent(); if (content != null) { Table resultTable = TableBuilder.newTable(); addHeaderInTable(resultTable, getGfJsonObject()); RowGroup rowGroup = resultTable.newRowGroup(); if (ResultData.TYPE_TABULAR.equals(resultData.getType())) { resultTable.setColumnSeparator(" "); resultTable.setTabularResult(true); buildTable(rowGroup, content); } else { buildInfoErrorData(rowGroup, content); } addFooterInTable(resultTable, getGfJsonObject()); resultLines.addAll(resultTable.buildTableList()); } } } catch (GfJsonException e) { resultLines .add("Error occurred while processing Command Result. Internal Error - Invalid Result."); } finally { isDataBuilt = true; } }