public XmlTask updateTask(
      T transaction, Handle<XmlTask> handle, XmlTask partialNewTask, Principal user)
      throws SQLException {
    if (user == null) {
      throw new AuthenticationNeededException("There is no user associated with this request");
    }
    // This needs to be a copy otherwise the cache will interfere with the changes
    XmlTask currentTask;
    {
      final XmlTask t = getTask(transaction, handle);
      if (t == null) {
        return null;
      }
      currentTask = new XmlTask(t);
    }
    for (XmlItem newItem : partialNewTask.getItems()) {
      if (newItem.getName() != null && newItem.getName().length() > 0) {
        XmlItem currentItem = currentTask.getItem(newItem.getName());
        if (currentItem != null) {
          currentItem.setValue(newItem.getValue());
        }
      }
    }
    // Store the data
    getTasks().set(transaction, handle, currentTask);
    transaction.commit(); // the actual state isn't stored anyway.
    // This may update the server.
    currentTask.setState(partialNewTask.getState(), user);

    return currentTask;
  }
 public Collection<XmlTask> getPendingTasks(T transaction, final Principal user) {
   final Iterable<XmlTask> tasks = getTasks().iterable(transaction);
   ArrayList<XmlTask> result = new ArrayList<>();
   for (XmlTask task : tasks) {
     if (!task.getState().isFinal()) {
       result.add(task);
     }
   }
   return result;
 }
 public boolean postTask(final T transaction, final XmlTask task) throws SQLException {
   // This must be handled as the response can get lost without the transaction failing.
   Handle<XmlTask> existingHandle =
       getTasks().containsRemoteHandle(transaction, task.getRemoteHandle());
   if (existingHandle != null) {
     task.setHandleValue(existingHandle.getHandleValue());
     return false; // no proper update
   }
   boolean result = getTasks().put(transaction, task) != null;
   task.setState(NodeInstanceState.Acknowledged, task.getOwner()); // Only now mark as acknowledged
   return result;
 }
 public NodeInstanceState finishTask(
     final T transaction, final Handle<XmlTask> taskHandle, final Principal user)
     throws SQLException {
   if (user == null) {
     throw new AuthenticationNeededException("There is no user associated with this request");
   }
   final XmlTask task = mTasks.get(transaction, taskHandle);
   task.setState(NodeInstanceState.Complete, user);
   if ((task.getState() == NodeInstanceState.Complete)
       || (task.getState() == NodeInstanceState.Failed)) {
     mTasks.remove(transaction, taskHandle);
   }
   return task.getState();
 }