25
25
import io .temporal .common .CronSchedule ;
26
26
import io .temporal .common .MethodRetry ;
27
27
import io .temporal .common .RetryOptions ;
28
+ import io .temporal .common .SearchAttributes ;
28
29
import io .temporal .common .context .ContextPropagator ;
29
30
import io .temporal .internal .common .OptionsUtils ;
30
31
import io .temporal .worker .WorkerFactory ;
@@ -72,6 +73,7 @@ public static WorkflowOptions merge(
72
73
.setCronSchedule (OptionsUtils .merge (cronAnnotation , o .getCronSchedule (), String .class ))
73
74
.setMemo (o .getMemo ())
74
75
.setSearchAttributes (o .getSearchAttributes ())
76
+ .setTypedSearchAttributes (o .getTypedSearchAttributes ())
75
77
.setContextPropagators (o .getContextPropagators ())
76
78
.setDisableEagerExecution (o .isDisableEagerExecution ())
77
79
.validateBuildWithDefaults ();
@@ -99,6 +101,8 @@ public static final class Builder {
99
101
100
102
private Map <String , ?> searchAttributes ;
101
103
104
+ private SearchAttributes typedSearchAttributes ;
105
+
102
106
private List <ContextPropagator > contextPropagators ;
103
107
104
108
private boolean disableEagerExecution ;
@@ -119,6 +123,7 @@ private Builder(WorkflowOptions options) {
119
123
this .cronSchedule = options .cronSchedule ;
120
124
this .memo = options .memo ;
121
125
this .searchAttributes = options .searchAttributes ;
126
+ this .typedSearchAttributes = options .typedSearchAttributes ;
122
127
this .contextPropagators = options .contextPropagators ;
123
128
this .disableEagerExecution = options .disableEagerExecution ;
124
129
}
@@ -265,13 +270,40 @@ public Builder setMemo(Map<String, Object> memo) {
265
270
* <li>OffsetDateTime
266
271
* <li>{@link Collection} of the types above
267
272
* </ul>
273
+ *
274
+ * @deprecated use {@link #setTypedSearchAttributes} instead.
268
275
*/
269
276
// Workflow#upsertSearchAttributes docs needs to be kept in sync with this method
277
+ @ Deprecated
270
278
public Builder setSearchAttributes (Map <String , ?> searchAttributes ) {
279
+ if (searchAttributes != null
280
+ && !searchAttributes .isEmpty ()
281
+ && this .typedSearchAttributes != null ) {
282
+ throw new IllegalArgumentException (
283
+ "Cannot have search attributes and typed search attributes" );
284
+ }
271
285
this .searchAttributes = searchAttributes ;
272
286
return this ;
273
287
}
274
288
289
+ /**
290
+ * Specifies Search Attributes that will be attached to the Workflow. Search Attributes are
291
+ * additional indexed information attributed to workflow and used for search and visibility.
292
+ *
293
+ * <p>The search attributes can be used in query of List/Scan/Count workflow APIs. The key and
294
+ * its value type must be registered on Temporal server side.
295
+ */
296
+ public Builder setTypedSearchAttributes (SearchAttributes typedSearchAttributes ) {
297
+ if (typedSearchAttributes != null
298
+ && searchAttributes != null
299
+ && !searchAttributes .isEmpty ()) {
300
+ throw new IllegalArgumentException (
301
+ "Cannot have typed search attributes and search attributes" );
302
+ }
303
+ this .typedSearchAttributes = typedSearchAttributes ;
304
+ return this ;
305
+ }
306
+
275
307
/**
276
308
* This list of context propagators overrides the list specified on {@link
277
309
* WorkflowClientOptions#getContextPropagators()}. <br>
@@ -319,6 +351,7 @@ public WorkflowOptions build() {
319
351
cronSchedule ,
320
352
memo ,
321
353
searchAttributes ,
354
+ typedSearchAttributes ,
322
355
contextPropagators ,
323
356
disableEagerExecution );
324
357
}
@@ -338,6 +371,7 @@ public WorkflowOptions validateBuildWithDefaults() {
338
371
cronSchedule ,
339
372
memo ,
340
373
searchAttributes ,
374
+ typedSearchAttributes ,
341
375
contextPropagators ,
342
376
disableEagerExecution );
343
377
}
@@ -363,6 +397,8 @@ public WorkflowOptions validateBuildWithDefaults() {
363
397
364
398
private final Map <String , ?> searchAttributes ;
365
399
400
+ private final SearchAttributes typedSearchAttributes ;
401
+
366
402
private final List <ContextPropagator > contextPropagators ;
367
403
368
404
private final boolean disableEagerExecution ;
@@ -378,6 +414,7 @@ private WorkflowOptions(
378
414
String cronSchedule ,
379
415
Map <String , Object > memo ,
380
416
Map <String , ?> searchAttributes ,
417
+ SearchAttributes typedSearchAttributes ,
381
418
List <ContextPropagator > contextPropagators ,
382
419
boolean disableEagerExecution ) {
383
420
this .workflowId = workflowId ;
@@ -390,6 +427,7 @@ private WorkflowOptions(
390
427
this .cronSchedule = cronSchedule ;
391
428
this .memo = memo ;
392
429
this .searchAttributes = searchAttributes ;
430
+ this .typedSearchAttributes = typedSearchAttributes ;
393
431
this .contextPropagators = contextPropagators ;
394
432
this .disableEagerExecution = disableEagerExecution ;
395
433
}
@@ -430,10 +468,18 @@ public Map<String, Object> getMemo() {
430
468
return memo ;
431
469
}
432
470
471
+ /**
472
+ * @deprecated use {@link #getTypedSearchAttributes} instead.
473
+ */
474
+ @ Deprecated
433
475
public Map <String , ?> getSearchAttributes () {
434
476
return searchAttributes ;
435
477
}
436
478
479
+ public SearchAttributes getTypedSearchAttributes () {
480
+ return typedSearchAttributes ;
481
+ }
482
+
437
483
/**
438
484
* @return the list of context propagators to use during this workflow. This list overrides the
439
485
* list specified on {@link WorkflowClientOptions#getContextPropagators()}, {@code null} means
@@ -466,6 +512,7 @@ public boolean equals(Object o) {
466
512
&& Objects .equal (cronSchedule , that .cronSchedule )
467
513
&& Objects .equal (memo , that .memo )
468
514
&& Objects .equal (searchAttributes , that .searchAttributes )
515
+ && Objects .equal (typedSearchAttributes , that .typedSearchAttributes )
469
516
&& Objects .equal (contextPropagators , that .contextPropagators )
470
517
&& Objects .equal (disableEagerExecution , that .disableEagerExecution );
471
518
}
@@ -483,6 +530,7 @@ public int hashCode() {
483
530
cronSchedule ,
484
531
memo ,
485
532
searchAttributes ,
533
+ typedSearchAttributes ,
486
534
contextPropagators ,
487
535
disableEagerExecution );
488
536
}
@@ -513,6 +561,8 @@ public String toString() {
513
561
+ memo
514
562
+ ", searchAttributes="
515
563
+ searchAttributes
564
+ + ", typedSearchAttributes="
565
+ + typedSearchAttributes
516
566
+ ", contextPropagators="
517
567
+ contextPropagators
518
568
+ ", disableEagerExecution="
0 commit comments