Java Code Examples for org.activiti.bpmn.model.BpmnModel#containsMessageId()

The following examples show how to use org.activiti.bpmn.model.BpmnModel#containsMessageId() . 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: DeploymentEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void restoreMessageStartEvent(ProcessDefinition previousProcessDefinition, BpmnModel bpmnModel, StartEvent startEvent, EventDefinition eventDefinition) {
  MessageEventDefinition messageEventDefinition = (MessageEventDefinition) eventDefinition;
  if (bpmnModel.containsMessageId(messageEventDefinition.getMessageRef())) {
    Message message = bpmnModel.getMessage(messageEventDefinition.getMessageRef());
    messageEventDefinition.setMessageRef(message.getName());
  }

  MessageEventSubscriptionEntity newSubscription = getEventSubscriptionEntityManager().createMessageEventSubscription();
  newSubscription.setEventName(messageEventDefinition.getMessageRef());
  newSubscription.setActivityId(startEvent.getId());
  newSubscription.setConfiguration(previousProcessDefinition.getId());
  newSubscription.setProcessDefinitionId(previousProcessDefinition.getId());

  if (previousProcessDefinition.getTenantId() != null) {
    newSubscription.setTenantId(previousProcessDefinition.getTenantId());
  }

  getEventSubscriptionEntityManager().insert(newSubscription);
}
 
Example 2
Source File: MessageEventDefinitionParseHandler.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void executeParse(BpmnParse bpmnParse, MessageEventDefinition messageDefinition) {
  BpmnModel bpmnModel = bpmnParse.getBpmnModel();
  String messageRef = messageDefinition.getMessageRef();
  if (bpmnModel.containsMessageId(messageRef)) {
    Message message = bpmnModel.getMessage(messageRef);
    messageDefinition.setMessageRef(message.getName());
    messageDefinition.setExtensionElements(message.getExtensionElements());
  }

  if (bpmnParse.getCurrentFlowElement() instanceof IntermediateCatchEvent) {
    IntermediateCatchEvent intermediateCatchEvent = (IntermediateCatchEvent) bpmnParse.getCurrentFlowElement();
    intermediateCatchEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createIntermediateCatchMessageEventActivityBehavior(intermediateCatchEvent, messageDefinition));

  } else if (bpmnParse.getCurrentFlowElement() instanceof BoundaryEvent) {
    BoundaryEvent boundaryEvent = (BoundaryEvent) bpmnParse.getCurrentFlowElement();
    boundaryEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createBoundaryMessageEventActivityBehavior(boundaryEvent, messageDefinition, boundaryEvent.isCancelActivity()));
  }

  else {
    // What to do here?
  }

}
 
Example 3
Source File: StartEventParseHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void executeParse(BpmnParse bpmnParse, StartEvent element) {
  if (element.getSubProcess() != null && element.getSubProcess() instanceof EventSubProcess) {
    if (CollectionUtil.isNotEmpty(element.getEventDefinitions())) {
      EventDefinition eventDefinition = element.getEventDefinitions().get(0);
      if (eventDefinition instanceof MessageEventDefinition) {
        MessageEventDefinition messageDefinition = (MessageEventDefinition) eventDefinition;
        BpmnModel bpmnModel = bpmnParse.getBpmnModel();
        String messageRef = messageDefinition.getMessageRef();
        if (bpmnModel.containsMessageId(messageRef)) {
          Message message = bpmnModel.getMessage(messageRef);
          messageDefinition.setMessageRef(message.getName());
          messageDefinition.setExtensionElements(message.getExtensionElements());
        }
        element.setBehavior(bpmnParse.getActivityBehaviorFactory().createEventSubProcessMessageStartEventActivityBehavior(element, messageDefinition));
      
      } else if (eventDefinition instanceof ErrorEventDefinition) {
        element.setBehavior(bpmnParse.getActivityBehaviorFactory().createEventSubProcessErrorStartEventActivityBehavior(element));
      }
    }
    
  } else if (CollectionUtil.isEmpty(element.getEventDefinitions())) {
    element.setBehavior(bpmnParse.getActivityBehaviorFactory().createNoneStartEventActivityBehavior(element));
  }
  
  if (element.getSubProcess() == null && (CollectionUtil.isEmpty(element.getEventDefinitions()) || 
      bpmnParse.getCurrentProcess().getInitialFlowElement() == null)) {

    bpmnParse.getCurrentProcess().setInitialFlowElement(element);
  }
}
 
Example 4
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 5
Source File: EventValidator.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void handleMessageEventDefinition(BpmnModel bpmnModel, Process process, Event event, EventDefinition eventDefinition, List<ValidationError> errors) {
  MessageEventDefinition messageEventDefinition = (MessageEventDefinition) eventDefinition;

  if (StringUtils.isEmpty(messageEventDefinition.getMessageRef())) {
    
    if (StringUtils.isEmpty(messageEventDefinition.getMessageExpression())) {
      // message ref should be filled in
      addError(errors, Problems.MESSAGE_EVENT_MISSING_MESSAGE_REF, process, event, "attribute 'messageRef' is required");
    }
    
  } else if (!bpmnModel.containsMessageId(messageEventDefinition.getMessageRef())) {
    // message ref should exist
    addError(errors, Problems.MESSAGE_EVENT_INVALID_MESSAGE_REF, process, event, "Invalid 'messageRef': no message with that id can be found in the model");
  }
}