@Override public String getValueFromContent(String key) { return getContent().get(key).toString(); }
@Override public List<String> getListFromContent(String key) { return getContent().getArrayValues(key); }
@Override public Map<String, String> getMapFromSection(String sectionID) { Map<String, String> result = new LinkedHashMap<>(); GfJsonObject obj = getContent().getJSONObject("__sections__-" + sectionID); Iterator<String> iter = obj.keys(); while (iter.hasNext()) { String key = iter.next(); result.put(key, obj.getString(key)); } return result; }
@Override public void saveIncomingFiles(String directory) throws IOException { // dump file data if any try { GfJsonObject content = getContent(); if (content != null) { GfJsonArray bytesArray = content.getJSONArray(ResultData.BYTE_DATA_ACCESSOR); AbstractResultData.readFileDataAndDump(bytesArray, directory); } else { throw new RuntimeException("No associated files to save .. "); } numTimesSaved = numTimesSaved + 1; } catch (DataFormatException | GfJsonException e) { throw new RuntimeException(e); } }
@Override public String getMessageFromContent() { List<String> messages; try { GfJsonArray jsonArray = getContent().getJSONArray("message"); if (jsonArray == null) { return ""; } messages = toList(jsonArray.getInternalJsonArray()); } catch (GfJsonException jex) { return ""; } return messages.stream().collect(Collectors.joining(". ")); }
@Override public boolean hasIncomingFiles() { GfJsonArray fileDataArray = null; try { GfJsonObject content = getContent(); if (content != null) { fileDataArray = content.getJSONArray(ResultData.BYTE_DATA_ACCESSOR); } } catch (GfJsonException e) { e.printStackTrace(); } return fileDataArray != null; }
/** * Tables can only occur within a section. Sections cannot be nested. */ private GfJsonObject getTableContent(String sectionId, String tableId) { GfJsonObject topLevelContent = getContent(); GfJsonObject sectionObject = topLevelContent; sectionObject = sectionObject.getJSONObject("__sections__-" + sectionId); if (sectionObject == null) { return topLevelContent; } GfJsonObject tableContent = sectionObject.getJSONObject("__tables__-" + tableId); if (tableContent == null) { return topLevelContent; } return tableContent.getJSONObject("content"); }
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; } }