use of org.kie.dmn.model.v1_2.dmndi.DMNEdge in project drools by kiegroup.
the class XStreamMarshaller method newXStream.
private XStream newXStream() {
XStream xStream = XStreamUtils.createNonTrustingXStream(staxDriver, Definitions.class.getClassLoader(), DMNXStream::from);
xStream.addPermission(new TypeHierarchyPermission(QName.class));
xStream.addPermission(new TypeHierarchyPermission(KieDMNModelInstrumentedBase.class));
xStream.alias("artifact", TArtifact.class);
xStream.alias("definitions", TDefinitions.class);
xStream.alias("inputData", TInputData.class);
xStream.alias("decision", TDecision.class);
xStream.alias("variable", TInformationItem.class);
xStream.alias("informationRequirement", TInformationRequirement.class);
xStream.alias("requiredInput", TDMNElementReference.class);
xStream.alias("literalExpression", TLiteralExpression.class);
xStream.alias("DMNElement", TDMNElement.class);
xStream.alias("allowedValues", TUnaryTests.class);
xStream.alias("artifact", TArtifact.class);
xStream.alias("association", TAssociation.class);
xStream.alias("authorityRequirement", TAuthorityRequirement.class);
xStream.alias("binding", TBinding.class);
xStream.alias("businessContextElement", TBusinessContextElement.class);
xStream.alias("businessKnowledgeModel", TBusinessKnowledgeModel.class);
xStream.alias("column", TInformationItem.class);
xStream.alias("context", TContext.class);
xStream.alias("contextEntry", TContextEntry.class);
xStream.alias("decision", TDecision.class);
xStream.alias("decisionMade", TDMNElementReference.class);
xStream.alias("decisionMaker", TDMNElementReference.class);
xStream.alias("decisionOwned", TDMNElementReference.class);
xStream.alias("decisionOwner", TDMNElementReference.class);
xStream.alias("decisionService", TDecisionService.class);
xStream.alias("decisionTable", TDecisionTable.class);
xStream.alias("defaultOutputEntry", TLiteralExpression.class);
xStream.alias("definitions", TDefinitions.class);
xStream.alias("drgElement", TDMNElementReference.class);
xStream.alias("elementCollection", TElementCollection.class);
xStream.alias("encapsulatedDecision", TDMNElementReference.class);
xStream.alias("encapsulatedLogic", TFunctionDefinition.class);
xStream.alias("expression", TExpression.class);
xStream.alias("formalParameter", TInformationItem.class);
xStream.alias("functionDefinition", TFunctionDefinition.class);
xStream.alias("impactedPerformanceIndicator", TDMNElementReference.class);
xStream.alias("impactingDecision", TDMNElementReference.class);
xStream.alias("import", TImport.class);
xStream.alias("import", TImport.class);
// TODO where?
xStream.alias("importedElement", String.class);
xStream.alias("importedValues", TImportedValues.class);
xStream.alias("informationItem", TInformationItem.class);
xStream.alias("informationRequirement", TInformationRequirement.class);
xStream.alias("input", TInputClause.class);
xStream.alias("inputData", TInputData.class);
xStream.alias("inputDecision", TDMNElementReference.class);
xStream.alias("inputEntry", TUnaryTests.class);
xStream.alias("inputExpression", TLiteralExpression.class);
xStream.alias("inputValues", TUnaryTests.class);
xStream.alias("invocation", TInvocation.class);
xStream.alias("itemComponent", TItemDefinition.class);
xStream.alias("itemDefinition", TItemDefinition.class);
xStream.alias("knowledgeRequirement", TKnowledgeRequirement.class);
xStream.alias("knowledgeSource", TKnowledgeSource.class);
xStream.alias("literalExpression", TLiteralExpression.class);
xStream.alias("namedElement", TNamedElement.class);
xStream.alias("organizationUnit", TOrganizationUnit.class);
xStream.alias("output", TOutputClause.class);
xStream.alias("outputDecision", TDMNElementReference.class);
xStream.alias("outputEntry", TLiteralExpression.class);
xStream.alias("outputValues", TUnaryTests.class);
xStream.alias("owner", TDMNElementReference.class);
xStream.alias("parameter", TInformationItem.class);
xStream.alias("performanceIndicator", TPerformanceIndicator.class);
xStream.alias("relation", TRelation.class);
xStream.alias("requiredAuthority", TDMNElementReference.class);
xStream.alias("requiredDecision", TDMNElementReference.class);
xStream.alias("requiredInput", TDMNElementReference.class);
xStream.alias("requiredKnowledge", TDMNElementReference.class);
xStream.alias("rule", TDecisionRule.class);
xStream.alias("sourceRef", TDMNElementReference.class);
xStream.alias("supportedObjective", TDMNElementReference.class);
xStream.alias("targetRef", TDMNElementReference.class);
xStream.alias("textAnnotation", TTextAnnotation.class);
// TODO where?
xStream.alias("type", String.class);
xStream.alias("typeRef", QName.class);
xStream.alias("usingProcess", TDMNElementReference.class);
xStream.alias("usingTask", TDMNElementReference.class);
xStream.alias("variable", TInformationItem.class);
xStream.alias("row", org.kie.dmn.model.v1_2.TList.class);
xStream.alias("list", org.kie.dmn.model.v1_2.TList.class);
xStream.alias("extensionElements", TDMNElement.TExtensionElements.class);
// Manually imported TEXT = String
xStream.alias(LiteralExpressionConverter.TEXT, String.class);
// unnecessary 'text' key repetition: xStream.alias( TextAnnotationConverter.TEXT, String.class );
// unnecessary 'text' key repetition: xStream.alias( UnaryTestsConverter.TEXT, String.class );
xStream.alias(DecisionConverter.QUESTION, String.class);
xStream.alias(DecisionConverter.ALLOWED_ANSWERS, String.class);
xStream.alias(DMNElementConverter.DESCRIPTION, String.class);
// unnecessary 'text' key repetition: xStream.alias("text", xsd:string.class );
// unnecessary 'text' key repetition: xStream.alias("text", xsd:string.class );
// unnecessary 'text' key repetition: xStream.alias("text", xsd:string.class );
// xStream.alias("question", xsd:string.class );
// xStream.alias("allowedAnswers", xsd:string.class );
// xStream.alias("description", xsd:string.class );
// DMN v1.2:
// Note, to comply with NS for XStream need also to adjust entries inside DMNModelInstrumentedBaseConverter
xStream.alias("annotation", TRuleAnnotationClause.class);
xStream.alias("annotationEntry", TRuleAnnotation.class);
xStream.registerConverter(new RuleAnnotationClauseConverter(xStream));
xStream.registerConverter(new RuleAnnotationConverter(xStream));
xStream.alias("DMNDI", DMNDI.class);
xStream.registerConverter(new DMNDIConverter(xStream));
xStream.alias("DMNDiagram", DMNDiagram.class);
xStream.registerConverter(new DMNDiagramConverter(xStream));
xStream.alias("DMNStyle", DMNStyle.class);
xStream.registerConverter(new DMNStyleConverter(xStream));
xStream.alias("Size", Dimension.class);
xStream.registerConverter(new DimensionConverter(xStream));
xStream.alias("DMNShape", DMNShape.class);
xStream.registerConverter(new DMNShapeConverter(xStream));
xStream.alias("FillColor", Color.class);
xStream.alias("StrokeColor", Color.class);
xStream.alias("FontColor", Color.class);
xStream.registerConverter(new ColorConverter(xStream));
xStream.alias("Bounds", Bounds.class);
xStream.registerConverter(new BoundsConverter(xStream));
xStream.alias("DMNLabel", DMNLabel.class);
xStream.registerConverter(new DMNLabelConverter(xStream));
xStream.alias("DMNEdge", DMNEdge.class);
xStream.registerConverter(new DMNEdgeConverter(xStream));
xStream.alias("DMNDecisionServiceDividerLine", DMNDecisionServiceDividerLine.class);
xStream.registerConverter(new DMNDecisionServiceDividerLineConverter(xStream));
xStream.alias("waypoint", Point.class);
xStream.registerConverter(new PointConverter(xStream));
xStream.alias("extension", DiagramElement.Extension.class);
xStream.alias(DMNLabelConverter.TEXT, String.class);
xStream.registerConverter(new AssociationConverter(xStream));
xStream.registerConverter(new AuthorityRequirementConverter(xStream));
xStream.registerConverter(new BindingConverter(xStream));
xStream.registerConverter(new BusinessKnowledgeModelConverter(xStream));
xStream.registerConverter(new ContextConverter(xStream));
xStream.registerConverter(new ContextEntryConverter(xStream));
xStream.registerConverter(new DecisionConverter(xStream));
xStream.registerConverter(new DecisionRuleConverter(xStream));
xStream.registerConverter(new DecisionServiceConverter(xStream));
xStream.registerConverter(new DecisionTableConverter(xStream));
xStream.registerConverter(new DefinitionsConverter(xStream));
xStream.registerConverter(new DMNElementReferenceConverter(xStream));
xStream.registerConverter(new FunctionDefinitionConverter(xStream));
xStream.registerConverter(new ImportConverter(xStream));
xStream.registerConverter(new ImportedValuesConverter(xStream));
xStream.registerConverter(new InformationItemConverter(xStream));
xStream.registerConverter(new InformationRequirementConverter(xStream));
xStream.registerConverter(new InputClauseConverter(xStream));
xStream.registerConverter(new InputDataConverter(xStream));
xStream.registerConverter(new InvocationConverter(xStream));
xStream.registerConverter(new ItemDefinitionConverter(xStream));
xStream.registerConverter(new KnowledgeRequirementConverter(xStream));
xStream.registerConverter(new KnowledgeSourceConverter(xStream));
xStream.registerConverter(new LiteralExpressionConverter(xStream));
xStream.registerConverter(new OrganizationUnitConverter(xStream));
xStream.registerConverter(new OutputClauseConverter(xStream));
xStream.registerConverter(new PerformanceIndicatorConverter(xStream));
xStream.registerConverter(new RelationConverter(xStream));
xStream.registerConverter(new TextAnnotationConverter(xStream));
xStream.registerConverter(new UnaryTestsConverter(xStream));
xStream.registerConverter(new QNameConverter());
xStream.registerConverter(new DMNListConverter(xStream));
xStream.registerConverter(new ElementCollectionConverter(xStream));
xStream.registerConverter(new ExtensionElementsConverter(xStream, extensionRegisters));
xStream.registerConverter(new DiagramElementExtensionConverter(xStream, extensionRegisters));
xStream.ignoreUnknownElements();
for (DMNExtensionRegister extensionRegister : extensionRegisters) {
extensionRegister.registerExtensionConverters(xStream);
}
return xStream;
}
use of org.kie.dmn.model.v1_2.dmndi.DMNEdge in project kie-wb-common by kiegroup.
the class DMNMarshallerStandalone method marshall.
@Override
@SuppressWarnings("unchecked")
public String marshall(final Diagram<Graph, Metadata> diagram) {
final Graph<?, Node<View, ?>> g = diagram.getGraph();
final Map<String, org.kie.dmn.model.api.DRGElement> nodes = new HashMap<>();
final Map<String, org.kie.dmn.model.api.TextAnnotation> textAnnotations = new HashMap<>();
final Node<View<DMNDiagram>, ?> dmnDiagramRoot = (Node<View<DMNDiagram>, ?>) findDMNDiagramRoot(g);
final Definitions definitionsStunnerPojo = ((DMNDiagram) DefinitionUtils.getElementDefinition(dmnDiagramRoot)).getDefinitions();
cleanImportedItemDefinitions(definitionsStunnerPojo);
final org.kie.dmn.model.api.Definitions definitions = DefinitionsConverter.dmnFromWB(definitionsStunnerPojo);
if (definitions.getExtensionElements() == null) {
if (definitions instanceof org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase) {
definitions.setExtensionElements(new org.kie.dmn.model.v1_1.TDMNElement.TExtensionElements());
} else if (definitions instanceof org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase) {
definitions.setExtensionElements(new org.kie.dmn.model.v1_2.TDMNElement.TExtensionElements());
} else {
definitions.setExtensionElements(new org.kie.dmn.model.v1_2.TDMNElement.TExtensionElements());
}
}
if (definitions.getDMNDI() == null) {
definitions.setDMNDI(new DMNDI());
}
final org.kie.dmn.model.api.dmndi.DMNDiagram dmnDDDMNDiagram = new org.kie.dmn.model.v1_2.dmndi.DMNDiagram();
definitions.getDMNDI().getDMNDiagram().add(dmnDDDMNDiagram);
final List<DMNEdge> dmnEdges = new ArrayList<>();
// Convert relative positioning to absolute
for (Node<?, ?> node : g.nodes()) {
PointUtils.convertToAbsoluteBounds(node);
}
// Setup callback for marshalling ComponentWidths
if (dmnDDDMNDiagram.getExtension() == null) {
dmnDDDMNDiagram.setExtension(new DiagramElement.Extension());
}
final ComponentsWidthsExtension componentsWidthsExtension = new ComponentsWidthsExtension();
dmnDDDMNDiagram.getExtension().getAny().add(componentsWidthsExtension);
final Consumer<ComponentWidths> componentWidthsConsumer = cw -> componentsWidthsExtension.getComponentsWidths().add(cw);
// Iterate Graph processing nodes..
for (Node<?, ?> node : g.nodes()) {
if (node.getContent() instanceof View<?>) {
final View<?> view = (View<?>) node.getContent();
if (view.getDefinition() instanceof DRGElement) {
final DRGElement drgElement = (org.kie.workbench.common.dmn.api.definition.model.DRGElement) view.getDefinition();
if (!drgElement.isAllowOnlyVisualChange()) {
nodes.put(drgElement.getId().getValue(), stunnerToDMN(node, componentWidthsConsumer));
}
dmnDDDMNDiagram.getDMNDiagramElement().add(stunnerToDDExt(definitionsStunnerPojo, (View<? extends DMNElement>) view));
} else if (view.getDefinition() instanceof TextAnnotation) {
final TextAnnotation textAnnotation = (TextAnnotation) view.getDefinition();
textAnnotations.put(textAnnotation.getId().getValue(), textAnnotationConverter.dmnFromNode((Node<View<TextAnnotation>, ?>) node, componentWidthsConsumer));
dmnDDDMNDiagram.getDMNDiagramElement().add(stunnerToDDExt(definitionsStunnerPojo, (View<? extends DMNElement>) view));
final List<org.kie.dmn.model.api.Association> associations = AssociationConverter.dmnFromWB((Node<View<TextAnnotation>, ?>) node);
definitions.getArtifact().addAll(associations);
}
// DMNDI Edge management.
final List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges();
for (Edge<?, ?> e : inEdges) {
if (e.getContent() instanceof ViewConnector) {
final ViewConnector connectionContent = (ViewConnector) e.getContent();
DiscreteConnection sourceConnection = (DiscreteConnection) connectionContent.getSourceConnection().orElse(null);
DiscreteConnection targetConnection = (DiscreteConnection) connectionContent.getTargetConnection().orElse(null);
if (sourceConnection != null && targetConnection != null) {
Point2D sourcePoint = sourceConnection.getLocation();
Point2D targetPoint = targetConnection.getLocation();
final Node<?, ?> sourceNode = e.getSourceNode();
final View<?> sourceView = (View<?>) sourceNode.getContent();
double xSource = xOfBound(upperLeftBound(sourceView));
double ySource = yOfBound(upperLeftBound(sourceView));
double xTarget = xOfBound(upperLeftBound(view));
double yTarget = yOfBound(upperLeftBound(view));
if (sourcePoint == null) {
// If the "connection source/target location is null" assume it's the centre of the shape.
if (sourceView.getDefinition() instanceof DMNViewDefinition) {
DMNViewDefinition dmnViewDefinition = (DMNViewDefinition) sourceView.getDefinition();
xSource += dmnViewDefinition.getDimensionsSet().getWidth().getValue() / 2;
ySource += dmnViewDefinition.getDimensionsSet().getHeight().getValue() / 2;
}
sourcePoint = Point2D.create(xSource, ySource);
} else {
// If it is non-null it is relative to the source/target shape location.
sourcePoint = Point2D.create(xSource + sourcePoint.getX(), ySource + sourcePoint.getY());
}
if (targetPoint == null) {
// If the "connection source/target location is null" assume it's the centre of the shape.
if (view.getDefinition() instanceof DMNViewDefinition) {
DMNViewDefinition dmnViewDefinition = (DMNViewDefinition) view.getDefinition();
xTarget += dmnViewDefinition.getDimensionsSet().getWidth().getValue() / 2;
yTarget += dmnViewDefinition.getDimensionsSet().getHeight().getValue() / 2;
}
targetPoint = Point2D.create(xTarget, yTarget);
} else {
// If it is non-null it is relative to the source/target shape location.
targetPoint = Point2D.create(xTarget + targetPoint.getX(), yTarget + targetPoint.getY());
}
final DMNEdge dmnEdge = new org.kie.dmn.model.v1_2.dmndi.DMNEdge();
// DMNDI edge elementRef is uuid of Stunner edge,
// with the only exception when edge contains as content a DMN Association (Association is an edge)
String uuid = e.getUUID();
if (e.getContent() instanceof View<?>) {
final View<?> edgeView = (View<?>) e.getContent();
if (edgeView.getDefinition() instanceof Association) {
uuid = ((Association) edgeView.getDefinition()).getId().getValue();
}
}
String autoConnectionId = "";
if (sourceConnection.isAuto()) {
autoConnectionId += AUTO_SOURCE_CONNECTION;
}
if (targetConnection.isAuto()) {
autoConnectionId += AUTO_TARGET_CONNECTION;
}
dmnEdge.setId("dmnedge-" + uuid + autoConnectionId);
dmnEdge.setDmnElementRef(new QName(uuid));
dmnEdge.getWaypoint().add(PointUtils.point2dToDMNDIPoint(sourcePoint));
for (ControlPoint cp : connectionContent.getControlPoints()) {
dmnEdge.getWaypoint().add(PointUtils.point2dToDMNDIPoint(cp.getLocation()));
}
dmnEdge.getWaypoint().add(PointUtils.point2dToDMNDIPoint(targetPoint));
dmnEdges.add(dmnEdge);
}
}
}
}
}
nodes.values().forEach(n -> {
n.setParent(definitions);
definitions.getDrgElement().add(n);
});
textAnnotations.values().forEach(definitions.getArtifact()::add);
// add DMNEdge last.
dmnDDDMNDiagram.getDMNDiagramElement().addAll(dmnEdges);
return marshaller.marshal(definitions);
}
use of org.kie.dmn.model.v1_2.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);
}
use of org.kie.dmn.model.v1_2.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.v1_2.dmndi.DMNEdge in project drools by kiegroup.
the class DMNModelInstrumentedBaseConverter method writeAttributes.
@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
KieDMNModelInstrumentedBase mib = (KieDMNModelInstrumentedBase) parent;
CustomStaxWriter staxWriter = ((CustomStaxWriter) writer.underlyingWriter());
for (Entry<String, String> kv : mib.getNsContext().entrySet()) {
try {
if (KieDMNModelInstrumentedBase.URI_DMN.equals(kv.getValue())) {
// skip as that is the default namespace xmlns<:prefix>=DMN is handled by the stax driver.
} else {
staxWriter.writeNamespace(kv.getKey(), kv.getValue());
}
} catch (Exception e) {
LOG.warn("The XML driver writer failed to manage writing namespace, namespaces prefixes could be wrong in the resulting file.", e);
}
}
for (Entry<QName, String> kv : mib.getAdditionalAttributes().entrySet()) {
staxWriter.addAttribute(kv.getKey().getPrefix() + ":" + kv.getKey().getLocalPart(), kv.getValue());
}
if (parent instanceof TDefinitions) {
TDefinitions tDefinitions = (TDefinitions) parent;
String dmndiPrefix = tDefinitions.getPrefixForNamespaceURI(KieDMNModelInstrumentedBase.URI_DMNDI).orElse("dmndi");
String diPrefix = tDefinitions.getPrefixForNamespaceURI(KieDMNModelInstrumentedBase.URI_DI).orElse("di");
String dcPrefix = tDefinitions.getPrefixForNamespaceURI(KieDMNModelInstrumentedBase.URI_DC).orElse("dc");
staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "DMNDI", dmndiPrefix), "DMNDI");
staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "DMNDiagram", dmndiPrefix), "DMNDiagram");
staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "DMNStyle", dmndiPrefix), "style");
staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "DMNStyle", dmndiPrefix), "DMNStyle");
staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "DMNShape", dmndiPrefix), "DMNShape");
staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "DMNEdge", dmndiPrefix), "DMNEdge");
staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "DMNDecisionServiceDividerLine", dmndiPrefix), "DMNDecisionServiceDividerLine");
staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "DMNLabel", dmndiPrefix), "DMNLabel");
staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, DMNLabelConverter.TEXT, dmndiPrefix), DMNLabelConverter.TEXT);
staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "Size", dmndiPrefix), "Size");
staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "FillColor", dmndiPrefix), "FillColor");
staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "StrokeColor", dmndiPrefix), "StrokeColor");
staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DMNDI, "FontColor", dmndiPrefix), "FontColor");
staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DI, "waypoint", diPrefix), "waypoint");
staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DI, "extension", diPrefix), "extension");
staxWriter.getQNameMap().registerMapping(new QName(KieDMNModelInstrumentedBase.URI_DC, "Bounds", dcPrefix), "Bounds");
}
}
Aggregations