protected Task parseTask(Element taskElement) {
    String name = taskElement.elementText("name");
    String description = taskElement.elementText("description");

    Task task = new Task(name, description);

    String metadata = taskElement.elementText("metadata");

    task.setMetadata(metadata);

    Element actionsElement = taskElement.element("actions");

    parseActionsElement(actionsElement, task);

    Element assignmentsElement = taskElement.element("assignments");

    if (assignmentsElement != null) {
      Set<Assignment> assignments = parseAssignments(assignmentsElement);

      task.setAssignments(assignments);
    }

    Element timersElement = taskElement.element("task-timers");

    parseTaskTimerElements(timersElement, task);

    return task;
  }
  @Override
  protected void exportAdditionalNodeElements(Node node, Element nodeElement) {

    Task task = (Task) node;

    exportAssignmentsElement(task.getAssignments(), nodeElement, "assignments");

    exportTimersElement(task, nodeElement, "task-timers", "task-timer");
  }
  public KaleoTask addKaleoTask(
      long kaleoDefinitionId, long kaleoNodeId, Task task, ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Kaleo task

    User user = userPersistence.findByPrimaryKey(serviceContext.getGuestOrUserId());
    Date now = new Date();

    long kaleoTaskId = counterLocalService.increment();

    KaleoTask kaleoTask = kaleoTaskPersistence.create(kaleoTaskId);

    kaleoTask.setCompanyId(user.getCompanyId());
    kaleoTask.setUserId(user.getUserId());
    kaleoTask.setUserName(user.getFullName());
    kaleoTask.setCreateDate(now);
    kaleoTask.setModifiedDate(now);
    kaleoTask.setKaleoDefinitionId(kaleoDefinitionId);
    kaleoTask.setKaleoNodeId(kaleoNodeId);
    kaleoTask.setName(task.getName());

    kaleoTaskPersistence.update(kaleoTask, false);

    // Kaleo assignments

    Set<Assignment> assignments = task.getAssignments();

    for (Assignment assignment : assignments) {
      kaleoTaskAssignmentLocalService.addKaleoTaskAssignment(
          KaleoTask.class.getName(), kaleoTaskId, kaleoDefinitionId, assignment, serviceContext);
    }

    // Kaleo task forms

    Set<Form> forms = task.getForms();

    for (Form form : forms) {
      kaleoTaskFormLocalService.addKaleoTaskForm(
          kaleoDefinitionId, kaleoTaskId, form, serviceContext);
    }

    return kaleoTask;
  }