Search in sources :

Example 46 with LiteralExpression

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

the class DeleteRelationColumnCommandTest method testCanvasCommandExecuteWithRows.

@Test
public void testCanvasCommandExecuteWithRows() {
    final List rowList = new List();
    relation.getRow().add(rowList);
    relation.getRow().get(0).getExpression().add(HasExpression.wrap(rowList, new LiteralExpression()));
    uiModel.appendRow(new BaseGridRow());
    uiModelMapper.fromDMNModel(0, 0);
    uiModelMapper.fromDMNModel(0, 1);
    makeCommand();
    final Command<AbstractCanvasHandler, CanvasViolation> cc = command.newCanvasCommand(handler);
    assertEquals(CanvasCommandResultBuilder.SUCCESS, cc.execute(handler));
    assertEquals(1, uiModel.getColumnCount());
    assertEquals(uiRowNumberColumn, uiModel.getColumns().get(0));
    assertEquals(1, uiModel.getRowCount());
    assertEquals(1, uiModel.getRows().get(0).getCells().size());
    assertEquals(1, uiModel.getCell(0, 0).getValue().getValue());
    verify(command).updateParentInformation();
    verify(executeCanvasOperation).execute();
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) List(org.kie.workbench.common.dmn.api.definition.model.List) Test(org.junit.Test)

Example 47 with LiteralExpression

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

the class DeleteRelationColumnCommandTest method testGraphCommandExecuteDeleteMiddleWithRows.

@Test
public void testGraphCommandExecuteDeleteMiddleWithRows() {
    final List rowList = new List();
    uiModel.appendColumn(mock(RelationColumn.class));
    uiModel.appendColumn(mock(RelationColumn.class));
    relation.getColumn().add(new InformationItem());
    relation.getColumn().add(new InformationItem());
    relation.getRow().add(rowList);
    final LiteralExpression firstExpression = new LiteralExpression();
    final LiteralExpression lastExpression = new LiteralExpression();
    relation.getRow().get(0).getExpression().add(HasExpression.wrap(rowList, firstExpression));
    relation.getRow().get(0).getExpression().add(HasExpression.wrap(rowList, new LiteralExpression()));
    relation.getRow().get(0).getExpression().add(HasExpression.wrap(rowList, lastExpression));
    makeCommand(2);
    final Command<GraphCommandExecutionContext, RuleViolation> c = command.newGraphCommand(handler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, c.execute(gce));
    assertEquals(2, relation.getColumn().size());
    assertEquals(1, relation.getRow().size());
    assertEquals(2, relation.getRow().get(0).getExpression().size());
    assertEquals(firstExpression, relation.getRow().get(0).getExpression().get(0).getExpression());
    assertEquals(lastExpression, relation.getRow().get(0).getExpression().get(1).getExpression());
}
Also used : RelationColumn(org.kie.workbench.common.dmn.client.editors.expressions.types.relation.RelationColumn) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) List(org.kie.workbench.common.dmn.api.definition.model.List) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 48 with LiteralExpression

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

the class RegisterNodeCommandTest method testExecuteWithBusinessKnowledgeModelNodeWhenNodeIsNotNew.

@Test
public void testExecuteWithBusinessKnowledgeModelNodeWhenNodeIsNotNew() {
    final FunctionDefinition functionDefinition = new FunctionDefinition();
    final LiteralExpression literalExpression = makeLiteralExpression("123");
    when(candidateContent.getDefinition()).thenReturn(businessKnowledgeModel);
    doReturn(functionDefinition).when(businessKnowledgeModel).getEncapsulatedLogic();
    functionDefinition.setExpression(literalExpression);
    literalExpression.setParent(functionDefinition);
    assertThat(command.execute(graphCommandExecutionContext).getType()).isEqualTo(CommandResult.Type.INFO);
    final FunctionDefinition encapsulatedLogic = businessKnowledgeModel.getEncapsulatedLogic();
    final Expression expression = encapsulatedLogic.getExpression();
    assertThat(expression).isEqualTo(makeLiteralExpression("123"));
    assertThat(expression.getParent()).isEqualTo(encapsulatedLogic);
    assertThat(KindUtilities.getKind(encapsulatedLogic)).isEqualTo(FunctionDefinition.Kind.FEEL);
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) Test(org.junit.Test) AbstractGraphCommandTest(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommandTest)

Example 49 with LiteralExpression

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

the class DecisionTableEditorDefinitionEnricher method enrichInputClauses.

@SuppressWarnings("unchecked")
void enrichInputClauses(final String uuid, final DecisionTable dtable) {
    final Graph<?, Node> graph = sessionManager.getCurrentSession().getCanvasHandler().getDiagram().getGraph();
    final Node<?, Edge> node = graph.getNode(uuid);
    if (Objects.isNull(node)) {
        return;
    }
    // Get all Decision nodes feeding into this DecisionTable
    final List<Decision> decisionSet = node.getInEdges().stream().map(Edge::getSourceNode).map(Node::getContent).filter(content -> content instanceof Definition).map(content -> (Definition) content).map(Definition::getDefinition).filter(definition -> definition instanceof Decision).map(definition -> (Decision) definition).collect(Collectors.toList());
    // Get all InputData nodes feeding into this DecisionTable
    final List<InputData> inputDataSet = node.getInEdges().stream().map(Edge::getSourceNode).map(Node::getContent).filter(content -> content instanceof Definition).map(content -> (Definition) content).map(Definition::getDefinition).filter(definition -> definition instanceof InputData).map(definition -> (InputData) definition).collect(Collectors.toList());
    if (decisionSet.isEmpty() && inputDataSet.isEmpty()) {
        return;
    }
    // Extract individual components of InputData TypeRefs
    final Definitions definitions = dmnGraphUtils.getModelDefinitions();
    final List<ClauseRequirement> inputClauseRequirements = new ArrayList<>();
    decisionSet.forEach(decision -> addInputClauseRequirement(decision.getVariable().getTypeRef(), definitions, inputClauseRequirements, decision.getName().getValue()));
    inputDataSet.forEach(inputData -> addInputClauseRequirement(inputData.getVariable().getTypeRef(), definitions, inputClauseRequirements, inputData.getName().getValue()));
    // Add InputClause columns for each InputData TypeRef component, sorted alphabetically
    dtable.getInput().clear();
    dtable.getRule().stream().forEach(decisionRule -> decisionRule.getInputEntry().clear());
    inputClauseRequirements.stream().sorted(Comparator.comparing(inputClauseRequirement -> inputClauseRequirement.text)).forEach(inputClauseRequirement -> {
        final InputClause inputClause = new InputClause();
        final InputClauseLiteralExpression literalExpression = new InputClauseLiteralExpression();
        literalExpression.getText().setValue(inputClauseRequirement.text);
        literalExpression.setTypeRef(inputClauseRequirement.typeRef);
        inputClause.setInputExpression(literalExpression);
        dtable.getInput().add(inputClause);
        dtable.getRule().stream().forEach(decisionRule -> {
            final UnaryTests decisionRuleUnaryTest = new UnaryTests();
            decisionRuleUnaryTest.getText().setValue(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT);
            decisionRule.getInputEntry().add(decisionRuleUnaryTest);
            decisionRuleUnaryTest.setParent(decisionRule);
        });
        inputClause.setParent(dtable);
        literalExpression.setParent(inputClause);
    });
}
Also used : DMNGraphUtils(org.kie.workbench.common.dmn.client.graph.DMNGraphUtils) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DecisionTableOrientation(org.kie.workbench.common.dmn.api.definition.model.DecisionTableOrientation) ANY(org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType.ANY) HasVariable(org.kie.workbench.common.dmn.api.definition.HasVariable) ItemDefinitionUtils(org.kie.workbench.common.dmn.client.editors.types.common.ItemDefinitionUtils) TypeRefUtils(org.kie.workbench.common.dmn.client.editors.expressions.util.TypeRefUtils) HasTypeRef(org.kie.workbench.common.dmn.api.definition.HasTypeRef) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) Predicate(java.util.function.Predicate) NULL_NS_URI(org.kie.workbench.common.dmn.api.property.dmn.QName.NULL_NS_URI) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) HitPolicy(org.kie.workbench.common.dmn.api.definition.model.HitPolicy) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) HasName(org.kie.workbench.common.dmn.api.definition.HasName) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) List(java.util.List) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) IsInformationItem(org.kie.workbench.common.dmn.api.definition.model.IsInformationItem) BuiltInType(org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Node(org.kie.workbench.common.stunner.core.graph.Node) BuiltInTypeUtils.isBuiltInType(org.kie.workbench.common.dmn.api.editors.types.BuiltInTypeUtils.isBuiltInType) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) SessionManager(org.kie.workbench.common.stunner.core.client.api.SessionManager) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) InputClauseLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression) ExpressionEditorModelEnricher(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorModelEnricher) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) Comparator(java.util.Comparator) Collections(java.util.Collections) Node(org.kie.workbench.common.stunner.core.graph.Node) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) ArrayList(java.util.ArrayList) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) InputClauseLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Edge(org.kie.workbench.common.stunner.core.graph.Edge) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause)

Example 50 with LiteralExpression

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

the class DecisionRuleFactory method makeDecisionRule.

public static DecisionRule makeDecisionRule(final DecisionTable dtable) {
    final DecisionRule rule = new DecisionRule();
    for (int ie = 0; ie < dtable.getInput().size(); ie++) {
        final UnaryTests ut = new UnaryTests();
        ut.getText().setValue(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT);
        rule.getInputEntry().add(ut);
        ut.setParent(rule);
    }
    for (int oe = 0; oe < dtable.getOutput().size(); oe++) {
        final LiteralExpression le = new LiteralExpression();
        le.getText().setValue(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT);
        rule.getOutputEntry().add(le);
        le.setParent(rule);
    }
    for (int index = 0; index < dtable.getAnnotations().size(); index++) {
        final RuleAnnotationClauseText ruleAnnotationClauseText = new RuleAnnotationClauseText();
        ruleAnnotationClauseText.getText().setValue(DecisionTableDefaultValueUtilities.RULE_ANNOTATION_CLAUSE_EXPRESSION_TEXT);
        rule.getAnnotationEntry().add(ruleAnnotationClauseText);
        ruleAnnotationClauseText.setParent(rule);
    }
    rule.setParent(dtable);
    return rule;
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule)

Aggregations

LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)113 Test (org.junit.Test)64 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)25 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)25 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)23 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)21 List (org.kie.workbench.common.dmn.api.definition.model.List)20 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)16 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)15 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)14 Before (org.junit.Before)13 RuleAnnotationClauseText (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)12 Optional (java.util.Optional)11 TLiteralExpression (org.kie.dmn.model.v1_2.TLiteralExpression)11 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)11 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)11 Context (org.kie.workbench.common.dmn.api.definition.model.Context)10 BaseGridData (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData)10 ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)9 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)9