private void commands(
      final OperationCommand command,
      final Task task,
      final User user,
      final OrganizationalEntity targetEntity,
      OrganizationalEntity... entities) {

    final PeopleAssignments people = task.getPeopleAssignments();
    final InternalTaskData taskData = (InternalTaskData) task.getTaskData();

    if (command.getNewStatus() != null) {
      taskData.setStatus(command.getNewStatus());
    } else if (command.isSetToPreviousStatus()) {
      taskData.setStatus(taskData.getPreviousStatus());
    }

    if (command.isAddTargetEntityToPotentialOwners()
        && !people.getPotentialOwners().contains(targetEntity)) {
      people.getPotentialOwners().add(targetEntity);
    }

    if (command.isRemoveUserFromPotentialOwners()) {
      people.getPotentialOwners().remove(user);
    }

    if (command.isSetNewOwnerToUser()) {
      taskData.setActualOwner(user);
    }

    if (command.isSetNewOwnerToNull()) {
      taskData.setActualOwner(null);
    }

    if (command.getExec() != null) {
      switch (command.getExec()) {
        case Claim:
          {
            taskData.setActualOwner((User) targetEntity);
            // @TODO: Ical stuff
            // Task was reserved so owner should get icals
            //                    SendIcal.getInstance().sendIcalForTask(task,
            // service.getUserinfo());

            break;
          }
        case Nominate:
          {
            if (entities != null && entities.length > 0) {
              List<OrganizationalEntity> potentialOwners =
                  new ArrayList<OrganizationalEntity>(Arrays.asList(entities));
              ((InternalPeopleAssignments) task.getPeopleAssignments())
                  .setPotentialOwners(potentialOwners);
              assignOwnerAndStatus((InternalTaskData) task.getTaskData(), potentialOwners);
            }
            break;
          }
      }
    }
  }
  /**
   * This method will potentially assign the actual owner of this TaskData and set the status of the
   * data.
   * <li>If there is only 1 potential owner, and it is a <code>User</code>, that will become the
   *     actual owner of the TaskData and the status will be set to <code>Status.Reserved</code>.
   * <li>f there is only 1 potential owner, and it is a <code>Group</code>, no owner will be
   *     assigned and the status will be set to <code>Status.Ready</code>.
   * <li>If there are more than 1 potential owners, the status will be set to <code>Status.Ready
   *     </code>.
   * <li>otherwise, the task data will be unchanged
   *
   * @param taskdata - task data
   * @param potentialOwners - list of potential owners
   * @return current status of task data
   */
  public static Status assignOwnerAndStatus(
      InternalTaskData taskData, List<OrganizationalEntity> potentialOwners) {
    if (taskData.getStatus() != Status.Created) {
      throw new PermissionDeniedException("Can only assign task owner if status is Created!");
    }

    Status assignedStatus = null;

    if (potentialOwners.size() == 1) {
      // if there is a single potential owner, assign and set status to Reserved
      OrganizationalEntity potentialOwner = potentialOwners.get(0);
      // if there is a single potential user owner, assign and set status to Reserved
      if (potentialOwner instanceof User) {
        taskData.setActualOwner((User) potentialOwner);
        assignedStatus = Status.Reserved;
      }
      // If there is a group set as potentialOwners, set the status to Ready ??
      if (potentialOwner instanceof Group) {
        assignedStatus = Status.Ready;
      }
    } else if (potentialOwners.size() > 1) {
      // multiple potential owners, so set to Ready so one can claim.
      assignedStatus = Status.Ready;
    } else {
      // @TODO we have no potential owners
    }

    if (assignedStatus != null) {
      taskData.setStatus(assignedStatus);
    } else {
      // status wasn't assigned, so just return the currrent status
      assignedStatus = taskData.getStatus();
    }

    return assignedStatus;
  }