org.camunda.bpm.model.bpmn.instance.SequenceFlow Java Examples

The following examples show how to use org.camunda.bpm.model.bpmn.instance.SequenceFlow. 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: BpmnProcessModelCustomizer.java    From wecube-platform with Apache License 2.0 6 votes vote down vote up
protected void enhanceSequenceFlows(BpmnModelInstance procModelInstance) {
    Collection<SequenceFlow> sequenceFlows = procModelInstance.getModelElementsByType(SequenceFlow.class);
    for (SequenceFlow sf : sequenceFlows) {

        FlowNode srcFlowNode = sf.getSource();
        FlowNode dstFlowNode = sf.getTarget();

        log.debug("validate sequence flow, id={},name={},srcType={},srcId={},srcOut={},dstId={},dstOut={} ",
                sf.getId(), sf.getName(), srcFlowNode.getElementType().getTypeName(), srcFlowNode.getId(),
                srcFlowNode.getOutgoing().size(), dstFlowNode.getId(), dstFlowNode.getOutgoing().size());

        validateLeafNode(dstFlowNode);

        enhanceSequenceFlow(sf);

    }
}
 
Example #2
Source File: FlowNodeImpl.java    From camunda-bpmn-model with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
public void updateAfterReplacement() {
  super.updateAfterReplacement();
  Collection<Reference> incomingReferences = getIncomingReferencesByType(SequenceFlow.class);
  for (Reference<?> reference : incomingReferences) {
    for (ModelElementInstance sourceElement : reference.findReferenceSourceElements(this)) {
      String referenceIdentifier = reference.getReferenceIdentifier(sourceElement);

      if (referenceIdentifier != null && referenceIdentifier.equals(getId()) && reference instanceof AttributeReference) {
        String attributeName = ((AttributeReference) reference).getReferenceSourceAttribute().getAttributeName();
        if (attributeName.equals(BPMN_ATTRIBUTE_SOURCE_REF)) {
          getOutgoing().add((SequenceFlow) sourceElement);
        }
        else if (attributeName.equals(BPMN_ATTRIBUTE_TARGET_REF)) {
          getIncoming().add((SequenceFlow) sourceElement);
        }
      }
    }

  }
}
 
Example #3
Source File: ComplexGatewayImpl.java    From camunda-bpmn-model with Apache License 2.0 6 votes vote down vote up
public static void registerType(ModelBuilder modelBuilder) {
  ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(ComplexGateway.class, BPMN_ELEMENT_COMPLEX_GATEWAY)
    .namespaceUri(BPMN20_NS)
    .extendsType(Gateway.class)
    .instanceProvider(new ModelTypeInstanceProvider<ComplexGateway>() {
      public ComplexGateway newInstance(ModelTypeInstanceContext instanceContext) {
        return new ComplexGatewayImpl(instanceContext);
      }
    });

  defaultAttribute = typeBuilder.stringAttribute(BPMN_ATTRIBUTE_DEFAULT)
    .idAttributeReference(SequenceFlow.class)
    .build();

  SequenceBuilder sequenceBuilder = typeBuilder.sequence();

  activationConditionChild = sequenceBuilder.element(ActivationCondition.class)
    .build();

  typeBuilder.build();
}
 
Example #4
Source File: TargetVariableScopeTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetLocalScopeWithExecutionListenerTake() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("process")
    .startEvent().id("activityId")
    .sequenceFlowId("sequenceFlow")
    .endEvent()
    .done();

  CamundaExecutionListener listener = modelInstance.newInstance(CamundaExecutionListener.class);
  listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
  listener.setCamundaClass(ExecutionListener.class.getName());
  modelInstance.<SequenceFlow>getModelElementById("sequenceFlow").builder().addExtensionElement(listener);

  testHelper.deploy(modelInstance);
  engineRule.getRuntimeService().startProcessInstanceByKey("process");
}
 
Example #5
Source File: InclusiveGatewayImpl.java    From camunda-bpmn-model with Apache License 2.0 6 votes vote down vote up
public static void registerType(ModelBuilder modelBuilder) {
  ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(InclusiveGateway.class, BPMN_ELEMENT_INCLUSIVE_GATEWAY)
    .namespaceUri(BPMN20_NS)
    .extendsType(Gateway.class)
    .instanceProvider(new ModelTypeInstanceProvider<InclusiveGateway>() {
      public InclusiveGateway newInstance(ModelTypeInstanceContext instanceContext) {
        return new InclusiveGatewayImpl(instanceContext);
      }
    });

  defaultAttribute = typeBuilder.stringAttribute(BPMN_ATTRIBUTE_DEFAULT)
    .idAttributeReference(SequenceFlow.class)
    .build();

  typeBuilder.build();
}
 
Example #6
Source File: BpmnModelInstanceCmdTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/repository/one.bpmn20.xml")
public void testRepositoryService() {
  String processDefinitionId = repositoryService.createProcessDefinitionQuery().processDefinitionKey(PROCESS_KEY).singleResult().getId();

  BpmnModelInstance modelInstance = repositoryService.getBpmnModelInstance(processDefinitionId);
  assertNotNull(modelInstance);

  Collection<ModelElementInstance> events = modelInstance.getModelElementsByType(modelInstance.getModel().getType(Event.class));
  assertEquals(2, events.size());

  Collection<ModelElementInstance> sequenceFlows = modelInstance.getModelElementsByType(modelInstance.getModel().getType(SequenceFlow.class));
  assertEquals(1, sequenceFlows.size());

  StartEvent startEvent = modelInstance.getModelElementById("start");
  assertNotNull(startEvent);
}
 
Example #7
Source File: ExclusiveGatewayImpl.java    From camunda-bpmn-model with Apache License 2.0 6 votes vote down vote up
public static void registerType(ModelBuilder modelBuilder) {
  ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(ExclusiveGateway.class, BPMN_ELEMENT_EXCLUSIVE_GATEWAY)
    .namespaceUri(BPMN20_NS)
    .extendsType(Gateway.class)
    .instanceProvider(new ModelTypeInstanceProvider<ExclusiveGateway>() {
      public ExclusiveGateway newInstance(ModelTypeInstanceContext instanceContext) {
        return new ExclusiveGatewayImpl(instanceContext);
      }
    });

  defaultAttribute = typeBuilder.stringAttribute(BPMN_ATTRIBUTE_DEFAULT)
    .idAttributeReference(SequenceFlow.class)
    .build();

  typeBuilder.build();
}
 
Example #8
Source File: PathCoverageExecutionListener.java    From camunda-bpm-process-test-coverage with Apache License 2.0 6 votes vote down vote up
/**
 * Events aren't reported like SequenceFlows and Activities, so we need
 * special handling. If a sequence flow has an event as the source or the
 * target, we add it to the coverage. It's pretty straight forward if a
 * sequence flow is active, then it's source has been covered anyway and it
 * will most definitely arrive at its target.
 * 
 * @param transitionId
 * @param processDefinition
 * @param repositoryService
 */
private void handleEvent(String transitionId, ProcessDefinition processDefinition,
        RepositoryService repositoryService) {

    final BpmnModelInstance modelInstance = repositoryService.getBpmnModelInstance(processDefinition.getId());

    final ModelElementInstance modelElement = modelInstance.getModelElementById(transitionId);
    if (modelElement.getElementType().getInstanceType() == SequenceFlow.class) {

        final SequenceFlow sequenceFlow = (SequenceFlow) modelElement;

        // If there is an event at the sequence flow source add it to the
        // coverage
        final FlowNode source = sequenceFlow.getSource();
        addEventToCoverage(processDefinition, source);

        // If there is an event at the sequence flow target add it to the
        // coverage
        final FlowNode target = sequenceFlow.getTarget();
        addEventToCoverage(processDefinition, target);

    }

}
 
Example #9
Source File: ExclusiveGatewayImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public static void registerType(ModelBuilder modelBuilder) {
  ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(ExclusiveGateway.class, BPMN_ELEMENT_EXCLUSIVE_GATEWAY)
    .namespaceUri(BPMN20_NS)
    .extendsType(Gateway.class)
    .instanceProvider(new ModelTypeInstanceProvider<ExclusiveGateway>() {
      public ExclusiveGateway newInstance(ModelTypeInstanceContext instanceContext) {
        return new ExclusiveGatewayImpl(instanceContext);
      }
    });

  defaultAttribute = typeBuilder.stringAttribute(BPMN_ATTRIBUTE_DEFAULT)
    .idAttributeReference(SequenceFlow.class)
    .build();

  typeBuilder.build();
}
 
Example #10
Source File: InclusiveGatewayImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public static void registerType(ModelBuilder modelBuilder) {
  ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(InclusiveGateway.class, BPMN_ELEMENT_INCLUSIVE_GATEWAY)
    .namespaceUri(BPMN20_NS)
    .extendsType(Gateway.class)
    .instanceProvider(new ModelTypeInstanceProvider<InclusiveGateway>() {
      public InclusiveGateway newInstance(ModelTypeInstanceContext instanceContext) {
        return new InclusiveGatewayImpl(instanceContext);
      }
    });

  defaultAttribute = typeBuilder.stringAttribute(BPMN_ATTRIBUTE_DEFAULT)
    .idAttributeReference(SequenceFlow.class)
    .build();

  typeBuilder.build();
}
 
Example #11
Source File: ClassCoverage.java    From camunda-bpm-process-test-coverage with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves the class coverage percentage.
 * All covered test methods' elements are aggregated and checked against the 
 * process definition elements.
 * 
 * @return The coverage percentage.
 */
public double getCoveragePercentage() {

    // All deployments must be the same, so we take the first one
    final MethodCoverage anyDeployment = getAnyMethodCoverage();

    final Set<FlowNode> definitionsFlowNodes = anyDeployment.getProcessDefinitionsFlowNodes();
    final Set<SequenceFlow> definitionsSeqenceFlows = anyDeployment.getProcessDefinitionsSequenceFlows();

    final Set<CoveredFlowNode> coveredFlowNodes = getCoveredFlowNodes();
    final Set<CoveredSequenceFlow> coveredSequenceFlows = getCoveredSequenceFlows();

    final double bpmnElementsCount = definitionsFlowNodes.size() + definitionsSeqenceFlows.size();
    final double coveredElementsCount = coveredFlowNodes.size() + coveredSequenceFlows.size();

    return coveredElementsCount / bpmnElementsCount;
}
 
Example #12
Source File: FlowNodeImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
public void updateAfterReplacement() {
  super.updateAfterReplacement();
  Collection<Reference> incomingReferences = getIncomingReferencesByType(SequenceFlow.class);
  for (Reference<?> reference : incomingReferences) {
    for (ModelElementInstance sourceElement : reference.findReferenceSourceElements(this)) {
      String referenceIdentifier = reference.getReferenceIdentifier(sourceElement);

      if (referenceIdentifier != null && referenceIdentifier.equals(getId()) && reference instanceof AttributeReference) {
        String attributeName = ((AttributeReference) reference).getReferenceSourceAttribute().getAttributeName();
        if (attributeName.equals(BPMN_ATTRIBUTE_SOURCE_REF)) {
          getOutgoing().add((SequenceFlow) sourceElement);
        }
        else if (attributeName.equals(BPMN_ATTRIBUTE_TARGET_REF)) {
          getIncoming().add((SequenceFlow) sourceElement);
        }
      }
    }

  }
}
 
Example #13
Source File: ComplexGatewayImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public static void registerType(ModelBuilder modelBuilder) {
  ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(ComplexGateway.class, BPMN_ELEMENT_COMPLEX_GATEWAY)
    .namespaceUri(BPMN20_NS)
    .extendsType(Gateway.class)
    .instanceProvider(new ModelTypeInstanceProvider<ComplexGateway>() {
      public ComplexGateway newInstance(ModelTypeInstanceContext instanceContext) {
        return new ComplexGatewayImpl(instanceContext);
      }
    });

  defaultAttribute = typeBuilder.stringAttribute(BPMN_ATTRIBUTE_DEFAULT)
    .idAttributeReference(SequenceFlow.class)
    .build();

  SequenceBuilder sequenceBuilder = typeBuilder.sequence();

  activationConditionChild = sequenceBuilder.element(ActivationCondition.class)
    .build();

  typeBuilder.build();
}
 
Example #14
Source File: BpmnProcessModelCustomizer.java    From wecube-platform with Apache License 2.0 6 votes vote down vote up
protected void enhanceSequenceFlow(SequenceFlow sf) {
    FlowNode srcFlowNode = sf.getSource();

    if (sf.getConditionExpression() == null && "exclusiveGateway".equals(srcFlowNode.getElementType().getTypeName())
            && srcFlowNode.getOutgoing().size() >= 2) {
        String sfName = sf.getName();
        if (StringUtils.isBlank(sfName)) {
            log.warn("the name of squence flow {} is blank.", sf.getId());
            throw new BpmnCustomizationException(String.format("The name of sequence flow %s cannot be blank.", sf.getId()));
        }

        List<SubProcess> preSubProcesses = srcFlowNode.getPreviousNodes().filterByType(SubProcess.class).list();
        if (preSubProcesses.size() == 1) {
            log.debug("to add condition,sequenceFlowId={}", sf.getId());
            SubProcess preSubProcess = preSubProcesses.get(0);
            ConditionExpression okCon = sf.getModelInstance().newInstance(ConditionExpression.class);
            okCon.setType(FORMAL_EXPR_TYPE);
            okCon.setTextContent(
                    String.format("${ subProcRetCode_%s == '%s' }", preSubProcess.getId(), sfName.trim()));
            sf.builder().condition(okCon).done();
        }

        
    }
}
 
Example #15
Source File: AbstractServiceTaskHandleDelegate.java    From wecube-platform with Apache License 2.0 6 votes vote down vote up
protected List<String> tryCalAllowedOptions(DelegateExecution execution) {
    List<String> allowedOptions = new ArrayList<>();
    FlowElement flowElement = execution.getBpmnModelElementInstance();
    ModelElementInstance parentEi = flowElement.getParentElement();
    if (parentEi != null) {
        SubProcess subProcess = execution.getBpmnModelInstance()
                .getModelElementById(parentEi.getAttributeValue("id"));

        List<ExclusiveGateway> exGws = subProcess.getSucceedingNodes().filterByType(ExclusiveGateway.class).list();
        if (exGws.size() == 1) {
            Collection<SequenceFlow> sfs = exGws.get(0).getOutgoing();
            if (!sfs.isEmpty()) {
                for (SequenceFlow sf : sfs) {
                    getLogger().debug("add sequence name: {}", sf.getName());
                    allowedOptions.add(sf.getName());
                }
            }
        }
    }

    return allowedOptions;
}
 
Example #16
Source File: ConditionalEventTriggeredByExecutionListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonInterruptingSetVariableInTakeListener() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent(START_EVENT_ID)
    .userTask(TASK_BEFORE_CONDITION_ID)
      .name(TASK_BEFORE_CONDITION)
    .sequenceFlowId(FLOW_ID)
    .userTask(TASK_WITH_CONDITION_ID)
      .name(TASK_WITH_CONDITION)
    .endEvent(END_EVENT_ID)
    .done();
  CamundaExecutionListener listener = modelInstance.newInstance(CamundaExecutionListener.class);
  listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
  listener.setCamundaExpression(EXPR_SET_VARIABLE);
  modelInstance.<SequenceFlow>getModelElementById(FLOW_ID).builder().addExtensionElement(listener);
  modelInstance = specifier.specifyConditionalProcess(modelInstance, false);
  engine.manageDeployment(repositoryService.createDeployment().addModelInstance(CONDITIONAL_MODEL, modelInstance).deploy());

  // given
  ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);

  TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
  Task task = taskQuery.singleResult();
  assertNotNull(task);
  assertEquals(TASK_BEFORE_CONDITION, task.getName());

  //when task is completed
  taskService.complete(task.getId());

  //then take listener sets variable
  //non interrupting boundary event is triggered
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(specifier.expectedTaskCount(), tasksAfterVariableIsSet.size());
  assertEquals(specifier.expectedSubscriptions(), conditionEventSubscriptionQuery.list().size());
  specifier.assertTaskNames(tasksAfterVariableIsSet, false, false);
}
 
Example #17
Source File: FlowNodeImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public Query<FlowNode> getPreviousNodes() {
  Collection<FlowNode> previousNodes = new HashSet<FlowNode>();
  for (SequenceFlow sequenceFlow : getIncoming()) {
    previousNodes.add(sequenceFlow.getSource());
  }
  return new QueryImpl<FlowNode>(previousNodes);
}
 
Example #18
Source File: ProcessCoverage.java    From camunda-bpm-process-test-coverage with Apache License 2.0 5 votes vote down vote up
private Set<SequenceFlow> getExecutableSequenceNodes(final Collection<SequenceFlow> sequenceFlows) {

        final HashSet<SequenceFlow> result = new HashSet<SequenceFlow>();
        for (final SequenceFlow sequenceFlow : sequenceFlows) {
            if (definitionFlowNodes.contains(sequenceFlow.getSource())) {
                result.add(sequenceFlow);
            }
        }
        return result;

    }
 
Example #19
Source File: TriggerConditionalEventFromDelegationCodeTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableInTakeListenerWithAsyncBefore() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent()
    .userTask(TASK_BEFORE_CONDITION_ID)
    .name(TASK_BEFORE_CONDITION)
    .sequenceFlowId(FLOW_ID)
    .userTask(TASK_WITH_CONDITION_ID).camundaAsyncBefore()
    .endEvent()
    .done();
  CamundaExecutionListener listener = modelInstance.newInstance(CamundaExecutionListener.class);
  listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
  listener.setCamundaClass(specifier.getDelegateClass().getName());
  modelInstance.<SequenceFlow>getModelElementById(FLOW_ID).builder().addExtensionElement(listener);
  deployConditionalEventSubProcess(modelInstance, CONDITIONAL_EVENT_PROCESS_KEY, specifier.getCondition(), true);

  // given
  ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);

  TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
  Task task = taskQuery.singleResult();
  assertNotNull(task);
  assertEquals(TASK_BEFORE_CONDITION, task.getName());

  //when task is completed
  taskService.complete(task.getId());

  //then take listener sets variable
  //conditional event is triggered
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(specifier.getExpectedInterruptingCount(), taskQuery.taskName(TASK_AFTER_CONDITION).count());
}
 
Example #20
Source File: BoundaryConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonInterruptingSetVariableInTakeListener() {
  final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
                                                .startEvent()
                                                .userTask(TASK_BEFORE_CONDITION_ID)
                                                  .name(TASK_BEFORE_CONDITION)
                                                .sequenceFlowId(FLOW_ID)
                                                .userTask(TASK_WITH_CONDITION_ID).name(TASK_WITH_CONDITION)
                                                .endEvent()
                                                .done();
  CamundaExecutionListener listener = modelInstance.newInstance(CamundaExecutionListener.class);
  listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
  listener.setCamundaExpression(EXPR_SET_VARIABLE);
  modelInstance.<SequenceFlow>getModelElementById(FLOW_ID).builder().addExtensionElement(listener);
  deployConditionalBoundaryEventProcess(modelInstance, TASK_WITH_CONDITION_ID, false);

  // given
  ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);

  TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
  Task task = taskQuery.singleResult();
  assertNotNull(task);
  assertEquals(TASK_BEFORE_CONDITION, task.getName());

  //when task is completed
  taskService.complete(task.getId());

  //then take listener sets variable
  //non interrupting boundary event is triggered with default evaluation behavior
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(2, tasksAfterVariableIsSet.size());
}
 
Example #21
Source File: SequenceFlowImpl.java    From camunda-bpmn-model with Apache License 2.0 5 votes vote down vote up
public static void registerType(ModelBuilder modelBuilder) {
  ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(SequenceFlow.class, BPMN_ELEMENT_SEQUENCE_FLOW)
    .namespaceUri(BPMN20_NS)
    .extendsType(FlowElement.class)
    .instanceProvider(new ModelTypeInstanceProvider<SequenceFlow>() {
      public SequenceFlow newInstance(ModelTypeInstanceContext instanceContext) {
        return new SequenceFlowImpl(instanceContext);
      }
    });

  sourceRefAttribute = typeBuilder.stringAttribute(BPMN_ATTRIBUTE_SOURCE_REF)
    .required()
    .idAttributeReference(FlowNode.class)
    .build();

  targetRefAttribute = typeBuilder.stringAttribute(BPMN_ATTRIBUTE_TARGET_REF)
    .required()
    .idAttributeReference(FlowNode.class)
    .build();

  isImmediateAttribute = typeBuilder.booleanAttribute(BPMN_ATTRIBUTE_IS_IMMEDIATE)
    .build();

  SequenceBuilder sequenceBuilder = typeBuilder.sequence();

  conditionExpressionCollection = sequenceBuilder.element(ConditionExpression.class)
    .build();

  typeBuilder.build();
}
 
Example #22
Source File: BoundaryConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableInTakeListener() {
  final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
                                                .startEvent()
                                                .userTask(TASK_BEFORE_CONDITION_ID)
                                                  .name(TASK_BEFORE_CONDITION)
                                                .sequenceFlowId(FLOW_ID)
                                                .userTask(TASK_WITH_CONDITION_ID).name(TASK_WITH_CONDITION)
                                                .endEvent()
                                                .done();
  CamundaExecutionListener listener = modelInstance.newInstance(CamundaExecutionListener.class);
  listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
  listener.setCamundaExpression(EXPR_SET_VARIABLE);
  modelInstance.<SequenceFlow>getModelElementById(FLOW_ID).builder().addExtensionElement(listener);
  deployConditionalBoundaryEventProcess(modelInstance, TASK_WITH_CONDITION_ID, true);

  // given
  ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);

  TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
  Task task = taskQuery.singleResult();
  assertNotNull(task);
  assertEquals(TASK_BEFORE_CONDITION, task.getName());

  //when task is completed
  taskService.complete(task.getId());

  //then take listener sets variable
  //non interrupting boundary event is triggered with default evaluation behavior
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(TASK_AFTER_CONDITION, tasksAfterVariableIsSet.get(0).getName());
}
 
Example #23
Source File: TriggerConditionalEventFromDelegationCodeTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableInTakeListener() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent()
    .userTask(TASK_BEFORE_CONDITION_ID)
    .name(TASK_BEFORE_CONDITION)
    .sequenceFlowId(FLOW_ID)
    .userTask(TASK_WITH_CONDITION_ID)
    .endEvent()
    .done();
  CamundaExecutionListener listener = modelInstance.newInstance(CamundaExecutionListener.class);
  listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
  listener.setCamundaClass(specifier.getDelegateClass().getName());
  modelInstance.<SequenceFlow>getModelElementById(FLOW_ID).builder().addExtensionElement(listener);
  deployConditionalEventSubProcess(modelInstance, CONDITIONAL_EVENT_PROCESS_KEY, specifier.getCondition(), true);

  // given
  ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);

  TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
  Task task = taskQuery.singleResult();
  assertNotNull(task);
  assertEquals(TASK_BEFORE_CONDITION, task.getName());

  //when task is completed
  taskService.complete(task.getId());

  //then take listener sets variable
  //conditional event is triggered
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(specifier.getExpectedInterruptingCount(), taskQuery.taskName(TASK_AFTER_CONDITION).count());
}
 
Example #24
Source File: FlowNodeImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static void registerType(ModelBuilder modelBuilder) {
  ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(FlowNode.class, BPMN_ELEMENT_FLOW_NODE)
    .namespaceUri(BPMN20_NS)
    .extendsType(FlowElement.class)
    .abstractType();

  SequenceBuilder sequenceBuilder = typeBuilder.sequence();

  incomingCollection = sequenceBuilder.elementCollection(Incoming.class)
    .qNameElementReferenceCollection(SequenceFlow.class)
    .build();

  outgoingCollection = sequenceBuilder.elementCollection(Outgoing.class)
    .qNameElementReferenceCollection(SequenceFlow.class)
    .build();

  /** Camunda Attributes */

  camundaAsyncAfter = typeBuilder.booleanAttribute(CAMUNDA_ATTRIBUTE_ASYNC_AFTER)
    .namespace(CAMUNDA_NS)
    .defaultValue(false)
    .build();

  camundaAsyncBefore = typeBuilder.booleanAttribute(CAMUNDA_ATTRIBUTE_ASYNC_BEFORE)
    .namespace(CAMUNDA_NS)
    .defaultValue(false)
    .build();

  camundaExclusive = typeBuilder.booleanAttribute(CAMUNDA_ATTRIBUTE_EXCLUSIVE)
    .namespace(CAMUNDA_NS)
    .defaultValue(true)
    .build();

  camundaJobPriority = typeBuilder.stringAttribute(CAMUNDA_ATTRIBUTE_JOB_PRIORITY)
     .namespace(CAMUNDA_NS)
     .build();

  typeBuilder.build();
}
 
Example #25
Source File: ConditionalEventTriggeredByExecutionListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableInTakeListener() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent(START_EVENT_ID)
    .userTask(TASK_BEFORE_CONDITION_ID)
      .name(TASK_BEFORE_CONDITION)
    .sequenceFlowId(FLOW_ID)
    .userTask(TASK_WITH_CONDITION_ID)
      .name(TASK_WITH_CONDITION)
    .endEvent(END_EVENT_ID)
    .done();
  CamundaExecutionListener listener = modelInstance.newInstance(CamundaExecutionListener.class);
  listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
  listener.setCamundaExpression(EXPR_SET_VARIABLE);
  modelInstance.<SequenceFlow>getModelElementById(FLOW_ID).builder().addExtensionElement(listener);
  modelInstance = specifier.specifyConditionalProcess(modelInstance, true);
  engine.manageDeployment(repositoryService.createDeployment().addModelInstance(CONDITIONAL_MODEL, modelInstance).deploy());

  // given
  ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);

  TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
  Task task = taskQuery.singleResult();
  assertNotNull(task);
  assertEquals(TASK_BEFORE_CONDITION, task.getName());

  //when task is completed
  taskService.complete(task.getId());

  //then take listener sets variable
  //conditional event is triggered
  tasksAfterVariableIsSet = taskQuery.list();
  specifier.assertTaskNames(tasksAfterVariableIsSet, true, false);
}
 
Example #26
Source File: ExecutionListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testThrowBpmnErrorInTakeListenerAndEventSubprocessWithCatch() {
  // given
  ProcessBuilder processBuilder = Bpmn.createExecutableProcess(PROCESS_KEY);
  BpmnModelInstance model = processBuilder
      .startEvent()
      .userTask("userTask1")
      .sequenceFlowId("flow1")
      .userTask("afterListener")
      .endEvent()
      .done();

  CamundaExecutionListener listener = model.newInstance(CamundaExecutionListener.class);
  listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
  listener.setCamundaClass(ThrowBPMNErrorDelegate.class.getName());
  model.<SequenceFlow>getModelElementById("flow1").builder().addExtensionElement(listener);

  processBuilder.eventSubProcess()
      .startEvent("errorEvent").error(ERROR_CODE)
      .userTask("afterCatch")
      .endEvent();

  testHelper.deploy(model);

  runtimeService.startProcessInstanceByKey(PROCESS_KEY);
  Task task = taskService.createTaskQuery().taskDefinitionKey("userTask1").singleResult();
  // when the listeners are invoked
  taskService.complete(task.getId());

  // then
  verifyErrorGotCaught();
}
 
Example #27
Source File: FlowNodeImpl.java    From camunda-bpmn-model with Apache License 2.0 5 votes vote down vote up
public Query<FlowNode> getPreviousNodes() {
  Collection<FlowNode> previousNodes = new HashSet<FlowNode>();
  for (SequenceFlow sequenceFlow : getIncoming()) {
    previousNodes.add(sequenceFlow.getSource());
  }
  return new QueryImpl<FlowNode>(previousNodes);
}
 
Example #28
Source File: FlowNodeImpl.java    From camunda-bpmn-model with Apache License 2.0 5 votes vote down vote up
public Query<FlowNode> getSucceedingNodes() {
  Collection<FlowNode> succeedingNodes = new HashSet<FlowNode>();
  for (SequenceFlow sequenceFlow : getOutgoing()) {
    succeedingNodes.add(sequenceFlow.getTarget());
  }
  return new QueryImpl<FlowNode>(succeedingNodes);
}
 
Example #29
Source File: FlowNodeImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public Query<FlowNode> getSucceedingNodes() {
  Collection<FlowNode> succeedingNodes = new HashSet<FlowNode>();
  for (SequenceFlow sequenceFlow : getOutgoing()) {
    succeedingNodes.add(sequenceFlow.getTarget());
  }
  return new QueryImpl<FlowNode>(succeedingNodes);
}
 
Example #30
Source File: SequenceFlowImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static void registerType(ModelBuilder modelBuilder) {
  ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(SequenceFlow.class, BPMN_ELEMENT_SEQUENCE_FLOW)
    .namespaceUri(BPMN20_NS)
    .extendsType(FlowElement.class)
    .instanceProvider(new ModelTypeInstanceProvider<SequenceFlow>() {
      public SequenceFlow newInstance(ModelTypeInstanceContext instanceContext) {
        return new SequenceFlowImpl(instanceContext);
      }
    });

  sourceRefAttribute = typeBuilder.stringAttribute(BPMN_ATTRIBUTE_SOURCE_REF)
    .required()
    .idAttributeReference(FlowNode.class)
    .build();

  targetRefAttribute = typeBuilder.stringAttribute(BPMN_ATTRIBUTE_TARGET_REF)
    .required()
    .idAttributeReference(FlowNode.class)
    .build();

  isImmediateAttribute = typeBuilder.booleanAttribute(BPMN_ATTRIBUTE_IS_IMMEDIATE)
    .build();

  SequenceBuilder sequenceBuilder = typeBuilder.sequence();

  conditionExpressionCollection = sequenceBuilder.element(ConditionExpression.class)
    .build();

  typeBuilder.build();
}