use of org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity in project Activiti by Activiti.
the class ScopeUtil method createCopyOfSubProcessExecutionForCompensation.
/**
* Creates a new event scope execution and moves existing event subscriptions to this new execution
*/
public static void createCopyOfSubProcessExecutionForCompensation(ExecutionEntity subProcessExecution) {
EventSubscriptionEntityManager eventSubscriptionEntityManager = Context.getCommandContext().getEventSubscriptionEntityManager();
List<EventSubscriptionEntity> eventSubscriptions = eventSubscriptionEntityManager.findEventSubscriptionsByExecutionAndType(subProcessExecution.getId(), "compensate");
List<CompensateEventSubscriptionEntity> compensateEventSubscriptions = new ArrayList<CompensateEventSubscriptionEntity>();
for (EventSubscriptionEntity event : eventSubscriptions) {
if (event instanceof CompensateEventSubscriptionEntity) {
compensateEventSubscriptions.add((CompensateEventSubscriptionEntity) event);
}
}
if (CollectionUtil.isNotEmpty(compensateEventSubscriptions)) {
ExecutionEntity processInstanceExecutionEntity = subProcessExecution.getProcessInstance();
ExecutionEntity eventScopeExecution = Context.getCommandContext().getExecutionEntityManager().createChildExecution(processInstanceExecutionEntity);
eventScopeExecution.setActive(false);
eventScopeExecution.setEventScope(true);
eventScopeExecution.setCurrentFlowElement(subProcessExecution.getCurrentFlowElement());
// copy local variables to eventScopeExecution by value. This way,
// the eventScopeExecution references a 'snapshot' of the local variables
new SubProcessVariableSnapshotter().setVariablesSnapshots(subProcessExecution, eventScopeExecution);
// set event subscriptions to the event scope execution:
for (CompensateEventSubscriptionEntity eventSubscriptionEntity : compensateEventSubscriptions) {
eventSubscriptionEntityManager.delete(eventSubscriptionEntity);
CompensateEventSubscriptionEntity newSubscription = eventSubscriptionEntityManager.insertCompensationEvent(eventScopeExecution, eventSubscriptionEntity.getActivityId());
newSubscription.setConfiguration(eventSubscriptionEntity.getConfiguration());
newSubscription.setCreated(eventSubscriptionEntity.getCreated());
}
CompensateEventSubscriptionEntity eventSubscription = eventSubscriptionEntityManager.insertCompensationEvent(processInstanceExecutionEntity, eventScopeExecution.getCurrentFlowElement().getId());
eventSubscription.setConfiguration(eventScopeExecution.getId());
}
}
use of org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity in project Activiti by Activiti.
the class EventSubscriptionManager method insertMessageEvent.
protected void insertMessageEvent(MessageEventDefinition messageEventDefinition, StartEvent startEvent, ProcessDefinitionEntity processDefinition, BpmnModel bpmnModel) {
CommandContext commandContext = Context.getCommandContext();
if (bpmnModel.containsMessageId(messageEventDefinition.getMessageRef())) {
Message message = bpmnModel.getMessage(messageEventDefinition.getMessageRef());
messageEventDefinition.setMessageRef(message.getName());
}
// look for subscriptions for the same name in db:
List<EventSubscriptionEntity> subscriptionsForSameMessageName = commandContext.getEventSubscriptionEntityManager().findEventSubscriptionsByName(MessageEventHandler.EVENT_HANDLER_TYPE, messageEventDefinition.getMessageRef(), processDefinition.getTenantId());
for (EventSubscriptionEntity eventSubscriptionEntity : subscriptionsForSameMessageName) {
// throw exception only if there's already a subscription as start event
if (eventSubscriptionEntity.getProcessInstanceId() == null || eventSubscriptionEntity.getProcessInstanceId().isEmpty()) {
// the event subscription has no instance-id, so it's a message start event
throw new ActivitiException("Cannot deploy process definition '" + processDefinition.getResourceName() + "': there already is a message event subscription for the message with name '" + messageEventDefinition.getMessageRef() + "'.");
}
}
MessageEventSubscriptionEntity newSubscription = commandContext.getEventSubscriptionEntityManager().createMessageEventSubscription();
newSubscription.setEventName(messageEventDefinition.getMessageRef());
newSubscription.setActivityId(startEvent.getId());
newSubscription.setConfiguration(processDefinition.getId());
newSubscription.setProcessDefinitionId(processDefinition.getId());
if (processDefinition.getTenantId() != null) {
newSubscription.setTenantId(processDefinition.getTenantId());
}
commandContext.getEventSubscriptionEntityManager().insert(newSubscription);
}
use of org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity in project Activiti by Activiti.
the class EventSubscriptionManager method removeObsoleteEventSubscriptionsImpl.
protected void removeObsoleteEventSubscriptionsImpl(ProcessDefinitionEntity processDefinition, String eventHandlerType) {
// remove all subscriptions for the previous version
EventSubscriptionEntityManager eventSubscriptionEntityManager = Context.getCommandContext().getEventSubscriptionEntityManager();
List<EventSubscriptionEntity> subscriptionsToDelete = eventSubscriptionEntityManager.findEventSubscriptionsByTypeAndProcessDefinitionId(eventHandlerType, processDefinition.getId(), processDefinition.getTenantId());
for (EventSubscriptionEntity eventSubscriptionEntity : subscriptionsToDelete) {
eventSubscriptionEntityManager.delete(eventSubscriptionEntity);
}
}
use of org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity in project Activiti by Activiti.
the class IntermediateCatchSignalEventActivityBehavior method deleteSignalEventSubscription.
protected ExecutionEntity deleteSignalEventSubscription(DelegateExecution execution) {
ExecutionEntity executionEntity = (ExecutionEntity) execution;
String eventName = null;
if (signal != null) {
eventName = signal.getName();
} else {
eventName = signalEventDefinition.getSignalRef();
}
EventSubscriptionEntityManager eventSubscriptionEntityManager = Context.getCommandContext().getEventSubscriptionEntityManager();
List<EventSubscriptionEntity> eventSubscriptions = executionEntity.getEventSubscriptions();
for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
if (eventSubscription instanceof SignalEventSubscriptionEntity && eventSubscription.getEventName().equals(eventName)) {
eventSubscriptionEntityManager.delete(eventSubscription);
}
}
return executionEntity;
}
use of org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity in project Activiti by Activiti.
the class EventBasedGatewayTest method testCatchSignalAndMessageAndTimer.
@Deployment
public void testCatchSignalAndMessageAndTimer() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("catchSignal");
assertThat(createEventSubscriptionQuery().count()).isEqualTo(2);
EventSubscriptionQueryImpl messageEventSubscriptionQuery = createEventSubscriptionQuery().eventType("message");
assertThat(messageEventSubscriptionQuery.count()).isEqualTo(1);
assertThat(createEventSubscriptionQuery().eventType("signal").count()).isEqualTo(1);
assertThat(runtimeService.createProcessInstanceQuery().count()).isEqualTo(1);
assertThat(managementService.createTimerJobQuery().count()).isEqualTo(1);
Execution execution = runtimeService.createExecutionQuery().messageEventSubscriptionName("newInvoice").singleResult();
assertThat(execution).isNotNull();
execution = runtimeService.createExecutionQuery().signalEventSubscriptionName("alert").singleResult();
assertThat(execution).isNotNull();
processEngineConfiguration.getClock().setCurrentTime(new Date(processEngineConfiguration.getClock().getCurrentTime().getTime() + 10000));
EventSubscriptionEntity messageEventSubscription = messageEventSubscriptionQuery.singleResult();
runtimeService.messageEventReceived(messageEventSubscription.getEventName(), messageEventSubscription.getExecutionId());
assertThat(createEventSubscriptionQuery().count()).isEqualTo(0);
assertThat(runtimeService.createProcessInstanceQuery().count()).isEqualTo(1);
assertThat(managementService.createTimerJobQuery().count()).isEqualTo(0);
assertThat(managementService.createJobQuery().count()).isEqualTo(0);
Task task = taskService.createTaskQuery().taskName("afterMessage").singleResult();
assertThat(task).isNotNull();
taskService.complete(task.getId());
assertHistoricActivitiesDeleteReason(processInstance, DeleteReason.EVENT_BASED_GATEWAY_CANCEL, "signalEvent");
assertHistoricActivitiesDeleteReason(processInstance, DeleteReason.EVENT_BASED_GATEWAY_CANCEL, "timerEvent");
}
Aggregations