Search in sources :

Example 11 with Decision

use of org.kie.workbench.common.dmn.api.definition.v1_1.Decision in project kie-wb-common by kiegroup.

the class DMNEditDecisionToolboxAction method onMouseClick.

@Override
@SuppressWarnings("unchecked")
public ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler, final String uuid, final MouseClickEvent event) {
    // Notice the toolbox factory ensure this action is only being included
    // for Decision definitions, next cast is safe.
    final Node<View<? extends Decision>, Edge> decisionNode = (Node<View<? extends Decision>, Edge>) AbstractToolboxAction.getElement(canvasHandler, uuid).asNode();
    final Decision decision = decisionNode.getContent().getDefinition();
    editExpressionEvent.fire(new EditExpressionEvent(sessionManager.getCurrentSession(), uuid, decision, Optional.of(decision)));
    return this;
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) EditExpressionEvent(org.kie.workbench.common.dmn.client.events.EditExpressionEvent) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision)

Example 12 with Decision

use of org.kie.workbench.common.dmn.api.definition.v1_1.Decision in project kie-wb-common by kiegroup.

the class RelationGridTest method setUp.

@Before
public void setUp() throws Exception {
    tupleWithoutValue = new GridCellTuple(0, 1, gridWidget);
    tupleWithValue = new GridCellValueTuple<>(0, 1, gridWidget, new BaseGridCellValue<>("value"));
    definition = new RelationEditorDefinition(gridPanel, gridLayer, definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, cellEditorControls, listSelector, translationService);
    final Decision decision = new Decision();
    decision.setName(new Name("name"));
    hasName = Optional.of(decision);
    expression = definition.getModelClass();
    doReturn(canvasHandler).when(dmnClientFullSession).getCanvasHandler();
    doReturn(dmnClientFullSession).when(sessionManager).getCurrentSession();
    doReturn(parentGridData).when(parentGridWidget).getModel();
    doReturn(Collections.singletonList(parentGridColumn)).when(parentGridData).getColumns();
    parent = spy(new GridCellTuple(0, 0, parentGridWidget));
    when(gridWidget.getModel()).thenReturn(new BaseGridData(false));
    doAnswer((i) -> i.getArguments()[0].toString()).when(translationService).format(anyString());
}
Also used : GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue) HasName(org.kie.workbench.common.dmn.api.definition.HasName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Before(org.junit.Before)

Example 13 with Decision

use of org.kie.workbench.common.dmn.api.definition.v1_1.Decision in project kie-wb-common by kiegroup.

the class DecisionTableGridTest method makeHasNameForDecision.

private Optional<HasName> makeHasNameForDecision() {
    final Decision decision = new Decision();
    decision.setName(new Name(HASNAME_NAME));
    return Optional.of(decision);
}
Also used : Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision) HasName(org.kie.workbench.common.dmn.api.definition.HasName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name)

Example 14 with Decision

use of org.kie.workbench.common.dmn.api.definition.v1_1.Decision in project kie-wb-common by kiegroup.

the class DMNMarshallerTest method test_wrong_context.

@Test
public void test_wrong_context() throws IOException {
    // DROOLS-2217
    // SPECIAL CASE: to represent a partially edited DMN file.
    // consider a LiteralExpression with null text as missing expression altogether.
    final DMNRuntime runtime = roundTripUnmarshalMarshalThenUnmarshalDMN(this.getClass().getResourceAsStream("/wrong_context.dmn"));
    DMNModel dmnModel = runtime.getModels().get(0);
    // the DMN file is schema valid but is not a valid-DMN (a context-entry value is a literal expression missing text, which is null)
    assertTrue(dmnModel.hasErrors());
    // identify the error message for context-entry "ciao":
    DMNMessage m0 = dmnModel.getMessages(DMNMessage.Severity.ERROR).get(0);
    assertTrue("expected a message identifying the problem on a context entry for 'ciao'", m0.getMessage().startsWith("No expression defined for name 'ciao'"));
    DecisionNode d0 = dmnModel.getDecisionById("_653b3426-933a-4050-9568-ab2a66b43c36");
    // the identified DMN Decision is composed of a DMN Context where the first context-entry value is a literal expression missing text (text is null).
    org.kie.dmn.model.v1_1.Context d0c = (org.kie.dmn.model.v1_1.Context) d0.getDecision().getExpression();
    org.kie.dmn.model.v1_1.Expression contextEntryValue = d0c.getContextEntry().get(0).getExpression();
    assertTrue(contextEntryValue instanceof org.kie.dmn.model.v1_1.LiteralExpression);
    assertEquals(null, ((org.kie.dmn.model.v1_1.LiteralExpression) contextEntryValue).getText());
    // -- Stunner side.
    DMNMarshaller m = new DMNMarshaller(new XMLEncoderDiagramMetadataMarshaller(), applicationFactoryManager);
    Graph<?, ?> g = m.unmarshall(null, this.getClass().getResourceAsStream("/wrong_context.dmn"));
    DiagramImpl diagram = new DiagramImpl("", null);
    Node<?, ?> decisionNode = g.getNode("_653b3426-933a-4050-9568-ab2a66b43c36");
    assertNodeContentDefinitionIs(decisionNode, Decision.class);
    View<Decision> view = ((View<Decision>) decisionNode.getContent());
    // the identified DMN Decision is composed of a DMN Context where the first context-entry has missing Expression.
    Context expression = (Context) view.getDefinition().getExpression();
    assertEquals("a literalexpression with null text is threated as a missing expression altogether.", null, expression.getContextEntry().get(0).getExpression());
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.v1_1.Context) DMNContext(org.kie.dmn.api.core.DMNContext) DiagramImpl(org.kie.workbench.common.stunner.core.diagram.DiagramImpl) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision) DMNMessage(org.kie.dmn.api.core.DMNMessage) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 15 with Decision

use of org.kie.workbench.common.dmn.api.definition.v1_1.Decision in project kie-wb-common by kiegroup.

the class DMNMarshallerTest method test_diamond.

@Test
public void test_diamond() throws IOException {
    // round trip test
    roundTripUnmarshalThenMarshalUnmarshal(this.getClass().getResourceAsStream("/diamond.dmn"), this::checkDiamongGraph);
    // additionally, check the marshalled is still DMN executable as expected
    DMNMarshaller m = new DMNMarshaller(new XMLEncoderDiagramMetadataMarshaller(), applicationFactoryManager);
    Graph<?, ?> g = m.unmarshall(null, this.getClass().getResourceAsStream("/diamond.dmn"));
    DiagramImpl diagram = new DiagramImpl("", null);
    diagram.setGraph(g);
    String mString = m.marshall(diagram);
    final KieServices ks = KieServices.Factory.get();
    final KieContainer kieContainer = KieHelper.getKieContainer(ks.newReleaseId("org.kie", "dmn-test_diamond", "1.0"), ks.getResources().newByteArrayResource(mString.getBytes()).setTargetPath("src/main/resources/diamond.dmn"));
    final DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
    Assert.assertNotNull(runtime);
    DMNModel diamondModel = runtime.getModel("http://www.trisotech.com/definitions/_8afa6c24-55c8-43cf-8a02-fdde7fc5d1f2", "three decisions in a diamond shape");
    DMNContext dmnContext = runtime.newContext();
    dmnContext.set("My Name", "John Doe");
    DMNResult dmnResult = runtime.evaluateAll(diamondModel, dmnContext);
    assertFalse(dmnResult.getMessages().toString(), dmnResult.hasErrors());
    DMNContext result = dmnResult.getContext();
    assertEquals("Hello, John Doe.", result.get("My Decision"));
    // additionally, check DMN DD/DI for version 1.1
    org.kie.dmn.api.marshalling.v1_1.DMNMarshaller dmnMarshaller = DMNMarshallerFactory.newMarshallerWithExtensions(Arrays.asList(new DDExtensionsRegister()));
    Definitions definitions = dmnMarshaller.unmarshal(mString);
    assertNotNull(definitions.getExtensionElements());
    assertNotNull(definitions.getExtensionElements().getAny());
    assertEquals(1, definitions.getExtensionElements().getAny().size());
    org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram ddRoot = (org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram) definitions.getExtensionElements().getAny().get(0);
    DMNShape myname = findShapeByDMNI(ddRoot, "_4cd17e52-6253-41d6-820d-5824bf5197f3");
    assertBounds(500, 500, 100, 50, myname.getBounds());
    assertColor(255, 255, 255, myname.getBgColor());
    assertColor(0, 0, 0, myname.getBorderColor());
    assertEquals(0.5, myname.getBorderSize().getValue(), 0);
    assertDMNStyle("Open Sans", 24, 1, 255, 0, 0, myname.getFontStyle());
    DMNShape prefix = findShapeByDMNI(ddRoot, "_e920f38a-293c-41b8-adb3-69d0dc184fab");
    assertBounds(300, 400, 100, 50, prefix.getBounds());
    assertColor(0, 253, 25, prefix.getBgColor());
    assertColor(253, 0, 0, prefix.getBorderColor());
    assertEquals(1, prefix.getBorderSize().getValue(), 0);
    assertDMNStyle("Times New Roman", 8, 2.5, 70, 60, 50, prefix.getFontStyle());
    DMNShape postfix = findShapeByDMNI(ddRoot, "_f49f9c34-29d5-4e72-91d2-f4f92117c8da");
    assertBounds(700, 400, 100, 50, postfix.getBounds());
    assertColor(247, 255, 0, postfix.getBgColor());
    assertColor(0, 51, 255, postfix.getBorderColor());
    assertEquals(2, postfix.getBorderSize().getValue(), 0);
    assertDMNStyle("Arial", 10, 1.5, 50, 60, 70, postfix.getFontStyle());
    DMNShape mydecision = findShapeByDMNI(ddRoot, "_9b061fc3-8109-42e2-9fe4-fc39c90b654e");
    assertBounds(487.5, 275, 125, 75, mydecision.getBounds());
    assertColor(255, 255, 255, mydecision.getBgColor());
    assertColor(0, 0, 0, mydecision.getBorderColor());
    assertEquals(0.5, mydecision.getBorderSize().getValue(), 0);
    assertDMNStyle("Monospaced", 32, 3.5, 55, 66, 77, mydecision.getFontStyle());
}
Also used : KieServices(org.kie.api.KieServices) Matchers.anyString(org.mockito.Matchers.anyString) DMNShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNShape) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) DMNModel(org.kie.dmn.api.core.DMNModel) KieContainer(org.kie.api.runtime.KieContainer) DMNDiagram(org.kie.workbench.common.dmn.api.definition.v1_1.DMNDiagram) DMNResult(org.kie.dmn.api.core.DMNResult) DiagramImpl(org.kie.workbench.common.stunner.core.diagram.DiagramImpl) Definitions(org.kie.dmn.model.v1_1.Definitions) DMNContext(org.kie.dmn.api.core.DMNContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DDExtensionsRegister(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DDExtensionsRegister) Test(org.junit.Test)

Aggregations

Decision (org.kie.workbench.common.dmn.api.definition.v1_1.Decision)16 Edge (org.kie.workbench.common.stunner.core.graph.Edge)7 View (org.kie.workbench.common.stunner.core.graph.content.view.View)7 Before (org.junit.Before)6 InputData (org.kie.workbench.common.dmn.api.definition.v1_1.InputData)6 KnowledgeSource (org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeSource)6 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)6 List (java.util.List)5 Optional (java.util.Optional)5 Test (org.junit.Test)5 HasName (org.kie.workbench.common.dmn.api.definition.HasName)5 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel)5 Decision (org.kie.dmn.model.v1_1.Decision)4 TextAnnotation (org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation)4 DMNShape (org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNShape)4 Node (org.kie.workbench.common.stunner.core.graph.Node)4 InputStream (java.io.InputStream)3 Consumer (java.util.function.Consumer)3 DMNMessage (org.kie.dmn.api.core.DMNMessage)3 DMNType (org.kie.dmn.api.core.DMNType)3