Search in sources :

Example 6 with Expression

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

the class ExpressionContainerGridTest method testGetBaseExpressionGrid.

@Test
public void testGetBaseExpressionGrid() {
    final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> expectedBaseExpressionGrid = Optional.of(mock(LiteralExpressionGrid.class));
    final ExpressionCellValue value = mock(ExpressionCellValue.class);
    final GridCell<?> cell = new BaseGridCell<>(value);
    final Supplier<GridCell<?>> cellSupplier = () -> cell;
    when(value.getValue()).thenReturn(expectedBaseExpressionGrid);
    grid.getModel().setCell(0, 0, cellSupplier);
    assertEquals(expectedBaseExpressionGrid, grid.getBaseExpressionGrid());
}
Also used : BaseGridCell(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCell) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) BaseUIModelMapper(org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) LiteralExpressionGrid(org.kie.workbench.common.dmn.client.editors.expressions.types.literal.LiteralExpressionGrid) GridCell(org.uberfire.ext.wires.core.grids.client.model.GridCell) BaseGridCell(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCell) Test(org.junit.Test)

Example 7 with Expression

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

the class ExpressionEditorColumnTest method setUp.

@Before
public void setUp() {
    gridData = new BaseGridData();
    widget = new BaseGrid<Expression>(gridLayer, gridData, renderer, sessionManager, sessionCommandManager, canvasCommandFactory, refreshFormPropertiesEvent, domainObjectSelectionEvent, cellEditorControls, translationService) {
    };
    column = new ExpressionEditorColumn(gridLayer, new BaseHeaderMetaData("column header"), ExpressionEditorColumn.DEFAULT_WIDTH, widget);
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) BaseHeaderMetaData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseHeaderMetaData) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Before(org.junit.Before)

Example 8 with Expression

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

the class DMNMarshallerStandaloneTest method test_wrong_context.

@Test
@SuppressWarnings("unchecked")
public void test_wrong_context() throws IOException {
    // DROOLS-2217
    final ErrorsAndDMNModelAsSerialized result = roundTripUnmarshalMarshalThenUnmarshalDMNexpectingErrors(this.getClass().getResourceAsStream("/wrong_context.dmn"));
    // although 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)
    // DROOLS-3152: once roundtripped through the Stunner marshaller it will receive an empty text. (empty expression, but a LiteralExpression with an empty text child xml element)
    // this will still naturally throw some error because unable to FEEL-parse/compile an empty expression.
    assertTrue(result.hasErrors());
    // identify the error message for context-entry "ciao":
    DMNMessage m0 = (DMNMessage) result.messages.get(0);
    assertTrue("expected a message identifying the problem on a context entry for 'ciao'", // DROOLS-3152 please notice FEEL reporting indeed an empty expression.
    m0.getMessage().startsWith("Error compiling FEEL expression '' for name "));
    org.kie.dmn.model.api.Decision d0 = (org.kie.dmn.model.api.Decision) result.definitions.getDrgElement().stream().filter(d -> d.getId().equals("_653b3426-933a-4050-9568-ab2a66b43c36")).findFirst().get();
    // 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.api.Context d0c = (org.kie.dmn.model.api.Context) d0.getExpression();
    org.kie.dmn.model.api.Expression contextEntryValue = d0c.getContextEntry().get(0).getExpression();
    assertTrue(contextEntryValue instanceof org.kie.dmn.model.api.LiteralExpression);
    // DROOLS-3152
    assertEquals("", ((org.kie.dmn.model.api.LiteralExpression) contextEntryValue).getText());
    // -- Stunner side.
    DMNMarshallerStandalone m = getDMNMarshaller();
    Graph<?, ?> g = m.unmarshall(createMetadata(), this.getClass().getResourceAsStream("/wrong_context.dmn"));
    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();
    // DROOLS-3116 empty Literal Expression is preserved
    assertNotNull(expression.getContextEntry().get(0).getExpression());
    assertEquals(LiteralExpression.class, expression.getContextEntry().get(0).getExpression().getClass());
    LiteralExpression le = (LiteralExpression) expression.getContextEntry().get(0).getExpression();
    // DROOLS-3152
    assertEquals("", le.getText().getValue());
}
Also used : Arrays(java.util.Arrays) DMNMessage(org.kie.dmn.api.core.DMNMessage) Edge(org.kie.workbench.common.stunner.core.graph.Edge) TInputData(org.kie.dmn.model.v1_2.TInputData) StringUtils(org.apache.commons.lang3.StringUtils) Collections.singletonList(java.util.Collections.singletonList) BigDecimal(java.math.BigDecimal) Bounds(org.kie.dmn.model.api.dmndi.Bounds) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) TItemDefinition(org.kie.dmn.model.v1_2.TItemDefinition) NamespaceContext(javax.xml.namespace.NamespaceContext) Namespace(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase.Namespace) StringInputStream(org.apache.tools.ant.filters.StringInputStream) Mockito.doReturn(org.mockito.Mockito.doReturn) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) Results(org.kie.api.builder.Results) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) FunctionKind(org.kie.dmn.model.api.FunctionKind) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) BusinessKnowledgeModelNode(org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode) DMNGraphFactoryImpl(org.kie.workbench.common.dmn.api.factory.DMNGraphFactoryImpl) Stream(java.util.stream.Stream) Assert.assertFalse(org.junit.Assert.assertFalse) DMNContext(org.kie.dmn.api.core.DMNContext) KieHelper(org.kie.dmn.core.util.KieHelper) QName(javax.xml.namespace.QName) DMNDiagramUtils(org.kie.workbench.common.dmn.api.graph.DMNDiagramUtils) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Mockito.mock(org.mockito.Mockito.mock) DMNDefinitionSet(org.kie.workbench.common.dmn.api.DMNDefinitionSet) XPath(javax.xml.xpath.XPath) DMNStyle(org.kie.dmn.model.api.dmndi.DMNStyle) Point(org.kie.dmn.model.api.dmndi.Point) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Color(org.kie.dmn.model.api.dmndi.Color) Mockito.spy(org.mockito.Mockito.spy) Definitions(org.kie.dmn.model.api.Definitions) ArrayList(java.util.ArrayList) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) DMNMarshallerFactory(org.kie.dmn.backend.marshalling.v1x.DMNMarshallerFactory) BiConsumer(java.util.function.BiConsumer) Message(org.kie.api.builder.Message) StreamSupport(java.util.stream.StreamSupport) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) MapIndexBuilder(org.kie.workbench.common.stunner.core.graph.processing.index.map.MapIndexBuilder) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Context(org.kie.workbench.common.dmn.api.definition.model.Context) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Before(org.junit.Before) BindableAdapterUtils(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) UUID(org.uberfire.commons.uuid.UUID) InputStreamReader(java.io.InputStreamReader) InputDataConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.InputDataConverter) Association(org.kie.workbench.common.dmn.api.definition.model.Association) TDecision(org.kie.dmn.model.v1_2.TDecision) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Assert.assertNull(org.junit.Assert.assertNull) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) DRGElement(org.kie.dmn.model.api.DRGElement) Assert(org.junit.Assert) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) Assert.assertEquals(org.junit.Assert.assertEquals) CoreMatchers.is(org.hamcrest.CoreMatchers.is) TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation) DecisionTable(org.kie.dmn.model.api.DecisionTable) DecisionConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.DecisionConverter) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) XPathExpressionException(javax.xml.xpath.XPathExpressionException) DMNResult(org.kie.dmn.api.core.DMNResult) Spliterators(java.util.Spliterators) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) Scanner(java.util.Scanner) DMNEdge(org.kie.dmn.model.api.dmndi.DMNEdge) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) TextAnnotationConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.TextAnnotationConverter) DMNElement(org.kie.workbench.common.dmn.api.definition.model.DMNElement) DMNModel(org.kie.dmn.api.core.DMNModel) DecisionEvaluationStatus(org.kie.dmn.api.core.DMNDecisionResult.DecisionEvaluationStatus) InformationRequirement(org.kie.workbench.common.dmn.api.definition.model.InformationRequirement) DMNMarshallerProducer(org.kie.workbench.common.dmn.backend.producers.DMNMarshallerProducer) TTextAnnotation(org.kie.dmn.model.v1_2.TTextAnnotation) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Import(org.kie.dmn.model.api.Import) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Collectors(java.util.stream.Collectors) DMNRuntimeUtil(org.kie.dmn.core.util.DMNRuntimeUtil) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) DiagramElement(org.kie.dmn.model.api.dmndi.DiagramElement) List(java.util.List) DMNShape(org.kie.dmn.model.api.dmndi.DMNShape) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) DMNImportTypes(org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes) BuiltInType(org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType) Optional(java.util.Optional) MappingContextSingleton(org.jboss.errai.marshalling.server.MappingContextSingleton) Spliterator(java.util.Spliterator) Node(org.kie.workbench.common.stunner.core.graph.Node) DMNDecisionResult(org.kie.dmn.api.core.DMNDecisionResult) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) HashMap(java.util.HashMap) OptionalInt(java.util.OptionalInt) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Level(org.kie.api.builder.Message.Level) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound) ReaderInputStream(org.apache.tools.ant.util.ReaderInputStream) KieServices(org.kie.api.KieServices) DiagramImpl(org.kie.workbench.common.stunner.core.diagram.DiagramImpl) KnowledgeRequirement(org.kie.workbench.common.dmn.api.definition.model.KnowledgeRequirement) Assume(org.junit.Assume) InputSource(org.xml.sax.InputSource) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) Assert.assertNotNull(org.junit.Assert.assertNotNull) KieContainer(org.kie.api.runtime.KieContainer) DMNMarshallerImportsHelperStandalone(org.kie.workbench.common.dmn.backend.common.DMNMarshallerImportsHelperStandalone) StunnerTestingGraphBackendAPI(org.kie.workbench.common.stunner.core.backend.StunnerTestingGraphBackendAPI) DMNMarshallerStandalone.getDmnElementRef(org.kie.workbench.common.dmn.backend.DMNMarshallerStandalone.getDmnElementRef) Mockito.when(org.mockito.Mockito.when) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) AuthorityRequirement(org.kie.workbench.common.dmn.api.definition.model.AuthorityRequirement) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) XPathFactory(javax.xml.xpath.XPathFactory) AbstractMap(java.util.AbstractMap) ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Collections(java.util.Collections) InputStream(java.io.InputStream) NamespaceContext(javax.xml.namespace.NamespaceContext) DMNContext(org.kie.dmn.api.core.DMNContext) Context(org.kie.workbench.common.dmn.api.definition.model.Context) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) TDecision(org.kie.dmn.model.v1_2.TDecision) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) DMNMessage(org.kie.dmn.api.core.DMNMessage) Test(org.junit.Test)

Example 9 with Expression

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

the class DMNMarshallerStandaloneTest method checkDecisionWithContextWithDefaultResult.

private void checkDecisionWithContextWithDefaultResult(Graph<?, Node<?, ?>> g) {
    Node<?, ?> decisionNode = g.getNode("_30810b88-8416-4c02-8ed1-8c19b7606243");
    assertNodeContentDefinitionIs(decisionNode, Decision.class);
    Context context = (Context) ((Decision) ((View<?>) decisionNode.getContent()).getDefinition()).getExpression();
    InformationItem defaultResultVariable = context.getContextEntry().get(1).getVariable();
    assertNull("Default result variable", defaultResultVariable);
    Expression defaultResultExpression = context.getContextEntry().get(1).getExpression();
    assertNotNull("Default result expression", defaultResultExpression);
    assertEquals("defaultResultExpression's parent-parent is contextNode", "_0f38d114-5d6e-40dd-aa9c-9f031f9b0571", ((DMNElement) (defaultResultExpression).getParent().getParent()).getId().getValue());
}
Also used : NamespaceContext(javax.xml.namespace.NamespaceContext) DMNContext(org.kie.dmn.api.core.DMNContext) Context(org.kie.workbench.common.dmn.api.definition.model.Context) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) DMNElement(org.kie.workbench.common.dmn.api.definition.model.DMNElement) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Example 10 with Expression

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

the class DMNMarshallerStandaloneTest method checkDecisionWithContext.

@SuppressWarnings("unchecked")
private void checkDecisionWithContext(Graph<?, Node<?, ?>> g) {
    Node<?, ?> decisionNode = g.getNode("_30810b88-8416-4c02-8ed1-8c19b7606243");
    assertNodeContentDefinitionIs(decisionNode, Decision.class);
    Node<?, ?> rootNode = DMNMarshallerStandalone.findDMNDiagramRoot((Graph) g);
    assertNotNull(rootNode);
    assertRootNodeConnectedTo(rootNode, decisionNode);
    assertEquals("decisionNode parent is Definitions DMN root", "_153e2b47-3bd2-4db0-828c-db3fce0b3199", ((DMNElement) ((Decision) ((View<?>) decisionNode.getContent()).getDefinition()).getParent()).getId().getValue());
    Context context = (Context) ((Decision) ((View<?>) decisionNode.getContent()).getDefinition()).getExpression();
    assertEquals("contextNode's parent is decisionNode", "_30810b88-8416-4c02-8ed1-8c19b7606243", ((DMNElement) context.getParent()).getId().getValue());
    Expression literalExpression1 = context.getContextEntry().get(0).getExpression();
    assertEquals("literalExpression1's parent-parent is contextNode", "_0f38d114-5d6e-40dd-aa9c-9f031f9b0571", ((DMNElement) (literalExpression1).getParent().getParent()).getId().getValue());
    Expression literalExpression2 = context.getContextEntry().get(1).getExpression();
    assertEquals("literalExpression2's parent-parent is contextNode", "_0f38d114-5d6e-40dd-aa9c-9f031f9b0571", ((DMNElement) (literalExpression2).getParent().getParent()).getId().getValue());
}
Also used : NamespaceContext(javax.xml.namespace.NamespaceContext) DMNContext(org.kie.dmn.api.core.DMNContext) Context(org.kie.workbench.common.dmn.api.definition.model.Context) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) DMNElement(org.kie.workbench.common.dmn.api.definition.model.DMNElement) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Aggregations

Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)75 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)41 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)29 Test (org.junit.Test)27 BaseExpressionGrid (org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid)26 GridData (org.uberfire.ext.wires.core.grids.client.model.GridData)26 BaseUIModelMapper (org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper)25 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)14 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)14 ExpressionCellValue (org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)12 View (org.kie.workbench.common.stunner.core.graph.content.view.View)12 GridWidget (org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget)11 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)10 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)9 ArrayList (java.util.ArrayList)8 Context (org.kie.workbench.common.dmn.api.definition.model.Context)8 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)8 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)7 DMNGridData (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData)7 GridCellTuple (org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple)7