2525import io .temporal .common .CronSchedule ;
2626import io .temporal .common .MethodRetry ;
2727import io .temporal .common .RetryOptions ;
28+ import io .temporal .common .SearchAttributes ;
2829import io .temporal .common .context .ContextPropagator ;
2930import io .temporal .internal .common .OptionsUtils ;
3031import io .temporal .worker .WorkerFactory ;
@@ -72,6 +73,7 @@ public static WorkflowOptions merge(
7273 .setCronSchedule (OptionsUtils .merge (cronAnnotation , o .getCronSchedule (), String .class ))
7374 .setMemo (o .getMemo ())
7475 .setSearchAttributes (o .getSearchAttributes ())
76+ .setTypedSearchAttributes (o .getTypedSearchAttributes ())
7577 .setContextPropagators (o .getContextPropagators ())
7678 .setDisableEagerExecution (o .isDisableEagerExecution ())
7779 .validateBuildWithDefaults ();
@@ -99,6 +101,8 @@ public static final class Builder {
99101
100102 private Map <String , ?> searchAttributes ;
101103
104+ private SearchAttributes typedSearchAttributes ;
105+
102106 private List <ContextPropagator > contextPropagators ;
103107
104108 private boolean disableEagerExecution ;
@@ -119,6 +123,7 @@ private Builder(WorkflowOptions options) {
119123 this .cronSchedule = options .cronSchedule ;
120124 this .memo = options .memo ;
121125 this .searchAttributes = options .searchAttributes ;
126+ this .typedSearchAttributes = options .typedSearchAttributes ;
122127 this .contextPropagators = options .contextPropagators ;
123128 this .disableEagerExecution = options .disableEagerExecution ;
124129 }
@@ -265,13 +270,40 @@ public Builder setMemo(Map<String, Object> memo) {
265270 * <li>OffsetDateTime
266271 * <li>{@link Collection} of the types above
267272 * </ul>
273+ *
274+ * @deprecated use {@link #setTypedSearchAttributes} instead.
268275 */
269276 // Workflow#upsertSearchAttributes docs needs to be kept in sync with this method
277+ @ Deprecated
270278 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+ }
271285 this .searchAttributes = searchAttributes ;
272286 return this ;
273287 }
274288
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+
275307 /**
276308 * This list of context propagators overrides the list specified on {@link
277309 * WorkflowClientOptions#getContextPropagators()}. <br>
@@ -319,6 +351,7 @@ public WorkflowOptions build() {
319351 cronSchedule ,
320352 memo ,
321353 searchAttributes ,
354+ typedSearchAttributes ,
322355 contextPropagators ,
323356 disableEagerExecution );
324357 }
@@ -338,6 +371,7 @@ public WorkflowOptions validateBuildWithDefaults() {
338371 cronSchedule ,
339372 memo ,
340373 searchAttributes ,
374+ typedSearchAttributes ,
341375 contextPropagators ,
342376 disableEagerExecution );
343377 }
@@ -363,6 +397,8 @@ public WorkflowOptions validateBuildWithDefaults() {
363397
364398 private final Map <String , ?> searchAttributes ;
365399
400+ private final SearchAttributes typedSearchAttributes ;
401+
366402 private final List <ContextPropagator > contextPropagators ;
367403
368404 private final boolean disableEagerExecution ;
@@ -378,6 +414,7 @@ private WorkflowOptions(
378414 String cronSchedule ,
379415 Map <String , Object > memo ,
380416 Map <String , ?> searchAttributes ,
417+ SearchAttributes typedSearchAttributes ,
381418 List <ContextPropagator > contextPropagators ,
382419 boolean disableEagerExecution ) {
383420 this .workflowId = workflowId ;
@@ -390,6 +427,7 @@ private WorkflowOptions(
390427 this .cronSchedule = cronSchedule ;
391428 this .memo = memo ;
392429 this .searchAttributes = searchAttributes ;
430+ this .typedSearchAttributes = typedSearchAttributes ;
393431 this .contextPropagators = contextPropagators ;
394432 this .disableEagerExecution = disableEagerExecution ;
395433 }
@@ -430,10 +468,18 @@ public Map<String, Object> getMemo() {
430468 return memo ;
431469 }
432470
471+ /**
472+ * @deprecated use {@link #getTypedSearchAttributes} instead.
473+ */
474+ @ Deprecated
433475 public Map <String , ?> getSearchAttributes () {
434476 return searchAttributes ;
435477 }
436478
479+ public SearchAttributes getTypedSearchAttributes () {
480+ return typedSearchAttributes ;
481+ }
482+
437483 /**
438484 * @return the list of context propagators to use during this workflow. This list overrides the
439485 * list specified on {@link WorkflowClientOptions#getContextPropagators()}, {@code null} means
@@ -466,6 +512,7 @@ public boolean equals(Object o) {
466512 && Objects .equal (cronSchedule , that .cronSchedule )
467513 && Objects .equal (memo , that .memo )
468514 && Objects .equal (searchAttributes , that .searchAttributes )
515+ && Objects .equal (typedSearchAttributes , that .typedSearchAttributes )
469516 && Objects .equal (contextPropagators , that .contextPropagators )
470517 && Objects .equal (disableEagerExecution , that .disableEagerExecution );
471518 }
@@ -483,6 +530,7 @@ public int hashCode() {
483530 cronSchedule ,
484531 memo ,
485532 searchAttributes ,
533+ typedSearchAttributes ,
486534 contextPropagators ,
487535 disableEagerExecution );
488536 }
@@ -513,6 +561,8 @@ public String toString() {
513561 + memo
514562 + ", searchAttributes="
515563 + searchAttributes
564+ + ", typedSearchAttributes="
565+ + typedSearchAttributes
516566 + ", contextPropagators="
517567 + contextPropagators
518568 + ", disableEagerExecution="
0 commit comments