org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity Java Examples

The following examples show how to use org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MessageEventReceivedCmd.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected Void execute(CommandContext commandContext, ExecutionEntity execution) {
  if (messageName == null) {
    throw new ActivitiIllegalArgumentException("messageName cannot be null");
  }
  
  if (Activiti5Util.isActiviti5ProcessDefinitionId(commandContext, execution.getProcessDefinitionId())) {
    Activiti5CompatibilityHandler activiti5CompatibilityHandler = Activiti5Util.getActiviti5CompatibilityHandler(); 
    activiti5CompatibilityHandler.messageEventReceived(messageName, executionId, payload, async);
    return null;
  }

  EventSubscriptionEntityManager eventSubscriptionEntityManager = commandContext.getEventSubscriptionEntityManager();
  List<EventSubscriptionEntity> eventSubscriptions = eventSubscriptionEntityManager.
      findEventSubscriptionsByNameAndExecution(MessageEventHandler.EVENT_HANDLER_TYPE, messageName, executionId);

  if (eventSubscriptions.isEmpty()) {
    throw new ActivitiException("Execution with id '" + executionId + "' does not have a subscription to a message event with name '" + messageName + "'");
  }

  // there can be only one:
  EventSubscriptionEntity eventSubscriptionEntity = eventSubscriptions.get(0);
  eventSubscriptionEntityManager.eventReceived(eventSubscriptionEntity, payload, async);

  return null;
}
 
Example #2
Source File: MessageEventsAndNewVersionDeploymentsTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
private List<String> getExecutionIdsForMessageEventSubscription(final String messageName) {
  return managementService.executeCommand(new Command<List<String>>() {
    public List<String> execute(CommandContext commandContext) {
      EventSubscriptionQueryImpl query = new EventSubscriptionQueryImpl(commandContext);
      query.eventType("message");
      query.eventName(messageName);
      query.orderByCreated().desc();
      List<EventSubscriptionEntity> eventSubscriptions = query.list();
      
      List<String> executionIds = new ArrayList<String>();
      for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
        executionIds.add(eventSubscription.getExecutionId());
      }
      return executionIds;
    }
  });
}
 
Example #3
Source File: IntermediateCatchSignalEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #4
Source File: BoundaryMessageEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void trigger(DelegateExecution execution, String triggerName, Object triggerData) {
  ExecutionEntity executionEntity = (ExecutionEntity) execution;
  BoundaryEvent boundaryEvent = (BoundaryEvent) execution.getCurrentFlowElement();

  if (boundaryEvent.isCancelActivity()) {
    EventSubscriptionEntityManager eventSubscriptionEntityManager = Context.getCommandContext().getEventSubscriptionEntityManager();
    List<EventSubscriptionEntity> eventSubscriptions = executionEntity.getEventSubscriptions();
    for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
      if (eventSubscription instanceof MessageEventSubscriptionEntity && eventSubscription.getEventName().equals(messageEventDefinition.getMessageRef())) {

        eventSubscriptionEntityManager.delete(eventSubscription);
      }
    }
  }

  super.trigger(executionEntity, triggerName, triggerData);
}
 
Example #5
Source File: BoundaryCompensateEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void trigger(DelegateExecution execution, String triggerName, Object triggerData) {
  ExecutionEntity executionEntity = (ExecutionEntity) execution;
  BoundaryEvent boundaryEvent = (BoundaryEvent) execution.getCurrentFlowElement();

  if (boundaryEvent.isCancelActivity()) {
    EventSubscriptionEntityManager eventSubscriptionEntityManager = Context.getCommandContext().getEventSubscriptionEntityManager();
    List<EventSubscriptionEntity> eventSubscriptions = executionEntity.getEventSubscriptions();
    for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
      if (eventSubscription instanceof CompensateEventSubscriptionEntity && eventSubscription.getActivityId().equals(compensateEventDefinition.getActivityRef())) {
        eventSubscriptionEntityManager.delete(eventSubscription);
      }
    }
  }

  super.trigger(executionEntity, triggerName, triggerData);
}
 
Example #6
Source File: AbstractEventHandler.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void dispatchActivityCancelled(EventSubscriptionEntity eventSubscription, ExecutionEntity boundaryEventExecution, FlowNode flowNode, CommandContext commandContext) {

    // Scope
    commandContext.getEventDispatcher().dispatchEvent(
        ActivitiEventBuilder.createActivityCancelledEvent(flowNode.getId(), flowNode.getName(), boundaryEventExecution.getId(),
            boundaryEventExecution.getProcessInstanceId(), boundaryEventExecution.getProcessDefinitionId(),
            parseActivityType(flowNode), eventSubscription));

    if (flowNode instanceof SubProcess) {
      // The parent of the boundary event execution will be the one on which the boundary event is set
      ExecutionEntity parentExecutionEntity = commandContext.getExecutionEntityManager().findById(boundaryEventExecution.getParentId());
      if (parentExecutionEntity != null) {
        dispatchActivityCancelledForChildExecution(eventSubscription, parentExecutionEntity, boundaryEventExecution, commandContext);
      }
    }
  }
 
Example #7
Source File: AbstractEventHandler.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void dispatchActivityCancelledForChildExecution(EventSubscriptionEntity eventSubscription,
    ExecutionEntity parentExecutionEntity, ExecutionEntity boundaryEventExecution, CommandContext commandContext) {

  List<ExecutionEntity> executionEntities = commandContext.getExecutionEntityManager().findChildExecutionsByParentExecutionId(parentExecutionEntity.getId());
  for (ExecutionEntity childExecution : executionEntities) {

    if (!boundaryEventExecution.getId().equals(childExecution.getId())
        && childExecution.getCurrentFlowElement() != null
        && childExecution.getCurrentFlowElement() instanceof FlowNode) {

      FlowNode flowNode = (FlowNode) childExecution.getCurrentFlowElement();
      commandContext.getEventDispatcher().dispatchEvent(
          ActivitiEventBuilder.createActivityCancelledEvent(flowNode.getId(), flowNode.getName(), childExecution.getId(),
              childExecution.getProcessInstanceId(), childExecution.getProcessDefinitionId(),
              parseActivityType(flowNode), eventSubscription));

      if (childExecution.isScope()) {
        dispatchActivityCancelledForChildExecution(eventSubscription, childExecution, boundaryEventExecution, commandContext);
      }

    }

  }

}
 
Example #8
Source File: MessageEventsAndNewVersionDeploymentsWithTenantIdTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
private List<String> getExecutionIdsForMessageEventSubscription(final String messageName) {
  return managementService.executeCommand(new Command<List<String>>() {
    public List<String> execute(CommandContext commandContext) {
      EventSubscriptionQueryImpl query = new EventSubscriptionQueryImpl(commandContext);
      query.eventType("message");
      query.eventName(messageName);
      query.tenantId(TENANT_ID);
      query.orderByCreated().desc();
      List<EventSubscriptionEntity> eventSubscriptions = query.list();
      
      List<String> executionIds = new ArrayList<String>();
      for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
        executionIds.add(eventSubscription.getExecutionId());
      }
      return executionIds;
    }
  });
}
 
Example #9
Source File: BoundarySignalEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void trigger(DelegateExecution execution, String triggerName, Object triggerData) {
  ExecutionEntity executionEntity = (ExecutionEntity) execution;
  BoundaryEvent boundaryEvent = (BoundaryEvent) execution.getCurrentFlowElement();

  if (boundaryEvent.isCancelActivity()) {
    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);
      }
    }
  }

  super.trigger(executionEntity, triggerName, triggerData);
}
 
Example #10
Source File: MessageThrowingEventListener.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void onEvent(ActivitiEvent event) {
  if (isValidEvent(event)) {

    if (event.getProcessInstanceId() == null) {
      throw new ActivitiIllegalArgumentException("Cannot throw process-instance scoped message, since the dispatched event is not part of an ongoing process instance");
    }

    EventSubscriptionEntityManager eventSubscriptionEntityManager = Context.getCommandContext().getEventSubscriptionEntityManager();
    List<MessageEventSubscriptionEntity> subscriptionEntities = eventSubscriptionEntityManager.findMessageEventSubscriptionsByProcessInstanceAndEventName(
        event.getProcessInstanceId(), messageName);
    
    for (EventSubscriptionEntity messageEventSubscriptionEntity : subscriptionEntities) {
      eventSubscriptionEntityManager.eventReceived(messageEventSubscriptionEntity, null, false);
    }
  }
}
 
Example #11
Source File: MessageEventsAndNewVersionDeploymentsWithTenantIdTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
private List<EventSubscriptionEntity> getAllEventSubscriptions() {
  return managementService.executeCommand(new Command<List<EventSubscriptionEntity>>() {
    public List<EventSubscriptionEntity> execute(CommandContext commandContext) {
      EventSubscriptionQueryImpl query = new EventSubscriptionQueryImpl(commandContext);
      query.tenantId(TENANT_ID);
      query.orderByCreated().desc();
      
      List<EventSubscriptionEntity> eventSubscriptionEntities = query.list();
      for (EventSubscriptionEntity entity : eventSubscriptionEntities) {
        assertEquals("message", entity.getEventType());
        assertNotNull(entity.getProcessDefinitionId());
      }
      return eventSubscriptionEntities;
    }
  });
}
 
Example #12
Source File: MessageEventsAndNewVersionDeploymentsTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
private List<String> getExecutionIdsForMessageEventSubscription(final String messageName) {
  return managementService.executeCommand(new Command<List<String>>() {
    public List<String> execute(CommandContext commandContext) {
      EventSubscriptionQueryImpl query = new EventSubscriptionQueryImpl(commandContext);
      query.eventType("message");
      query.eventName(messageName);
      query.orderByCreated().desc();
      List<EventSubscriptionEntity> eventSubscriptions = query.list();
      
      List<String> executionIds = new ArrayList<String>();
      for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
        executionIds.add(eventSubscription.getExecutionId());
      }
      return executionIds;
    }
  });
}
 
Example #13
Source File: AbstractEventHandler.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void dispatchExecutionCancelled(EventSubscriptionEntity eventSubscription, ExecutionEntity execution, CommandContext commandContext) {
    // subprocesses
    for (ExecutionEntity subExecution : execution.getExecutions()) {
        dispatchExecutionCancelled(eventSubscription, subExecution, commandContext);
    }

    // call activities
    ExecutionEntity subProcessInstance = commandContext.getExecutionEntityManager().findSubProcessInstanceBySuperExecutionId(execution.getId());
    if (subProcessInstance != null) {
        dispatchExecutionCancelled(eventSubscription, subProcessInstance, commandContext);
    }

    // activity with message/signal boundary events
    ActivityImpl activity = execution.getActivity();
    if (activity != null && activity.getActivityBehavior() != null) {
        dispatchActivityCancelled(eventSubscription, execution, activity, commandContext);
    }
}
 
Example #14
Source File: MessageEventsAndNewVersionDeploymentsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * v1 -> has start message event
 * v2 -> has no start message event
 * v3 -> has start message event
 */
public void testDeployIntermediateVersionWithoutMessageStartEvent() {
  String deploymentId1 = deployStartMessageTestProcess();
  assertEquals(1, getAllEventSubscriptions().size());
  assertEquals(0, runtimeService.createProcessInstanceQuery().count());
  runtimeService.startProcessInstanceByMessage("myStartMessage");
  assertEquals(1, runtimeService.createProcessInstanceQuery().count());
  assertEventSubscriptionsCount(1);
  
  String deploymentId2 = deployProcessWithoutEvents();
  assertEquals(0, getAllEventSubscriptions().size());
  assertEquals(1, runtimeService.createProcessInstanceQuery().count());
  try {
    runtimeService.startProcessInstanceByMessage("myStartMessage");
    fail();
  } catch (Exception e) { }
  assertEquals(1, runtimeService.createProcessInstanceQuery().count());
  assertEventSubscriptionsCount(0);
  
  String deploymentId3 = deployStartMessageTestProcess();
  assertEquals(1, getAllEventSubscriptions().size());
  assertEquals(1, runtimeService.createProcessInstanceQuery().count());
  runtimeService.startProcessInstanceByMessage("myStartMessage");
  assertEquals(2, runtimeService.createProcessInstanceQuery().count());
  assertEventSubscriptionsCount(1);
  
  List<EventSubscriptionEntity> eventSubscriptions = getAllEventSubscriptions();
  assertEquals(repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId3).singleResult().getId(), 
      eventSubscriptions.get(0).getProcessDefinitionId());
  
  cleanup(deploymentId1, deploymentId2, deploymentId3);
}
 
Example #15
Source File: ProcessEventJobHandler.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Job job, String configuration, ExecutionEntity execution, CommandContext commandContext) {
    // lookup subscription:
    EventSubscriptionEntity eventSubscription = commandContext.getEventSubscriptionEntityManager()
            .findEventSubscriptionbyId(configuration);

    // if event subscription is null, ignore
    if (eventSubscription != null) {
        eventSubscription.eventReceived(null, false);
    }

}
 
Example #16
Source File: SignalEventsAndNewVersionDeploymentsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * v1 -> has start signal event
 * v2 -> has no start signal event
 * v3 -> has start signal event
 */
public void testDeployIntermediateVersionWithoutSignalStartEvent() {
  String deploymentId1 = deployStartSignalTestProcess();
  assertEquals(1, getAllEventSubscriptions().size());
  assertEquals(0, runtimeService.createProcessInstanceQuery().count());
  runtimeService.signalEventReceived("myStartSignal");
  assertEquals(1, runtimeService.createProcessInstanceQuery().count());
  assertEventSubscriptionsCount(1);
  
  String deploymentId2 = deployProcessWithoutEvents();
  assertEquals(0, getAllEventSubscriptions().size());
  assertEquals(1, runtimeService.createProcessInstanceQuery().count());
  runtimeService.signalEventReceived("myStartSignal");
  assertEquals(1, runtimeService.createProcessInstanceQuery().count());
  assertEventSubscriptionsCount(0);
  
  String deploymentId3 = deployStartSignalTestProcess();
  assertEquals(1, getAllEventSubscriptions().size());
  assertEquals(1, runtimeService.createProcessInstanceQuery().count());
  runtimeService.signalEventReceived("myStartSignal");
  assertEquals(2, runtimeService.createProcessInstanceQuery().count());
  assertEventSubscriptionsCount(1);
  
  List<EventSubscriptionEntity> eventSubscriptions = getAllEventSubscriptions();
  assertEquals(repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId3).singleResult().getId(), 
      eventSubscriptions.get(0).getProcessDefinitionId());
  
  cleanup(deploymentId1, deploymentId2, deploymentId3);
}
 
Example #17
Source File: MessageEventsAndNewVersionDeploymentsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private List<EventSubscriptionEntity> getAllEventSubscriptions() {
  return managementService.executeCommand(new Command<List<EventSubscriptionEntity>>() {
    public List<EventSubscriptionEntity> execute(CommandContext commandContext) {
      EventSubscriptionQueryImpl query = new EventSubscriptionQueryImpl(commandContext);
      query.orderByCreated().desc();
      
      List<EventSubscriptionEntity> eventSubscriptionEntities = query.list();
      for (EventSubscriptionEntity entity : eventSubscriptionEntities) {
        assertEquals("message", entity.getEventType());
      }
      return eventSubscriptionEntities;
    }
  });
}
 
Example #18
Source File: TransactionSubProcessTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/bpmn/subprocess/transaction/TransactionSubProcessTest.testMultiInstanceTx.bpmn20.xml" })
public void testMultiInstanceTxSuccessful() {

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("transactionProcess");

  // there are now 5 instances of the transaction:

  List<EventSubscriptionEntity> EventSubscriptionEntitys = createEventSubscriptionQuery().eventType("compensate").list();

  // there are 10 compensation event subscriptions
  assertEquals(10, EventSubscriptionEntitys.size());

  // first complete the inner user-tasks
  List<Task> tasks = taskService.createTaskQuery().list();
  for (Task task : tasks) {
    taskService.setVariable(task.getId(), "confirmed", true);
    taskService.complete(task.getId());
  }

  // now complete the inner receive tasks
  List<Execution> executions = runtimeService.createExecutionQuery().activityId("receive").list();
  for (Execution execution : executions) {
    runtimeService.trigger(execution.getId());
  }

  runtimeService.trigger(runtimeService.createExecutionQuery().activityId("afterSuccess").singleResult().getId());

  assertEquals(0, createEventSubscriptionQuery().count());
  assertProcessEnded(processInstance.getId());

}
 
Example #19
Source File: MessageEventsAndNewVersionDeploymentsWithTenantIdTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * v1 -> has start message event
 * v2 -> has no start message event
 * v3 -> has start message event
 */
public void testDeployIntermediateVersionWithoutMessageStartEvent() {
  String deploymentId1 = deployStartMessageTestProcess();
  assertEquals(1, getAllEventSubscriptions().size());
  assertEquals(0, runtimeService.createProcessInstanceQuery().count());
  runtimeService.startProcessInstanceByMessageAndTenantId("myStartMessage", TENANT_ID);
  assertEquals(1, runtimeService.createProcessInstanceQuery().count());
  assertEventSubscriptionsCount(1);
  
  String deploymentId2 = deployProcessWithoutEvents();
  assertEquals(0, getAllEventSubscriptions().size());
  assertEquals(1, runtimeService.createProcessInstanceQuery().count());
  try {
    runtimeService.startProcessInstanceByMessageAndTenantId("myStartMessage", TENANT_ID);
    fail();
  } catch (Exception e) { }
  assertEquals(1, runtimeService.createProcessInstanceQuery().count());
  assertEventSubscriptionsCount(0);
  
  String deploymentId3 = deployStartMessageTestProcess();
  assertEquals(1, getAllEventSubscriptions().size());
  assertEquals(1, runtimeService.createProcessInstanceQuery().count());
  runtimeService.startProcessInstanceByMessageAndTenantId("myStartMessage", TENANT_ID);
  assertEquals(2, runtimeService.createProcessInstanceQuery().count());
  assertEventSubscriptionsCount(1);
  
  List<EventSubscriptionEntity> eventSubscriptions = getAllEventSubscriptions();
  assertEquals(repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId3).singleResult().getId(), 
      eventSubscriptions.get(0).getProcessDefinitionId());
  
  cleanup(deploymentId1, deploymentId2, deploymentId3);
}
 
Example #20
Source File: MessageEventsAndNewVersionDeploymentsWithTenantIdTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testMessageStartEventSubscriptionAfterDeploymentDelete() {
  
  // Deploy two version of process definition, delete latest and check if all is good
  
  String deploymentId1 = deployStartMessageTestProcess();
  List<EventSubscriptionEntity> eventSubscriptions = getAllEventSubscriptions();
  assertEquals(1, eventSubscriptions.size());

  String deploymentId2 = deployStartMessageTestProcess();
  eventSubscriptions = getAllEventSubscriptions();
  assertEventSubscriptionsCount(1);
  
  repositoryService.deleteDeployment(deploymentId2, true);
  eventSubscriptions = getAllEventSubscriptions();
  assertEquals(1, eventSubscriptions.size());
  
  cleanup(deploymentId1);
  assertEquals(0, getAllEventSubscriptions().size());
  
  // Deploy two versions of process definition, delete the first
  deploymentId1 = deployStartMessageTestProcess();
  deploymentId2 = deployStartMessageTestProcess();
  assertEquals(1, getAllEventSubscriptions().size());
  repositoryService.deleteDeployment(deploymentId1, true);
  eventSubscriptions = getAllEventSubscriptions();
  assertEquals(1, eventSubscriptions.size());
  assertEquals(repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId2).singleResult().getId(), eventSubscriptions.get(0).getProcessDefinitionId());
  
  cleanup(deploymentId2);
  assertEquals(0, getAllEventSubscriptions().size());
}
 
Example #21
Source File: MessageEventsAndNewVersionDeploymentsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testMessageStartEventSubscriptionAfterDeploymentDelete() {
  
  // Deploy two version of process definition, delete latest and check if all is good
  
  String deploymentId1 = deployStartMessageTestProcess();
  List<EventSubscriptionEntity> eventSubscriptions = getAllEventSubscriptions();
  assertEquals(1, eventSubscriptions.size());

  String deploymentId2 = deployStartMessageTestProcess();
  eventSubscriptions = getAllEventSubscriptions();
  assertEventSubscriptionsCount(1);
  
  repositoryService.deleteDeployment(deploymentId2, true);
  eventSubscriptions = getAllEventSubscriptions();
  assertEquals(1, eventSubscriptions.size());
  
  cleanup(deploymentId1);
  assertEquals(0, getAllEventSubscriptions().size());
  
  // Deploy two versions of process definition, delete the first
  deploymentId1 = deployStartMessageTestProcess();
  deploymentId2 = deployStartMessageTestProcess();
  assertEquals(1, getAllEventSubscriptions().size());
  repositoryService.deleteDeployment(deploymentId1, true);
  eventSubscriptions = getAllEventSubscriptions();
  assertEquals(1, eventSubscriptions.size());
  assertEquals(repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId2).singleResult().getId(), eventSubscriptions.get(0).getProcessDefinitionId());
  
  cleanup(deploymentId2);
  assertEquals(0, getAllEventSubscriptions().size());
}
 
Example #22
Source File: EventSubscriptionQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testQueryByEventType() {

    processEngineConfiguration.getCommandExecutor().execute(new Command<Void>() {
      public Void execute(CommandContext commandContext) {

        MessageEventSubscriptionEntity messageEventSubscriptionEntity1 = commandContext.getEventSubscriptionEntityManager().createMessageEventSubscription();
        messageEventSubscriptionEntity1.setEventName("messageName");
        commandContext.getEventSubscriptionEntityManager().insert(messageEventSubscriptionEntity1);

        MessageEventSubscriptionEntity messageEventSubscriptionEntity2 = commandContext.getEventSubscriptionEntityManager().createMessageEventSubscription();
        messageEventSubscriptionEntity2.setEventName("messageName");
        commandContext.getEventSubscriptionEntityManager().insert(messageEventSubscriptionEntity2);

        SignalEventSubscriptionEntity signalEventSubscriptionEntity3 = commandContext.getEventSubscriptionEntityManager().createSignalEventSubscription();
        signalEventSubscriptionEntity3.setEventName("messageName2");
        commandContext.getEventSubscriptionEntityManager().insert(signalEventSubscriptionEntity3);

        return null;
      }
    });

    List<EventSubscriptionEntity> list = newEventSubscriptionQuery().eventType("signal").list();
    assertEquals(1, list.size());

    list = newEventSubscriptionQuery().eventType("message").list();
    assertEquals(2, list.size());

    cleanDb();

  }
 
Example #23
Source File: EventSubscriptionQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testQueryByEventName() {

    processEngineConfiguration.getCommandExecutor().execute(new Command<Void>() {
      public Void execute(CommandContext commandContext) {

        MessageEventSubscriptionEntity messageEventSubscriptionEntity1 = commandContext.getEventSubscriptionEntityManager().createMessageEventSubscription();
        messageEventSubscriptionEntity1.setEventName("messageName");
        commandContext.getEventSubscriptionEntityManager().insert(messageEventSubscriptionEntity1);

        MessageEventSubscriptionEntity messageEventSubscriptionEntity2 = commandContext.getEventSubscriptionEntityManager().createMessageEventSubscription();
        messageEventSubscriptionEntity2.setEventName("messageName");
        commandContext.getEventSubscriptionEntityManager().insert(messageEventSubscriptionEntity2);

        MessageEventSubscriptionEntity messageEventSubscriptionEntity3 = commandContext.getEventSubscriptionEntityManager().createMessageEventSubscription();
        messageEventSubscriptionEntity3.setEventName("messageName2");
        commandContext.getEventSubscriptionEntityManager().insert(messageEventSubscriptionEntity3);

        return null;
      }
    });

    List<EventSubscriptionEntity> list = newEventSubscriptionQuery().eventName("messageName").list();
    assertEquals(2, list.size());

    list = newEventSubscriptionQuery().eventName("messageName2").list();
    assertEquals(1, list.size());

    cleanDb();

  }
 
Example #24
Source File: EventSubscriptionManager.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
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()) { // processInstanceId != null or not empty -> it's a message related to an execution
      // 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);
}
 
Example #25
Source File: EventSubscriptionManager.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example #26
Source File: EventSubscriptionQueryTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void cleanDb() {
    CommandExecutor commandExecutor = (CommandExecutor) processEngineConfiguration.getFlowable5CompatibilityHandler().getRawCommandExecutor();
    commandExecutor.execute(new Command<Void>() {
        public Void execute(CommandContext commandContext) {
            final List<EventSubscriptionEntity> subscriptions = new EventSubscriptionQueryImpl(commandContext).list();
            for (EventSubscriptionEntity eventSubscriptionEntity : subscriptions) {
                eventSubscriptionEntity.delete();
            }
            return null;
        }
    });

}
 
Example #27
Source File: EventSubscriptionQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void cleanDb() {
  processEngineConfiguration.getCommandExecutor().execute(new Command<Void>() {
    public Void execute(CommandContext commandContext) {
      final List<EventSubscriptionEntity> subscriptions = new EventSubscriptionQueryImpl(commandContext).list();
      for (EventSubscriptionEntity eventSubscriptionEntity : subscriptions) {
        EventSubscriptionEntityManager eventSubscriptionEntityManager = Context.getCommandContext().getEventSubscriptionEntityManager();
        eventSubscriptionEntityManager.delete(eventSubscriptionEntity);
      }
      return null;
    }
  });

}
 
Example #28
Source File: IntermediateCatchMessageEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected ExecutionEntity deleteMessageEventSubScription(DelegateExecution execution) {
  ExecutionEntity executionEntity = (ExecutionEntity) execution;
  EventSubscriptionEntityManager eventSubscriptionEntityManager = Context.getCommandContext().getEventSubscriptionEntityManager();
  List<EventSubscriptionEntity> eventSubscriptions = executionEntity.getEventSubscriptions();
  for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
    if (eventSubscription instanceof MessageEventSubscriptionEntity && eventSubscription.getEventName().equals(messageEventDefinition.getMessageRef())) {

      eventSubscriptionEntityManager.delete(eventSubscription);
    }
  }
  return executionEntity;
}
 
Example #29
Source File: ScopeUtil.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * we create a separate execution for each compensation handler invocation.
 */
public static void throwCompensationEvent(List<CompensateEventSubscriptionEntity> eventSubscriptions, DelegateExecution execution, boolean async) {

  ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager();
  
  // first spawn the compensating executions
  for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
    ExecutionEntity compensatingExecution = null;
    
    // check whether compensating execution is already created (which is the case when compensating an embedded subprocess,
    // where the compensating execution is created when leaving the subprocess and holds snapshot data).
    if (eventSubscription.getConfiguration() != null) {
      compensatingExecution = executionEntityManager.findById(eventSubscription.getConfiguration());
      compensatingExecution.setParent(compensatingExecution.getProcessInstance());
      compensatingExecution.setEventScope(false);
    } else {
      compensatingExecution = executionEntityManager.createChildExecution((ExecutionEntity) execution); 
      eventSubscription.setConfiguration(compensatingExecution.getId());
    }
    
  }

  // signal compensation events in reverse order of their 'created' timestamp
  Collections.sort(eventSubscriptions, new Comparator<EventSubscriptionEntity>() {
    public int compare(EventSubscriptionEntity o1, EventSubscriptionEntity o2) {
      return o2.getCreated().compareTo(o1.getCreated());
    }
  });

  for (CompensateEventSubscriptionEntity compensateEventSubscriptionEntity : eventSubscriptions) {
    Context.getCommandContext().getEventSubscriptionEntityManager().eventReceived(compensateEventSubscriptionEntity, null, async);
  }
}
 
Example #30
Source File: BpmnDeployer.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void removeExistingSignalEventSubScription(ProcessDefinitionEntity processDefinition, ProcessDefinitionEntity latestProcessDefinition) {
    // remove all subscriptions for the previous version
    if (latestProcessDefinition != null) {
        CommandContext commandContext = Context.getCommandContext();

        List<EventSubscriptionEntity> subscriptionsToDelete = commandContext
                .getEventSubscriptionEntityManager()
                .findEventSubscriptionsByTypeAndProcessDefinitionId(SignalEventHandler.EVENT_HANDLER_TYPE, latestProcessDefinition.getId(), latestProcessDefinition.getTenantId());

        for (EventSubscriptionEntity eventSubscriptionEntity : subscriptionsToDelete) {
            eventSubscriptionEntity.delete();
        }

    }
}