code: @VisibleForTesting
      TaskDef getDynamicTaskDefinition(WorkflowTask taskToSchedule) throws TerminateWorkflowException { //TODO this is a common pattern in code base can be moved to DAO
          return Optional.ofNullable(taskToSchedule.getTaskDefinition())
                  .orElseGet(() -> Optional.ofNullable(metadataDAO.getTaskDef(taskToSchedule.getName()))
                          .orElseThrow(() -> {
                              String reason = String.format("Invalid task specified.  Cannot find task by name %s in the task definitions",
                                      taskToSchedule.getName());
                              return new TerminateWorkflowException(reason);
                          }));
      }
docs: This method gets the TaskDefinition for a specific {@link WorkflowTask}
  
  @param taskToSchedule: An instance of {@link WorkflowTask} which has the name of the using which the {@link TaskDef} can be retrieved.
  @return An instance of TaskDefinition
  @throws TerminateWorkflowException : in case of no workflow definition available