private void addPostActionParametersToTaskContext(
      ActionEvent action, Integer actionIndex, TaskContext taskContext, Object object)
      throws TaskHandlerException {
    for (ActionParameter postActionParameter : action.getPostActionParameters()) {

      taskContext.addPostActionParameterObject(
          actionIndex.toString(), postActionParameter.getKey(), object, true);
    }
  }
  /**
   * Executes the action for the given task.
   *
   * @param task the task for which its action should be executed, not null
   * @param actionInformation the information about the action, not null
   * @param actionIndex the order of the task action
   * @param taskContext the context of the current task execution, not null
   * @param activityId the ID of the activity associated with this execution
   * @throws TaskHandlerException when the task couldn't be executed
   */
  public void execute(
      Task task,
      TaskActionInformation actionInformation,
      Integer actionIndex,
      TaskContext taskContext,
      long activityId)
      throws TaskHandlerException {
    LOGGER.info(
        "Executing task action: {} from task: {}", actionInformation.getName(), task.getName());
    KeyEvaluator keyEvaluator = new KeyEvaluator(taskContext);

    ActionEvent action = getActionEvent(actionInformation);
    Map<String, Object> parameters = createParameters(actionInformation, action, keyEvaluator);
    addTriggerParameters(task, action, parameters, taskContext.getTriggerParameters());

    LOGGER.debug(
        "Parameters created: {} for task action: {}", parameters.toString(), action.getName());
    if (action.hasService() && bundleContext != null) {
      if (callActionServiceMethod(action, actionIndex, parameters, taskContext)) {
        LOGGER.info(
            "Action: {} from task: {} was executed through an OSGi service call",
            actionInformation.getName(),
            task.getName());
        postExecutionHandler.handleActionExecuted(
            taskContext.getTriggerParameters(), taskContext.getMetadata(), activityId);
        return;
      }
      LOGGER.info("There is no service: {}", action.getServiceInterface());

      activityService.addWarning(
          task, "task.warning.serviceUnavailable", action.getServiceInterface());
    }
    if (!action.hasSubject()) {
      throw new TaskHandlerException(ACTION, "task.error.cantExecuteAction");
    } else {
      eventRelay.sendEventMessage(
          new MotechEvent(
              action.getSubject(),
              parameters,
              TasksEventCallbackService.TASKS_EVENT_CALLBACK_NAME,
              taskContext.getMetadata()));
      LOGGER.info("Event: {} was sent", action.getSubject());
    }
  }