Writing ExecutionListener in JavaScript/Groovy

Hi,

Can someone help me how to implement the below functionality in groovy & javascript?

public class ProcessInstanceChecker implements ExecutionListener {

  private final Logger log = LoggerFactory.getLogger(ProcessInstanceChecker.class.getName());

  @Override
  public void notify(DelegateExecution execution) throws Exception {
    log.info("ProcessInstanceChecker execution started...");
    long processCount = execution.getProcessEngineServices().getHistoryService().createHistoricProcessInstanceQuery()
        .processInstanceBusinessKey(execution.getBusinessKey()).active().count();
    if (processCount > 0) {
      throw new CamundaException("Process already exists for businessKey: " + execution.getBusinessKey());
    }
  }
}