use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method checkEdgewaypoint.
@SuppressWarnings("unchecked")
private void checkEdgewaypoint(Graph<?, Node<?, ?>> graph) {
Node<?, ?> decision = graph.getNode("_7647e26b-6c7c-46db-aa34-1a1a2b4d8d79");
assertNodeContentDefinitionIs(decision, Decision.class);
Decision decisionDefinition = ((View<Decision>) decision.getContent()).getDefinition();
assertEquals("my decision", decisionDefinition.getName().getValue());
Node<?, ?> inputdata = graph.getNode("_fd528e66-e2a4-4b7f-aae1-c3ca6723d0cb");
assertNodeEdgesTo(inputdata, decision, InformationRequirement.class);
// asserted the two Stunner graph nodes are properly connected, assert location of edge.
List<Edge<?, ?>> outEdges = (List<Edge<?, ?>>) inputdata.getOutEdges();
Edge<?, ?> edge = outEdges.stream().filter(e -> e.getTargetNode().equals(decision)).findFirst().get();
ViewConnector<?> connectionContent = (ViewConnector<?>) edge.getContent();
Point2D sourceLocation = connectionContent.getSourceConnection().get().getLocation();
assertEquals(266.9968013763428d, ((View) inputdata.getContent()).getBounds().getUpperLeft().getX() + sourceLocation.getX(), 0.1d);
assertEquals(225.99999618530273d, ((View) inputdata.getContent()).getBounds().getUpperLeft().getY() + sourceLocation.getY(), 0.1d);
Point2D targetLocation = connectionContent.getTargetConnection().get().getLocation();
assertEquals(552.2411708831787d, ((View) decision.getContent()).getBounds().getUpperLeft().getX() + targetLocation.getX(), 0.1d);
assertEquals(226d, ((View) decision.getContent()).getBounds().getUpperLeft().getY() + targetLocation.getY(), 0.1d);
assertEquals(1, connectionContent.getControlPoints().length);
Point2D controlPointLocation = connectionContent.getControlPoints()[0].getLocation();
assertEquals(398.61898612976074d, controlPointLocation.getX(), 0.1d);
assertEquals(116.99999809265137d, controlPointLocation.getY(), 0.1d);
final Connection sourceConnection = connectionContent.getSourceConnection().get();
assertTrue(sourceConnection instanceof MagnetConnection);
assertFalse(((MagnetConnection) sourceConnection).isAuto());
final Connection targetConnection = connectionContent.getTargetConnection().get();
assertTrue(targetConnection instanceof MagnetConnection);
assertFalse(((MagnetConnection) targetConnection).isAuto());
}
use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method testGetDmnElementRefWithFakeNamespace.
@Test
public void testGetDmnElementRefWithFakeNamespace() {
final Decision drgElement = mock(Decision.class);
final View<? extends DMNElement> view = new ViewImpl<>(drgElement, null);
final Name drgElementName = mock(Name.class);
final Id id = mock(Id.class);
final org.kie.workbench.common.dmn.api.definition.model.Definitions definitions = mock(org.kie.workbench.common.dmn.api.definition.model.Definitions.class);
when(id.getValue()).thenReturn("0000-1111-2222");
when(drgElementName.getValue()).thenReturn("fakeNamespace.Decision");
when(drgElement.getId()).thenReturn(id);
when(drgElement.getName()).thenReturn(drgElementName);
when(drgElement.getParent()).thenReturn(definitions);
when(definitions.getImport()).thenReturn(emptyList());
final String actual = getDmnElementRef(definitions, view).getLocalPart();
final String expected = "0000-1111-2222";
assertEquals(expected, actual);
}
use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method newDiagramDecisionWithExpression.
@SuppressWarnings("unchecked")
private Diagram<Graph, Metadata> newDiagramDecisionWithExpression(final Expression expression) {
final Diagram<Graph, Metadata> diagram = createDiagram();
final Graph<DefinitionSet, Node> graph = mock(Graph.class);
final Node<View, ?> diagramNode = mock(Node.class);
final View diagramView = mock(View.class);
final DMNDiagram dmnDiagram = new DMNDiagram();
doReturn(diagramView).when(diagramNode).getContent();
doReturn(dmnDiagram).when(diagramView).getDefinition();
final Node<View, ?> decisionNode = mock(Node.class);
final View decisionView = mock(View.class);
final Decision decision = new Decision();
doReturn(decisionView).when(decisionNode).getContent();
doReturn(decision).when(decisionView).getDefinition();
decision.setExpression(expression);
doReturn(asList(diagramNode, decisionNode)).when(graph).nodes();
((DiagramImpl) diagram).setGraph(graph);
return diagram;
}
use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method testGetDmnElementRefWithoutNamespace.
@Test
public void testGetDmnElementRefWithoutNamespace() {
final Decision drgElement = mock(Decision.class);
final View<? extends DMNElement> view = new ViewImpl<>(drgElement, null);
final Name drgElementName = mock(Name.class);
final Id id = mock(Id.class);
final org.kie.workbench.common.dmn.api.definition.model.Definitions definitions = mock(org.kie.workbench.common.dmn.api.definition.model.Definitions.class);
when(id.getValue()).thenReturn("0000-1111-2222");
when(drgElementName.getValue()).thenReturn("Decision");
when(drgElement.getId()).thenReturn(id);
when(drgElement.getName()).thenReturn(drgElementName);
when(drgElement.getParent()).thenReturn(definitions);
when(definitions.getImport()).thenReturn(emptyList());
final String actual = getDmnElementRef(definitions, view).getLocalPart();
final String expected = "0000-1111-2222";
assertEquals(expected, actual);
}
use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.
the class KnowledgeSourceConverter method dmnFromNode.
@Override
public org.kie.dmn.model.api.KnowledgeSource dmnFromNode(final Node<View<KnowledgeSource>, ?> node, final Consumer<ComponentWidths> componentWidthsConsumer) {
final KnowledgeSource source = (KnowledgeSource) DefinitionUtils.getElementDefinition(node);
final org.kie.dmn.model.api.KnowledgeSource result = new org.kie.dmn.model.v1_2.TKnowledgeSource();
result.setId(source.getId().getValue());
result.setDescription(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
result.setName(source.getName().getValue());
result.setType(source.getType().getValue());
result.setLocationURI(source.getLocationURI().getValue());
DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, result);
// DMN spec table 2: Requirements connection rules
final List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges();
for (Edge<?, ?> e : inEdges) {
final Node<?, ?> sourceNode = e.getSourceNode();
if (sourceNode.getContent() instanceof View<?>) {
final View<?> view = (View<?>) sourceNode.getContent();
if (view.getDefinition() instanceof DRGElement) {
final DRGElement drgElement = (DRGElement) view.getDefinition();
if (drgElement instanceof Decision) {
final org.kie.dmn.model.api.AuthorityRequirement iReq = new org.kie.dmn.model.v1_2.TAuthorityRequirement();
iReq.setId(e.getUUID());
final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredDecision(ri);
result.getAuthorityRequirement().add(iReq);
} else if (drgElement instanceof KnowledgeSource) {
final org.kie.dmn.model.api.AuthorityRequirement iReq = new org.kie.dmn.model.v1_2.TAuthorityRequirement();
iReq.setId(e.getUUID());
final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredAuthority(ri);
result.getAuthorityRequirement().add(iReq);
} else if (drgElement instanceof InputData) {
final org.kie.dmn.model.api.AuthorityRequirement iReq = new org.kie.dmn.model.v1_2.TAuthorityRequirement();
iReq.setId(e.getUUID());
final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredInput(ri);
result.getAuthorityRequirement().add(iReq);
} else {
throw new UnsupportedOperationException("wrong model definition.");
}
}
}
}
return result;
}
Aggregations