@Override
  public void handleEvent(Event event) {
    EventContext eventContext = event.getContext();
    Serializable property =
        eventContext.getProperty(TaskService.TASK_INSTANCE_EVENT_PROPERTIES_KEY);
    if (property == null || !(property instanceof Task)) {
      // do nothing
      return;
    }
    Task task = (Task) property;

    Boolean validated =
        Boolean.valueOf(task.getVariable(TaskService.VariableName.validated.name()));

    String chain;
    if (validated) {
      chain = task.getVariable(OperationTaskVariableName.acceptOperationChain.name());
    } else {
      chain = task.getVariable(OperationTaskVariableName.rejectOperationChain.name());
    }

    if (!StringUtils.isEmpty(chain)) {
      try {
        // run the given operation
        AutomationService os = Framework.getService(AutomationService.class);
        OperationContext ctx = new OperationContext(eventContext.getCoreSession());
        if (eventContext instanceof DocumentEventContext) {
          ctx.setInput(((DocumentEventContext) eventContext).getSourceDocument());
          ctx.put(OperationTaskVariableName.taskDocument.name(), task.getDocument());
        }
        try {
          os.run(ctx, chain);
        } catch (InvalidChainException e) {
          log.error("Unknown chain: " + chain);
        }
      } catch (OperationException t) {
        log.error(t, t);
      }
    }
  }