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;
}
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();
}
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);
}
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;
}
}
}
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);
}
Aggregations