}
@Override
public Promise<StartChildWorkflowReply> startChildWorkflow(final StartChildWorkflowExecutionParameters parameters) {
final OpenRequestInfo<StartChildWorkflowReply, WorkflowType> context = new OpenRequestInfo<StartChildWorkflowReply, WorkflowType>();
final StartChildWorkflowExecutionDecisionAttributes attributes = new StartChildWorkflowExecutionDecisionAttributes();
attributes.setWorkflowType(parameters.getWorkflowType());
String workflowId = parameters.getWorkflowId();
if (workflowId == null) {
workflowId = generateUniqueId();
}
attributes.setWorkflowId(workflowId);
attributes.setInput(parameters.getInput());
attributes.setExecutionStartToCloseTimeout(FlowHelpers.secondsToDuration(parameters.getExecutionStartToCloseTimeoutSeconds()));
attributes.setTaskStartToCloseTimeout(FlowHelpers.secondsToDuration(parameters.getTaskStartToCloseTimeoutSeconds()));
List<String> tagList = parameters.getTagList();
if (tagList != null) {
attributes.setTagList(tagList);
}
ChildPolicy childPolicy = parameters.getChildPolicy();
if (childPolicy != null) {
attributes.setChildPolicy(childPolicy);
}
String taskList = parameters.getTaskList();
if (taskList != null && !taskList.isEmpty()) {
attributes.setTaskList(new TaskList().withName(taskList));
}
String taskName = "workflowId=" + workflowId + ", workflowType=" + attributes.getWorkflowType();
new ExternalTask() {
@Override
protected ExternalTaskCancellationHandler doExecute(final ExternalTaskCompletionHandle handle) throws Throwable {
decisions.startChildWorkflowExecution(attributes);
context.setCompletionHandle(handle);
scheduledExternalWorkflows.put(attributes.getWorkflowId(), context);
return new ChildWorkflowCancellationHandler(attributes.getWorkflowId(), handle);
}
}.setName(taskName);
context.setResultDescription("startChildWorkflow " + taskName);
return context.getResult();
}