• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

temporalio / sdk-java / #120

pending completion
#120

push

github-actions

web-flow
Rename sdk-features to features (#1599)

16189 of 20022 relevant lines covered (80.86%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/temporal-sdk/src/main/java/io/temporal/internal/common/HistoryProtoTextUtils.java
1
/*
2
 * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
3
 *
4
 * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
 *
6
 * Modifications copyright (C) 2017 Uber Technologies, Inc.
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this material except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *   http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20

21
package io.temporal.internal.common;
22

23
import com.google.protobuf.MessageOrBuilder;
24
import com.google.protobuf.TextFormat;
25
import io.temporal.api.history.v1.History;
26
import io.temporal.api.history.v1.HistoryEvent;
27

28
/** Converts history protos into human readable format */
29
public final class HistoryProtoTextUtils {
30

31
  private HistoryProtoTextUtils() {}
32

33
  public static String toProtoText(History history, boolean showWorkflowTasks) {
34
    TextFormat.Printer printer = TextFormat.printer();
×
35
    StringBuilder result = new StringBuilder();
×
36
    for (HistoryEvent event : history.getEventsList()) {
×
37
      if (!showWorkflowTasks
×
38
          && event.getEventType().name().startsWith("EVENT_TYPE_WORKFLOW_TASK")) {
×
39
        continue;
×
40
      }
41
      printEvent(printer, result, event);
×
42
      result.append("\n");
×
43
    }
×
44

45
    return result.toString();
×
46
  }
47

48
  private static void printEvent(
49
      TextFormat.Printer printer, StringBuilder result, HistoryEvent event) {
50
    event
×
51
        .getAllFields()
×
52
        .forEach(
×
53
            (d, v) -> {
54
              if (d.getName().endsWith("_attributes")) {
×
55
                result.append(d.getName()).append(" { \n");
×
56
                String printedAttributes = printEventAttributes(printer, (MessageOrBuilder) v);
×
57
                for (String attributeField : printedAttributes.split("\\n")) {
×
58
                  result.append("  ").append(attributeField).append('\n');
×
59
                }
60
                result.append("}");
×
61
              } else {
×
62
                result.append(printer.shortDebugString(d, v));
×
63
              }
64
              result.append("\n");
×
65
            });
×
66
  }
×
67

68
  private static String printEventAttributes(
69
      TextFormat.Printer printer, MessageOrBuilder attributesValue) {
70
    StringBuilder result = new StringBuilder();
×
71
    attributesValue
×
72
        .getAllFields()
×
73
        .forEach(
×
74
            (d, v) -> {
75
              String fieldName = d.getName();
×
76
              if (fieldName.equals("input")
×
77
                  || fieldName.equals("result")
×
78
                  || fieldName.equals("details")) {
×
79
                result.append(printer.printFieldToString(d, v));
×
80
              } else {
81
                result.append(printer.shortDebugString(d, v));
×
82
                result.append("\n");
×
83
              }
84
            });
×
85
    if (result.length() > 0 && result.charAt(result.length() - 1) == '\n') {
×
86
      // delete trailing \n
87
      result.deleteCharAt(result.length() - 1);
×
88
    }
89

90
    return result.toString();
×
91
  }
92
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc