snippets/four-eyes-advanced/four-eyes-advanced-process-engine-plugin/src/main/java/org/camunda/bpm/examples/FourEyesExtensionsParseListener.java
private void addFourEyesTaskListener(ActivityImpl activity) {
    UserTaskActivityBehavior userTaskActivityBehavior = (UserTaskActivityBehavior) activity.getActivityBehavior();

    boolean listenerAlreadyExists = false;

    // check that the listener wasn't added in the XML explicitly
    List<TaskListener> existingListeners = userTaskActivityBehavior.getTaskDefinition().getTaskListeners().get("complete");
    for (TaskListener taskListener : existingListeners) {
      if (taskListener instanceof ClassDelegate &&
          ((ClassDelegate)taskListener).getClassName().equals(TaskCompletionListener.class.getName())) {
        listenerAlreadyExists = true;
        logger.info(TaskCompletionListener.class.getSimpleName() + " was already explicitly added to usertask in the bpmn xml.");
        break;
      }
    }

    if (!listenerAlreadyExists) {
      logger.info("Adding " + TaskCompletionListener.class.getSimpleName() + " implicitly to usertask.");
      ClassDelegate taskListener = new ClassDelegate(TaskCompletionListener.class, null);
      userTaskActivityBehavior.getTaskDefinition().addTaskListener("complete", taskListener);
    }

  }
private void addFourEyesTaskListener(ActivityImpl activity) {
    UserTaskActivityBehavior userTaskActivityBehavior = (UserTaskActivityBehavior) activity.getActivityBehavior();

    boolean listenerAlreadyExists = false;

    // check that the listener wasn't added in the XML explicitly
    List<TaskListener> existingListeners = userTaskActivityBehavior.getTaskDefinition().getTaskListeners().get("complete");
    for (TaskListener taskListener : existingListeners) {
      if (taskListener instanceof ClassDelegate &&
          ((ClassDelegate)taskListener).getClassName().equals(TaskCompletionListener.class.getName())) {
        listenerAlreadyExists = true;
        logger.info(TaskCompletionListener.class.getSimpleName() + " was already explicitly added to usertask in the bpmn xml.");
        break;
      }
    }

    if (!listenerAlreadyExists) {
      logger.info("Adding " + TaskCompletionListener.class.getSimpleName() + " implicitly to usertask.");
      ClassDelegate taskListener = new ClassDelegate(TaskCompletionListener.class, null);
      userTaskActivityBehavior.getTaskDefinition().addTaskListener("complete", taskListener);
    }

  }
Add TaskListener on "complete" event generically every time, so we don't
have to add it in the XML.