Search in sources :

Example 11 with UnaryTests

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

the class DeleteInputClauseCommandTest method testGraphCommandExecuteRemoveMiddle.

@Test
public void testGraphCommandExecuteRemoveMiddle() {
    final InputClause firstInput = mock(InputClause.class);
    final InputClause lastInput = mock(InputClause.class);
    dtable.getInput().add(0, firstInput);
    dtable.getInput().add(lastInput);
    final UnaryTests inputOneValue = mock(UnaryTests.class);
    final UnaryTests inputTwoValue = mock(UnaryTests.class);
    final UnaryTests inputThreeValue = mock(UnaryTests.class);
    final DecisionRule rule = new DecisionRule();
    rule.getInputEntry().add(inputOneValue);
    rule.getInputEntry().add(inputTwoValue);
    rule.getInputEntry().add(inputThreeValue);
    dtable.getRule().add(rule);
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT + 1);
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
    assertEquals(2, dtable.getInput().size());
    assertEquals(firstInput, dtable.getInput().get(0));
    assertEquals(lastInput, dtable.getInput().get(1));
    assertEquals(2, dtable.getRule().get(0).getInputEntry().size());
    assertEquals(inputOneValue, dtable.getRule().get(0).getInputEntry().get(0));
    assertEquals(inputThreeValue, dtable.getRule().get(0).getInputEntry().get(1));
}
Also used : GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Test(org.junit.Test)

Example 12 with UnaryTests

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

the class AddInputClauseCommand method newGraphCommand.

@Override
protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler context) {
    return new AbstractGraphCommand() {

        @Override
        protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
            dtable.getComponentWidths().add(uiColumnIndex, null);
            final int clauseIndex = uiColumnIndex - DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT;
            dtable.getInput().add(clauseIndex, inputClause);
            final InputClauseLiteralExpression le = new InputClauseLiteralExpression();
            inputClause.setInputExpression(le);
            le.getText().setValue(name);
            dtable.getRule().forEach(rule -> {
                final UnaryTests ut = new UnaryTests();
                ut.getText().setValue(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT);
                rule.getInputEntry().add(clauseIndex, ut);
                ut.setParent(rule);
            });
            inputClause.setParent(dtable);
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) {
            dtable.getComponentWidths().remove(uiColumnIndex);
            final int clauseIndex = dtable.getInput().indexOf(inputClause);
            dtable.getRule().forEach(rule -> rule.getInputEntry().remove(clauseIndex));
            dtable.getInput().remove(inputClause);
            return GraphCommandResultBuilder.SUCCESS;
        }
    };
}
Also used : AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) InputClauseLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests)

Example 13 with UnaryTests

use of org.kie.workbench.common.dmn.api.definition.model.UnaryTests 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 14 with UnaryTests

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

the class DecisionTableEditorDefinitionEnricher method enrich.

@Override
public void enrich(final Optional<String> nodeUUID, final HasExpression hasExpression, final Optional<DecisionTable> expression) {
    expression.ifPresent(dtable -> {
        dtable.setHitPolicy(HitPolicy.UNIQUE);
        dtable.setPreferredOrientation(DecisionTableOrientation.RULE_AS_ROW);
        final InputClause inputClause = new InputClause();
        final InputClauseLiteralExpression literalExpression = new InputClauseLiteralExpression();
        literalExpression.getText().setValue(DecisionTableDefaultValueUtilities.getNewInputClauseName(dtable));
        inputClause.setInputExpression(literalExpression);
        dtable.getInput().add(inputClause);
        final RuleAnnotationClause ruleAnnotationClause = new RuleAnnotationClause();
        ruleAnnotationClause.getName().setValue(DecisionTableDefaultValueUtilities.getNewRuleAnnotationClauseName(dtable));
        dtable.getAnnotations().add(ruleAnnotationClause);
        final DecisionRule decisionRule = new DecisionRule();
        final UnaryTests decisionRuleUnaryTest = new UnaryTests();
        decisionRuleUnaryTest.getText().setValue(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT);
        decisionRule.getInputEntry().add(decisionRuleUnaryTest);
        buildOutputClausesByDataType(hasExpression, dtable, decisionRule);
        final RuleAnnotationClauseText ruleAnnotationEntry = new RuleAnnotationClauseText();
        ruleAnnotationEntry.getText().setValue(DecisionTableDefaultValueUtilities.RULE_DESCRIPTION);
        decisionRule.getAnnotationEntry().add(ruleAnnotationEntry);
        dtable.getRule().add(decisionRule);
        // Setup parent relationships
        inputClause.setParent(dtable);
        decisionRule.setParent(dtable);
        literalExpression.setParent(inputClause);
        decisionRuleUnaryTest.setParent(decisionRule);
        ruleAnnotationEntry.setParent(dtable);
        if (nodeUUID.isPresent()) {
            enrichInputClauses(nodeUUID.get(), dtable);
        } else {
            enrichOutputClauses(dtable);
        }
    });
}
Also used : InputClauseLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule)

Example 15 with UnaryTests

use of org.kie.workbench.common.dmn.api.definition.model.UnaryTests 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

UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)36 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)16 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)16 Test (org.junit.Test)15 RuleAnnotationClauseText (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)13 ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)10 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)9 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)8 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)8 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)6 Text (org.kie.workbench.common.dmn.api.property.dmn.Text)6 ConstraintType (org.kie.workbench.common.dmn.api.definition.model.ConstraintType)5 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)5 InputClauseLiteralExpression (org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression)4 RuleAnnotationClause (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause)4 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)4 DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)4 JSITUnaryTests (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITUnaryTests)4 List (java.util.List)3 Before (org.junit.Before)3