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;
}
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());
}
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);
}
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());
}
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());
}
Aggregations