package org.camunda.bpm.integrationtest.jobexecutor;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.cdi.BusinessProcess;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.camunda.bpm.engine.impl.context.Context;
import org.camunda.bpm.engine.impl.interceptor.CommandContext;
import org.camunda.bpm.engine.impl.persistence.entity.SignalEventSubscriptionEntity;

@Named
public class SendSignalDelegate implements JavaDelegate {

  @Inject
  private RuntimeService runtimeService;  

  @Inject
  private BusinessProcess businessProcess;   

  public void execute(DelegateExecution execution) throws Exception {
    businessProcess.setVariable("processName", "throwSignal-visited (was " + businessProcess.getVariable("processName")  + ")");

    String signalProcessInstanceId = (String) execution.getVariable("signalProcessInstanceId");      
    String executionId = runtimeService.createExecutionQuery().processInstanceId(signalProcessInstanceId).signalEventSubscriptionName("alert").singleResult().getId();      
    
    CommandContext commandContext = Context.getCommandContext();
    List<SignalEventSubscriptionEntity> findSignalEventSubscriptionsByEventName = commandContext
            .getEventSubscriptionManager()
            .findSignalEventSubscriptionsByNameAndExecution("alert", executionId);

    for (SignalEventSubscriptionEntity signalEventSubscriptionEntity : findSignalEventSubscriptionsByEventName) {
        signalEventSubscriptionEntity.eventReceived(null, true);
    }       
  }
}

@@ -504,22 +504,16 @@
 .entity.
-Signal
 EventSub
@@ -646,18 +646,16 @@
 Service;
-  
 %0A%0A  @Inj
@@ -700,19 +700,16 @@
 Process;
-   
 %0A%0A  publ
@@ -997,22 +997,16 @@
 nceId%22);
-      
 %0A    Str
@@ -1168,19 +1168,9 @@
 d();
-      %0A    
+%0A
 %0A   
@@ -1240,22 +1240,16 @@
    List%3C
-Signal
 EventSub
@@ -1458,22 +1458,16 @@
    for (
-Signal
 EventSub
@@ -1627,22 +1627,15 @@
 );%0A    %7D
-       
 %0A  %7D%0A%7D%0A

replace usage of SignalEventSubscriptionEntity