TaskResultImpl toTaskResult(TaskId taskId) {

    TaskResultImpl result =
        new TaskResultImpl(
            taskId,
            getSerializedValue(),
            getSerializedException(),
            getLogs(),
            getPropagatedVariables());

    result.setPreviewerClassName(getPreviewerClassName());
    FlowActionData actionData = getFlowAction();
    if (actionData != null) {
      FlowAction action = new FlowAction(actionData.getType());
      action.setDupNumber(actionData.getDupNumber());
      action.setTarget(actionData.getTarget());
      action.setTargetContinuation(actionData.getTargetContinuation());
      action.setTargetElse(actionData.getTargetElse());
      result.setAction(action);
    }

    return result;
  }
  static TaskResultData createTaskResultData(TaskData taskRuntimeData, TaskResultImpl result) {
    TaskResultData resultData = new TaskResultData();
    resultData.setTaskRuntimeData(taskRuntimeData);
    resultData.setLogs(result.getOutput());
    resultData.setPreviewerClassName(result.getPreviewerClassName());
    resultData.setPropagatedVariables(result.getPropagatedVariables());
    resultData.setSerializedException(result.getSerializedException());
    resultData.setSerializedValue(result.getSerializedValue());
    resultData.setResultTime(System.currentTimeMillis());

    FlowAction flowAction = result.getAction();
    if (flowAction != null) {
      FlowActionData actionData = new FlowActionData();
      actionData.setDupNumber(flowAction.getDupNumber());
      actionData.setTarget(flowAction.getTarget());
      actionData.setTargetContinuation(flowAction.getTargetContinuation());
      actionData.setTargetElse(flowAction.getTargetElse());
      actionData.setType(flowAction.getType());
      resultData.setFlowAction(actionData);
    }

    return resultData;
  }