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

temporalio / sdk-java / #185

28 Aug 2023 02:02PM CUT coverage: 77.642% (-0.04%) from 77.685%
#185

push

github-actions

web-flow
Reconcile typed search attributes with schedules (#1848)

Reconcile typed search attributes with schedules

30 of 30 new or added lines in 6 files covered. (100.0%)

18579 of 23929 relevant lines covered (77.64%)

0.78 hits per line

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

76.92
/temporal-sdk/src/main/java/io/temporal/common/SearchAttributeKey.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.common;
22

23
import com.google.common.reflect.TypeToken;
24
import io.temporal.api.common.v1.Payload;
25
import io.temporal.api.enums.v1.IndexedValueType;
26
import java.lang.reflect.Type;
27
import java.time.OffsetDateTime;
28
import java.util.List;
29
import java.util.Objects;
30
import javax.annotation.Nonnull;
31

32
/** Representation of a typed search attribute key. */
33
public class SearchAttributeKey<T> implements Comparable<SearchAttributeKey<T>> {
34
  private static final Type KEYWORD_LIST_REFLECT_TYPE = new TypeToken<List<String>>() {}.getType();
1✔
35

36
  /** Create a search attribute key for a text attribute type. */
37
  public static SearchAttributeKey<String> forText(String name) {
38
    return new SearchAttributeKey<>(name, IndexedValueType.INDEXED_VALUE_TYPE_TEXT, String.class);
1✔
39
  }
40

41
  /** Create a search attribute key for a keyword attribute type. */
42
  public static SearchAttributeKey<String> forKeyword(String name) {
43
    return new SearchAttributeKey<>(
1✔
44
        name, IndexedValueType.INDEXED_VALUE_TYPE_KEYWORD, String.class);
45
  }
46

47
  /** Create a search attribute key for an int attribute type. */
48
  public static SearchAttributeKey<Long> forLong(String name) {
49
    return new SearchAttributeKey<>(name, IndexedValueType.INDEXED_VALUE_TYPE_INT, Long.class);
1✔
50
  }
51

52
  /** Create a search attribute key for a double attribute type. */
53
  public static SearchAttributeKey<Double> forDouble(String name) {
54
    return new SearchAttributeKey<>(name, IndexedValueType.INDEXED_VALUE_TYPE_DOUBLE, Double.class);
1✔
55
  }
56

57
  /** Create a search attribute key for a boolean attribute type. */
58
  public static SearchAttributeKey<Boolean> forBoolean(String name) {
59
    return new SearchAttributeKey<>(name, IndexedValueType.INDEXED_VALUE_TYPE_BOOL, Boolean.class);
1✔
60
  }
61

62
  /** Create a search attribute key for a datetime attribute type. */
63
  public static SearchAttributeKey<OffsetDateTime> forOffsetDateTime(String name) {
64
    return new SearchAttributeKey<>(
1✔
65
        name, IndexedValueType.INDEXED_VALUE_TYPE_DATETIME, OffsetDateTime.class);
66
  }
67

68
  /** Create a search attribute key for a keyword list attribute type. */
69
  public static SearchAttributeKey<List<String>> forKeywordList(String name) {
70
    return new SearchAttributeKey<>(
1✔
71
        name,
72
        IndexedValueType.INDEXED_VALUE_TYPE_KEYWORD_LIST,
73
        List.class,
74
        KEYWORD_LIST_REFLECT_TYPE);
75
  }
76

77
  /**
78
   * Create a search attribute key for an untyped attribute type.
79
   *
80
   * <p>This should only be used when the server can return untyped search attributes, for example,
81
   * when describing a schedule workflow action.
82
   */
83
  public static SearchAttributeKey<Payload> forUntyped(String name) {
84
    return new SearchAttributeKey<>(
×
85
        name, IndexedValueType.INDEXED_VALUE_TYPE_UNSPECIFIED, Payload.class);
86
  }
87

88
  private final String name;
89
  private final IndexedValueType valueType;
90
  private final Class<? super T> valueClass;
91
  private final Type valueReflectType;
92

93
  private SearchAttributeKey(String name, IndexedValueType valueType, Class<? super T> valueClass) {
94
    this(name, valueType, valueClass, valueClass);
1✔
95
  }
1✔
96

97
  private SearchAttributeKey(
98
      String name, IndexedValueType valueType, Class<? super T> valueClass, Type valueReflectType) {
1✔
99
    this.name = name;
1✔
100
    this.valueType = valueType;
1✔
101
    this.valueClass = valueClass;
1✔
102
    this.valueReflectType = valueReflectType;
1✔
103
  }
1✔
104

105
  /** Get the name of the search attribute. */
106
  public String getName() {
107
    return name;
1✔
108
  }
109

110
  /** Get the search attribute value type. */
111
  public IndexedValueType getValueType() {
112
    return valueType;
1✔
113
  }
114

115
  /** Get the class that the search attribute value will be. */
116
  public Class<? super T> getValueClass() {
117
    return valueClass;
1✔
118
  }
119

120
  /**
121
   * Get the reflect type that the search attribute will be. For all key types except keyword list,
122
   * this is the same as {@link #getValueType}.
123
   */
124
  public Type getValueReflectType() {
125
    return valueReflectType;
1✔
126
  }
127

128
  /** Create an update that sets a value for this key. */
129
  public SearchAttributeUpdate<T> valueSet(@Nonnull T value) {
130
    if (valueType == IndexedValueType.INDEXED_VALUE_TYPE_UNSPECIFIED) {
1✔
131
      throw new IllegalStateException("untyped keys should not be used in workflows");
×
132
    }
133
    return SearchAttributeUpdate.valueSet(this, value);
1✔
134
  }
135

136
  /** Create an update that unsets a value for this key. */
137
  public SearchAttributeUpdate<T> valueUnset() {
138
    if (valueType == IndexedValueType.INDEXED_VALUE_TYPE_UNSPECIFIED) {
1✔
139
      throw new IllegalStateException("untyped keys should not be used in workflows");
×
140
    }
141
    return SearchAttributeUpdate.valueUnset(this);
1✔
142
  }
143

144
  @Override
145
  public boolean equals(Object o) {
146
    if (this == o) return true;
×
147
    if (o == null || getClass() != o.getClass()) return false;
×
148
    SearchAttributeKey<?> that = (SearchAttributeKey<?>) o;
×
149
    return name.equals(that.name)
×
150
        && valueType == that.valueType
151
        && valueClass.equals(that.valueClass);
×
152
  }
153

154
  @Override
155
  public int hashCode() {
156
    return Objects.hash(name, valueType, valueClass);
×
157
  }
158

159
  @Override
160
  public int compareTo(SearchAttributeKey<T> o) {
161
    int c = name.compareTo(o.name);
1✔
162
    if (c == 0) {
1✔
163
      c = valueType.compareTo(o.valueType);
1✔
164
    }
165
    if (c == 0) {
1✔
166
      c = valueClass.getName().compareTo(o.valueClass.getName());
1✔
167
    }
168
    return c;
1✔
169
  }
170
}
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