use of org.kie.dmn.model.api.dmndi.DMNEdge in project drools by kiegroup.
the class DMNEdgeConverter method writeAttributes.
@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
super.writeAttributes(writer, parent);
DMNEdge concrete = (DMNEdge) parent;
if (concrete.getDmnElementRef() != null) {
writer.addAttribute(DMN_ELEMENT_REF, MarshallingUtils.formatQName(concrete.getDmnElementRef(), concrete));
}
}
use of org.kie.dmn.model.api.dmndi.DMNEdge in project drools by kiegroup.
the class DMNEdgeConverter method writeChildren.
@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
DMNEdge concrete = (DMNEdge) parent;
if (concrete.getDMNLabel() != null) {
writeChildrenNode(writer, context, concrete.getDMNLabel(), DMN_LABEL);
}
}
use of org.kie.dmn.model.api.dmndi.DMNEdge in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method testStunnerConstellationButtonCausingPoint2DbeingNull.
/**
* DROOLS-3184: If the "connection source/target location is null" assume it's the centre of the shape.
* [source/target location is null] If the connection was created from the Toolbox (i.e. add a InputData and then the Decision from it using the Decision toolbox icon).
* <p>
* This test re-create by hard-code the behavior of the Stunner framework "Toolbox" by instrumenting API calls to achieve the same behavior.
*/
@SuppressWarnings("unchecked")
@Test
public void testStunnerConstellationButtonCausingPoint2DbeingNull() throws IOException {
final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer = (uuid, hcw) -> {
/*NOP*/
};
Diagram diagram = createDiagram();
Graph g = diagram.getGraph();
Node diagramRoot = DMNMarshallerStandalone.findDMNDiagramRoot(g);
testAugmentWithNSPrefixes(((DMNDiagram) ((View<?>) diagramRoot.getContent()).getDefinition()).getDefinitions());
org.kie.dmn.model.api.InputData dmnInputData = new TInputData();
dmnInputData.setId("inputDataID");
dmnInputData.setName(dmnInputData.getId());
Node inputDataNode = new InputDataConverter(api.getFactoryManager()).nodeFromDMN(dmnInputData, hasComponentWidthsConsumer);
org.kie.dmn.model.api.Decision dmnDecision = new TDecision();
dmnDecision.setId("decisionID");
dmnDecision.setName(dmnDecision.getId());
Node decisionNode = new DecisionConverter(api.getFactoryManager()).nodeFromDMN(dmnDecision, hasComponentWidthsConsumer);
g.addNode(inputDataNode);
g.addNode(decisionNode);
View content = (View) decisionNode.getContent();
content.setBounds(org.kie.workbench.common.stunner.core.graph.content.Bounds.create(200, 200, 300, 250));
final String irID = "irID";
Edge myEdge = api.getFactoryManager().newElement(irID, DMNMarshallerStandalone.INFO_REQ_ID).asEdge();
myEdge.setSourceNode(inputDataNode);
myEdge.setTargetNode(decisionNode);
inputDataNode.getOutEdges().add(myEdge);
decisionNode.getInEdges().add(myEdge);
ViewConnector connectionContent = (ViewConnector) myEdge.getContent();
// DROOLS-3184: If the "connection source/target location is null" assume it's the centre of the shape.
// keep Stunner behavior of constellation button
connectionContent.setSourceConnection(MagnetConnection.Builder.atCenter(inputDataNode).setLocation(null).setAuto(true));
connectionContent.setTargetConnection(MagnetConnection.Builder.atCenter(decisionNode).setLocation(null).setAuto(true));
DMNMarshallerStandalone.connectRootWithChild(diagramRoot, inputDataNode);
DMNMarshallerStandalone.connectRootWithChild(diagramRoot, decisionNode);
DMNMarshallerStandalone m = getDMNMarshaller();
String output = m.marshall(diagram);
LOG.debug(output);
Definitions dmnDefinitions = DMNMarshallerFactory.newDefaultMarshaller().unmarshal(output);
DMNEdge dmndiEdge = findEdgeByDMNI(dmnDefinitions.getDMNDI().getDMNDiagram().get(0), irID);
assertThat(dmndiEdge.getWaypoint()).hasSize(2);
Point wpSource = dmndiEdge.getWaypoint().get(0);
assertThat(wpSource.getX()).isEqualByComparingTo(50d);
assertThat(wpSource.getY()).isEqualByComparingTo(25d);
Point wpTarget = dmndiEdge.getWaypoint().get(1);
assertThat(wpTarget.getX()).isEqualByComparingTo(250d);
assertThat(wpTarget.getY()).isEqualByComparingTo(225d);
}
use of org.kie.dmn.model.api.dmndi.DMNEdge in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method testIsAutoConnection.
@Test
public void testIsAutoConnection() {
String id = "DMNEdge-ID";
String autoConnectionID = "-AUTO-CONNECTION";
DMNEdge dmnEdge1 = mock(DMNEdge.class);
when(dmnEdge1.getId()).thenReturn(id);
DMNEdge dmnEdge2 = mock(DMNEdge.class);
when(dmnEdge2.getId()).thenReturn(id + autoConnectionID);
DMNEdge dmnEdge3 = mock(DMNEdge.class);
when(dmnEdge3.getId()).thenReturn(null);
DMNMarshallerStandalone dmnMarshallerStandalone = new DMNMarshallerStandalone();
assertFalse(dmnMarshallerStandalone.isAutoConnection(dmnEdge1, autoConnectionID));
assertTrue(dmnMarshallerStandalone.isAutoConnection(dmnEdge2, autoConnectionID));
assertFalse(dmnMarshallerStandalone.isAutoConnection(dmnEdge3, autoConnectionID));
}
use of org.kie.dmn.model.api.dmndi.DMNEdge in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method testAssociationEdgeDMNDI.
/**
* DROOLS-2569 [DMN Designer] Marshalling of magnet positions -- Association DMN Edge DMNDI serialization.
* This test re-create by hard-code the graph to simulate the behavior of the Stunner framework programmatically.
*/
@SuppressWarnings("unchecked")
@Test
public void testAssociationEdgeDMNDI() throws IOException {
final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer = (uuid, hcw) -> {
/*NOP*/
};
Diagram diagram = createDiagram();
Graph g = diagram.getGraph();
Node diagramRoot = DMNMarshallerStandalone.findDMNDiagramRoot(g);
testAugmentWithNSPrefixes(((DMNDiagram) ((View<?>) diagramRoot.getContent()).getDefinition()).getDefinitions());
org.kie.dmn.model.api.InputData dmnInputData = new TInputData();
dmnInputData.setId("inputDataID");
dmnInputData.setName(dmnInputData.getId());
Node inputDataNode = new InputDataConverter(api.getFactoryManager()).nodeFromDMN(dmnInputData, hasComponentWidthsConsumer);
org.kie.dmn.model.api.TextAnnotation dmnTextAnnotation = new TTextAnnotation();
dmnTextAnnotation.setId("textAnnotationID");
Node textAnnotationNode = new TextAnnotationConverter(api.getFactoryManager()).nodeFromDMN(dmnTextAnnotation, hasComponentWidthsConsumer);
g.addNode(inputDataNode);
g.addNode(textAnnotationNode);
View content = (View) textAnnotationNode.getContent();
content.setBounds(org.kie.workbench.common.stunner.core.graph.content.Bounds.create(200, 200, 300, 250));
final String edgeID = "edgeID";
final String associationID = "associationID";
Edge myEdge = api.getFactoryManager().newElement(edgeID, DMNMarshallerStandalone.ASSOCIATION_ID).asEdge();
final View<?> edgeView = (View<?>) myEdge.getContent();
((Association) edgeView.getDefinition()).setId(new Id(associationID));
myEdge.setSourceNode(inputDataNode);
myEdge.setTargetNode(textAnnotationNode);
inputDataNode.getOutEdges().add(myEdge);
textAnnotationNode.getInEdges().add(myEdge);
ViewConnector connectionContent = (ViewConnector) myEdge.getContent();
connectionContent.setSourceConnection(MagnetConnection.Builder.atCenter(inputDataNode));
connectionContent.setTargetConnection(MagnetConnection.Builder.atCenter(textAnnotationNode));
DMNMarshallerStandalone.connectRootWithChild(diagramRoot, inputDataNode);
DMNMarshallerStandalone.connectRootWithChild(diagramRoot, textAnnotationNode);
DMNMarshallerStandalone m = getDMNMarshaller();
String output = m.marshall(diagram);
LOG.debug(output);
Definitions dmnDefinitions = DMNMarshallerFactory.newDefaultMarshaller().unmarshal(output);
assertThat(dmnDefinitions.getDMNDI().getDMNDiagram().get(0).getDMNDiagramElement().stream().filter(DMNEdge.class::isInstance).count()).isEqualTo(1);
DMNEdge dmndiEdge = findEdgeByDMNI(dmnDefinitions.getDMNDI().getDMNDiagram().get(0), associationID);
assertThat(dmndiEdge.getWaypoint()).hasSize(2);
}
Aggregations