@Override
  public void onApplicationEvent (PiperEvent aEvent) {
    if(aEvent.getType().equals(Events.JOB_STATUS)) {
      
      String jobId = aEvent.getRequiredString("jobId");
      JobStatus status = JobStatus.valueOf(aEvent.getRequiredString("status"));
      Job job = jobRepository.getById(jobId);
      
      if(job.getParentTaskExecutionId() == null) {
        return; // not a subflow -- nothing to do
      }
      
      switch(status) {
        case CREATED:
        case STARTED:
          break;
        case STOPPED: {
          TaskExecution subflowTask = taskExecutionRepository.findOne(job.getParentTaskExecutionId());
          coordinator.stop(subflowTask.getJobId());
          break;
        }
        case FAILED: {
          SimpleTaskExecution errorable = SimpleTaskExecution.of(taskExecutionRepository.findOne(job.getParentTaskExecutionId()));
          errorable.setError(new ErrorObject("An error occured with subflow",new String[0]));
          coordinator.handleError(errorable);
          break;
        }
        case COMPLETED:{
          SimpleTaskExecution completion = SimpleTaskExecution.of(taskExecutionRepository.findOne(job.getParentTaskExecutionId()));
          Object output = job.getOutputs();
          if(completion.getOutput() != null) {
            TaskExecution evaluated = taskEvaluator.evaluate(completion, new MapContext ("execution", new MapContext("output", output)));
            completion = SimpleTaskExecution.of(evaluated);
          }
          else {
            completion.setOutput(output);
          }
          coordinator.complete(completion);
          break;
        }
        default:
          throw new IllegalStateException("Unnown status: " + status);
      }
    }
  }
an {@link EventListener} which is used for listening to subflow
job status events. When a sub-flow completes/fails or stops its
parent job and its parent task needs to be informed so as to
resume its execution.

@author Arik Cohen
@since Sep 06, 2018
@see SubflowTaskDispatcher
src/main/java/com/creactiviti/piper/core/task/SubflowJobStatusEventListener.java