Java源码示例:org.camunda.bpm.model.bpmn.instance.FlowNode

示例1
protected void populateFlowNodes(ProcDefOutline outline, FlowNode flowNode) {
	ProcFlowNode pfn = outline.findFlowNode(flowNode.getId());
	if (pfn == null) {
		pfn = buildProcFlowNode(flowNode);
		outline.addFlowNodes(pfn);
	}

	Collection<FlowNode> succeedingFlowNodes = flowNode.getSucceedingNodes().list();

	for (FlowNode fn : succeedingFlowNodes) {
		ProcFlowNode childPfn = outline.findFlowNode(fn.getId());
		boolean needPopulateChild = false;
		if (childPfn == null) {
			childPfn = buildProcFlowNode(fn);
			outline.addFlowNodes(childPfn);
			needPopulateChild = true;
		}

		pfn.addSucceedingFlowNodes(childPfn);

		if (needPopulateChild) {
			populateFlowNodes(outline, fn);
		}
	}

}
 
示例2
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();
        }

        
    }
}
 
示例3
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);

    }
}
 
示例4
/**
 * 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;
}
 
示例5
/**
 * 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);

    }

}
 
示例6
@BeforeClass
public static void createModelInstance() {
  modelInstance = Bpmn.createProcess()
    .startEvent().id("start")
    .userTask().id("user")
    .parallelGateway().id("gateway1")
      .serviceTask()
      .endEvent()
    .moveToLastGateway()
      .parallelGateway().id("gateway2")
        .userTask()
        .endEvent()
      .moveToLastGateway()
        .serviceTask()
        .endEvent()
      .moveToLastGateway()
        .scriptTask()
        .endEvent()
    .done();

  startSucceeding = ((FlowNode) modelInstance.getModelElementById("start")).getSucceedingNodes();
  gateway1Succeeding = ((FlowNode) modelInstance.getModelElementById("gateway1")).getSucceedingNodes();
  gateway2Succeeding = ((FlowNode) modelInstance.getModelElementById("gateway2")).getSucceedingNodes();

}
 
示例7
@BeforeClass
public static void createModelInstance() {
  modelInstance = Bpmn.createProcess()
    .startEvent().id("start")
    .userTask().id("user")
    .parallelGateway().id("gateway1")
      .serviceTask()
      .endEvent()
    .moveToLastGateway()
      .parallelGateway().id("gateway2")
        .userTask()
        .endEvent()
      .moveToLastGateway()
        .serviceTask()
        .endEvent()
      .moveToLastGateway()
        .scriptTask()
        .endEvent()
    .done();

  startSucceeding = ((FlowNode) modelInstance.getModelElementById("start")).getSucceedingNodes();
  gateway1Succeeding = ((FlowNode) modelInstance.getModelElementById("gateway1")).getSucceedingNodes();
  gateway2Succeeding = ((FlowNode) modelInstance.getModelElementById("gateway2")).getSucceedingNodes();

}
 
示例8
protected void populateFlowNodeInsts(ProcInstOutline outline, FlowNode flowNode) {
	ProcFlowNodeInst pfn = outline.findProcFlowNodeInstByNodeId(flowNode.getId());
	if (pfn == null) {
		pfn = new ProcFlowNodeInst();
		pfn.setId(flowNode.getId());
		pfn.setNodeType(flowNode.getElementType().getTypeName());
		pfn.setNodeName(flowNode.getName() == null ? "" : flowNode.getName());
		outline.addNodeInsts(pfn);
	}

	ServiceNodeStatusEntity nodeStatus = serviceNodeStatusRepository
			.findOneByProcInstanceIdAndNodeId(outline.getId(), pfn.getId());

	if (nodeStatus != null) {
		pfn.setStartTime(nodeStatus.getStartTime());
		pfn.setEndTime(nodeStatus.getEndTime());
		pfn.setStatus(nodeStatus.getStatus().name());
	}

	for (FlowNode fn : flowNode.getSucceedingNodes().list()) {
		ProcFlowNodeInst childPfn = outline.findProcFlowNodeInstByNodeId(fn.getId());
		boolean needPopulateChild = false;
		if (childPfn == null) {
			childPfn = new ProcFlowNodeInst();
			childPfn.setId(fn.getId());
			childPfn.setNodeType(fn.getElementType().getTypeName());
			childPfn.setNodeName(fn.getName() == null ? "" : fn.getName());
			outline.addNodeInsts(childPfn);
			needPopulateChild = true;
		}

		pfn.addSucceedingFlowNodes(childPfn);

		if (needPopulateChild) {
			populateFlowNodeInsts(outline, fn);
		}
	}

}
 
示例9
protected ProcFlowNode buildProcFlowNode(FlowNode fn) {
	ProcFlowNode pfn = new ProcFlowNode();
	pfn.setId(fn.getId());
	pfn.setNodeName(fn.getName() == null ? "" : fn.getName());
	pfn.setNodeType(fn.getElementType().getTypeName());

	return pfn;
}
 
示例10
protected void validateLeafNode(FlowNode dstFlowNode) {
    if (dstFlowNode.getOutgoing().isEmpty()) {
        if ("endEvent".equals(dstFlowNode.getElementType().getTypeName())) {
            log.info("end event,id={}", dstFlowNode.getId());
        } else {
            log.warn("the leaf node must be end event,id={}", dstFlowNode.getId());
            throw new BpmnCustomizationException("The leaf node must be end event.");
        }
    }
}
 
示例11
private Set<FlowNode> getExecutableFlowNodes(final Collection<FlowNode> flowNodes) {

        final HashSet<FlowNode> result = new HashSet<FlowNode>();
        for (final FlowNode node : flowNodes) {
            if (isExecutable(node)) {
                result.add(node);
            }
        }
        return result;

    }
 
示例12
private void addEventToCoverage(ProcessDefinition processDefinition, FlowNode node) {

        if (node instanceof IntermediateThrowEvent) {

            final CoveredFlowNode coveredElement = new CoveredFlowNode(processDefinition.getKey(), node.getId());
            // We consider entered throw elements as also ended
            coveredElement.setEnded(true);

            coverageTestRunState.addCoveredElement(coveredElement);
        }
    }
 
示例13
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();
}
 
示例14
public static void registerType(ModelBuilder modelBuilder) {
  ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(Lane.class, BPMN_ELEMENT_LANE)
    .namespaceUri(BPMN20_NS)
    .extendsType(BaseElement.class)
    .instanceProvider(new ModelTypeInstanceProvider<Lane>() {
      public Lane newInstance(ModelTypeInstanceContext instanceContext) {
        return new LaneImpl(instanceContext);
      }
    });

  nameAttribute = typeBuilder.stringAttribute(BPMN_ATTRIBUTE_NAME)
    .build();

  partitionElementRefAttribute = typeBuilder.stringAttribute(BPMN_ATTRIBUTE_PARTITION_ELEMENT_REF)
    .qNameAttributeReference(PartitionElement.class)
    .build();

  SequenceBuilder sequenceBuilder = typeBuilder.sequence();

  partitionElementChild = sequenceBuilder.element(PartitionElement.class)
    .build();

  flowNodeRefCollection = sequenceBuilder.elementCollection(FlowNodeRef.class)
    .idElementReferenceCollection(FlowNode.class)
    .build();

  childLaneSetChild = sequenceBuilder.element(ChildLaneSet.class)
    .build();



  typeBuilder.build();
}
 
示例15
public static void registerType(ModelBuilder modelBuilder) {
  ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(Gateway.class, BPMN_ELEMENT_GATEWAY)
    .namespaceUri(BPMN20_NS)
    .extendsType(FlowNode.class)
    .abstractType();

  gatewayDirectionAttribute = typeBuilder.enumAttribute(BPMN_ATTRIBUTE_GATEWAY_DIRECTION, GatewayDirection.class)
    .defaultValue(GatewayDirection.Unspecified)
    .build();

  typeBuilder.build();
}
 
示例16
public static void registerType(ModelBuilder modelBuilder) {
  ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(Event.class, BPMN_ELEMENT_EVENT)
    .namespaceUri(BPMN20_NS)
    .extendsType(FlowNode.class)
    .abstractType();

  SequenceBuilder sequence = typeBuilder.sequence();

  propertyCollection = sequence.elementCollection(Property.class)
    .build();

  typeBuilder.build();
}
 
示例17
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();
}
 
示例18
public Query<FlowNode> getPreviousNodes() {
  Collection<FlowNode> previousNodes = new HashSet<FlowNode>();
  for (SequenceFlow sequenceFlow : getIncoming()) {
    previousNodes.add(sequenceFlow.getSource());
  }
  return new QueryImpl<FlowNode>(previousNodes);
}
 
示例19
public Query<FlowNode> getSucceedingNodes() {
  Collection<FlowNode> succeedingNodes = new HashSet<FlowNode>();
  for (SequenceFlow sequenceFlow : getOutgoing()) {
    succeedingNodes.add(sequenceFlow.getTarget());
  }
  return new QueryImpl<FlowNode>(succeedingNodes);
}
 
示例20
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();
}
 
示例21
public static void registerType(ModelBuilder modelBuilder) {
  ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(Lane.class, BPMN_ELEMENT_LANE)
    .namespaceUri(BPMN20_NS)
    .extendsType(BaseElement.class)
    .instanceProvider(new ModelTypeInstanceProvider<Lane>() {
      public Lane newInstance(ModelTypeInstanceContext instanceContext) {
        return new LaneImpl(instanceContext);
      }
    });

  nameAttribute = typeBuilder.stringAttribute(BPMN_ATTRIBUTE_NAME)
    .build();

  partitionElementRefAttribute = typeBuilder.stringAttribute(BPMN_ATTRIBUTE_PARTITION_ELEMENT_REF)
    .qNameAttributeReference(PartitionElement.class)
    .build();

  SequenceBuilder sequenceBuilder = typeBuilder.sequence();

  partitionElementChild = sequenceBuilder.element(PartitionElement.class)
    .build();

  flowNodeRefCollection = sequenceBuilder.elementCollection(FlowNodeRef.class)
    .idElementReferenceCollection(FlowNode.class)
    .build();

  childLaneSetChild = sequenceBuilder.element(ChildLaneSet.class)
    .build();



  typeBuilder.build();
}
 
示例22
public static void registerType(ModelBuilder modelBuilder) {
  ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(Gateway.class, BPMN_ELEMENT_GATEWAY)
    .namespaceUri(BPMN20_NS)
    .extendsType(FlowNode.class)
    .abstractType();

  gatewayDirectionAttribute = typeBuilder.enumAttribute(BPMN_ATTRIBUTE_GATEWAY_DIRECTION, GatewayDirection.class)
    .defaultValue(GatewayDirection.Unspecified)
    .build();

  typeBuilder.build();
}
 
示例23
public static void registerType(ModelBuilder modelBuilder) {
  ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(Event.class, BPMN_ELEMENT_EVENT)
    .namespaceUri(BPMN20_NS)
    .extendsType(FlowNode.class)
    .abstractType();

  SequenceBuilder sequence = typeBuilder.sequence();

  propertyCollection = sequence.elementCollection(Property.class)
    .build();

  typeBuilder.build();
}
 
示例24
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();
}
 
示例25
public Query<FlowNode> getPreviousNodes() {
  Collection<FlowNode> previousNodes = new HashSet<FlowNode>();
  for (SequenceFlow sequenceFlow : getIncoming()) {
    previousNodes.add(sequenceFlow.getSource());
  }
  return new QueryImpl<FlowNode>(previousNodes);
}
 
示例26
public Query<FlowNode> getSucceedingNodes() {
  Collection<FlowNode> succeedingNodes = new HashSet<FlowNode>();
  for (SequenceFlow sequenceFlow : getOutgoing()) {
    succeedingNodes.add(sequenceFlow.getTarget());
  }
  return new QueryImpl<FlowNode>(succeedingNodes);
}
 
示例27
public FlowNode getSource() {
  return sourceRefAttribute.getReferenceTargetElement(this);
}
 
示例28
public void setSource(FlowNode source) {
  sourceRefAttribute.setReferenceTargetElement(this, source);
}
 
示例29
public FlowNode getTarget() {
  return targetRefAttribute.getReferenceTargetElement(this);
}
 
示例30
public void setTarget(FlowNode target) {
  targetRefAttribute.setReferenceTargetElement(this, target);
}