Java Code Examples for org.flowable.bpmn.model.BpmnModel#getFlowLocationGraphicInfo()

The following examples show how to use org.flowable.bpmn.model.BpmnModel#getFlowLocationGraphicInfo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelImageService.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void calculateWidthForFlowElements(Collection<FlowElement> elementList, BpmnModel bpmnModel, GraphicInfo diagramInfo) {
    for (FlowElement flowElement : elementList) {
        List<GraphicInfo> graphicInfoList = new ArrayList<>();
        if (flowElement instanceof SequenceFlow) {
            List<GraphicInfo> flowGraphics = bpmnModel.getFlowLocationGraphicInfo(flowElement.getId());
            if (flowGraphics != null && flowGraphics.size() > 0) {
                graphicInfoList.addAll(flowGraphics);
            }
        } else {
            GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowElement.getId());
            if (graphicInfo != null) {
                graphicInfoList.add(graphicInfo);
            }
        }

        processGraphicInfoList(graphicInfoList, diagramInfo);
    }
}
 
Example 2
Source File: ModelImageService.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void scaleFlowElements(Collection<FlowElement> elementList, BpmnModel bpmnModel, double scaleFactor) {
    for (FlowElement flowElement : elementList) {
        List<GraphicInfo> graphicInfoList = new ArrayList<>();
        if (flowElement instanceof SequenceFlow) {
            List<GraphicInfo> flowList = bpmnModel.getFlowLocationGraphicInfo(flowElement.getId());
            if (flowList != null) {
                graphicInfoList.addAll(flowList);
            }

        // no graphic info for Data Objects
        } else if (!DataObject.class.isInstance(flowElement)) {
            graphicInfoList.add(bpmnModel.getGraphicInfo(flowElement.getId()));
        }

        scaleGraphicInfoList(graphicInfoList, scaleFactor);

        if (flowElement instanceof SubProcess) {
            SubProcess subProcess = (SubProcess) flowElement;
            scaleFlowElements(subProcess.getFlowElements(), bpmnModel, scaleFactor);
        }
    }
}
 
Example 3
Source File: BpmnDisplayJsonConverter.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void fillWaypoints(String id, BpmnModel model, ObjectNode elementNode, GraphicInfo diagramInfo) {
    List<GraphicInfo> flowInfo = model.getFlowLocationGraphicInfo(id);
    ArrayNode waypointArray = objectMapper.createArrayNode();
    for (GraphicInfo graphicInfo : flowInfo) {
        ObjectNode pointNode = objectMapper.createObjectNode();
        fillGraphicInfo(pointNode, graphicInfo, false);
        waypointArray.add(pointNode);
        fillDiagramInfo(graphicInfo, diagramInfo);
    }
    elementNode.set("waypoints", waypointArray);
}
 
Example 4
Source File: ModelImageService.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void scaleArtifacts(Collection<Artifact> artifactList, BpmnModel bpmnModel, double scaleFactor) {
    for (Artifact artifact : artifactList) {
        List<GraphicInfo> graphicInfoList = new ArrayList<>();
        if (artifact instanceof Association) {
            List<GraphicInfo> flowList = bpmnModel.getFlowLocationGraphicInfo(artifact.getId());
            if (flowList != null) {
                graphicInfoList.addAll(flowList);
            }
        } else {
            graphicInfoList.add(bpmnModel.getGraphicInfo(artifact.getId()));
        }

        scaleGraphicInfoList(graphicInfoList, scaleFactor);
    }
}
 
Example 5
Source File: RuntimeDisplayJsonClientResource.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void fillWaypoints(String id, BpmnModel model, ObjectNode elementNode, GraphicInfo diagramInfo) {
    List<GraphicInfo> flowInfo = model.getFlowLocationGraphicInfo(id);
    ArrayNode waypointArray = objectMapper.createArrayNode();
    for (GraphicInfo graphicInfo : flowInfo) {
        ObjectNode pointNode = objectMapper.createObjectNode();
        fillGraphicInfo(pointNode, graphicInfo, false);
        waypointArray.add(pointNode);
        fillDiagramInfo(graphicInfo, diagramInfo);
    }
    elementNode.set("waypoints", waypointArray);
}
 
Example 6
Source File: BaseDynamicSubProcessInjectUtil.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected static void processSubProcessFlowElements(CommandContext commandContext, String prefix, Process process, BpmnModel bpmnModel, 
                SubProcess subProcess, BpmnModel subProcessBpmnModel, ProcessDefinition originalProcessDefinition, 
                DeploymentEntity newDeploymentEntity, Map<String, FlowElement> generatedIds, boolean includeDiInfo) {
    
    Collection<FlowElement> flowElementsOfSubProcess = subProcess.getFlowElementMap().values(); 
    for (FlowElement flowElement : flowElementsOfSubProcess) {

        if (process.getFlowElement(flowElement.getId(), true) != null) {
            generateIdForDuplicateFlowElement(prefix, process, bpmnModel, subProcessBpmnModel, flowElement, generatedIds, includeDiInfo);
        } else {
            if (includeDiInfo) {
                if (flowElement instanceof SequenceFlow) {
                    List<GraphicInfo> wayPoints = subProcessBpmnModel.getFlowLocationGraphicInfo(flowElement.getId());
                    if (wayPoints != null) {
                        bpmnModel.addFlowGraphicInfoList(flowElement.getId(), wayPoints);
                    }
                    
                } else {
                    GraphicInfo graphicInfo = subProcessBpmnModel.getGraphicInfo(flowElement.getId());
                    if (graphicInfo != null) {
                        bpmnModel.addGraphicInfo(flowElement.getId(), subProcessBpmnModel.getGraphicInfo(flowElement.getId()));
                    }
                }
            }
        }
        
        processUserTask(flowElement, originalProcessDefinition, newDeploymentEntity, commandContext);
        processDecisionTask(flowElement, originalProcessDefinition, newDeploymentEntity, commandContext);

        if (flowElement instanceof SubProcess) {
            processSubProcessFlowElements(commandContext, prefix, process, bpmnModel, (SubProcess) flowElement, 
                    subProcessBpmnModel, originalProcessDefinition, newDeploymentEntity, generatedIds, includeDiInfo);
        }
    }
}
 
Example 7
Source File: BpmnParseTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void assertSequenceFlowWayPoints(BpmnModel bpmnModel, String sequenceFlowId, Integer... waypoints) {
    List<GraphicInfo> graphicInfos = bpmnModel.getFlowLocationGraphicInfo(sequenceFlowId);
    assertEquals(waypoints.length / 2, graphicInfos.size());
    for (int i = 0; i < waypoints.length; i += 2) {
        Integer x = waypoints[i];
        Integer y = waypoints[i + 1];
        assertEquals(x.doubleValue(), graphicInfos.get(i / 2).getX());
        assertEquals(y.doubleValue(), graphicInfos.get(i / 2).getY());
    }
}
 
Example 8
Source File: EventSubprocessSequenceFlowTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private void validate(BpmnModel model) {
    EventSubProcess eventSubProcess = (EventSubProcess) model.getFlowElement(EVENT_SUBPROCESS_ID);

    //assert that there where 5 sequenceflows registered.
    assertThat(model.getFlowLocationMap()).hasSize(5);

    List<GraphicInfo> graphicInfo = model.getFlowLocationGraphicInfo(FROM_SE_TO_TASK);
    GraphicInfo start = graphicInfo.get(0);
    assertThat(start.getX()).isCloseTo(180.5, offset(PRECISION)); //75.0+105.5 (parent + interception point)
    assertThat(start.getY()).isCloseTo(314.0, offset(PRECISION)); //230.0 + 99.0 - 15.0 (parent + lower right y - bounds y)

    GraphicInfo end = graphicInfo.get(1);
    assertThat(end.getX()).isCloseTo(225.5, offset(PRECISION)); //75.0 +150.5
    assertThat(end.getY()).isCloseTo(314.0, offset(PRECISION)); //230.0 + 44.0 + 40
}
 
Example 9
Source File: AssociationJsonConverter.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void convertToJson(BpmnJsonConverterContext converterContext, BaseElement baseElement, ActivityProcessor processor, BpmnModel model,
        FlowElementsContainer container, ArrayNode shapesArrayNode, double subProcessX, double subProcessY) {

    Association association = (Association) baseElement;
    ObjectNode flowNode = BpmnJsonConverterUtil.createChildShape(association.getId(), STENCIL_ASSOCIATION, 172, 212, 128, 212);
    ArrayNode dockersArrayNode = objectMapper.createArrayNode();
    ObjectNode dockNode = objectMapper.createObjectNode();
    dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(association.getSourceRef()).getWidth() / 2.0);
    dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(association.getSourceRef()).getHeight() / 2.0);
    dockersArrayNode.add(dockNode);

    List<GraphicInfo> graphicInfoList = model.getFlowLocationGraphicInfo(association.getId());
    if (graphicInfoList.size() > 2) {
        for (int i = 1; i < graphicInfoList.size() - 1; i++) {
            GraphicInfo graphicInfo = graphicInfoList.get(i);
            dockNode = objectMapper.createObjectNode();
            dockNode.put(EDITOR_BOUNDS_X, graphicInfo.getX());
            dockNode.put(EDITOR_BOUNDS_Y, graphicInfo.getY());
            dockersArrayNode.add(dockNode);
        }
    }

    GraphicInfo targetGraphicInfo = model.getGraphicInfo(association.getTargetRef());
    GraphicInfo flowGraphicInfo = graphicInfoList.get(graphicInfoList.size() - 1);

    double diffTopY = Math.abs(flowGraphicInfo.getY() - targetGraphicInfo.getY());
    double diffRightX = Math.abs(flowGraphicInfo.getX() - (targetGraphicInfo.getX() + targetGraphicInfo.getWidth()));
    double diffBottomY = Math.abs(flowGraphicInfo.getY() - (targetGraphicInfo.getY() + targetGraphicInfo.getHeight()));

    dockNode = objectMapper.createObjectNode();
    if (diffTopY < 5) {
        dockNode.put(EDITOR_BOUNDS_X, targetGraphicInfo.getWidth() / 2.0);
        dockNode.put(EDITOR_BOUNDS_Y, 0.0);

    } else if (diffRightX < 5) {
        dockNode.put(EDITOR_BOUNDS_X, targetGraphicInfo.getWidth());
        dockNode.put(EDITOR_BOUNDS_Y, targetGraphicInfo.getHeight() / 2.0);

    } else if (diffBottomY < 5) {
        dockNode.put(EDITOR_BOUNDS_X, targetGraphicInfo.getWidth() / 2.0);
        dockNode.put(EDITOR_BOUNDS_Y, targetGraphicInfo.getHeight());

    } else {
        dockNode.put(EDITOR_BOUNDS_X, 0.0);
        dockNode.put(EDITOR_BOUNDS_Y, targetGraphicInfo.getHeight() / 2.0);
    }
    dockersArrayNode.add(dockNode);
    flowNode.set("dockers", dockersArrayNode);
    ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
    outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(association.getTargetRef()));
    flowNode.set("outgoing", outgoingArrayNode);
    flowNode.set("target", BpmnJsonConverterUtil.createResourceNode(association.getTargetRef()));

    ObjectNode propertiesNode = objectMapper.createObjectNode();
    propertiesNode.put(PROPERTY_OVERRIDE_ID, association.getId());

    flowNode.set(EDITOR_SHAPE_PROPERTIES, propertiesNode);

    shapesArrayNode.add(flowNode);
}
 
Example 10
Source File: CollapsebleSubprocessTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
private void validateModel(BpmnModel bpmnModel) {
    //temp vars
    GraphicInfo gi = null;
    GraphicInfo start = null;
    GraphicInfo end = null;
    List<GraphicInfo> flowLocationGraphicInfo = null;

    //validate parent
    gi = bpmnModel.getGraphicInfo(START_EVENT);
    assertThat(gi.getX()).isEqualTo(73.0);
    assertThat(gi.getY()).isEqualTo(96.0);
    assertThat(gi.getWidth()).isEqualTo(30.0);
    assertThat(gi.getHeight()).isEqualTo(30.0);

    flowLocationGraphicInfo = bpmnModel.getFlowLocationGraphicInfo(SEQUENCEFLOW_TO_COLLAPSEDSUBPROCESS);
    assertThat(flowLocationGraphicInfo).hasSize(2);

    gi = bpmnModel.getGraphicInfo(COLLAPSEDSUBPROCESS);
    assertThat(gi.getExpanded()).isFalse();

    //the intersection points are not full values so its a strange double here...
    start = flowLocationGraphicInfo.get(0);
    assertThat(start.getX()).isCloseTo(102.99814034216989, offset(PRECISION));
    assertThat(start.getY()).isCloseTo(111.23619118649086, offset(PRECISION));

    end = flowLocationGraphicInfo.get(1);
    assertThat(end.getX()).isCloseTo(165.0, offset(PRECISION));
    assertThat(end.getY()).isCloseTo(112.21259842519686, offset(PRECISION));

    //validate graphic infos
    FlowElement flowElement = bpmnModel.getFlowElement(IN_CSB_START_EVENT);
    assertThat(flowElement).isInstanceOf(StartEvent.class);

    gi = bpmnModel.getGraphicInfo(IN_CSB_START_EVENT);
    assertThat(gi.getX()).isEqualTo(90.0);
    assertThat(gi.getY()).isEqualTo(135.0);
    assertThat(gi.getWidth()).isEqualTo(30.0);
    assertThat(gi.getHeight()).isEqualTo(30.0);

    flowElement = bpmnModel.getFlowElement(IN_CSB_SEQUENCEFLOW_TO_USERTASK);
    assertThat(flowElement).isInstanceOf(SequenceFlow.class);
    assertThat(flowElement.getName()).isEqualTo("to ut");

    flowLocationGraphicInfo = bpmnModel.getFlowLocationGraphicInfo(IN_CSB_SEQUENCEFLOW_TO_USERTASK);
    assertThat(flowLocationGraphicInfo).hasSize(2);

    start = flowLocationGraphicInfo.get(0);
    assertThat(start.getX()).isCloseTo(120.0, offset(PRECISION));
    assertThat(start.getY()).isCloseTo(150.0, offset(PRECISION));

    end = flowLocationGraphicInfo.get(1);
    assertThat(end.getX()).isCloseTo(232.0, offset(PRECISION));
    assertThat(end.getY()).isEqualTo(150.0);

    flowElement = bpmnModel.getFlowElement(IN_CSB_USERTASK);
    assertThat(flowElement).isInstanceOf(UserTask.class);
    assertThat(flowElement.getName()).isEqualTo("User task 1");

    gi = bpmnModel.getGraphicInfo(IN_CSB_USERTASK);
    assertThat(gi.getX()).isEqualTo(232.0);
    assertThat(gi.getY()).isEqualTo(110.0);
    assertThat(gi.getWidth()).isEqualTo(100.0);
    assertThat(gi.getHeight()).isEqualTo(80.0);

    flowElement = bpmnModel.getFlowElement(IN_CSB_SEQUENCEFLOW_TO_END);
    assertThat(flowElement).isInstanceOf(SequenceFlow.class);
    assertThat(flowElement.getName()).isEqualTo("to end");

    flowLocationGraphicInfo = bpmnModel.getFlowLocationGraphicInfo(IN_CSB_SEQUENCEFLOW_TO_END);
    assertThat(flowLocationGraphicInfo).hasSize(2);

    start = flowLocationGraphicInfo.get(0);
    assertThat(start.getX()).isCloseTo(332.0, offset(PRECISION));
    assertThat(start.getY()).isCloseTo(150.0, offset(PRECISION));

    end = flowLocationGraphicInfo.get(1);
    assertThat(end.getX()).isEqualTo(435.0);
    assertThat(end.getY()).isEqualTo(150.0);
}
 
Example 11
Source File: BPMNDIExport.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
protected static void createBpmnEdge(BpmnModel model, String elementId, XMLStreamWriter xtw) throws Exception {
    xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_EDGE, BPMNDI_NAMESPACE);
    xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, elementId);
    xtw.writeAttribute(ATTRIBUTE_ID, "BPMNEdge_" + elementId);

    List<GraphicInfo> graphicInfoList = model.getFlowLocationGraphicInfo(elementId);
    for (GraphicInfo graphicInfo : graphicInfoList) {
        xtw.writeStartElement(OMGDI_PREFIX, ELEMENT_DI_WAYPOINT, OMGDI_NAMESPACE);
        xtw.writeAttribute(ATTRIBUTE_DI_X, String.valueOf(graphicInfo.getX()));
        xtw.writeAttribute(ATTRIBUTE_DI_Y, String.valueOf(graphicInfo.getY()));
        xtw.writeEndElement();
    }

    GraphicInfo labelGraphicInfo = model.getLabelGraphicInfo(elementId);
    FlowElement flowElement = model.getFlowElement(elementId);
    MessageFlow messageFlow = null;
    if (flowElement == null) {
        messageFlow = model.getMessageFlow(elementId);
    }

    boolean hasName = false;
    if (flowElement != null && StringUtils.isNotEmpty(flowElement.getName())) {
        hasName = true;

    } else if (messageFlow != null && StringUtils.isNotEmpty(messageFlow.getName())) {
        hasName = true;
    }

    if (labelGraphicInfo != null && hasName) {
        xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_LABEL, BPMNDI_NAMESPACE);
        xtw.writeStartElement(OMGDC_PREFIX, ELEMENT_DI_BOUNDS, OMGDC_NAMESPACE);
        xtw.writeAttribute(ATTRIBUTE_DI_HEIGHT, String.valueOf(labelGraphicInfo.getHeight()));
        xtw.writeAttribute(ATTRIBUTE_DI_WIDTH, String.valueOf(labelGraphicInfo.getWidth()));
        xtw.writeAttribute(ATTRIBUTE_DI_X, String.valueOf(labelGraphicInfo.getX()));
        xtw.writeAttribute(ATTRIBUTE_DI_Y, String.valueOf(labelGraphicInfo.getY()));
        xtw.writeEndElement();
        xtw.writeEndElement();
    }

    xtw.writeEndElement();
}
 
Example 12
Source File: CollapsedSubProcessConverterTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
private void validateModel(BpmnModel bpmnModel) {
    //temp vars
    GraphicInfo gi;
    List<GraphicInfo> flowLocationGraphicInfo;

    //validate parent
    gi = bpmnModel.getGraphicInfo(START_EVENT);
    assertThat(gi.getX()).isEqualTo(73.0);
    assertThat(gi.getY()).isEqualTo(96.0);
    assertThat(gi.getWidth()).isEqualTo(30.0);
    assertThat(gi.getHeight()).isEqualTo(30.0);
    assertThat(gi.getExpanded()).isNull();

    flowLocationGraphicInfo = bpmnModel.getFlowLocationGraphicInfo(SEQUENCEFLOW_TO_COLLAPSEDSUBPROCESS);

    gi = bpmnModel.getGraphicInfo(COLLAPSEDSUBPROCESS);
    assertThat(gi.getExpanded()).isFalse();

    //intersection points traversed from xml are full points it seems...
    assertThat(flowLocationGraphicInfo)
            .extracting(GraphicInfo::getX, GraphicInfo::getY)
            .containsExactly(
                    tuple(102.0, 111.0),
                    tuple(165.0, 112.0)
            );

    //validate graphic infos
    FlowElement flowElement = bpmnModel.getFlowElement(IN_CSB_START_EVENT);
    assertThat(flowElement).isInstanceOf(StartEvent.class);

    gi = bpmnModel.getGraphicInfo(IN_CSB_START_EVENT);
    assertThat(gi.getX()).isEqualTo(90.0);
    assertThat(gi.getY()).isEqualTo(135.0);
    assertThat(gi.getWidth()).isEqualTo(30.0);
    assertThat(gi.getHeight()).isEqualTo(30.0);

    flowElement = bpmnModel.getFlowElement(IN_CSB_SEQUENCEFLOW_TO_USERTASK);
    assertThat(flowElement).isInstanceOf(SequenceFlow.class);
    assertThat(flowElement.getName()).isEqualTo("to ut");

    flowLocationGraphicInfo = bpmnModel.getFlowLocationGraphicInfo(IN_CSB_SEQUENCEFLOW_TO_USERTASK);
    assertThat(flowLocationGraphicInfo)
            .extracting(GraphicInfo::getX, GraphicInfo::getY)
            .containsExactly(
                    tuple(120.0, 150.0),
                    tuple(232.0, 150.0)
            );

    flowElement = bpmnModel.getFlowElement(IN_CSB_USERTASK);
    assertThat(flowElement).isInstanceOf(UserTask.class);
    assertThat(flowElement.getName()).isEqualTo("User task 1");

    gi = bpmnModel.getGraphicInfo(IN_CSB_USERTASK);
    assertThat(gi.getX()).isEqualTo(232.0);
    assertThat(gi.getY()).isEqualTo(110.0);
    assertThat(gi.getWidth()).isEqualTo(100.0);
    assertThat(gi.getHeight()).isEqualTo(80.0);

    flowElement = bpmnModel.getFlowElement(IN_CSB_SEQUENCEFLOW_TO_END);
    assertThat(flowElement).isInstanceOf(SequenceFlow.class);
    assertThat(flowElement.getName()).isEqualTo("to end");

    flowLocationGraphicInfo = bpmnModel.getFlowLocationGraphicInfo(IN_CSB_SEQUENCEFLOW_TO_END);
    assertThat(flowLocationGraphicInfo)
            .extracting(GraphicInfo::getX, GraphicInfo::getY)
            .containsExactly(
                    tuple(332.0, 150.0),
                    tuple(435.0, 150.0)
            );

}