use of org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity in project camunda-bpm-platform by camunda.
the class TransactionSubProcessTest method testSimpleCaseTxSuccessful.
@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/subprocess/transaction/TransactionSubProcessTest.testSimpleCase.bpmn20.xml" })
public void testSimpleCaseTxSuccessful() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("transactionProcess");
// after the process is started, we have compensate event subscriptions:
assertEquals(5, runtimeService.createEventSubscriptionQuery().eventType("compensate").activityId("undoBookHotel").count());
assertEquals(1, runtimeService.createEventSubscriptionQuery().eventType("compensate").activityId("undoBookFlight").count());
// the task is present:
Task task = taskService.createTaskQuery().singleResult();
assertNotNull(task);
// making the tx succeed:
taskService.setVariable(task.getId(), "confirmed", true);
taskService.complete(task.getId());
// now the process instance execution is sitting in the 'afterSuccess' task
// -> has left the transaction using the "normal" sequence flow
List<String> activeActivityIds = runtimeService.getActiveActivityIds(processInstance.getId());
assertTrue(activeActivityIds.contains("afterSuccess"));
// there is a compensate event subscription for the transaction under the process instance
EventSubscriptionEntity eventSubscriptionEntity = (EventSubscriptionEntity) runtimeService.createEventSubscriptionQuery().eventType("compensate").activityId("tx").executionId(processInstance.getId()).singleResult();
// there is an event-scope execution associated with the event-subscription:
assertNotNull(eventSubscriptionEntity.getConfiguration());
Execution eventScopeExecution = runtimeService.createExecutionQuery().executionId(eventSubscriptionEntity.getConfiguration()).singleResult();
assertNotNull(eventScopeExecution);
// there is a compensate event subscription for the miBody of 'bookHotel' activity
EventSubscriptionEntity miBodyEventSubscriptionEntity = (EventSubscriptionEntity) runtimeService.createEventSubscriptionQuery().eventType("compensate").activityId("bookHotel" + BpmnParse.MULTI_INSTANCE_BODY_ID_SUFFIX).executionId(eventScopeExecution.getId()).singleResult();
assertNotNull(miBodyEventSubscriptionEntity);
String miBodyEventScopeExecutionId = miBodyEventSubscriptionEntity.getConfiguration();
// we still have compensate event subscriptions for the compensation handlers, only now they are part of the event scope
assertEquals(5, runtimeService.createEventSubscriptionQuery().eventType("compensate").activityId("undoBookHotel").executionId(miBodyEventScopeExecutionId).count());
assertEquals(1, runtimeService.createEventSubscriptionQuery().eventType("compensate").activityId("undoBookFlight").executionId(eventScopeExecution.getId()).count());
assertEquals(1, runtimeService.createEventSubscriptionQuery().eventType("compensate").activityId("undoChargeCard").executionId(eventScopeExecution.getId()).count());
// assert that the compensation handlers have not been invoked:
assertNull(runtimeService.getVariable(processInstance.getId(), "undoBookHotel"));
assertNull(runtimeService.getVariable(processInstance.getId(), "undoBookFlight"));
assertNull(runtimeService.getVariable(processInstance.getId(), "undoChargeCard"));
// end the process instance
runtimeService.signal(processInstance.getId());
assertProcessEnded(processInstance.getId());
assertEquals(0, runtimeService.createExecutionQuery().count());
}
use of org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity in project camunda-bpm-platform by camunda.
the class SignalEventDeploymentTest method testUpdateEventSubscriptionOnDeployment.
public void testUpdateEventSubscriptionOnDeployment() {
deploymentId = repositoryService.createDeployment().addClasspathResource(SIGNAL_START_EVENT_PROCESS).deploy().getId();
EventSubscription eventSubscription = runtimeService.createEventSubscriptionQuery().eventType("signal").singleResult();
assertNotNull(eventSubscription);
assertEquals("alert", eventSubscription.getEventName());
// deploy a new version of the process with different signal name
String newDeploymentId = repositoryService.createDeployment().addClasspathResource(SIGNAL_START_EVENT_PROCESS_NEW_VERSION).deploy().getId();
ProcessDefinition newProcessDefinition = repositoryService.createProcessDefinitionQuery().latestVersion().singleResult();
assertEquals(2, newProcessDefinition.getVersion());
List<EventSubscription> newEventSubscriptions = runtimeService.createEventSubscriptionQuery().eventType("signal").list();
// only one event subscription for the new version of the process definition
assertEquals(1, newEventSubscriptions.size());
EventSubscriptionEntity newEventSubscription = (EventSubscriptionEntity) newEventSubscriptions.iterator().next();
assertEquals(newProcessDefinition.getId(), newEventSubscription.getConfiguration());
assertEquals("abort", newEventSubscription.getEventName());
// clean db
repositoryService.deleteDeployment(newDeploymentId);
}
use of org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity in project camunda-bpm-platform by camunda.
the class SendSignalDelegate method execute.
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<EventSubscriptionEntity> findSignalEventSubscriptionsByEventName = commandContext.getEventSubscriptionManager().findSignalEventSubscriptionsByNameAndExecution("alert", executionId);
for (EventSubscriptionEntity signalEventSubscriptionEntity : findSignalEventSubscriptionsByEventName) {
signalEventSubscriptionEntity.eventReceived(null, true);
}
}
use of org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity in project camunda-bpm-platform by camunda.
the class BpmnDeployer method addSignalStartEventSubscription.
protected void addSignalStartEventSubscription(EventSubscriptionDeclaration signalEventDefinition, ProcessDefinitionEntity processDefinition) {
EventSubscriptionEntity newSubscription = signalEventDefinition.createSubscriptionForStartEvent(processDefinition);
newSubscription.insert();
}
use of org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity in project camunda-bpm-platform by camunda.
the class CompensationUtil method collectCompensateEventSubscriptionsForScope.
/**
* Collect all compensate event subscriptions for scope of given execution.
*/
public static List<EventSubscriptionEntity> collectCompensateEventSubscriptionsForScope(ActivityExecution execution) {
final Map<ScopeImpl, PvmExecutionImpl> scopeExecutionMapping = execution.createActivityExecutionMapping();
ScopeImpl activity = (ScopeImpl) execution.getActivity();
// <LEGACY>: different flow scopes may have the same scope execution =>
// collect subscriptions in a set
final Set<EventSubscriptionEntity> subscriptions = new HashSet<EventSubscriptionEntity>();
TreeVisitor<ScopeImpl> eventSubscriptionCollector = new TreeVisitor<ScopeImpl>() {
@Override
public void visit(ScopeImpl obj) {
PvmExecutionImpl execution = scopeExecutionMapping.get(obj);
subscriptions.addAll(((ExecutionEntity) execution).getCompensateEventSubscriptions());
}
};
new FlowScopeWalker(activity).addPostVisitor(eventSubscriptionCollector).walkUntil(new ReferenceWalker.WalkCondition<ScopeImpl>() {
@Override
public boolean isFulfilled(ScopeImpl element) {
Boolean consumesCompensationProperty = (Boolean) element.getProperty(BpmnParse.PROPERTYNAME_CONSUMES_COMPENSATION);
return consumesCompensationProperty == null || consumesCompensationProperty == Boolean.TRUE;
}
});
return new ArrayList<EventSubscriptionEntity>(subscriptions);
}
Aggregations