Search in sources :

Example 1 with BaseElement

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

the class ExpectedValidationResult method matches.

public boolean matches(final ValidationResult result) {
    boolean match = true;
    final ModelElementInstance element = result.getElement();
    if (expectedElementId != null) {
        if (element instanceof BaseElement) {
            if (!((BaseElement) element).getId().equals(expectedElementId)) {
                match = false;
            }
        } else {
            match = false;
        }
    }
    if (expectedElementType != null && !expectedElementType.isAssignableFrom(element.getClass())) {
        match = false;
    }
    if (!result.getMessage().startsWith(expectedMessage)) {
        match = false;
    }
    if (expectedType != result.getType()) {
        match = false;
    }
    return match;
}
Also used : BaseElement(io.camunda.zeebe.model.bpmn.instance.BaseElement) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) BpmnModelElementInstance(io.camunda.zeebe.model.bpmn.instance.BpmnModelElementInstance)

Example 2 with BaseElement

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

the class ExpectedValidationResult method toString.

public static String toString(final ValidationResult result) {
    final ModelElementInstance element = result.getElement();
    final StringBuilder sb = new StringBuilder();
    sb.append(result.getType());
    sb.append(": {");
    if (element instanceof BaseElement) {
        sb.append("id: ");
        sb.append(((BaseElement) element).getId());
        sb.append(", ");
    }
    sb.append("type: ");
    sb.append(element.getElementType().getInstanceType().getSimpleName());
    sb.append(", ");
    sb.append("message: ");
    sb.append(result.getMessage());
    sb.append("}");
    return sb.toString();
}
Also used : BaseElement(io.camunda.zeebe.model.bpmn.instance.BaseElement) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) BpmnModelElementInstance(io.camunda.zeebe.model.bpmn.instance.BpmnModelElementInstance)

Example 3 with BaseElement

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

the class AbstractBaseElementBuilder method setWaypoints.

protected void setWaypoints(final BpmnEdge edge) {
    final BaseElement bpmnElement = edge.getBpmnElement();
    final FlowNode edgeSource;
    final FlowNode edgeTarget;
    if (bpmnElement instanceof SequenceFlow) {
        final SequenceFlow sequenceFlow = (SequenceFlow) bpmnElement;
        edgeSource = sequenceFlow.getSource();
        edgeTarget = sequenceFlow.getTarget();
    } else if (bpmnElement instanceof Association) {
        final Association association = (Association) bpmnElement;
        edgeSource = (FlowNode) association.getSource();
        edgeTarget = (FlowNode) association.getTarget();
    } else {
        throw new RuntimeException("Bpmn element type not supported");
    }
    setWaypointsWithSourceAndTarget(edge, edgeSource, edgeTarget);
}
Also used : BaseElement(io.camunda.zeebe.model.bpmn.instance.BaseElement) Association(io.camunda.zeebe.model.bpmn.instance.Association) SequenceFlow(io.camunda.zeebe.model.bpmn.instance.SequenceFlow) FlowNode(io.camunda.zeebe.model.bpmn.instance.FlowNode)

Example 4 with BaseElement

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

the class AbstractBaseElementBuilder method resizeSubProcess.

protected void resizeSubProcess(final BpmnShape innerShape) {
    BaseElement innerElement = innerShape.getBpmnElement();
    Bounds innerShapeBounds = innerShape.getBounds();
    ModelElementInstance parent = innerElement.getParentElement();
    while (parent instanceof SubProcess) {
        final BpmnShape subProcessShape = findBpmnShape((SubProcess) parent);
        if (subProcessShape != null) {
            final Bounds subProcessBounds = subProcessShape.getBounds();
            final double innerX = innerShapeBounds.getX();
            final double innerWidth = innerShapeBounds.getWidth();
            final double innerY = innerShapeBounds.getY();
            final double innerHeight = innerShapeBounds.getHeight();
            final double subProcessY = subProcessBounds.getY();
            final double subProcessHeight = subProcessBounds.getHeight();
            final double subProcessX = subProcessBounds.getX();
            final double subProcessWidth = subProcessBounds.getWidth();
            final double tmpWidth = innerX + innerWidth + SPACE;
            final double tmpHeight = innerY + innerHeight + SPACE;
            if (innerY == subProcessY) {
                subProcessBounds.setY(subProcessY - SPACE);
                subProcessBounds.setHeight(subProcessHeight + SPACE);
            }
            if (tmpWidth >= subProcessX + subProcessWidth) {
                final double newWidth = tmpWidth - subProcessX;
                subProcessBounds.setWidth(newWidth);
            }
            if (tmpHeight >= subProcessY + subProcessHeight) {
                final double newHeight = tmpHeight - subProcessY;
                subProcessBounds.setHeight(newHeight);
            }
            innerElement = (SubProcess) parent;
            innerShapeBounds = subProcessBounds;
            parent = innerElement.getParentElement();
        } else {
            break;
        }
    }
}
Also used : SubProcess(io.camunda.zeebe.model.bpmn.instance.SubProcess) BaseElement(io.camunda.zeebe.model.bpmn.instance.BaseElement) BpmnShape(io.camunda.zeebe.model.bpmn.instance.bpmndi.BpmnShape) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) BpmnModelElementInstance(io.camunda.zeebe.model.bpmn.instance.BpmnModelElementInstance) Bounds(io.camunda.zeebe.model.bpmn.instance.dc.Bounds)

Example 5 with BaseElement

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

the class ModelWalkerTest method shouldVisitModelTopDownDepthFirst.

@Test
public void shouldVisitModelTopDownDepthFirst() {
    // given
    final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("process").startEvent("start-1-1").subProcess("sub-1-2").embeddedSubProcess().startEvent("start-2-1").subProcessDone().subProcess("sub-1-3").embeddedSubProcess().startEvent("start-3-1").subProcessDone().endEvent("end-1-4").done();
    final List<BpmnModelElementInstance> visitedElements = new ArrayList<>();
    final ModelWalker walker = new ModelWalker(modelInstance);
    // when
    walker.walk(visitedElements::add);
    // then
    final List<BaseElement> visitedBaseElements = visitedElements.stream().filter(e -> e instanceof BaseElement).map(e -> (BaseElement) e).collect(Collectors.toList());
    final List<String> subprocessVisitingOrder = visitedBaseElements.stream().filter(e -> e instanceof SubProcess).map(e -> e.getId()).collect(Collectors.toList());
    assertThat(subprocessVisitingOrder).hasSize(2);
    final String firstSubprocess = subprocessVisitingOrder.get(0);
    final String secondSubprocess = subprocessVisitingOrder.get(1);
    final String firstSubprocessStart = "sub-1-2".equals(firstSubprocess) ? "start-2-1" : "start-3-1";
    final String secondSubprocessStart = "sub-1-2".equals(secondSubprocess) ? "start-2-1" : "start-3-1";
    assertThat(visitedBaseElements).extracting(e -> e.getId()).containsSubsequence("process", "start-1-1").containsSubsequence("process", "sub-1-2").containsSubsequence("process", "sub-1-3").containsSubsequence("process", "end-1-4").containsSubsequence(firstSubprocess, secondSubprocess).containsSubsequence(firstSubprocess, firstSubprocessStart).containsSubsequence(secondSubprocess, secondSubprocessStart).containsSubsequence(firstSubprocessStart, secondSubprocessStart);
}
Also used : ModelElementType(org.camunda.bpm.model.xml.type.ModelElementType) Task(io.camunda.zeebe.model.bpmn.instance.Task) BpmnModelElementInstance(io.camunda.zeebe.model.bpmn.instance.BpmnModelElementInstance) FlowNode(io.camunda.zeebe.model.bpmn.instance.FlowNode) FlowElement(io.camunda.zeebe.model.bpmn.instance.FlowElement) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BaseElement(io.camunda.zeebe.model.bpmn.instance.BaseElement) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) Test(org.junit.Test) UserTask(io.camunda.zeebe.model.bpmn.instance.UserTask) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) Activity(io.camunda.zeebe.model.bpmn.instance.Activity) SubProcess(io.camunda.zeebe.model.bpmn.instance.SubProcess) SubProcess(io.camunda.zeebe.model.bpmn.instance.SubProcess) BaseElement(io.camunda.zeebe.model.bpmn.instance.BaseElement) BpmnModelElementInstance(io.camunda.zeebe.model.bpmn.instance.BpmnModelElementInstance) ArrayList(java.util.ArrayList) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) Test(org.junit.Test)

Aggregations

BaseElement (io.camunda.zeebe.model.bpmn.instance.BaseElement)24 BpmnModelElementInstance (io.camunda.zeebe.model.bpmn.instance.BpmnModelElementInstance)18 ModelElementInstance (org.camunda.bpm.model.xml.instance.ModelElementInstance)18 FlowNode (io.camunda.zeebe.model.bpmn.instance.FlowNode)6 SubProcess (io.camunda.zeebe.model.bpmn.instance.SubProcess)6 ArrayList (java.util.ArrayList)6 Bpmn (io.camunda.zeebe.model.bpmn.Bpmn)3 BpmnModelInstance (io.camunda.zeebe.model.bpmn.BpmnModelInstance)3 Activity (io.camunda.zeebe.model.bpmn.instance.Activity)3 Association (io.camunda.zeebe.model.bpmn.instance.Association)3 FlowElement (io.camunda.zeebe.model.bpmn.instance.FlowElement)3 SequenceFlow (io.camunda.zeebe.model.bpmn.instance.SequenceFlow)3 Task (io.camunda.zeebe.model.bpmn.instance.Task)3 UserTask (io.camunda.zeebe.model.bpmn.instance.UserTask)3 BpmnShape (io.camunda.zeebe.model.bpmn.instance.bpmndi.BpmnShape)3 Bounds (io.camunda.zeebe.model.bpmn.instance.dc.Bounds)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 ModelElementType (org.camunda.bpm.model.xml.type.ModelElementType)3