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

temporalio / sdk-java / #201

16 Oct 2023 03:47PM UTC coverage: 77.389% (+0.02%) from 77.368%
#201

push

github-actions

web-flow
Apply data converter context in more places (#1896)

Add data converter context to memo, lastFailure and schedules

23 of 23 new or added lines in 5 files covered. (100.0%)

18718 of 24187 relevant lines covered (77.39%)

0.77 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/client/WorkflowExecutionMetadata.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.client;
22

23
import com.google.common.base.Preconditions;
24
import io.temporal.api.common.v1.Payload;
25
import io.temporal.api.common.v1.WorkflowExecution;
26
import io.temporal.api.enums.v1.WorkflowExecutionStatus;
27
import io.temporal.api.workflow.v1.WorkflowExecutionInfo;
28
import io.temporal.common.SearchAttributes;
29
import io.temporal.common.converter.DataConverter;
30
import io.temporal.internal.common.ProtobufTimeUtils;
31
import io.temporal.internal.common.SearchAttributesUtil;
32
import io.temporal.payload.context.WorkflowSerializationContext;
33
import java.lang.reflect.Type;
34
import java.time.Instant;
35
import java.util.Collections;
36
import java.util.List;
37
import java.util.Map;
38
import java.util.Objects;
39
import javax.annotation.Nonnull;
40
import javax.annotation.Nullable;
41

42
public class WorkflowExecutionMetadata {
43
  private final @Nonnull WorkflowExecutionInfo info;
44
  private final @Nonnull DataConverter dataConverter;
45

46
  WorkflowExecutionMetadata(
47
      @Nonnull WorkflowExecutionInfo info, @Nonnull DataConverter dataConverter) {
×
48
    this.info = Preconditions.checkNotNull(info, "info");
×
49
    this.dataConverter = Preconditions.checkNotNull(dataConverter, "dataConverter");
×
50
  }
×
51

52
  @Nonnull
53
  public WorkflowExecution getExecution() {
54
    return info.getExecution();
×
55
  }
56

57
  @Nonnull
58
  public String getWorkflowType() {
59
    return info.getType().getName();
×
60
  }
61

62
  @Nonnull
63
  public String getTaskQueue() {
64
    return info.getTaskQueue();
×
65
  }
66

67
  @Nonnull
68
  public Instant getStartTime() {
69
    return ProtobufTimeUtils.toJavaInstant(info.getStartTime());
×
70
  }
71

72
  @Nonnull
73
  public Instant getExecutionTime() {
74
    return ProtobufTimeUtils.toJavaInstant(info.getExecutionTime());
×
75
  }
76

77
  @Nullable
78
  public Instant getCloseTime() {
79
    return info.hasCloseTime() ? ProtobufTimeUtils.toJavaInstant(info.getCloseTime()) : null;
×
80
  }
81

82
  @Nonnull
83
  public WorkflowExecutionStatus getStatus() {
84
    return info.getStatus();
×
85
  }
86

87
  public long getHistoryLength() {
88
    return info.getHistoryLength();
×
89
  }
90

91
  @Nullable
92
  public String getParentNamespace() {
93
    return info.hasParentExecution() ? info.getParentNamespaceId() : null;
×
94
  }
95

96
  @Nullable
97
  public WorkflowExecution getParentExecution() {
98
    return info.hasParentExecution() ? info.getParentExecution() : null;
×
99
  }
100

101
  /**
102
   * @deprecated use {@link #getTypedSearchAttributes} instead.
103
   */
104
  @Deprecated
105
  @Nonnull
106
  public Map<String, List<?>> getSearchAttributes() {
107
    return Collections.unmodifiableMap(SearchAttributesUtil.decode(info.getSearchAttributes()));
×
108
  }
109

110
  /** Get search attributes as a typed set. */
111
  @Nonnull
112
  public SearchAttributes getTypedSearchAttributes() {
113
    return SearchAttributesUtil.decodeTyped(info.getSearchAttributes());
×
114
  }
115

116
  @Nullable
117
  public <T> Object getMemo(String key, Class<T> valueClass) {
118
    return getMemo(key, valueClass, valueClass);
×
119
  }
120

121
  @Nullable
122
  public <T> T getMemo(String key, Class<T> valueClass, Type genericType) {
123
    Payload memo = info.getMemo().getFieldsMap().get(key);
×
124
    if (memo == null) {
×
125
      return null;
×
126
    }
127
    return dataConverter
×
128
        .withContext(
×
129
            new WorkflowSerializationContext(
130
                info.getParentNamespaceId(), info.getExecution().getWorkflowId()))
×
131
        .fromPayload(memo, valueClass, genericType);
×
132
  }
133

134
  @Nonnull
135
  public WorkflowExecutionInfo getWorkflowExecutionInfo() {
136
    return info;
×
137
  }
138

139
  @Override
140
  public boolean equals(Object o) {
141
    if (this == o) return true;
×
142
    if (o == null || getClass() != o.getClass()) return false;
×
143
    WorkflowExecutionMetadata that = (WorkflowExecutionMetadata) o;
×
144
    return info.equals(that.info);
×
145
  }
146

147
  @Override
148
  public int hashCode() {
149
    return Objects.hash(info);
×
150
  }
151
}
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