Search in sources :

Example 1 with Process

use of io.camunda.zeebe.model.bpmn.instance.Process in project zeebe by camunda.

the class ProcessBuilderTest method testCreateEmptyProcess.

@Test
public void testCreateEmptyProcess() {
    modelInstance = Bpmn.createProcess().done();
    final Definitions definitions = modelInstance.getDefinitions();
    assertThat(definitions).isNotNull();
    assertThat(definitions.getTargetNamespace()).isEqualTo(BPMN20_NS);
    final Collection<ModelElementInstance> processes = modelInstance.getModelElementsByType(processType);
    assertThat(processes).hasSize(1);
    final Process process = (Process) processes.iterator().next();
    assertThat(process.getId()).isNotNull();
}
Also used : ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) BpmnModelElementInstance(io.camunda.zeebe.model.bpmn.instance.BpmnModelElementInstance) Definitions(io.camunda.zeebe.model.bpmn.instance.Definitions) Process(io.camunda.zeebe.model.bpmn.instance.Process) SubProcess(io.camunda.zeebe.model.bpmn.instance.SubProcess) Test(org.junit.Test)

Example 2 with Process

use of io.camunda.zeebe.model.bpmn.instance.Process in project zeebe by camunda.

the class DefinitionsTest method shouldNotAffectComments.

@Test
@BpmnModelResource
public void shouldNotAffectComments() throws IOException {
    final Definitions definitions = bpmnModelInstance.getDefinitions();
    assertThat(definitions).isNotNull();
    // create another Process element and add it to the definitions
    final Process process = bpmnModelInstance.newInstance(Process.class);
    process.setId("another-process-id");
    definitions.getRootElements().add(process);
    // create another Import element and add it to the definitions
    final Import importElement = bpmnModelInstance.newInstance(Import.class);
    importElement.setNamespace("Imports");
    importElement.setLocation("there");
    importElement.setImportType("example");
    definitions.getImports().add(importElement);
    // validate model
    try {
        Bpmn.validateModel(bpmnModelInstance);
    } catch (final ModelValidationException e) {
        Assert.fail();
    }
    // convert the model to the XML string representation
    final OutputStream outputStream = new ByteArrayOutputStream();
    Bpmn.writeModelToStream(outputStream, bpmnModelInstance);
    InputStream inputStream = IoUtil.convertOutputStreamToInputStream(outputStream);
    final String modelString = IoUtil.getStringFromInputStream(inputStream);
    IoUtil.closeSilently(outputStream);
    IoUtil.closeSilently(inputStream);
    // read test process from file as string
    inputStream = getClass().getResourceAsStream("DefinitionsTest.shouldNotAffectCommentsResult.bpmn");
    final String fileString = IoUtil.getStringFromInputStream(inputStream);
    IoUtil.closeSilently(inputStream);
    // compare strings
    assertThat(modelString).endsWith(fileString);
}
Also used : Import(io.camunda.zeebe.model.bpmn.instance.Import) ModelValidationException(org.camunda.bpm.model.xml.ModelValidationException) InputStream(java.io.InputStream) Definitions(io.camunda.zeebe.model.bpmn.instance.Definitions) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Process(io.camunda.zeebe.model.bpmn.instance.Process) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BpmnModelResource(io.camunda.zeebe.model.bpmn.util.BpmnModelResource) Test(org.junit.Test)

Example 3 with Process

use of io.camunda.zeebe.model.bpmn.instance.Process in project zeebe by camunda.

the class GenerateIdTest method shouldGenerateIdsOnCreate.

@Test
public void shouldGenerateIdsOnCreate() {
    final BpmnModelInstance modelInstance = Bpmn.createEmptyModel();
    final Definitions definitions = modelInstance.newInstance(Definitions.class);
    assertThat(definitions.getId()).isNotNull();
    final Process process = modelInstance.newInstance(Process.class);
    assertThat(process.getId()).isNotNull();
    final StartEvent startEvent = modelInstance.newInstance(StartEvent.class);
    assertThat(startEvent.getId()).isNotNull();
    final UserTask userTask = modelInstance.newInstance(UserTask.class);
    assertThat(userTask.getId()).isNotNull();
}
Also used : Definitions(io.camunda.zeebe.model.bpmn.instance.Definitions) StartEvent(io.camunda.zeebe.model.bpmn.instance.StartEvent) UserTask(io.camunda.zeebe.model.bpmn.instance.UserTask) Process(io.camunda.zeebe.model.bpmn.instance.Process) Test(org.junit.Test)

Example 4 with Process

use of io.camunda.zeebe.model.bpmn.instance.Process in project zeebe by camunda.

the class ProcessTest method shouldImportProcess.

@Test
@BpmnModelResource
public void shouldImportProcess() {
    final ModelElementInstance modelElementById = bpmnModelInstance.getModelElementById("exampleProcessId");
    assertThat(modelElementById).isNotNull();
    final Collection<RootElement> rootElements = bpmnModelInstance.getDefinitions().getRootElements();
    assertThat(rootElements).hasSize(1);
    final io.camunda.zeebe.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();
}
Also used : RootElement(io.camunda.zeebe.model.bpmn.instance.RootElement) Process(io.camunda.zeebe.model.bpmn.instance.Process) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) Process(io.camunda.zeebe.model.bpmn.instance.Process) BpmnModelResource(io.camunda.zeebe.model.bpmn.util.BpmnModelResource) Test(org.junit.Test)

Example 5 with Process

use of io.camunda.zeebe.model.bpmn.instance.Process in project zeebe by camunda.

the class BpmnResourceTransformer method transformProcessResource.

private void transformProcessResource(final DeploymentRecord deploymentEvent, final DeploymentResource deploymentResource, final BpmnModelInstance definition) {
    final Collection<Process> processes = definition.getDefinitions().getChildElementsByType(Process.class);
    for (final Process process : processes) {
        if (process.isExecutable()) {
            final String bpmnProcessId = process.getId();
            final DeployedProcess lastProcess = processState.getLatestProcessVersionByProcessId(BufferUtil.wrapString(bpmnProcessId));
            final DirectBuffer lastDigest = processState.getLatestVersionDigest(wrapString(bpmnProcessId));
            final DirectBuffer resourceDigest = checksumGenerator.apply(deploymentResource);
            // adds process record to deployment record
            final var processMetadata = deploymentEvent.processesMetadata().add();
            processMetadata.setBpmnProcessId(BufferUtil.wrapString(process.getId())).setChecksum(resourceDigest).setResourceName(deploymentResource.getResourceNameBuffer());
            final var isDuplicate = isDuplicateOfLatest(deploymentResource, resourceDigest, lastProcess, lastDigest);
            if (isDuplicate) {
                processMetadata.setVersion(lastProcess.getVersion()).setKey(lastProcess.getKey()).markAsDuplicate();
            } else {
                final var key = keyGenerator.nextKey();
                processMetadata.setKey(key).setVersion(processState.getProcessVersion(bpmnProcessId) + 1);
                stateWriter.appendFollowUpEvent(key, ProcessIntent.CREATED, new ProcessRecord().wrap(processMetadata, deploymentResource.getResource()));
            }
        }
    }
}
Also used : DirectBuffer(org.agrona.DirectBuffer) DeployedProcess(io.camunda.zeebe.engine.state.deployment.DeployedProcess) DeployedProcess(io.camunda.zeebe.engine.state.deployment.DeployedProcess) Process(io.camunda.zeebe.model.bpmn.instance.Process) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) ProcessRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.ProcessRecord)

Aggregations

Process (io.camunda.zeebe.model.bpmn.instance.Process)54 Test (org.junit.Test)33 Definitions (io.camunda.zeebe.model.bpmn.instance.Definitions)27 StartEvent (io.camunda.zeebe.model.bpmn.instance.StartEvent)21 UserTask (io.camunda.zeebe.model.bpmn.instance.UserTask)12 ModelValidationException (org.camunda.bpm.model.xml.ModelValidationException)12 Message (io.camunda.zeebe.model.bpmn.instance.Message)9 MessageEventDefinition (io.camunda.zeebe.model.bpmn.instance.MessageEventDefinition)9 SubProcess (io.camunda.zeebe.model.bpmn.instance.SubProcess)9 EndEvent (io.camunda.zeebe.model.bpmn.instance.EndEvent)6 ExtensionElements (io.camunda.zeebe.model.bpmn.instance.ExtensionElements)6 Import (io.camunda.zeebe.model.bpmn.instance.Import)6 BpmnModelResource (io.camunda.zeebe.model.bpmn.util.BpmnModelResource)6 ModelElementInstance (org.camunda.bpm.model.xml.instance.ModelElementInstance)6 ExecutableFlowElementContainer (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableFlowElementContainer)3 ExecutableProcess (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableProcess)3 ExecutableStartEvent (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableStartEvent)3 DeployedProcess (io.camunda.zeebe.engine.state.deployment.DeployedProcess)3 Bpmn (io.camunda.zeebe.model.bpmn.Bpmn)3 BpmnModelInstance (io.camunda.zeebe.model.bpmn.BpmnModelInstance)3