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

示例1
public void testJavaDelegateModelExecutionContext() {
  deploy();

  runtimeService.startProcessInstanceByKey(PROCESS_ID);

  BpmnModelInstance modelInstance = ModelExecutionContextServiceTask.modelInstance;
  assertNotNull(modelInstance);

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

  Process process = (Process) modelInstance.getDefinitions().getRootElements().iterator().next();
  assertEquals(PROCESS_ID, process.getId());
  assertTrue(process.isExecutable());

  ServiceTask serviceTask = ModelExecutionContextServiceTask.serviceTask;
  assertNotNull(serviceTask);
  assertEquals(ModelExecutionContextServiceTask.class.getName(), serviceTask.getCamundaClass());
}
 
示例2
public static ProcessBuilder createProcess() {
  BpmnModelInstance modelInstance = INSTANCE.doCreateEmptyModel();
  Definitions definitions = modelInstance.newInstance(Definitions.class);
  definitions.setTargetNamespace(BPMN20_NS);
  definitions.getDomElement().registerNamespace("camunda", CAMUNDA_NS);
  modelInstance.setDefinitions(definitions);
  Process process = modelInstance.newInstance(Process.class);
  definitions.addChildElement(process);

  BpmnDiagram bpmnDiagram = modelInstance.newInstance(BpmnDiagram.class);

  BpmnPlane bpmnPlane = modelInstance.newInstance(BpmnPlane.class);
  bpmnPlane.setBpmnElement(process);

  bpmnDiagram.addChildElement(bpmnPlane);
  definitions.addChildElement(bpmnDiagram);

  return process.builder();
}
 
示例3
@Test
public void createProcessWithParallelGateway() {
  // create process
  Process process = createElement(definitions, "process-with-parallel-gateway", Process.class);

  // create elements
  StartEvent startEvent = createElement(process, "start", StartEvent.class);
  ParallelGateway fork = createElement(process, "fork", ParallelGateway.class);
  UserTask task1 = createElement(process, "task1", UserTask.class);
  ServiceTask task2 = createElement(process, "task2", ServiceTask.class);
  ParallelGateway join = createElement(process, "join", ParallelGateway.class);
  EndEvent endEvent = createElement(process, "end", EndEvent.class);

  // create flows
  createSequenceFlow(process, startEvent, fork);
  createSequenceFlow(process, fork, task1);
  createSequenceFlow(process, fork, task2);
  createSequenceFlow(process, task1, join);
  createSequenceFlow(process, task2, join);
  createSequenceFlow(process, join, endEvent);
}
 
示例4
@Test
@BpmnModelResource
public void shouldImportProcess() {

  ModelElementInstance modelElementById = bpmnModelInstance.getModelElementById("exampleProcessId");
  assertThat(modelElementById).isNotNull();

  Collection<RootElement> rootElements = bpmnModelInstance.getDefinitions().getRootElements();
  assertThat(rootElements).hasSize(1);
  org.camunda.bpm.model.bpmn.instance.Process process = (Process) rootElements.iterator().next();

  assertThat(process.getId()).isEqualTo("exampleProcessId");
  assertThat(process.getName()).isNull();
  assertThat(process.getProcessType()).isEqualTo(ProcessType.None);
  assertThat(process.isExecutable()).isFalse();
  assertThat(process.isClosed()).isFalse();



}
 
示例5
@Test
public void testCreateEmptyProcess() {
  modelInstance = Bpmn.createProcess()
    .done();

  Definitions definitions = modelInstance.getDefinitions();
  assertThat(definitions).isNotNull();
  assertThat(definitions.getTargetNamespace()).isEqualTo(BPMN20_NS);

  Collection<ModelElementInstance> processes = modelInstance.getModelElementsByType(processType);
  assertThat(processes)
    .hasSize(1);

  Process process = (Process) processes.iterator().next();
  assertThat(process.getId()).isNotNull();
}
 
示例6
@Test
public void testProcessCamundaExtensions() {
  modelInstance = Bpmn.createProcess(PROCESS_ID)
    .camundaJobPriority("${somePriority}")
    .camundaTaskPriority(TEST_PROCESS_TASK_PRIORITY)
    .camundaHistoryTimeToLive(TEST_HISTORY_TIME_TO_LIVE)
    .camundaStartableInTasklist(TEST_STARTABLE_IN_TASKLIST)
    .camundaVersionTag(TEST_VERSION_TAG)
    .startEvent()
    .endEvent()
    .done();

  Process process = modelInstance.getModelElementById(PROCESS_ID);
  assertThat(process.getCamundaJobPriority()).isEqualTo("${somePriority}");
  assertThat(process.getCamundaTaskPriority()).isEqualTo(TEST_PROCESS_TASK_PRIORITY);
  assertThat(process.getCamundaHistoryTimeToLive()).isEqualTo(TEST_HISTORY_TIME_TO_LIVE);
  assertThat(process.isCamundaStartableInTasklist()).isEqualTo(TEST_STARTABLE_IN_TASKLIST);
  assertThat(process.getCamundaVersionTag()).isEqualTo(TEST_VERSION_TAG);
}
 
示例7
@Before
public void createModel() {
  testBpmnModelInstance = Bpmn.createEmptyModel();
  Definitions definitions = testBpmnModelInstance.newInstance(Definitions.class);
  testBpmnModelInstance.setDefinitions(definitions);

  message = testBpmnModelInstance.newInstance(Message.class);
  message.setId("message-id");
  definitions.getRootElements().add(message);

  Process process = testBpmnModelInstance.newInstance(Process.class);
  process.setId("process-id");
  definitions.getRootElements().add(process);

  startEvent = testBpmnModelInstance.newInstance(StartEvent.class);
  startEvent.setId("start-event-id");
  process.getFlowElements().add(startEvent);

  messageEventDefinition = testBpmnModelInstance.newInstance(MessageEventDefinition.class);
  messageEventDefinition.setId("msg-def-id");
  messageEventDefinition.setMessage(message);
  startEvent.getEventDefinitions().add(messageEventDefinition);

  startEvent.getEventDefinitionRefs().add(messageEventDefinition);
}
 
示例8
public static ProcessBuilder createProcess() {
  BpmnModelInstance modelInstance = INSTANCE.doCreateEmptyModel();
  Definitions definitions = modelInstance.newInstance(Definitions.class);
  definitions.setTargetNamespace(BPMN20_NS);
  definitions.getDomElement().registerNamespace("camunda", CAMUNDA_NS);
  modelInstance.setDefinitions(definitions);
  Process process = modelInstance.newInstance(Process.class);
  definitions.addChildElement(process);

  BpmnDiagram bpmnDiagram = modelInstance.newInstance(BpmnDiagram.class);

  BpmnPlane bpmnPlane = modelInstance.newInstance(BpmnPlane.class);
  bpmnPlane.setBpmnElement(process);

  bpmnDiagram.addChildElement(bpmnPlane);
  definitions.addChildElement(bpmnDiagram);

  return process.builder();
}
 
示例9
@Test
public void createProcessWithParallelGateway() {
  // create process
  Process process = createElement(definitions, "process-with-parallel-gateway", Process.class);

  // create elements
  StartEvent startEvent = createElement(process, "start", StartEvent.class);
  ParallelGateway fork = createElement(process, "fork", ParallelGateway.class);
  UserTask task1 = createElement(process, "task1", UserTask.class);
  ServiceTask task2 = createElement(process, "task2", ServiceTask.class);
  ParallelGateway join = createElement(process, "join", ParallelGateway.class);
  EndEvent endEvent = createElement(process, "end", EndEvent.class);

  // create flows
  createSequenceFlow(process, startEvent, fork);
  createSequenceFlow(process, fork, task1);
  createSequenceFlow(process, fork, task2);
  createSequenceFlow(process, task1, join);
  createSequenceFlow(process, task2, join);
  createSequenceFlow(process, join, endEvent);
}
 
示例10
@Test
@BpmnModelResource
public void shouldImportProcess() {

  ModelElementInstance modelElementById = bpmnModelInstance.getModelElementById("exampleProcessId");
  assertThat(modelElementById).isNotNull();

  Collection<RootElement> rootElements = bpmnModelInstance.getDefinitions().getRootElements();
  assertThat(rootElements).hasSize(1);
  org.camunda.bpm.model.bpmn.instance.Process process = (Process) rootElements.iterator().next();

  assertThat(process.getId()).isEqualTo("exampleProcessId");
  assertThat(process.getName()).isNull();
  assertThat(process.getProcessType()).isEqualTo(ProcessType.None);
  assertThat(process.isExecutable()).isFalse();
  assertThat(process.isClosed()).isFalse();



}
 
示例11
@Test
public void testCreateEmptyProcess() {
  modelInstance = Bpmn.createProcess()
    .done();

  Definitions definitions = modelInstance.getDefinitions();
  assertThat(definitions).isNotNull();
  assertThat(definitions.getTargetNamespace()).isEqualTo(BPMN20_NS);

  Collection<ModelElementInstance> processes = modelInstance.getModelElementsByType(processType);
  assertThat(processes)
    .hasSize(1);

  Process process = (Process) processes.iterator().next();
  assertThat(process.getId()).isNotNull();
}
 
示例12
@Test
public void testProcessCamundaExtensions() {
  modelInstance = Bpmn.createProcess(PROCESS_ID)
    .camundaJobPriority("${somePriority}")
    .camundaTaskPriority(TEST_PROCESS_TASK_PRIORITY)
    .camundaHistoryTimeToLive(TEST_HISTORY_TIME_TO_LIVE)
    .camundaStartableInTasklist(TEST_STARTABLE_IN_TASKLIST)
    .camundaVersionTag(TEST_VERSION_TAG)
    .startEvent()
    .endEvent()
    .done();

  Process process = modelInstance.getModelElementById(PROCESS_ID);
  assertThat(process.getCamundaJobPriority()).isEqualTo("${somePriority}");
  assertThat(process.getCamundaTaskPriority()).isEqualTo(TEST_PROCESS_TASK_PRIORITY);
  assertThat(process.getCamundaHistoryTimeToLive()).isEqualTo(TEST_HISTORY_TIME_TO_LIVE);
  assertThat(process.isCamundaStartableInTasklist()).isEqualTo(TEST_STARTABLE_IN_TASKLIST);
  assertThat(process.getCamundaVersionTag()).isEqualTo(TEST_VERSION_TAG);
}
 
示例13
@Before
public void createModel() {
  testBpmnModelInstance = Bpmn.createEmptyModel();
  Definitions definitions = testBpmnModelInstance.newInstance(Definitions.class);
  testBpmnModelInstance.setDefinitions(definitions);

  message = testBpmnModelInstance.newInstance(Message.class);
  message.setId("message-id");
  definitions.getRootElements().add(message);

  Process process = testBpmnModelInstance.newInstance(Process.class);
  process.setId("process-id");
  definitions.getRootElements().add(process);

  startEvent = testBpmnModelInstance.newInstance(StartEvent.class);
  startEvent.setId("start-event-id");
  process.getFlowElements().add(startEvent);

  messageEventDefinition = testBpmnModelInstance.newInstance(MessageEventDefinition.class);
  messageEventDefinition.setId("msg-def-id");
  messageEventDefinition.setMessage(message);
  startEvent.getEventDefinitions().add(messageEventDefinition);

  startEvent.getEventDefinitionRefs().add(messageEventDefinition);
}
 
示例14
public static void registerType(ModelBuilder modelBuilder) {
  ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(Participant.class, BPMN_ELEMENT_PARTICIPANT)
    .namespaceUri(BPMN20_NS)
    .extendsType(BaseElement.class)
    .instanceProvider(new ModelTypeInstanceProvider<Participant>() {
      public Participant newInstance(ModelTypeInstanceContext instanceContext) {
        return new ParticipantImpl(instanceContext);
      }
    });

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

  processRefAttribute = typeBuilder.stringAttribute(BPMN_ATTRIBUTE_PROCESS_REF)
    .qNameAttributeReference(Process.class)
    .build();

  SequenceBuilder sequenceBuilder = typeBuilder.sequence();

  interfaceRefCollection = sequenceBuilder.elementCollection(InterfaceRef.class)
    .qNameElementReferenceCollection(Interface.class)
    .build();

  endPointRefCollection = sequenceBuilder.elementCollection(EndPointRef.class)
    .qNameElementReferenceCollection(EndPoint.class)
    .build();

  participantMultiplicityChild = sequenceBuilder.element(ParticipantMultiplicity.class)
    .build();

  typeBuilder.build();
}
 
示例15
public SequenceFlow createSequenceFlow(Process process, FlowNode from, FlowNode to) {
  SequenceFlow sequenceFlow = createElement(process, from.getId() + "-" + to.getId(), SequenceFlow.class);
  process.addChildElement(sequenceFlow);
  sequenceFlow.setSource(from);
  from.getOutgoing().add(sequenceFlow);
  sequenceFlow.setTarget(to);
  to.getIncoming().add(sequenceFlow);
  return sequenceFlow;
}
 
示例16
@Test
public void createProcessWithOneTask() {
  // create process
  Process process = createElement(definitions, "process-with-one-task", Process.class);

  // create elements
  StartEvent startEvent = createElement(process, "start", StartEvent.class);
  UserTask task1 = createElement(process, "task1", UserTask.class);
  EndEvent endEvent = createElement(process, "end", EndEvent.class);

  // create flows
  createSequenceFlow(process, startEvent, task1);
  createSequenceFlow(process, task1, endEvent);
}
 
示例17
@Override
public void validate(Process process, ValidationResultCollector validationResultCollector) {
  Collection<StartEvent> startEvents = process.getChildElementsByType(StartEvent.class);
  int startEventCount = startEvents.size();

  if(startEventCount != 1) {
    validationResultCollector.addError(10, String.format("Process does not have exactly one start event. Got %d.", startEventCount));
  }
}
 
示例18
@Test
public void shouldNotGenerateIdsOnRead() {
  BpmnModelInstance modelInstance = Bpmn.readModelFromStream(GenerateIdTest.class.getResourceAsStream("GenerateIdTest.bpmn"));
  Definitions definitions = modelInstance.getDefinitions();
  assertThat(definitions.getId()).isNull();

  Process process = modelInstance.getModelElementsByType(Process.class).iterator().next();
  assertThat(process.getId()).isNull();

  StartEvent startEvent = modelInstance.getModelElementsByType(StartEvent.class).iterator().next();
  assertThat(startEvent.getId()).isNull();

  UserTask userTask = modelInstance.getModelElementsByType(UserTask.class).iterator().next();
  assertThat(userTask.getId()).isNull();
}
 
示例19
@Test
public void shouldGenerateIdsOnCreate() {
  BpmnModelInstance modelInstance = Bpmn.createEmptyModel();
  Definitions definitions = modelInstance.newInstance(Definitions.class);
  assertThat(definitions.getId()).isNotNull();

  Process process = modelInstance.newInstance(Process.class);
  assertThat(process.getId()).isNotNull();

  StartEvent startEvent = modelInstance.newInstance(StartEvent.class);
  assertThat(startEvent.getId()).isNotNull();

  UserTask userTask = modelInstance.newInstance(UserTask.class);
  assertThat(userTask.getId()).isNotNull();
}
 
示例20
@BeforeClass
public static void getElementTypes() {
  Model model = Bpmn.createEmptyModel().getModel();
  taskType = model.getType(Task.class);
  gatewayType = model.getType(Gateway.class);
  eventType = model.getType(Event.class);
  processType = model.getType(Process.class);
}
 
示例21
@Test
public void testProcessStartableInTasklist() {
  modelInstance = Bpmn.createProcess(PROCESS_ID)
    .startEvent()
    .endEvent()
    .done();

  Process process = modelInstance.getModelElementById(PROCESS_ID);
  assertThat(process.isCamundaStartableInTasklist()).isEqualTo(true);
}
 
示例22
public static void registerType(ModelBuilder modelBuilder) {
  ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(Participant.class, BPMN_ELEMENT_PARTICIPANT)
    .namespaceUri(BPMN20_NS)
    .extendsType(BaseElement.class)
    .instanceProvider(new ModelTypeInstanceProvider<Participant>() {
      public Participant newInstance(ModelTypeInstanceContext instanceContext) {
        return new ParticipantImpl(instanceContext);
      }
    });

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

  processRefAttribute = typeBuilder.stringAttribute(BPMN_ATTRIBUTE_PROCESS_REF)
    .qNameAttributeReference(Process.class)
    .build();

  SequenceBuilder sequenceBuilder = typeBuilder.sequence();

  interfaceRefCollection = sequenceBuilder.elementCollection(InterfaceRef.class)
    .qNameElementReferenceCollection(Interface.class)
    .build();

  endPointRefCollection = sequenceBuilder.elementCollection(EndPointRef.class)
    .qNameElementReferenceCollection(EndPoint.class)
    .build();

  participantMultiplicityChild = sequenceBuilder.element(ParticipantMultiplicity.class)
    .build();

  typeBuilder.build();
}
 
示例23
public SequenceFlow createSequenceFlow(Process process, FlowNode from, FlowNode to) {
  SequenceFlow sequenceFlow = createElement(process, from.getId() + "-" + to.getId(), SequenceFlow.class);
  process.addChildElement(sequenceFlow);
  sequenceFlow.setSource(from);
  from.getOutgoing().add(sequenceFlow);
  sequenceFlow.setTarget(to);
  to.getIncoming().add(sequenceFlow);
  return sequenceFlow;
}
 
示例24
@Test
public void createProcessWithOneTask() {
  // create process
  Process process = createElement(definitions, "process-with-one-task", Process.class);

  // create elements
  StartEvent startEvent = createElement(process, "start", StartEvent.class);
  UserTask task1 = createElement(process, "task1", UserTask.class);
  EndEvent endEvent = createElement(process, "end", EndEvent.class);

  // create flows
  createSequenceFlow(process, startEvent, task1);
  createSequenceFlow(process, task1, endEvent);
}
 
示例25
@Override
public void validate(Process process, ValidationResultCollector validationResultCollector) {
  Collection<StartEvent> startEvents = process.getChildElementsByType(StartEvent.class);
  int startEventCount = startEvents.size();

  if(startEventCount != 1) {
    validationResultCollector.addError(10, String.format("Process does not have exactly one start event. Got %d.", startEventCount));
  }
}
 
示例26
@Test
public void shouldNotGenerateIdsOnRead() {
  BpmnModelInstance modelInstance = Bpmn.readModelFromStream(GenerateIdTest.class.getResourceAsStream("GenerateIdTest.bpmn"));
  Definitions definitions = modelInstance.getDefinitions();
  assertThat(definitions.getId()).isNull();

  Process process = modelInstance.getModelElementsByType(Process.class).iterator().next();
  assertThat(process.getId()).isNull();

  StartEvent startEvent = modelInstance.getModelElementsByType(StartEvent.class).iterator().next();
  assertThat(startEvent.getId()).isNull();

  UserTask userTask = modelInstance.getModelElementsByType(UserTask.class).iterator().next();
  assertThat(userTask.getId()).isNull();
}
 
示例27
@Test
public void shouldGenerateIdsOnCreate() {
  BpmnModelInstance modelInstance = Bpmn.createEmptyModel();
  Definitions definitions = modelInstance.newInstance(Definitions.class);
  assertThat(definitions.getId()).isNotNull();

  Process process = modelInstance.newInstance(Process.class);
  assertThat(process.getId()).isNotNull();

  StartEvent startEvent = modelInstance.newInstance(StartEvent.class);
  assertThat(startEvent.getId()).isNotNull();

  UserTask userTask = modelInstance.newInstance(UserTask.class);
  assertThat(userTask.getId()).isNotNull();
}
 
示例28
@BeforeClass
public static void getElementTypes() {
  Model model = Bpmn.createEmptyModel().getModel();
  taskType = model.getType(Task.class);
  gatewayType = model.getType(Gateway.class);
  eventType = model.getType(Event.class);
  processType = model.getType(Process.class);
}
 
示例29
@Test
public void testBaseElementDocumentation() {
  modelInstance = Bpmn.createProcess("process")
          .documentation("processDocumentation")
          .startEvent("startEvent")
          .documentation("startEventDocumentation_1")
          .documentation("startEventDocumentation_2")
          .documentation("startEventDocumentation_3")
          .userTask("task")
          .documentation("taskDocumentation")
          .businessRuleTask("businessruletask")
          .subProcess("subprocess")
          .documentation("subProcessDocumentation")
          .embeddedSubProcess()
          .startEvent("subprocessStartEvent")
          .endEvent("subprocessEndEvent")
          .subProcessDone()
          .endEvent("endEvent")
          .documentation("endEventDocumentation")
          .done();

  assertThat(((Process) modelInstance.getModelElementById("process")).getDocumentations().iterator().next().getTextContent()).isEqualTo("processDocumentation");
  assertThat(((UserTask) modelInstance.getModelElementById("task")).getDocumentations().iterator().next().getTextContent()).isEqualTo("taskDocumentation");
  assertThat(((SubProcess) modelInstance.getModelElementById("subprocess")).getDocumentations().iterator().next().getTextContent()).isEqualTo("subProcessDocumentation");
  assertThat(((EndEvent) modelInstance.getModelElementById("endEvent")).getDocumentations().iterator().next().getTextContent()).isEqualTo("endEventDocumentation");

  final Documentation[] startEventDocumentations = ((StartEvent) modelInstance.getModelElementById("startEvent")).getDocumentations().toArray(new Documentation[]{});
  assertThat(startEventDocumentations.length).isEqualTo(3);
  for (int i = 1; i <=3; i++) {
    assertThat(startEventDocumentations[i - 1].getTextContent()).isEqualTo("startEventDocumentation_" + i);
  }
}
 
示例30
@Test
public void testProcessStartableInTasklist() {
  modelInstance = Bpmn.createProcess(PROCESS_ID)
    .startEvent()
    .endEvent()
    .done();

  Process process = modelInstance.getModelElementById(PROCESS_ID);
  assertThat(process.isCamundaStartableInTasklist()).isEqualTo(true);
}