public String getDataAsTable()

in dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/MessageTableHelper.java [94:316]


    public String getDataAsTable(
            String exchangeId, String exchangePattern,
            JsonObject endpoint, JsonObject endpointService,
            JsonObject root, JsonObject cause) {

        List<TableRow> rows = new ArrayList<>();
        TableRow eRow;
        String tab0 = null;
        String tab0b = null;
        String tab1 = null;
        String tab1b = null;
        String tab2 = null;
        String tab3 = null;
        String tab4 = null;
        String tab5 = null;
        String tab6 = null;

        if (endpoint != null) {
            eRow = new TableRow("Endpoint", null, null, endpoint.getString("endpoint"));
            tab0 = AsciiTable.getTable(AsciiTable.NO_BORDERS, List.of(eRow), Arrays.asList(
                    new Column().dataAlign(HorizontalAlign.LEFT)
                            .minWidth(showExchangeProperties || showExchangeVariables ? 12 : 10).with(TableRow::kindAsString),
                    new Column().dataAlign(HorizontalAlign.LEFT).with(TableRow::valueAsString)));
        }
        if (endpointService != null) {
            eRow = new TableRow("Service", null, null, endpointService.getString("serviceUrl"));
            TableRow eRow2 = null;
            StringJoiner sj = new StringJoiner(", ");
            String protocol = endpointService.getString("serviceProtocol");
            if (protocol != null) {
                sj.add("protocol=" + protocol);
            }
            Map arr = endpointService.getMap("serviceMetadata");
            if (arr != null) {
                arr.forEach((k, v) -> sj.add(k + "=" + v));
            }
            if (sj.length() > 0) {
                String data = "(" + sj + ")";
                eRow2 = new TableRow(null, null, null, data);
            }
            tab0b = AsciiTable.getTable(AsciiTable.NO_BORDERS, eRow2 != null ? List.of(eRow, eRow2) : List.of(eRow),
                    Arrays.asList(
                            new Column().dataAlign(HorizontalAlign.LEFT)
                                    .minWidth(showExchangeProperties || showExchangeVariables ? 12 : 10)
                                    .with(TableRow::kindAsString),
                            new Column().dataAlign(HorizontalAlign.LEFT).with(TableRow::valueAsString)));
        }

        if (root != null) {
            if (exchangeId != null) {
                eRow = new TableRow("Exchange", root.getString("exchangeType"), exchangePattern, exchangeId);
                tab1 = AsciiTable.getTable(AsciiTable.NO_BORDERS, List.of(eRow), Arrays.asList(
                        new Column().dataAlign(HorizontalAlign.LEFT)
                                .minWidth(showExchangeProperties || showExchangeVariables ? 12 : 10)
                                .with(TableRow::kindAsString),
                        new Column().dataAlign(HorizontalAlign.LEFT).with(TableRow::typeAsString)));
                tab1b = AsciiTable.getTable(AsciiTable.NO_BORDERS, List.of(eRow), Arrays.asList(
                        new Column().dataAlign(HorizontalAlign.CENTER)
                                .minWidth(18).maxWidth(18).with(TableRow::mepAsKey),
                        new Column().dataAlign(HorizontalAlign.RIGHT)
                                .maxWidth(80).with(TableRow::exchangeIdAsValue)));
            }
            // exchange variables
            JsonArray arr = root.getCollection("exchangeVariables");
            if (arr != null) {
                for (Object o : arr) {
                    JsonObject jo = (JsonObject) o;
                    rows.add(new TableRow("Variable", jo.getString("type"), jo.getString("key"), jo.get("value")));
                }
            }
            // exchange properties
            arr = root.getCollection("exchangeProperties");
            if (arr != null) {
                for (Object o : arr) {
                    JsonObject jo = (JsonObject) o;
                    rows.add(new TableRow("Property", jo.getString("type"), jo.getString("key"), jo.get("value")));
                }
            }
            // internal exchange properties
            arr = root.getCollection("internalExchangeProperties");
            if (arr != null) {
                for (Object o : arr) {
                    JsonObject jo = (JsonObject) o;
                    rows.add(new TableRow("Property", jo.getString("type"), jo.getString("key"), jo.get("value")));
                }
            }
            if (!rows.isEmpty()) {
                tab2 = AsciiTable.getTable(AsciiTable.NO_BORDERS, rows, Arrays.asList(
                        new Column().dataAlign(HorizontalAlign.LEFT)
                                .minWidth(showExchangeProperties || showExchangeVariables ? 12 : 10)
                                .with(TableRow::kindAsString),
                        new Column().dataAlign(HorizontalAlign.LEFT)
                                .minWidth(25).maxWidth(50, OverflowBehaviour.CLIP_LEFT).with(TableRow::typeAsString),
                        new Column().dataAlign(HorizontalAlign.RIGHT)
                                .minWidth(25).maxWidth(40, OverflowBehaviour.NEWLINE).with(TableRow::keyAsString),
                        new Column().dataAlign(HorizontalAlign.LEFT)
                                .maxWidth(80, OverflowBehaviour.NEWLINE).with(TableRow::valueAsString)));
            }
            rows.clear();

            // message type before headers
            if (root.getString("messageType") != null) {
                TableRow msgRow = new TableRow("Message", root.getString("messageType"), null, null);
                tab3 = AsciiTable.getTable(AsciiTable.NO_BORDERS, List.of(msgRow), Arrays.asList(
                        new Column().dataAlign(HorizontalAlign.LEFT)
                                .minWidth(showExchangeProperties || showExchangeVariables ? 12 : 10)
                                .with(TableRow::kindAsString),
                        new Column().dataAlign(HorizontalAlign.LEFT).with(TableRow::typeAsString)));
            }
            arr = root.getCollection("headers");
            if (arr != null) {
                for (Object o : arr) {
                    JsonObject jo = (JsonObject) o;
                    String key = jo.getString("key");
                    Object value = jo.get("value");
                    if ("CamelMessageTimestamp".equals(key)) {
                        long val = jo.getLongOrDefault("value", 0);
                        if (val > 0) {
                            String df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(val);
                            String since = TimeUtils.printSince(val);
                            value = "(" + df + " / " + since + " ago)";
                            if (loggingColor) {
                                value = val + " " + Ansi.ansi().fgBrightDefault().a(Ansi.Attribute.INTENSITY_FAINT).a(value)
                                        .reset().toString();
                            } else {
                                value = val + " " + value;
                            }
                        }
                    }
                    rows.add(new TableRow("Header", jo.getString("type"), key, value));
                }
            }
            if (!rows.isEmpty()) {
                // headers
                tab4 = AsciiTable.getTable(AsciiTable.NO_BORDERS, rows, Arrays.asList(
                        new Column().dataAlign(HorizontalAlign.LEFT)
                                .minWidth(showExchangeProperties || showExchangeVariables ? 12 : 10)
                                .with(TableRow::kindAsString),
                        new Column().dataAlign(HorizontalAlign.LEFT)
                                .minWidth(25).maxWidth(50, OverflowBehaviour.CLIP_LEFT).with(TableRow::typeAsString),
                        new Column().dataAlign(HorizontalAlign.RIGHT)
                                .minWidth(25).maxWidth(40, OverflowBehaviour.NEWLINE).with(TableRow::keyAsString),
                        new Column().dataAlign(HorizontalAlign.LEFT)
                                .maxWidth(80, OverflowBehaviour.NEWLINE).with(TableRow::valueAsString)));
            }
            rows.clear();

            // body and type
            JsonObject jo = root.getMap("body");
            if (jo != null) {
                TableRow bodyRow = new TableRow(
                        "Body", jo.getString("type"), null, jo.get("value"), jo.getLong("size"), jo.getLong("position"));
                tab5 = AsciiTable.getTable(AsciiTable.NO_BORDERS, List.of(bodyRow), Arrays.asList(
                        new Column().dataAlign(HorizontalAlign.LEFT)
                                .minWidth(showExchangeProperties || showExchangeVariables ? 12 : 10)
                                .with(TableRow::kindAsString),
                        new Column().dataAlign(HorizontalAlign.LEFT).with(TableRow::typeAndLengthAsString)));
                // body value only (span)
                if (bodyRow.value != null) {
                    tab6 = AsciiTable.getTable(AsciiTable.NO_BORDERS, List.of(bodyRow), Collections.singletonList(
                            new Column().dataAlign(HorizontalAlign.LEFT).maxWidth(160, OverflowBehaviour.NEWLINE)
                                    .with(b -> pretty ? bodyRow.valueAsStringPretty() : bodyRow.valueAsString())));
                }
            }
        }

        String tab7 = null;
        if (cause != null) {
            eRow = new TableRow("Exception", cause.getString("type"), null, cause.get("message"));
            tab7 = AsciiTable.getTable(AsciiTable.NO_BORDERS, List.of(eRow), Arrays.asList(
                    new Column().dataAlign(HorizontalAlign.LEFT)
                            .minWidth(showExchangeProperties || showExchangeVariables ? 12 : 10)
                            .with(TableRow::kindAsStringRed),
                    new Column().dataAlign(HorizontalAlign.LEFT)
                            .maxWidth(40, OverflowBehaviour.CLIP_LEFT).with(TableRow::typeAsString),
                    new Column().dataAlign(HorizontalAlign.LEFT)
                            .maxWidth(80, OverflowBehaviour.NEWLINE).with(TableRow::valueAsStringRed)));
        }
        // stacktrace only (span)
        String tab8 = null;
        if (cause != null) {
            String value = cause.getString("stackTrace");
            if (value != null) {
                value = Jsoner.unescape(value);
                eRow = new TableRow("Stacktrace", null, null, value);
                tab8 = AsciiTable.getTable(AsciiTable.NO_BORDERS, List.of(eRow), Collections.singletonList(
                        new Column().dataAlign(HorizontalAlign.LEFT).maxWidth(160, OverflowBehaviour.NEWLINE)
                                .with(TableRow::valueAsStringRed)));
            }
        }
        String answer = "";
        if (tab0 != null && !tab0.isEmpty()) {
            answer = answer + tab0 + System.lineSeparator();
        }
        if (tab0b != null && !tab0b.isEmpty()) {
            answer = answer + tab0b + System.lineSeparator();
        }
        if (tab1 != null && tab1b != null && !tab1.isEmpty()) {
            answer = answer + tab1 + tab1b + System.lineSeparator();
        }
        if (tab2 != null && !tab2.isEmpty()) {
            answer = answer + tab2 + System.lineSeparator();
        }
        if (tab3 != null && !tab3.isEmpty()) {
            answer = answer + tab3 + System.lineSeparator();
        }
        if (tab4 != null && !tab4.isEmpty()) {
            answer = answer + tab4 + System.lineSeparator();
        }
        if (tab5 != null && !tab5.isEmpty()) {
            answer = answer + tab5 + System.lineSeparator();
        }
        if (tab6 != null && !tab6.isEmpty()) {
            answer = answer + tab6 + System.lineSeparator();
        }
        if (tab7 != null && !tab7.isEmpty()) {
            answer = answer + tab7 + System.lineSeparator();
        }
        if (tab8 != null && !tab8.isEmpty()) {
            answer = answer + tab8 + System.lineSeparator();
        }
        return answer;
    }