org.activiti.bpmn.model.BoundaryEvent Java Examples

The following examples show how to use org.activiti.bpmn.model.BoundaryEvent. 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: AbstractBpmnActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void executeCompensateBoundaryEvents(Collection<BoundaryEvent> boundaryEvents, DelegateExecution execution) {

    // The parent execution becomes a scope, and a child execution is created for each of the boundary events
    for (BoundaryEvent boundaryEvent : boundaryEvents) {

      if (CollectionUtil.isEmpty(boundaryEvent.getEventDefinitions())) {
        continue;
      }
      
      if (boundaryEvent.getEventDefinitions().get(0) instanceof CompensateEventDefinition == false) {
        continue;
      }

      ExecutionEntity childExecutionEntity = Context.getCommandContext().getExecutionEntityManager().createChildExecution((ExecutionEntity) execution); 
      childExecutionEntity.setParentId(execution.getId());
      childExecutionEntity.setCurrentFlowElement(boundaryEvent);
      childExecutionEntity.setScope(false);

      ActivityBehavior boundaryEventBehavior = ((ActivityBehavior) boundaryEvent.getBehavior());
      boundaryEventBehavior.execute(childExecutionEntity);
    }

  }
 
Example #2
Source File: TriggerExecutionOperation.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
  FlowElement currentFlowElement = getCurrentFlowElement(execution);
  if (currentFlowElement instanceof FlowNode) {
    
    ActivityBehavior activityBehavior = (ActivityBehavior) ((FlowNode) currentFlowElement).getBehavior();
    if (activityBehavior instanceof TriggerableActivityBehavior) {
      
      if (currentFlowElement instanceof BoundaryEvent) {
        commandContext.getHistoryManager().recordActivityStart(execution);
      }
      
      ((TriggerableActivityBehavior) activityBehavior).trigger(execution, null, null);
      
      if (currentFlowElement instanceof BoundaryEvent) {
        commandContext.getHistoryManager().recordActivityEnd(execution, null);
      }
      
    } else {
      throw new ActivitiException("Invalid behavior: " + activityBehavior + " should implement " + TriggerableActivityBehavior.class.getName());
    }

  } else {
    throw new ActivitiException("Programmatic error: no current flow element found or invalid type: " + currentFlowElement + ". Halting.");
  }
}
 
Example #3
Source File: TimerDefinitionConverterTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
private void validateModel(BpmnModel model) {
  IntermediateCatchEvent timer = (IntermediateCatchEvent) model.getMainProcess().getFlowElement("timer");
  assertNotNull(timer);
  TimerEventDefinition timerEvent = (TimerEventDefinition) timer.getEventDefinitions().get(0);
  assertThat(timerEvent.getCalendarName(), is("custom"));
  assertEquals("PT5M", timerEvent.getTimeDuration());

  StartEvent start = (StartEvent) model.getMainProcess().getFlowElement("theStart");
  assertNotNull(start);
  TimerEventDefinition startTimerEvent = (TimerEventDefinition) start.getEventDefinitions().get(0);
  assertThat(startTimerEvent.getCalendarName(), is("custom"));
  assertEquals("R2/PT5S", startTimerEvent.getTimeCycle());
  assertEquals("${EndDate}", startTimerEvent.getEndDate());

  BoundaryEvent boundaryTimer = (BoundaryEvent) model.getMainProcess().getFlowElement("boundaryTimer");
  assertNotNull(boundaryTimer);
  TimerEventDefinition boundaryTimerEvent = (TimerEventDefinition) boundaryTimer.getEventDefinitions().get(0);
  assertThat(boundaryTimerEvent.getCalendarName(), is("custom"));
  assertEquals("PT10S", boundaryTimerEvent.getTimeDuration());
  assertNull(boundaryTimerEvent.getEndDate());
}
 
Example #4
Source File: BpmnAutoLayout.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void handleBoundaryEvents() {
  for (BoundaryEvent boundaryEvent : boundaryEvents) {
    mxGeometry geometry = new mxGeometry(0.8, 1.0, eventSize, eventSize);
    geometry.setOffset(new mxPoint(-(eventSize / 2), -(eventSize / 2)));
    geometry.setRelative(true);
    mxCell boundaryPort = new mxCell(null, geometry, "shape=ellipse;perimter=ellipsePerimeter");
    boundaryPort.setId("boundary-event-" + boundaryEvent.getId());
    boundaryPort.setVertex(true);

    Object portParent = null;
    if (boundaryEvent.getAttachedToRefId() != null) {
      portParent = generatedVertices.get(boundaryEvent.getAttachedToRefId());
    } else if (boundaryEvent.getAttachedToRef() != null) {
      portParent = generatedVertices.get(boundaryEvent.getAttachedToRef().getId());
    } else {
      throw new RuntimeException("Could not generate DI: boundaryEvent '" + boundaryEvent.getId() + "' has no attachedToRef");
    }

    graph.addCell(boundaryPort, portParent);
    generatedVertices.put(boundaryEvent.getId(), boundaryPort);
  }
}
 
Example #5
Source File: BoundaryEventXMLConverter.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model) throws Exception {
  BoundaryEvent boundaryEvent = new BoundaryEvent();
  BpmnXMLUtil.addXMLLocation(boundaryEvent, xtr);
  if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_BOUNDARY_CANCELACTIVITY))) {
    String cancelActivity = xtr.getAttributeValue(null, ATTRIBUTE_BOUNDARY_CANCELACTIVITY);
    if (ATTRIBUTE_VALUE_FALSE.equalsIgnoreCase(cancelActivity)) {
      boundaryEvent.setCancelActivity(false);
    }
  }
  boundaryEvent.setAttachedToRefId(xtr.getAttributeValue(null, ATTRIBUTE_BOUNDARY_ATTACHEDTOREF));
  parseChildElements(getXMLElementName(), boundaryEvent, model, xtr);

  // Explicitly set cancel activity to false for error boundary events
  if (boundaryEvent.getEventDefinitions().size() == 1) {
    EventDefinition eventDef = boundaryEvent.getEventDefinitions().get(0);

    if (eventDef instanceof ErrorEventDefinition) {
      boundaryEvent.setCancelActivity(false);
    }
  }

  return boundaryEvent;
}
 
Example #6
Source File: SignalEventDefinitionParseHandler.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void executeParse(BpmnParse bpmnParse, SignalEventDefinition signalDefinition) {

    Signal signal = null;
    if (bpmnParse.getBpmnModel().containsSignalId(signalDefinition.getSignalRef())) {
      signal = bpmnParse.getBpmnModel().getSignal(signalDefinition.getSignalRef());
    }

    if (bpmnParse.getCurrentFlowElement() instanceof IntermediateCatchEvent) {
      IntermediateCatchEvent intermediateCatchEvent = (IntermediateCatchEvent) bpmnParse.getCurrentFlowElement();
      intermediateCatchEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createIntermediateCatchSignalEventActivityBehavior(intermediateCatchEvent, signalDefinition, signal));

    } else if (bpmnParse.getCurrentFlowElement() instanceof BoundaryEvent) {
      BoundaryEvent boundaryEvent = (BoundaryEvent) bpmnParse.getCurrentFlowElement();
      boundaryEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createBoundarySignalEventActivityBehavior(boundaryEvent, signalDefinition, signal, boundaryEvent.isCancelActivity()));
    }
  }
 
Example #7
Source File: BoundaryEventParseHandler.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void executeParse(BpmnParse bpmnParse, BoundaryEvent boundaryEvent) {

    if (boundaryEvent.getAttachedToRef() == null) {
      logger.warn("Invalid reference in boundary event. Make sure that the referenced activity " + "is defined in the same scope as the boundary event " + boundaryEvent.getId());
      return;
    }

    EventDefinition eventDefinition = null;
    if (boundaryEvent.getEventDefinitions().size() > 0) {
      eventDefinition = boundaryEvent.getEventDefinitions().get(0);
    }

    if (eventDefinition instanceof TimerEventDefinition || eventDefinition instanceof ErrorEventDefinition || eventDefinition instanceof SignalEventDefinition
        || eventDefinition instanceof CancelEventDefinition || eventDefinition instanceof MessageEventDefinition || eventDefinition instanceof CompensateEventDefinition) {

      bpmnParse.getBpmnParserHandlers().parseElement(bpmnParse, eventDefinition);

    } else {
      // Should already be picked up by process validator on deploy, so this is just to be sure
      logger.warn("Unsupported boundary event type for boundary event " + boundaryEvent.getId());
    }

  }
 
Example #8
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 #9
Source File: MultiInstanceActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void executeCompensationBoundaryEvents(FlowElement flowElement, DelegateExecution execution) {

    //Execute compensation boundary events
    Collection<BoundaryEvent> boundaryEvents = findBoundaryEventsForFlowNode(execution.getProcessDefinitionId(), flowElement);
    if (CollectionUtil.isNotEmpty(boundaryEvents)) {

      // The parent execution becomes a scope, and a child execution is created for each of the boundary events
      for (BoundaryEvent boundaryEvent : boundaryEvents) {

        if (CollectionUtil.isEmpty(boundaryEvent.getEventDefinitions())) {
          continue;
        }

        if (boundaryEvent.getEventDefinitions().get(0) instanceof CompensateEventDefinition) {
          ExecutionEntity childExecutionEntity = Context.getCommandContext().getExecutionEntityManager()
              .createChildExecution((ExecutionEntity) execution);
          childExecutionEntity.setParentId(execution.getId());
          childExecutionEntity.setCurrentFlowElement(boundaryEvent);
          childExecutionEntity.setScope(false);

          ActivityBehavior boundaryEventBehavior = ((ActivityBehavior) boundaryEvent.getBehavior());
          boundaryEventBehavior.execute(childExecutionEntity);
        }
      }
    }
  }
 
Example #10
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 #11
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 #12
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 #13
Source File: BoundaryEventJsonConverter.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected String getStencilId(BaseElement baseElement) {
  BoundaryEvent boundaryEvent = (BoundaryEvent) baseElement;
  List<EventDefinition> eventDefinitions = boundaryEvent.getEventDefinitions();
  if (eventDefinitions.size() != 1) {
    // return timer event as default;
    return STENCIL_EVENT_BOUNDARY_TIMER;
  }

  EventDefinition eventDefinition = eventDefinitions.get(0);
  if (eventDefinition instanceof ErrorEventDefinition) {
    return STENCIL_EVENT_BOUNDARY_ERROR;
  } else if (eventDefinition instanceof SignalEventDefinition) {
    return STENCIL_EVENT_BOUNDARY_SIGNAL;
  } else if (eventDefinition instanceof MessageEventDefinition) {
    return STENCIL_EVENT_BOUNDARY_MESSAGE;
  } else if (eventDefinition instanceof CancelEventDefinition) {
    return STENCIL_EVENT_BOUNDARY_CANCEL;
  } else if (eventDefinition instanceof CompensateEventDefinition) {
    return STENCIL_EVENT_BOUNDARY_COMPENSATION;
  } else {
    return STENCIL_EVENT_BOUNDARY_TIMER;
  }
}
 
Example #14
Source File: AbstractBpmnActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Subclasses that call leave() will first pass through this method, before the regular {@link FlowNodeActivityBehavior#leave(ActivityExecution)} is called. This way, we can check if the activity
 * has loop characteristics, and delegate to the behavior if this is the case.
 */
public void leave(DelegateExecution execution) {
  FlowElement currentFlowElement = execution.getCurrentFlowElement();
  Collection<BoundaryEvent> boundaryEvents = findBoundaryEventsForFlowNode(execution.getProcessDefinitionId(), currentFlowElement);
  if (CollectionUtil.isNotEmpty(boundaryEvents)) {
    executeCompensateBoundaryEvents(boundaryEvents, execution);
  }
  if (!hasLoopCharacteristics()) {
    super.leave(execution);
  } else if (hasMultiInstanceCharacteristics()) {
    multiInstanceActivityBehavior.leave(execution);
  }
}
 
Example #15
Source File: CancelEventDefinitionParseHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void executeParse(BpmnParse bpmnParse, CancelEventDefinition cancelEventDefinition) {
  if (bpmnParse.getCurrentFlowElement() instanceof BoundaryEvent) {
    ActivityImpl activity = bpmnParse.getCurrentActivity();
    activity.setProperty("type", "cancelBoundaryCatch");
    activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createCancelBoundaryEventActivityBehavior(cancelEventDefinition));
  }

}
 
Example #16
Source File: CompensateEventDefinitionParseHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void executeParse(BpmnParse bpmnParse, CompensateEventDefinition eventDefinition) {
  
  ScopeImpl scope = bpmnParse.getCurrentScope();
  if(StringUtils.isNotEmpty(eventDefinition.getActivityRef())) {
    if(scope.findActivity(eventDefinition.getActivityRef()) == null) {
      logger.warn("Invalid attribute value for 'activityRef': no activity with id '" + eventDefinition.getActivityRef() +
          "' in current scope " + scope.getId());
    }
  }
  
  org.activiti5.engine.impl.bpmn.parser.CompensateEventDefinition compensateEventDefinition = 
          new org.activiti5.engine.impl.bpmn.parser.CompensateEventDefinition();
  compensateEventDefinition.setActivityRef(eventDefinition.getActivityRef());
  compensateEventDefinition.setWaitForCompletion(eventDefinition.isWaitForCompletion());
  
  ActivityImpl activity = bpmnParse.getCurrentActivity();
  if (bpmnParse.getCurrentFlowElement() instanceof ThrowEvent) {
    
    activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createIntermediateThrowCompensationEventActivityBehavior((ThrowEvent) bpmnParse.getCurrentFlowElement(), compensateEventDefinition));
    
  } else if (bpmnParse.getCurrentFlowElement() instanceof BoundaryEvent) {
   
    BoundaryEvent boundaryEvent = (BoundaryEvent) bpmnParse.getCurrentFlowElement();
    boolean interrupting = boundaryEvent.isCancelActivity();
    
    activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createBoundaryEventActivityBehavior(boundaryEvent, interrupting, activity));
    activity.setProperty("type", "compensationBoundaryCatch");
    
  } else {
    
    // What to do?
    
  }
  
}
 
Example #17
Source File: BoundaryEventConverterTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private void validateModel(BpmnModel model) {

    BoundaryEvent errorElement = (BoundaryEvent) model.getMainProcess().getFlowElement("errorEvent", true);
    ErrorEventDefinition errorEvent = (ErrorEventDefinition) extractEventDefinition(errorElement);
    assertTrue(errorElement.isCancelActivity()); // always true
    assertEquals("errorRef", errorEvent.getErrorCode());
    assertEquals("sid-F21E9F4D-EA19-44DF-B1D3-14663A809CAE", errorElement.getAttachedToRefId());

    BoundaryEvent signalElement = (BoundaryEvent) model.getMainProcess().getFlowElement("signalEvent", true);
    SignalEventDefinition signalEvent = (SignalEventDefinition) extractEventDefinition(signalElement);
    assertFalse(signalElement.isCancelActivity());
    assertEquals("signalRef", signalEvent.getSignalRef());
    assertEquals("sid-F21E9F4D-EA19-44DF-B1D3-14663A809CAE", errorElement.getAttachedToRefId());

    BoundaryEvent messageElement = (BoundaryEvent) model.getMainProcess().getFlowElement("messageEvent", true);
    MessageEventDefinition messageEvent = (MessageEventDefinition) extractEventDefinition(messageElement);
    assertFalse(messageElement.isCancelActivity());
    assertEquals("messageRef", messageEvent.getMessageRef());
    assertEquals("sid-F21E9F4D-EA19-44DF-B1D3-14663A809CAE", errorElement.getAttachedToRefId());

    BoundaryEvent timerElement = (BoundaryEvent) model.getMainProcess().getFlowElement("timerEvent", true);
    TimerEventDefinition timerEvent = (TimerEventDefinition) extractEventDefinition(timerElement);
    assertFalse(timerElement.isCancelActivity());
    assertEquals("PT5M", timerEvent.getTimeDuration());
    assertEquals("sid-F21E9F4D-EA19-44DF-B1D3-14663A809CAE", errorElement.getAttachedToRefId());

  }
 
Example #18
Source File: ScopedConverterTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private void validateModel(BpmnModel model) {
  FlowElement flowElement = model.getMainProcess().getFlowElement("outerSubProcess", true);
  assertNotNull(flowElement);
  assertTrue(flowElement instanceof SubProcess);
  assertEquals("outerSubProcess", flowElement.getId());
  SubProcess outerSubProcess = (SubProcess) flowElement;
  List<BoundaryEvent> eventList = outerSubProcess.getBoundaryEvents();
  assertEquals(1, eventList.size());
  BoundaryEvent boundaryEvent = eventList.get(0);
  assertEquals("outerBoundaryEvent", boundaryEvent.getId());

  FlowElement subElement = outerSubProcess.getFlowElement("innerSubProcess");
  assertNotNull(subElement);
  assertTrue(subElement instanceof SubProcess);
  assertEquals("innerSubProcess", subElement.getId());
  SubProcess innerSubProcess = (SubProcess) subElement;
  eventList = innerSubProcess.getBoundaryEvents();
  assertEquals(1, eventList.size());
  boundaryEvent = eventList.get(0);
  assertEquals("innerBoundaryEvent", boundaryEvent.getId());

  FlowElement taskElement = innerSubProcess.getFlowElement("usertask");
  assertNotNull(taskElement);
  assertTrue(taskElement instanceof UserTask);
  UserTask userTask = (UserTask) taskElement;
  assertEquals("usertask", userTask.getId());
  eventList = userTask.getBoundaryEvents();
  assertEquals(1, eventList.size());
  boundaryEvent = eventList.get(0);
  assertEquals("taskBoundaryEvent", boundaryEvent.getId());
}
 
Example #19
Source File: FlowNodeHistoryParseHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void parse(BpmnParse bpmnParse, BaseElement element) {
  ActivityImpl activity = bpmnParse.getCurrentScope().findActivity(element.getId());
  if(element instanceof BoundaryEvent) {
  	// A boundary-event never receives an activity start-event
  	activity.addExecutionListener(org.activiti5.engine.impl.pvm.PvmEvent.EVENTNAME_END, ACTIVITY_INSTANCE_START_LISTENER, 0);
  	activity.addExecutionListener(org.activiti5.engine.impl.pvm.PvmEvent.EVENTNAME_END, ACTIVITI_INSTANCE_END_LISTENER, 1);
  } else {
  	activity.addExecutionListener(org.activiti5.engine.impl.pvm.PvmEvent.EVENTNAME_START, ACTIVITY_INSTANCE_START_LISTENER, 0);
  	activity.addExecutionListener(org.activiti5.engine.impl.pvm.PvmEvent.EVENTNAME_END, ACTIVITI_INSTANCE_END_LISTENER);
  }
}
 
Example #20
Source File: BpmnAutoLayout.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void handleAssociations() {

    Hashtable<String, Object> edgeStyle = new Hashtable<String, Object>();
    edgeStyle.put(mxConstants.STYLE_ORTHOGONAL, true);
    edgeStyle.put(mxConstants.STYLE_EDGE, mxEdgeStyle.ElbowConnector);
    edgeStyle.put(mxConstants.STYLE_ENTRY_X, 0.0);
    edgeStyle.put(mxConstants.STYLE_ENTRY_Y, 0.5);
    graph.getStylesheet().putCellStyle(STYLE_SEQUENCEFLOW, edgeStyle);

    Hashtable<String, Object> boundaryEdgeStyle = new Hashtable<String, Object>();
    boundaryEdgeStyle.put(mxConstants.STYLE_EXIT_X, 0.5);
    boundaryEdgeStyle.put(mxConstants.STYLE_EXIT_Y, 1.0);
    boundaryEdgeStyle.put(mxConstants.STYLE_ENTRY_X, 0.5);
    boundaryEdgeStyle.put(mxConstants.STYLE_ENTRY_Y, 1.0);
    boundaryEdgeStyle.put(mxConstants.STYLE_EDGE, mxEdgeStyle.orthConnector);
    graph.getStylesheet().putCellStyle(STYLE_BOUNDARY_SEQUENCEFLOW, boundaryEdgeStyle);

    for (Association association : associations.values()) {
      Object sourceVertex = generatedVertices.get(association.getSourceRef());
      Object targetVertex = generatedVertices.get(association.getTargetRef());

      String style = null;

      if (handledFlowElements.get(association.getSourceRef()) instanceof BoundaryEvent) {
        // Sequence flow out of boundary events are handled in a different way,
        // to make them visually appealing for the eye of the dear end user.
        style = STYLE_BOUNDARY_SEQUENCEFLOW;
      } else {
        style = STYLE_SEQUENCEFLOW;
      }

      Object associationEdge = graph.insertEdge(cellParent, association.getId(), "", sourceVertex, targetVertex, style);
      generatedAssociationEdges.put(association.getId(), associationEdge);
    }
  }
 
Example #21
Source File: BoundaryEventJsonConverter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void convertElementToJson(ObjectNode propertiesNode, BaseElement baseElement) {
  BoundaryEvent boundaryEvent = (BoundaryEvent) baseElement;
  ArrayNode dockersArrayNode = objectMapper.createArrayNode();
  ObjectNode dockNode = objectMapper.createObjectNode();
  GraphicInfo graphicInfo = model.getGraphicInfo(boundaryEvent.getId());
  GraphicInfo parentGraphicInfo = model.getGraphicInfo(boundaryEvent.getAttachedToRef().getId());
  dockNode.put(EDITOR_BOUNDS_X, graphicInfo.getX() - parentGraphicInfo.getX());
  dockNode.put(EDITOR_BOUNDS_Y, graphicInfo.getY() - parentGraphicInfo.getY());
  dockersArrayNode.add(dockNode);
  flowElementNode.set("dockers", dockersArrayNode);

  propertiesNode.put(PROPERTY_CANCEL_ACTIVITY, boundaryEvent.isCancelActivity());

  addEventProperties(boundaryEvent, propertiesNode);
}
 
Example #22
Source File: BoundaryEventJsonConverter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected FlowElement convertJsonToElement(JsonNode elementNode, JsonNode modelNode, Map<String, JsonNode> shapeMap) {
  BoundaryEvent boundaryEvent = new BoundaryEvent();
  String stencilId = BpmnJsonConverterUtil.getStencilId(elementNode);
  if (STENCIL_EVENT_BOUNDARY_TIMER.equals(stencilId)) {
    convertJsonToTimerDefinition(elementNode, boundaryEvent);
    boundaryEvent.setCancelActivity(getPropertyValueAsBoolean(PROPERTY_CANCEL_ACTIVITY, elementNode));

  } else if (STENCIL_EVENT_BOUNDARY_ERROR.equals(stencilId)) {
    convertJsonToErrorDefinition(elementNode, boundaryEvent);

  } else if (STENCIL_EVENT_BOUNDARY_SIGNAL.equals(stencilId)) {
    convertJsonToSignalDefinition(elementNode, boundaryEvent);
    boundaryEvent.setCancelActivity(getPropertyValueAsBoolean(PROPERTY_CANCEL_ACTIVITY, elementNode));

  } else if (STENCIL_EVENT_BOUNDARY_MESSAGE.equals(stencilId)) {
    convertJsonToMessageDefinition(elementNode, boundaryEvent);
    boundaryEvent.setCancelActivity(getPropertyValueAsBoolean(PROPERTY_CANCEL_ACTIVITY, elementNode));
    
  } else if (STENCIL_EVENT_BOUNDARY_CANCEL.equals(stencilId)) {
    CancelEventDefinition cancelEventDefinition = new CancelEventDefinition();
    boundaryEvent.getEventDefinitions().add(cancelEventDefinition);
    boundaryEvent.setCancelActivity(getPropertyValueAsBoolean(PROPERTY_CANCEL_ACTIVITY, elementNode));
  
  } else if (STENCIL_EVENT_BOUNDARY_COMPENSATION.equals(stencilId)) {
    CompensateEventDefinition compensateEventDefinition = new CompensateEventDefinition();
    boundaryEvent.getEventDefinitions().add(compensateEventDefinition);
    boundaryEvent.setCancelActivity(getPropertyValueAsBoolean(PROPERTY_CANCEL_ACTIVITY, elementNode));
  }
  boundaryEvent.setAttachedToRefId(lookForAttachedRef(elementNode.get(EDITOR_SHAPE_ID).asText(), modelNode.get(EDITOR_CHILD_SHAPES)));
  return boundaryEvent;
}
 
Example #23
Source File: BoundaryEventParseHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void executeParse(BpmnParse bpmnParse, BoundaryEvent boundaryEvent) {
  
  ActivityImpl parentActivity = findActivity(bpmnParse, boundaryEvent.getAttachedToRefId());
  if (parentActivity == null) {
    logger.warn("Invalid reference in boundary event. Make sure that the referenced activity is defined in the same scope as the boundary event " +  boundaryEvent.getId());
    return;
  }
 
  ActivityImpl nestedActivity = createActivityOnScope(bpmnParse, boundaryEvent, BpmnXMLConstants.ELEMENT_EVENT_BOUNDARY, parentActivity);
  bpmnParse.setCurrentActivity(nestedActivity);

  EventDefinition eventDefinition = null;
  if (!boundaryEvent.getEventDefinitions().isEmpty()) {
    eventDefinition = boundaryEvent.getEventDefinitions().get(0);
  }
  
  if (eventDefinition instanceof TimerEventDefinition
          || eventDefinition instanceof org.activiti.bpmn.model.ErrorEventDefinition
          || eventDefinition instanceof SignalEventDefinition
          || eventDefinition instanceof CancelEventDefinition
          || eventDefinition instanceof MessageEventDefinition
          || eventDefinition instanceof org.activiti.bpmn.model.CompensateEventDefinition) {

    bpmnParse.getBpmnParserHandlers().parseElement(bpmnParse, eventDefinition);
    
  } else {
    logger.warn("Unsupported boundary event type for boundary event " + boundaryEvent.getId());
  }
}
 
Example #24
Source File: BpmnXMLConverter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void processFlowElements(Collection<FlowElement> flowElementList, BaseElement parentScope) {
  for (FlowElement flowElement : flowElementList) {
    if (flowElement instanceof SequenceFlow) {
      SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
      FlowNode sourceNode = getFlowNodeFromScope(sequenceFlow.getSourceRef(), parentScope);
      if (sourceNode != null) {
        sourceNode.getOutgoingFlows().add(sequenceFlow);
        sequenceFlow.setSourceFlowElement(sourceNode);
      }
      
      FlowNode targetNode = getFlowNodeFromScope(sequenceFlow.getTargetRef(), parentScope);
      if (targetNode != null) {
        targetNode.getIncomingFlows().add(sequenceFlow);
        sequenceFlow.setTargetFlowElement(targetNode);
      }
      
    } else if (flowElement instanceof BoundaryEvent) {
      BoundaryEvent boundaryEvent = (BoundaryEvent) flowElement;
      FlowElement attachedToElement = getFlowNodeFromScope(boundaryEvent.getAttachedToRefId(), parentScope);
      if (attachedToElement instanceof Activity) {
        Activity attachedActivity = (Activity) attachedToElement;
        boundaryEvent.setAttachedToRef(attachedActivity);
        attachedActivity.getBoundaryEvents().add(boundaryEvent);
      }
      
    } else if (flowElement instanceof SubProcess) {
      SubProcess subProcess = (SubProcess) flowElement;
      processFlowElements(subProcess.getFlowElements(), subProcess);
    }
  }
}
 
Example #25
Source File: ScopedConverterTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private void validateModel(BpmnModel model) {
  FlowElement flowElement = model.getMainProcess().getFlowElement("outerSubProcess");
  assertNotNull(flowElement);
  assertTrue(flowElement instanceof SubProcess);
  assertEquals("outerSubProcess", flowElement.getId());
  SubProcess outerSubProcess = (SubProcess) flowElement;
  List<BoundaryEvent> eventList = outerSubProcess.getBoundaryEvents();
  assertEquals(1, eventList.size());
  BoundaryEvent boundaryEvent = eventList.get(0);
  assertEquals("outerBoundaryEvent", boundaryEvent.getId());

  FlowElement subElement = outerSubProcess.getFlowElement("innerSubProcess");
  assertNotNull(subElement);
  assertTrue(subElement instanceof SubProcess);
  assertEquals("innerSubProcess", subElement.getId());
  SubProcess innerSubProcess = (SubProcess) subElement;
  eventList = innerSubProcess.getBoundaryEvents();
  assertEquals(1, eventList.size());
  boundaryEvent = eventList.get(0);
  assertEquals("innerBoundaryEvent", boundaryEvent.getId());

  FlowElement taskElement = innerSubProcess.getFlowElement("usertask");
  assertNotNull(taskElement);
  assertTrue(taskElement instanceof UserTask);
  UserTask userTask = (UserTask) taskElement;
  assertEquals("usertask", userTask.getId());
  eventList = userTask.getBoundaryEvents();
  assertEquals(1, eventList.size());
  boundaryEvent = eventList.get(0);
  assertEquals("taskBoundaryEvent", boundaryEvent.getId());
}
 
Example #26
Source File: BoundaryTimerEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {

  ExecutionEntity executionEntity = (ExecutionEntity) execution;
  if (!(execution.getCurrentFlowElement() instanceof BoundaryEvent)) {
    throw new ActivitiException("Programmatic error: " + this.getClass() + " should not be used for anything else than a boundary event");
  }

  JobManager jobManager = Context.getCommandContext().getJobManager();
  TimerJobEntity timerJob = jobManager.createTimerJob(timerEventDefinition, interrupting, executionEntity, TriggerTimerEventJobHandler.TYPE, 
      TimerEventHandler.createConfiguration(execution.getCurrentActivityId(), timerEventDefinition.getEndDate(), timerEventDefinition.getCalendarName()));
  if (timerJob != null) {
    jobManager.scheduleTimerJob(timerJob);
  }
}
 
Example #27
Source File: BoundaryEventXMLConverter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void writeAdditionalAttributes(BaseElement element, BpmnModel model, XMLStreamWriter xtw) throws Exception {
  BoundaryEvent boundaryEvent = (BoundaryEvent) element;
  if (boundaryEvent.getAttachedToRef() != null) {
    writeDefaultAttribute(ATTRIBUTE_BOUNDARY_ATTACHEDTOREF, boundaryEvent.getAttachedToRef().getId(), xtw);
  }

  if (boundaryEvent.getEventDefinitions().size() == 1) {
    EventDefinition eventDef = boundaryEvent.getEventDefinitions().get(0);

    if (eventDef instanceof ErrorEventDefinition == false) {
      writeDefaultAttribute(ATTRIBUTE_BOUNDARY_CANCELACTIVITY, String.valueOf(boundaryEvent.isCancelActivity()).toLowerCase(), xtw);
    }
  }
}
 
Example #28
Source File: CancelEventDefinitionParseHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void executeParse(BpmnParse bpmnParse, CancelEventDefinition cancelEventDefinition) {
  if (bpmnParse.getCurrentFlowElement() instanceof BoundaryEvent) {
    BoundaryEvent boundaryEvent = (BoundaryEvent) bpmnParse.getCurrentFlowElement();
    boundaryEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createBoundaryCancelEventActivityBehavior(cancelEventDefinition));
  }

}
 
Example #29
Source File: AbstractBpmnActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected Collection<BoundaryEvent> findBoundaryEventsForFlowNode(final String processDefinitionId, final FlowElement flowElement) {
  Process process = getProcessDefinition(processDefinitionId);

  // This could be cached or could be done at parsing time
  List<BoundaryEvent> results = new ArrayList<BoundaryEvent>(1);
  Collection<BoundaryEvent> boundaryEvents = process.findFlowElementsOfType(BoundaryEvent.class, true);
  for (BoundaryEvent boundaryEvent : boundaryEvents) {
    if (boundaryEvent.getAttachedToRefId() != null && boundaryEvent.getAttachedToRefId().equals(flowElement.getId())) {
      results.add(boundaryEvent);
    }
  }
  return results;
}
 
Example #30
Source File: MultiInstanceActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected Collection<BoundaryEvent> findBoundaryEventsForFlowNode(final String processDefinitionId, final FlowElement flowElement) {
  Process process = getProcessDefinition(processDefinitionId);

  // This could be cached or could be done at parsing time
  List<BoundaryEvent> results = new ArrayList<BoundaryEvent>(1);
  Collection<BoundaryEvent> boundaryEvents = process.findFlowElementsOfType(BoundaryEvent.class, true);
  for (BoundaryEvent boundaryEvent : boundaryEvents) {
    if (boundaryEvent.getAttachedToRefId() != null && boundaryEvent.getAttachedToRefId().equals(flowElement.getId())) {
      results.add(boundaryEvent);
    }
  }
  return results;
}