org.activiti.bpmn.model.ExclusiveGateway Java Examples

The following examples show how to use org.activiti.bpmn.model.ExclusiveGateway. 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: ExclusiveGatewayParseHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void executeParse(BpmnParse bpmnParse, ExclusiveGateway gateway) {
  ActivityImpl activity = createActivityOnCurrentScope(bpmnParse, gateway, BpmnXMLConstants.ELEMENT_GATEWAY_EXCLUSIVE);
  
  activity.setAsync(gateway.isAsynchronous());
  activity.setExclusive(!gateway.isNotExclusive());
  
  activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createExclusiveGatewayActivityBehavior(gateway));
}
 
Example #2
Source File: ComplexGatewayXMLConverter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model) throws Exception {
  ExclusiveGateway gateway = new ExclusiveGateway();
  BpmnXMLUtil.addXMLLocation(gateway, xtr);
  parseChildElements(getXMLElementName(), gateway, model, xtr);
  return gateway;
}
 
Example #3
Source File: FlowNodeConverterTest.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("sid-B074A0DD-934A-4053-A537-20ADF0781023", true);
  assertNotNull(flowElement);
  assertTrue(flowElement instanceof ExclusiveGateway);
  ExclusiveGateway gateway = (ExclusiveGateway) flowElement;
  List<SequenceFlow> sequenceFlows = gateway.getOutgoingFlows();
  assertTrue(sequenceFlows.size() == 2);
  assertTrue(sequenceFlows.get(0).getId().equals("sid-07A7E174-8857-4DE9-A7CD-A041706D79C3") || sequenceFlows.get(0).getId().equals("sid-C2068B1E-9A82-41C9-B876-C58E2736C186"));
  assertTrue(sequenceFlows.get(1).getId().equals("sid-07A7E174-8857-4DE9-A7CD-A041706D79C3") || sequenceFlows.get(1).getId().equals("sid-C2068B1E-9A82-41C9-B876-C58E2736C186"));
  assertTrue(sequenceFlows.get(0).getSourceRef().equals("sid-B074A0DD-934A-4053-A537-20ADF0781023"));
  assertTrue(sequenceFlows.get(1).getSourceRef().equals("sid-B074A0DD-934A-4053-A537-20ADF0781023"));
  assertEquals("sid-07A7E174-8857-4DE9-A7CD-A041706D79C3", gateway.getDefaultFlow());
}
 
Example #4
Source File: ExclusiveGatewayXMLConverter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model) throws Exception {
  ExclusiveGateway gateway = new ExclusiveGateway();
  BpmnXMLUtil.addXMLLocation(gateway, xtr);
  parseChildElements(getXMLElementName(), gateway, model, xtr);
  return gateway;
}
 
Example #5
Source File: ExclusiveGatewayValidator.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void validateExclusiveGateway(Process process, ExclusiveGateway exclusiveGateway, List<ValidationError> errors) {
  if (exclusiveGateway.getOutgoingFlows().isEmpty()) {
    addError(errors, Problems.EXCLUSIVE_GATEWAY_NO_OUTGOING_SEQ_FLOW, process, exclusiveGateway, "Exclusive gateway has no outgoing sequence flow");
  } else if (exclusiveGateway.getOutgoingFlows().size() == 1) {
    SequenceFlow sequenceFlow = exclusiveGateway.getOutgoingFlows().get(0);
    if (StringUtils.isNotEmpty(sequenceFlow.getConditionExpression())) {
      addError(errors, Problems.EXCLUSIVE_GATEWAY_CONDITION_NOT_ALLOWED_ON_SINGLE_SEQ_FLOW, process, exclusiveGateway,
          "Exclusive gateway has only one outgoing sequence flow. This is not allowed to have a condition.");
    }
  } else {
    String defaultSequenceFlow = exclusiveGateway.getDefaultFlow();

    List<SequenceFlow> flowsWithoutCondition = new ArrayList<SequenceFlow>();
    for (SequenceFlow flow : exclusiveGateway.getOutgoingFlows()) {
      String condition = flow.getConditionExpression();
      boolean isDefaultFlow = flow.getId() != null && flow.getId().equals(defaultSequenceFlow);
      boolean hasConditon = StringUtils.isNotEmpty(condition);

      if (!hasConditon && !isDefaultFlow) {
        flowsWithoutCondition.add(flow);
      }
      if (hasConditon && isDefaultFlow) {
        addError(errors, Problems.EXCLUSIVE_GATEWAY_CONDITION_ON_DEFAULT_SEQ_FLOW, process, exclusiveGateway, "Default sequenceflow has a condition, which is not allowed");
      }
    }

    if (!flowsWithoutCondition.isEmpty()) {
      addWarning(errors, Problems.EXCLUSIVE_GATEWAY_SEQ_FLOW_WITHOUT_CONDITIONS, process, exclusiveGateway,
          "Exclusive gateway has at least one outgoing sequence flow without a condition (which isn't the default one)");
    }

  }
}
 
Example #6
Source File: ExclusiveGatewayValidator.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
  List<ExclusiveGateway> gateways = process.findFlowElementsOfType(ExclusiveGateway.class);
  for (ExclusiveGateway gateway : gateways) {
    validateExclusiveGateway(process, gateway, errors);
  }
}
 
Example #7
Source File: ExclusiveGatewayParseHandler.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
protected void executeParse(BpmnParse bpmnParse, ExclusiveGateway gateway) {
  gateway.setBehavior(bpmnParse.getActivityBehaviorFactory().createExclusiveGatewayActivityBehavior(gateway));
}
 
Example #8
Source File: TraceService.java    From lemon with Apache License 2.0 4 votes vote down vote up
public NodeDTO convertNodeDto(GraphicInfo graphicInfo,
        FlowElement flowElement, String id, BpmnModel bpmnModel) {
    NodeDTO nodeDto = new NodeDTO();
    nodeDto.setX((int) graphicInfo.getX());
    nodeDto.setY((int) graphicInfo.getY());
    nodeDto.setWidth((int) graphicInfo.getWidth());
    nodeDto.setHeight((int) graphicInfo.getHeight());
    //
    nodeDto.setId(id);
    nodeDto.setName(flowElement.getName());

    if (flowElement instanceof UserTask) {
        nodeDto.setType("用户任务");

        UserTask userTask = (UserTask) flowElement;
        nodeDto.setAssignee(userTask.getAssignee());
    } else if (flowElement instanceof StartEvent) {
        nodeDto.setType("开始事件");
    } else if (flowElement instanceof EndEvent) {
        nodeDto.setType("结束事件");
    } else if (flowElement instanceof ExclusiveGateway) {
        nodeDto.setType("选择网关");
    }

    if (flowElement instanceof FlowNode) {
        FlowNode flowNode = (FlowNode) flowElement;

        for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) {
            EdgeDTO edgeDto = new EdgeDTO();
            edgeDto.setId(sequenceFlow.getTargetRef());

            for (GraphicInfo flowGraphicInfo : bpmnModel
                    .getFlowLocationGraphicInfo(sequenceFlow.getId())) {
                List<Integer> position = new ArrayList<Integer>();
                position.add((int) flowGraphicInfo.getX()
                        - ((int) graphicInfo.getWidth() / 2));
                position.add((int) flowGraphicInfo.getY()
                        - ((int) graphicInfo.getHeight() / 2));
                edgeDto.getG().add(position);
            }

            edgeDto.getG().remove(0);
            edgeDto.getG().remove(edgeDto.getG().size() - 1);
            logger.debug("{}", edgeDto.getG());
            nodeDto.getOutgoings().add(edgeDto);
        }
    }

    return nodeDto;
}
 
Example #9
Source File: ActivityBehaviorFactoryDelegate.java    From openwebflow with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ExclusiveGatewayActivityBehavior createExclusiveGatewayActivityBehavior(ExclusiveGateway exclusiveGateway)
{
	return _source.createExclusiveGatewayActivityBehavior(exclusiveGateway);
}
 
Example #10
Source File: TestActivityBehaviorFactory.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public ExclusiveGatewayActivityBehavior createExclusiveGatewayActivityBehavior(ExclusiveGateway exclusiveGateway) {
	return wrappedActivityBehaviorFactory.createExclusiveGatewayActivityBehavior(exclusiveGateway);
}
 
Example #11
Source File: SimpleConverterTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
private void validateModel(BpmnModel model) {
  assertEquals(2, model.getDefinitionsAttributes().size());
  assertEquals("2.2A", model.getDefinitionsAttributeValue("http://activiti.com/modeler", "version"));
  assertEquals("20140312T10:45:23", model.getDefinitionsAttributeValue("http://activiti.com/modeler", "exportDate"));

  assertEquals("simpleProcess", model.getMainProcess().getId());
  assertEquals("Simple process", model.getMainProcess().getName());
  assertEquals("simple doc", model.getMainProcess().getDocumentation());
  assertEquals(true, model.getMainProcess().isExecutable());

  FlowElement flowElement = model.getMainProcess().getFlowElement("flow1");
  assertNotNull(flowElement);
  assertTrue(flowElement instanceof SequenceFlow);
  assertEquals("flow1", flowElement.getId());

  flowElement = model.getMainProcess().getFlowElement("catchEvent");
  assertNotNull(flowElement);
  assertTrue(flowElement instanceof IntermediateCatchEvent);
  assertEquals("catchEvent", flowElement.getId());
  IntermediateCatchEvent catchEvent = (IntermediateCatchEvent) flowElement;
  assertTrue(catchEvent.getEventDefinitions().size() == 1);
  EventDefinition eventDefinition = catchEvent.getEventDefinitions().get(0);
  assertTrue(eventDefinition instanceof TimerEventDefinition);
  TimerEventDefinition timerDefinition = (TimerEventDefinition) eventDefinition;
  assertEquals("PT5M", timerDefinition.getTimeDuration());

  flowElement = model.getMainProcess().getFlowElement("userTask1");
  assertNotNull(flowElement);
  assertTrue(flowElement instanceof UserTask);
  UserTask task = (UserTask) flowElement;
  assertEquals("task doc", task.getDocumentation());

  flowElement = model.getMainProcess().getFlowElement("flow1Condition");
  assertNotNull(flowElement);
  assertTrue(flowElement instanceof SequenceFlow);
  assertEquals("flow1Condition", flowElement.getId());
  SequenceFlow flow = (SequenceFlow) flowElement;
  assertEquals("${number <= 1}", flow.getConditionExpression());

  flowElement = model.getMainProcess().getFlowElement("gateway1");
  assertNotNull(flowElement);
  assertTrue(flowElement instanceof ExclusiveGateway);
}
 
Example #12
Source File: ExclusiveGatewayXMLConverter.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public Class<? extends BaseElement> getBpmnElementType() {
  return ExclusiveGateway.class;
}
 
Example #13
Source File: TestActivityBehaviorFactory.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public ExclusiveGatewayActivityBehavior createExclusiveGatewayActivityBehavior(ExclusiveGateway exclusiveGateway) {
  return wrappedActivityBehaviorFactory.createExclusiveGatewayActivityBehavior(exclusiveGateway);
}
 
Example #14
Source File: ExclusiveGatewayActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
/**
 * The default behaviour of BPMN, taking every outgoing sequence flow (where the condition evaluates to true), is not valid for an exclusive gateway.
 * 
 * Hence, this behaviour is overridden and replaced by the correct behavior: selecting the first sequence flow which condition evaluates to true (or which hasn't got a condition) and leaving the
 * activity through that sequence flow.
 * 
 * If no sequence flow is selected (ie all conditions evaluate to false), then the default sequence flow is taken (if defined).
 */
@Override
public void leave(DelegateExecution execution) {

  if (log.isDebugEnabled()) {
    log.debug("Leaving exclusive gateway '{}'", execution.getCurrentActivityId());
  }

  ExclusiveGateway exclusiveGateway = (ExclusiveGateway) execution.getCurrentFlowElement();
  
  if (Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
    Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
        ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_COMPLETED, exclusiveGateway.getId(), exclusiveGateway.getName(), execution.getId(),
            execution.getProcessInstanceId(), execution.getProcessDefinitionId(), exclusiveGateway));
  }

  SequenceFlow outgoingSequenceFlow = null;
  SequenceFlow defaultSequenceFlow = null;
  String defaultSequenceFlowId = exclusiveGateway.getDefaultFlow();

  // Determine sequence flow to take
  Iterator<SequenceFlow> sequenceFlowIterator = exclusiveGateway.getOutgoingFlows().iterator();
  while (outgoingSequenceFlow == null && sequenceFlowIterator.hasNext()) {
    SequenceFlow sequenceFlow = sequenceFlowIterator.next();
    
    String skipExpressionString = sequenceFlow.getSkipExpression();
    if (!SkipExpressionUtil.isSkipExpressionEnabled(execution, skipExpressionString)) {
      boolean conditionEvaluatesToTrue = ConditionUtil.hasTrueCondition(sequenceFlow, execution);
      if (conditionEvaluatesToTrue && (defaultSequenceFlowId == null || !defaultSequenceFlowId.equals(sequenceFlow.getId()))) {
        if (log.isDebugEnabled()) {
          log.debug("Sequence flow '{}'selected as outgoing sequence flow.", sequenceFlow.getId());
        }
        outgoingSequenceFlow = sequenceFlow;
      }
    } else if (SkipExpressionUtil.shouldSkipFlowElement(Context.getCommandContext(), execution, skipExpressionString)) {
      outgoingSequenceFlow = sequenceFlow;
    }

    // Already store it, if we would need it later. Saves one for loop.
    if (defaultSequenceFlowId != null && defaultSequenceFlowId.equals(sequenceFlow.getId())) {
      defaultSequenceFlow = sequenceFlow;
    }
    
  }
  
  // We have to record the end here, or else we're already past it
  Context.getCommandContext().getHistoryManager().recordActivityEnd((ExecutionEntity) execution, null);

  // Leave the gateway
  if (outgoingSequenceFlow != null) {
    execution.setCurrentFlowElement(outgoingSequenceFlow);
  } else {
    if (defaultSequenceFlow != null) {
      execution.setCurrentFlowElement(defaultSequenceFlow);
    } else {

      // No sequence flow could be found, not even a default one
      throw new ActivitiException("No outgoing sequence flow of the exclusive gateway '" + exclusiveGateway.getId() + "' could be selected for continuing the process");
    }
  }

  super.leave(execution);
}
 
Example #15
Source File: DefaultActivityBehaviorFactory.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public ExclusiveGatewayActivityBehavior createExclusiveGatewayActivityBehavior(ExclusiveGateway exclusiveGateway) {
  return new ExclusiveGatewayActivityBehavior();
}
 
Example #16
Source File: ExclusiveGatewayParseHandler.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public Class<? extends BaseElement> getHandledType() {
  return ExclusiveGateway.class;
}
 
Example #17
Source File: DefaultActivityBehaviorFactory.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public ExclusiveGatewayActivityBehavior createExclusiveGatewayActivityBehavior(ExclusiveGateway exclusiveGateway) {
  return new ExclusiveGatewayActivityBehavior();
}
 
Example #18
Source File: ExclusiveGatewayJsonConverter.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
protected FlowElement convertJsonToElement(JsonNode elementNode, JsonNode modelNode, Map<String, JsonNode> shapeMap) {
  ExclusiveGateway gateway = new ExclusiveGateway();
  return gateway;
}
 
Example #19
Source File: ExclusiveGatewayJsonConverter.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public static void fillBpmnTypes(Map<Class<? extends BaseElement>, Class<? extends BaseBpmnJsonConverter>> convertersToJsonMap) {
  convertersToJsonMap.put(ExclusiveGateway.class, ExclusiveGatewayJsonConverter.class);
}
 
Example #20
Source File: SequenceFlowJsonConverter.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public void convertToJson(BaseElement baseElement, ActivityProcessor processor, BpmnModel model, FlowElementsContainer container, ArrayNode shapesArrayNode, double subProcessX, double subProcessY) {

  SequenceFlow sequenceFlow = (SequenceFlow) baseElement;
  ObjectNode flowNode = BpmnJsonConverterUtil.createChildShape(sequenceFlow.getId(), STENCIL_SEQUENCE_FLOW, 172, 212, 128, 212);
  ArrayNode dockersArrayNode = objectMapper.createArrayNode();
  ObjectNode dockNode = objectMapper.createObjectNode();
  dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(sequenceFlow.getSourceRef()).getWidth() / 2.0);
  dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(sequenceFlow.getSourceRef()).getHeight() / 2.0);
  dockersArrayNode.add(dockNode);

  if (model.getFlowLocationGraphicInfo(sequenceFlow.getId()).size() > 2) {
    for (int i = 1; i < model.getFlowLocationGraphicInfo(sequenceFlow.getId()).size() - 1; i++) {
      GraphicInfo graphicInfo = model.getFlowLocationGraphicInfo(sequenceFlow.getId()).get(i);
      dockNode = objectMapper.createObjectNode();
      dockNode.put(EDITOR_BOUNDS_X, graphicInfo.getX());
      dockNode.put(EDITOR_BOUNDS_Y, graphicInfo.getY());
      dockersArrayNode.add(dockNode);
    }
  }

  dockNode = objectMapper.createObjectNode();
  dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(sequenceFlow.getTargetRef()).getWidth() / 2.0);
  dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(sequenceFlow.getTargetRef()).getHeight() / 2.0);
  dockersArrayNode.add(dockNode);
  flowNode.set("dockers", dockersArrayNode);
  ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
  outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(sequenceFlow.getTargetRef()));
  flowNode.set("outgoing", outgoingArrayNode);
  flowNode.set("target", BpmnJsonConverterUtil.createResourceNode(sequenceFlow.getTargetRef()));

  ObjectNode propertiesNode = objectMapper.createObjectNode();
  propertiesNode.put(PROPERTY_OVERRIDE_ID, sequenceFlow.getId());
  if (StringUtils.isNotEmpty(sequenceFlow.getName())) {
    propertiesNode.put(PROPERTY_NAME, sequenceFlow.getName());
  }

  if (StringUtils.isNotEmpty(sequenceFlow.getDocumentation())) {
    propertiesNode.put(PROPERTY_DOCUMENTATION, sequenceFlow.getDocumentation());
  }

  if (StringUtils.isNotEmpty(sequenceFlow.getConditionExpression())) {
    propertiesNode.put(PROPERTY_SEQUENCEFLOW_CONDITION, sequenceFlow.getConditionExpression());
  }

  if (StringUtils.isNotEmpty(sequenceFlow.getSourceRef())) {

    FlowElement sourceFlowElement = container.getFlowElement(sequenceFlow.getSourceRef());
    if (sourceFlowElement != null) {
      String defaultFlowId = null;
      if (sourceFlowElement instanceof ExclusiveGateway) {
        ExclusiveGateway parentExclusiveGateway = (ExclusiveGateway) sourceFlowElement;
        defaultFlowId = parentExclusiveGateway.getDefaultFlow();
      } else if (sourceFlowElement instanceof Activity) {
        Activity parentActivity = (Activity) sourceFlowElement;
        defaultFlowId = parentActivity.getDefaultFlow();
      }

      if (defaultFlowId != null && defaultFlowId.equals(sequenceFlow.getId())) {
        propertiesNode.put(PROPERTY_SEQUENCEFLOW_DEFAULT, true);
      }

    }
  }

  if (sequenceFlow.getExecutionListeners().size() > 0) {
    BpmnJsonConverterUtil.convertListenersToJson(sequenceFlow.getExecutionListeners(), true, propertiesNode);
  }

  flowNode.set(EDITOR_SHAPE_PROPERTIES, propertiesNode);
  shapesArrayNode.add(flowNode);
}
 
Example #21
Source File: ExclusiveGatewayParseHandler.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public Class< ? extends BaseElement> getHandledType() {
  return ExclusiveGateway.class;
}
 
Example #22
Source File: ActivityBehaviorFactory.java    From activiti6-boot2 with Apache License 2.0 votes vote down vote up
public abstract ExclusiveGatewayActivityBehavior createExclusiveGatewayActivityBehavior(ExclusiveGateway exclusiveGateway); 
Example #23
Source File: ActivityBehaviorFactory.java    From activiti6-boot2 with Apache License 2.0 votes vote down vote up
public abstract ExclusiveGatewayActivityBehavior createExclusiveGatewayActivityBehavior(ExclusiveGateway exclusiveGateway);