Search in sources :

Example 21 with UnaryTests

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

the class DeleteInputClauseCommand method newGraphCommand.

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

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

        @Override
        public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext gce) {
            dtable.getComponentWidths().remove(uiColumnIndex);
            final int clauseIndex = getInputClauseIndex();
            dtable.getRule().forEach(row -> row.getInputEntry().remove(clauseIndex));
            dtable.getInput().remove(clauseIndex);
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext gce) {
            dtable.getComponentWidths().add(uiColumnIndex, oldUiModelColumn.getWidth());
            final int clauseIndex = getInputClauseIndex();
            dtable.getInput().add(clauseIndex, oldInputClause);
            IntStream.range(0, dtable.getRule().size()).forEach(rowIndex -> {
                final UnaryTests value = oldColumnData.get(rowIndex);
                dtable.getRule().get(rowIndex).getInputEntry().add(clauseIndex, value);
            });
            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) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests)

Example 22 with UnaryTests

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

the class ItemDefinitionPropertyConverterTest method testSetUnaryTestsWhenUnaryTestsIsNotNull.

@Test
public void testSetUnaryTestsWhenUnaryTestsIsNotNull() {
    final ItemDefinition wb = mock(ItemDefinition.class);
    final ArgumentCaptor<UnaryTests> argument = ArgumentCaptor.forClass(UnaryTests.class);
    final org.kie.dmn.model.api.ItemDefinition dmn = mock(org.kie.dmn.model.api.ItemDefinition.class);
    final org.kie.dmn.model.api.UnaryTests dmnAllowedValues = mock(org.kie.dmn.model.api.UnaryTests.class);
    when(dmn.getAllowedValues()).thenReturn(dmnAllowedValues);
    setUnaryTests(wb, dmn);
    verify(wb).setAllowedValues(argument.capture());
    assertEquals(wb, argument.getValue().getParent());
}
Also used : ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) ItemDefinitionPropertyConverter.setUnaryTests(org.kie.workbench.common.dmn.backend.definition.v1_1.ItemDefinitionPropertyConverter.setUnaryTests) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) Test(org.junit.Test)

Example 23 with UnaryTests

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

the class DecisionRuleFactory method duplicateDecisionRule.

public static DecisionRule duplicateDecisionRule(final int index, final DecisionTable dtable) {
    final DecisionRule rule = new DecisionRule();
    final DecisionRule source = dtable.getRule().get(index);
    for (UnaryTests ie : source.getInputEntry()) {
        final UnaryTests ut = new UnaryTests();
        ut.getText().setValue(ie.getText().getValue());
        ut.setConstraintType(ie.getConstraintType());
        rule.getInputEntry().add(ut);
        ut.setParent(rule);
    }
    for (LiteralExpression oe : source.getOutputEntry()) {
        final LiteralExpression le = new LiteralExpression();
        le.getText().setValue(oe.getText().getValue());
        rule.getOutputEntry().add(le);
        le.setParent(rule);
    }
    for (final RuleAnnotationClauseText text : source.getAnnotationEntry()) {
        final RuleAnnotationClauseText copy = new RuleAnnotationClauseText();
        copy.getText().setValue(text.getText().getValue());
        copy.setParent(rule);
        rule.getAnnotationEntry().add(copy);
    }
    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)

Example 24 with UnaryTests

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

the class DecisionTableGrid method doAfterSelectionChange.

@Override
public void doAfterSelectionChange(final int uiRowIndex, final int uiColumnIndex) {
    if (hasAnyHeaderCellSelected() || hasMultipleCellsSelected()) {
        super.doAfterSelectionChange(uiRowIndex, uiColumnIndex);
        return;
    }
    if (getExpression().get().isPresent()) {
        final DecisionTable dtable = getExpression().get().get();
        final DecisionTableUIModelMapperHelper.DecisionTableSection section = DecisionTableUIModelMapperHelper.getSection(dtable, uiColumnIndex);
        switch(section) {
            case INPUT_CLAUSES:
                final int icIndex = DecisionTableUIModelMapperHelper.getInputEntryIndex(dtable, uiColumnIndex);
                final UnaryTests unaryTests = dtable.getRule().get(uiRowIndex).getInputEntry().get(icIndex);
                fireDomainObjectSelectionEvent(unaryTests);
                return;
            case OUTPUT_CLAUSES:
                final int ocIndex = DecisionTableUIModelMapperHelper.getOutputEntryIndex(dtable, uiColumnIndex);
                final LiteralExpression literalExpression = dtable.getRule().get(uiRowIndex).getOutputEntry().get(ocIndex);
                fireDomainObjectSelectionEvent(literalExpression);
                return;
        }
    }
    super.doAfterSelectionChange(uiRowIndex, uiColumnIndex);
}
Also used : DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests)

Example 25 with UnaryTests

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

the class DecisionRulePropertyConverter method dmnFromWB.

public static org.kie.dmn.model.api.DecisionRule dmnFromWB(final DecisionRule wb) {
    final org.kie.dmn.model.api.DecisionRule result = new org.kie.dmn.model.v1_2.TDecisionRule();
    result.setId(wb.getId().getValue());
    result.setDescription(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
    for (final RuleAnnotationClauseText ruleAnnotationClauseText : wb.getAnnotationEntry()) {
        final org.kie.dmn.model.api.RuleAnnotation ruleAnnotation = RuleAnnotationClauseTextConverter.dmnFromWB(ruleAnnotationClauseText);
        if (ruleAnnotation != null) {
            ruleAnnotation.setParent(result);
        }
        result.getAnnotationEntry().add(ruleAnnotation);
    }
    for (final UnaryTests ie : wb.getInputEntry()) {
        final org.kie.dmn.model.api.UnaryTests inputEntryConverted = UnaryTestsPropertyConverter.dmnFromWB(ie);
        if (inputEntryConverted != null) {
            inputEntryConverted.setParent(result);
        }
        result.getInputEntry().add(inputEntryConverted);
    }
    for (final LiteralExpression oe : wb.getOutputEntry()) {
        final org.kie.dmn.model.api.LiteralExpression outputEntryConverted = LiteralExpressionPropertyConverter.dmnFromWB(oe);
        if (outputEntryConverted != null) {
            outputEntryConverted.setParent(result);
        }
        result.getOutputEntry().add(outputEntryConverted);
    }
    return result;
}
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)

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