use of io.temporal.api.common.v1.SearchAttributes in project sdk-java by temporalio.
the class SyncWorkflowContext method upsertSearchAttributes.
@Override
public void upsertSearchAttributes(Map<String, Object> searchAttributes) {
if (searchAttributes.isEmpty()) {
throw new IllegalArgumentException("Empty search attributes");
}
SearchAttributes attr = InternalUtils.convertMapToSearchAttributes(searchAttributes);
context.upsertSearchAttributes(attr);
}
use of io.temporal.api.common.v1.SearchAttributes in project sdk-java by temporalio.
the class SyncWorkflowContext method continueAsNew.
@Override
public void continueAsNew(ContinueAsNewInput input) {
ContinueAsNewWorkflowExecutionCommandAttributes.Builder attributes = ContinueAsNewWorkflowExecutionCommandAttributes.newBuilder();
String workflowType = input.getWorkflowType();
if (workflowType != null) {
attributes.setWorkflowType(WorkflowType.newBuilder().setName(workflowType));
}
@Nullable ContinueAsNewOptions options = input.getOptions();
if (options != null) {
if (options.getWorkflowRunTimeout() != null) {
attributes.setWorkflowRunTimeout(ProtobufTimeUtils.toProtoDuration(options.getWorkflowRunTimeout()));
}
if (options.getWorkflowTaskTimeout() != null) {
attributes.setWorkflowTaskTimeout(ProtobufTimeUtils.toProtoDuration(options.getWorkflowTaskTimeout()));
}
if (!options.getTaskQueue().isEmpty()) {
attributes.setTaskQueue(TaskQueue.newBuilder().setName(options.getTaskQueue()));
}
Map<String, Object> searchAttributes = options.getSearchAttributes();
if (searchAttributes != null) {
attributes.setSearchAttributes(SearchAttributes.newBuilder().putAllIndexedFields(intoPayloadMap(DataConverter.getDefaultInstance(), searchAttributes)));
}
Map<String, Object> memo = options.getMemo();
if (memo != null) {
attributes.setMemo(Memo.newBuilder().putAllFields(intoPayloadMap(getDataConverter(), memo)));
}
}
List<ContextPropagator> propagators = options != null && options.getContextPropagators() != null ? options.getContextPropagators() : this.contextPropagators;
io.temporal.api.common.v1.Header grpcHeader = toHeaderGrpc(input.getHeader(), extractContextsAndConvertToBytes(propagators));
attributes.setHeader(grpcHeader);
Optional<Payloads> payloads = getDataConverter().toPayloads(input.getArgs());
payloads.ifPresent(attributes::setInput);
context.continueAsNewOnCompletion(attributes.build());
WorkflowThread.exit(null);
}
use of io.temporal.api.common.v1.SearchAttributes in project sdk-java by temporalio.
the class SearchAttributesUtilTest method TestGetValueFromSearchAttributes.
@Test
public void TestGetValueFromSearchAttributes() {
assertEquals(null, SearchAttributesUtil.getValueFromSearchAttributes(null, "key", String.class));
assertEquals(null, SearchAttributesUtil.getValueFromSearchAttributes(SearchAttributes.getDefaultInstance(), "", String.class));
Map<String, Object> attr = new HashMap<>();
String stringVal = "keyword";
attr.put("CustomKeywordField", stringVal);
Integer intVal = 1;
attr.put("CustomIntField", intVal);
Double doubleVal = 1.0;
attr.put("CustomDoubleField", doubleVal);
Boolean boolVal = Boolean.TRUE;
attr.put("CustomBooleanField", boolVal);
SearchAttributes searchAttributes = InternalUtils.convertMapToSearchAttributes(attr);
assertEquals(stringVal, SearchAttributesUtil.getValueFromSearchAttributes(searchAttributes, "CustomKeywordField", String.class));
assertEquals(intVal, SearchAttributesUtil.getValueFromSearchAttributes(searchAttributes, "CustomIntField", Integer.class));
assertEquals(doubleVal, SearchAttributesUtil.getValueFromSearchAttributes(searchAttributes, "CustomDoubleField", Double.class));
assertEquals(boolVal, SearchAttributesUtil.getValueFromSearchAttributes(searchAttributes, "CustomBooleanField", Boolean.class));
}
use of io.temporal.api.common.v1.SearchAttributes in project sdk-java by temporalio.
the class SearchAttributesUtilTest method TestGetValueFromSearchAttributesRepeated.
@Test
public void TestGetValueFromSearchAttributesRepeated() {
Map<String, Object> attr = new HashMap<>();
String stringVal = "keyword";
attr.put("CustomKeywordField", stringVal);
SearchAttributes searchAttributes = InternalUtils.convertMapToSearchAttributes(attr);
assertEquals(stringVal, SearchAttributesUtil.getValueFromSearchAttributes(searchAttributes, "CustomKeywordField", String.class));
assertEquals(stringVal, SearchAttributesUtil.getValueFromSearchAttributes(searchAttributes, "CustomKeywordField", String.class));
}
use of io.temporal.api.common.v1.SearchAttributes in project sdk-java by temporalio.
the class InternalUtils method convertMapToSearchAttributes.
public static SearchAttributes convertMapToSearchAttributes(Map<String, Object> searchAttributes) {
DataConverter converter = DataConverter.getDefaultInstance();
Map<String, Payload> mapOfByteBuffer = new HashMap<>();
searchAttributes.forEach((key, value) -> mapOfByteBuffer.put(key, converter.toPayload(value).get()));
return SearchAttributes.newBuilder().putAllIndexedFields(mapOfByteBuffer).build();
}
Aggregations