Search in sources :

Example 1 with ThrowEvent

use of org.activiti.bpmn.model.ThrowEvent in project Activiti by Activiti.

the class FeedbackStepDefinitionConverter method createProcessArtifact.

@Override
protected Map<String, BaseElement> createProcessArtifact(FeedbackStepDefinition feedbackStepDefinition, WorkflowDefinitionConversion conversion) {
    // See feedback-step.png in the resource folder to get a graphical understanding of the conversion below
    Map<String, BaseElement> processElements = new HashMap<String, BaseElement>();
    // The first user task, responsible for configuring the feedback
    UserTask selectPeopleUserTask = createSelectPeopleUserTask(feedbackStepDefinition, conversion, processElements);
    // Parallel gateways (forking/joining)
    ParallelGateway fork = createForkParallelGateway(conversion, processElements);
    addSequenceFlow(conversion, selectPeopleUserTask, fork);
    // Gather feedback user task for the initiator of the feedback step
    UserTask gatherFeedbackUserTask = createGatherFeedbackUserTask(feedbackStepDefinition, conversion, processElements);
    addSequenceFlow(conversion, fork, gatherFeedbackUserTask);
    // Global signal event
    Signal signal = createSignalDeclaration(conversion);
    // Signal throw event after the gather feedback task
    ThrowEvent signalThrowEvent = createSignalThrow(conversion, signal);
    addSequenceFlow(conversion, gatherFeedbackUserTask, signalThrowEvent);
    // Povide feedback step
    UserTask feedbackTask = createFeedbackUserTask(feedbackStepDefinition, conversion, processElements);
    addSequenceFlow(conversion, fork, feedbackTask);
    // Boundary signal catch to shut down all tasks if the 'gather feedback' task is completed
    BoundaryEvent boundarySignalCatch = createBoundarySignalCatch(conversion, signal, feedbackTask);
    // Exclusive gateway after the feedback task, needed to correctly merge the sequence flow
    // such that the joining parallel gateway has exactly two incoming sequence flow
    ExclusiveGateway mergingExclusiveGateway = createMergingExclusiveGateway(conversion);
    addSequenceFlow(conversion, feedbackTask, mergingExclusiveGateway);
    addSequenceFlow(conversion, boundarySignalCatch, mergingExclusiveGateway);
    // Parallel gateway that will join  it all together
    ParallelGateway join = createJoinParallelGateway(conversion, processElements);
    addSequenceFlow(conversion, signalThrowEvent, join);
    addSequenceFlow(conversion, mergingExclusiveGateway, join);
    // Set the last activity id, such that next steps can connect correctly
    conversion.setLastActivityId(join.getId());
    return processElements;
}
Also used : ThrowEvent(org.activiti.bpmn.model.ThrowEvent) BaseElement(org.activiti.bpmn.model.BaseElement) ExclusiveGateway(org.activiti.bpmn.model.ExclusiveGateway) Signal(org.activiti.bpmn.model.Signal) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) HashMap(java.util.HashMap) ParallelGateway(org.activiti.bpmn.model.ParallelGateway) UserTask(org.activiti.bpmn.model.UserTask)

Example 2 with ThrowEvent

use of org.activiti.bpmn.model.ThrowEvent in project Activiti by Activiti.

the class IntermediateThrowCompensationEventActivityBehavior method execute.

@Override
public void execute(DelegateExecution execution) {
    ThrowEvent throwEvent = (ThrowEvent) execution.getCurrentFlowElement();
    /*
     * From the BPMN 2.0 spec:
     * 
     * The Activity to be compensated MAY be supplied.
     *  
     * If an Activity is not supplied, then the compensation is broadcast to all completed Activities in 
     * the current Sub- Process (if present), or the entire Process instance (if at the global level). This “throws” the compensation.
     */
    final String activityRef = compensateEventDefinition.getActivityRef();
    CommandContext commandContext = Context.getCommandContext();
    EventSubscriptionEntityManager eventSubscriptionEntityManager = commandContext.getEventSubscriptionEntityManager();
    List<CompensateEventSubscriptionEntity> eventSubscriptions = new ArrayList<CompensateEventSubscriptionEntity>();
    if (StringUtils.isNotEmpty(activityRef)) {
        // If an activity ref is provided, only that activity is compensated
        eventSubscriptions.addAll(eventSubscriptionEntityManager.findCompensateEventSubscriptionsByProcessInstanceIdAndActivityId(execution.getProcessInstanceId(), activityRef));
    } else {
        // If no activity ref is provided, it is broadcast to the current sub process / process instance
        Process process = ProcessDefinitionUtil.getProcess(execution.getProcessDefinitionId());
        FlowElementsContainer flowElementsContainer = null;
        if (throwEvent.getSubProcess() == null) {
            flowElementsContainer = process;
        } else {
            flowElementsContainer = throwEvent.getSubProcess();
        }
        for (FlowElement flowElement : flowElementsContainer.getFlowElements()) {
            if (flowElement instanceof Activity) {
                eventSubscriptions.addAll(eventSubscriptionEntityManager.findCompensateEventSubscriptionsByProcessInstanceIdAndActivityId(execution.getProcessInstanceId(), flowElement.getId()));
            }
        }
    }
    if (eventSubscriptions.isEmpty()) {
        leave(execution);
    } else {
        // TODO: implement async (waitForCompletion=false in bpmn)
        ScopeUtil.throwCompensationEvent(eventSubscriptions, execution, false);
        leave(execution);
    }
}
Also used : ThrowEvent(org.activiti.bpmn.model.ThrowEvent) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) EventSubscriptionEntityManager(org.activiti.engine.impl.persistence.entity.EventSubscriptionEntityManager) FlowElement(org.activiti.bpmn.model.FlowElement) ArrayList(java.util.ArrayList) FlowElementsContainer(org.activiti.bpmn.model.FlowElementsContainer) Activity(org.activiti.bpmn.model.Activity) Process(org.activiti.bpmn.model.Process) CompensateEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.CompensateEventSubscriptionEntity)

Example 3 with ThrowEvent

use of org.activiti.bpmn.model.ThrowEvent in project Activiti by Activiti.

the class CompensateEventDefinitionParseHandler method executeParse.

protected void executeParse(BpmnParse bpmnParse, CompensateEventDefinition eventDefinition) {
    if (bpmnParse.getCurrentFlowElement() instanceof ThrowEvent) {
        ThrowEvent throwEvent = (ThrowEvent) bpmnParse.getCurrentFlowElement();
        throwEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createIntermediateThrowCompensationEventActivityBehavior(throwEvent, eventDefinition));
    } else if (bpmnParse.getCurrentFlowElement() instanceof BoundaryEvent) {
        BoundaryEvent boundaryEvent = (BoundaryEvent) bpmnParse.getCurrentFlowElement();
        boundaryEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createBoundaryCompensateEventActivityBehavior(boundaryEvent, eventDefinition, boundaryEvent.isCancelActivity()));
    } else {
    // What to do?
    }
}
Also used : ThrowEvent(org.activiti.bpmn.model.ThrowEvent) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent)

Example 4 with ThrowEvent

use of org.activiti.bpmn.model.ThrowEvent in project Activiti by Activiti.

the class IntermediateThrowCatchSignalEventConverterTest method checkThrowEvent.

private void checkThrowEvent(BpmnModel model, String id, String signalRef) {
    FlowElement flowElement = model.getMainProcess().getFlowElement(id);
    assertThat(flowElement).isNotNull();
    assertThat(flowElement).isInstanceOf(ThrowEvent.class);
    ThrowEvent throwEvent = (ThrowEvent) flowElement;
    assertThat(throwEvent.getIncomingFlows()).hasSize(1);
    assertThat(throwEvent.getOutgoingFlows()).hasSize(1);
    assertThat(throwEvent.getEventDefinitions()).hasSize(1);
    assertThat(throwEvent.getIncomingFlows().get(0).getXmlRowNumber()).isLessThan(throwEvent.getEventDefinitions().get(0).getXmlRowNumber());
    checkSignalEventDefinition(throwEvent, signalRef);
}
Also used : ThrowEvent(org.activiti.bpmn.model.ThrowEvent) FlowElement(org.activiti.bpmn.model.FlowElement)

Example 5 with ThrowEvent

use of org.activiti.bpmn.model.ThrowEvent in project Activiti by Activiti.

the class ThrowEventXMLConverter method writeAdditionalChildElements.

@Override
protected void writeAdditionalChildElements(BaseElement element, BpmnModel model, XMLStreamWriter xtw) throws Exception {
    ThrowEvent throwEvent = (ThrowEvent) element;
    writeEventDefinitions(throwEvent, throwEvent.getEventDefinitions(), model, xtw);
}
Also used : ThrowEvent(org.activiti.bpmn.model.ThrowEvent)

Aggregations

ThrowEvent (org.activiti.bpmn.model.ThrowEvent)11 SignalEventDefinition (org.activiti.bpmn.model.SignalEventDefinition)3 ArrayList (java.util.ArrayList)2 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)2 EventDefinition (org.activiti.bpmn.model.EventDefinition)2 FlowElement (org.activiti.bpmn.model.FlowElement)2 HashMap (java.util.HashMap)1 Activity (org.activiti.bpmn.model.Activity)1 BaseElement (org.activiti.bpmn.model.BaseElement)1 ExclusiveGateway (org.activiti.bpmn.model.ExclusiveGateway)1 FlowElementsContainer (org.activiti.bpmn.model.FlowElementsContainer)1 ParallelGateway (org.activiti.bpmn.model.ParallelGateway)1 Process (org.activiti.bpmn.model.Process)1 Signal (org.activiti.bpmn.model.Signal)1 UserTask (org.activiti.bpmn.model.UserTask)1 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)1 CompensateEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.CompensateEventSubscriptionEntity)1 EventSubscriptionEntityManager (org.activiti.engine.impl.persistence.entity.EventSubscriptionEntityManager)1