Search in sources :

Example 21 with DecisionTable

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

the class MoveColumnsCommandTest method setUp.

@Before
public void setUp() {
    this.dtable = new DecisionTable();
    this.uiModel = new DMNGridData();
    dtable.getInput().add(inputClauseOne);
    dtable.getInput().add(inputClauseTwo);
    dtable.getInput().add(inputClauseThree);
    dtable.getOutput().add(outputClauseOne);
    dtable.getOutput().add(outputClauseTwo);
    dtable.getOutput().add(outputClauseThree);
    dtable.getAnnotations().add(annotationClauseOne);
    dtable.getAnnotations().add(annotationClauseTwo);
    dtable.getAnnotations().add(annotationClauseThree);
    dtable.getRule().add(new DecisionRule() {

        {
            getInputEntry().add(new UnaryTests());
            getInputEntry().add(new UnaryTests());
            getInputEntry().add(new UnaryTests());
            getOutputEntry().add(new LiteralExpression());
            getOutputEntry().add(new LiteralExpression());
            getOutputEntry().add(new LiteralExpression());
            getAnnotationEntry().add(new RuleAnnotationClauseText());
            getAnnotationEntry().add(new RuleAnnotationClauseText());
            getAnnotationEntry().add(new RuleAnnotationClauseText());
        }
    });
    uiModel.appendColumn(uiRowNumberColumn);
    uiModel.appendColumn(uiInputClauseColumnOne);
    uiModel.appendColumn(uiInputClauseColumnTwo);
    uiModel.appendColumn(uiInputClauseColumnThree);
    uiModel.appendColumn(uiOutputClauseColumnOne);
    uiModel.appendColumn(uiOutputClauseColumnTwo);
    uiModel.appendColumn(uiOutputClauseColumnThree);
    uiModel.appendColumn(uiRuleAnnotationClauseColumnOne);
    uiModel.appendColumn(uiRuleAnnotationClauseColumnTwo);
    uiModel.appendColumn(uiRuleAnnotationClauseColumnThree);
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiInputClauseColumnOne).getIndex();
    doReturn(2).when(uiInputClauseColumnTwo).getIndex();
    doReturn(3).when(uiInputClauseColumnThree).getIndex();
    doReturn(4).when(uiOutputClauseColumnOne).getIndex();
    doReturn(5).when(uiOutputClauseColumnTwo).getIndex();
    doReturn(6).when(uiOutputClauseColumnThree).getIndex();
    doReturn(7).when(uiRuleAnnotationClauseColumnOne).getIndex();
    doReturn(8).when(uiRuleAnnotationClauseColumnTwo).getIndex();
    doReturn(9).when(uiRuleAnnotationClauseColumnThree).getIndex();
}
Also used : DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Before(org.junit.Before)

Example 22 with DecisionTable

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

the class MoveRowsCommandTest method setUp.

@Before
public void setUp() throws Exception {
    this.dtable = new DecisionTable();
    this.uiModel = new DMNGridData();
    dtable.getInput().add(inputClause);
    dtable.getOutput().add(outputClause);
    uiModel.appendColumn(uiRowNumberColumn);
    uiModel.appendColumn(uiInputClauseColumn);
    uiModel.appendColumn(uiOutputClauseColumn);
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiInputClauseColumn).getIndex();
    doReturn(2).when(uiOutputClauseColumn).getIndex();
    rowsUnderTest.clear();
    appendRow(0, "a");
    appendRow(1, "b");
    appendRow(2, "c");
}
Also used : DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) Before(org.junit.Before)

Example 23 with DecisionTable

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

the class SetHitPolicyCommandTest method makeCommand.

private void makeCommand(final HitPolicy hitPolicy) {
    this.dtable = new DecisionTable();
    this.dtable.setHitPolicy(hitPolicy);
    this.command = new SetHitPolicyCommand(dtable, NEW_HIT_POLICY, canvasOperation);
}
Also used : DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable)

Example 24 with DecisionTable

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

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

the class DecisionTableGrid method doAfterHeaderSelectionChange.

@Override
public void doAfterHeaderSelectionChange(final int uiHeaderRowIndex, final int uiHeaderColumnIndex) {
    if (getExpression().get().isPresent()) {
        final DecisionTable dtable = getExpression().get().get();
        final DecisionTableUIModelMapperHelper.DecisionTableSection section = DecisionTableUIModelMapperHelper.getSection(dtable, uiHeaderColumnIndex);
        switch(section) {
            case INPUT_CLAUSES:
                doAfterHeaderInputClauseSelectionChange(dtable, uiHeaderColumnIndex);
                return;
            case OUTPUT_CLAUSES:
                doAfterHeaderOutputClauseSelectionChange(dtable, uiHeaderRowIndex, uiHeaderColumnIndex);
                return;
        }
    }
    super.doAfterHeaderSelectionChange(uiHeaderRowIndex, uiHeaderColumnIndex);
}
Also used : DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable)

Aggregations

DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)56 Test (org.junit.Test)32 OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)22 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)17 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)15 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)13 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)12 Before (org.junit.Before)11 ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)10 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)9 DMNGridData (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData)9 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)8 Context (org.kie.workbench.common.dmn.api.definition.model.Context)7 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)7 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)7 RuleAnnotationClause (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause)7 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)6 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)6 TDecisionTable (org.kie.dmn.model.v1_2.TDecisionTable)5 InformationItemPrimary (org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary)5