Search in sources :

Example 16 with UnaryTests

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

the class ItemDefinitionUtilsTest method testGetConstraintTextWhenItemDefinitionHasAllowedValues.

@Test
public void testGetConstraintTextWhenItemDefinitionHasAllowedValues() {
    final ItemDefinition itemDefinition = mock(ItemDefinition.class);
    final UnaryTests allowedValues = mock(UnaryTests.class);
    final String expectedText = "(1..10)";
    when(allowedValues.getText()).thenReturn(new Text(expectedText));
    when(itemDefinition.getAllowedValues()).thenReturn(allowedValues);
    final String actualText = utils.getConstraintText(itemDefinition);
    assertEquals(expectedText, actualText);
}
Also used : ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) Test(org.junit.Test)

Example 17 with UnaryTests

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

the class ItemDefinitionUpdateHandlerTest method testMakeAllowedValuesWhenDataTypeAndItemDefinitionConstraintAreNotEqual.

@Test
public void testMakeAllowedValuesWhenDataTypeAndItemDefinitionConstraintAreNotEqual() {
    final DataType dataType = mock(DataType.class);
    final ItemDefinition itemDefinition = mock(ItemDefinition.class);
    final String expectedText = "(1..20)";
    final ConstraintType expectedConstraintType = ConstraintType.RANGE;
    when(dataType.getConstraint()).thenReturn(expectedText);
    when(dataType.getConstraintType()).thenReturn(expectedConstraintType);
    final UnaryTests actualAllowedValues = handler.makeAllowedValues(dataType, itemDefinition);
    assertNotNull(actualAllowedValues.getId());
    assertNotNull(actualAllowedValues.getDescription());
    assertEquals(expectedText, actualAllowedValues.getText().getValue());
    assertNull(actualAllowedValues.getExpressionLanguage());
    assertEquals(expectedConstraintType, actualAllowedValues.getConstraintType());
}
Also used : ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) ConstraintType(org.kie.workbench.common.dmn.api.definition.model.ConstraintType) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) Test(org.junit.Test)

Example 18 with UnaryTests

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

the class ItemDefinitionUpdateHandlerTest method testMakeAllowedValuesWhenDataTypeConstraintIsBlank.

@Test
public void testMakeAllowedValuesWhenDataTypeConstraintIsBlank() {
    final DataType dataType = mock(DataType.class);
    final ItemDefinition itemDefinition = mock(ItemDefinition.class);
    when(dataType.getConstraint()).thenReturn("");
    final UnaryTests actualAllowedValues = handler.makeAllowedValues(dataType, itemDefinition);
    assertNull(actualAllowedValues);
}
Also used : ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) Test(org.junit.Test)

Example 19 with UnaryTests

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

the class DataTypeManagerTest method makeItem.

private ItemDefinition makeItem(final String itemName, final String itemType, final String constraint, final ItemDefinition... subItemDefinitions) {
    final ItemDefinition itemDefinition = makeItem(itemName, itemType, false, subItemDefinitions);
    final UnaryTests unaryTests = mock(UnaryTests.class);
    when(unaryTests.getText()).thenReturn(new Text(constraint));
    when(itemDefinition.getAllowedValues()).thenReturn(unaryTests);
    return itemDefinition;
}
Also used : ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests)

Example 20 with UnaryTests

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

the class MoveColumnsCommand method newGraphCommand.

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

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

        private boolean isColumnInValidSection() {
            final DecisionTableSection section = DecisionTableUIModelMapperHelper.getSection(dtable, index);
            return section == DecisionTableSection.INPUT_CLAUSES || section == DecisionTableSection.OUTPUT_CLAUSES || section == DecisionTableSection.ANNOTATION_CLAUSES;
        }

        @Override
        public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
            return moveClauses(index);
        }

        @Override
        public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) {
            return moveClauses(oldIndex);
        }

        private CommandResult<RuleViolation> moveClauses(final int index) {
            final DecisionTableSection section = DecisionTableUIModelMapperHelper.getSection(dtable, index);
            if (section == DecisionTableSection.INPUT_CLAUSES) {
                final int oldIndex = uiModel.getColumns().indexOf(columns.get(0));
                final int relativeIndex = DecisionTableUIModelMapperHelper.getInputEntryIndex(dtable, index);
                final int relativeOldIndex = DecisionTableUIModelMapperHelper.getInputEntryIndex(dtable, oldIndex);
                final List<Integer> uiColumnIndexesToMove = columns.stream().map(c -> uiModel.getColumns().indexOf(c)).collect(Collectors.toList());
                final List<Integer> inputClauseIndexesToMove = uiColumnIndexesToMove.stream().map(i -> DecisionTableUIModelMapperHelper.getInputEntryIndex(dtable, i)).collect(Collectors.toList());
                moveClauses(relativeIndex, relativeOldIndex, dtable.getInput(), inputClauseIndexesToMove);
                CommandUtils.moveComponentWidths(index, oldIndex, dtable.getComponentWidths(), uiColumnIndexesToMove);
                final List<List<UnaryTests>> decisionRulesInputEntries = dtable.getRule().stream().map(DecisionRule::getInputEntry).collect(Collectors.toList());
                updateDecisionRules(relativeIndex, relativeOldIndex, decisionRulesInputEntries, inputClauseIndexesToMove);
                return GraphCommandResultBuilder.SUCCESS;
            } else if (section == DecisionTableSection.OUTPUT_CLAUSES) {
                final int oldIndex = uiModel.getColumns().indexOf(columns.get(0));
                final int relativeIndex = DecisionTableUIModelMapperHelper.getOutputEntryIndex(dtable, index);
                final int relativeOldIndex = DecisionTableUIModelMapperHelper.getOutputEntryIndex(dtable, oldIndex);
                final List<Integer> uiColumnIndexesToMove = columns.stream().map(c -> uiModel.getColumns().indexOf(c)).collect(Collectors.toList());
                final List<Integer> outputClauseIndexesToMove = uiColumnIndexesToMove.stream().map(i -> DecisionTableUIModelMapperHelper.getOutputEntryIndex(dtable, i)).collect(Collectors.toList());
                moveClauses(relativeIndex, relativeOldIndex, dtable.getOutput(), outputClauseIndexesToMove);
                CommandUtils.moveComponentWidths(index, oldIndex, dtable.getComponentWidths(), uiColumnIndexesToMove);
                final List<List<LiteralExpression>> decisionRulesOutputEntries = dtable.getRule().stream().map(DecisionRule::getOutputEntry).collect(Collectors.toList());
                updateDecisionRules(relativeIndex, relativeOldIndex, decisionRulesOutputEntries, outputClauseIndexesToMove);
                return GraphCommandResultBuilder.SUCCESS;
            } else if (section == DecisionTableSection.ANNOTATION_CLAUSES) {
                final int oldIndex = uiModel.getColumns().indexOf(columns.get(0));
                final int relativeIndex = DecisionTableUIModelMapperHelper.getAnnotationEntryIndex(dtable, index);
                final int relativeOldIndex = DecisionTableUIModelMapperHelper.getAnnotationEntryIndex(dtable, oldIndex);
                final List<Integer> uiColumnIndexesToMove = columns.stream().map(c -> uiModel.getColumns().indexOf(c)).collect(Collectors.toList());
                final List<Integer> annotationClauseIndexesToMove = uiColumnIndexesToMove.stream().map(i -> DecisionTableUIModelMapperHelper.getAnnotationEntryIndex(dtable, i)).collect(Collectors.toList());
                moveClauses(relativeIndex, relativeOldIndex, dtable.getAnnotations(), annotationClauseIndexesToMove);
                CommandUtils.moveComponentWidths(index, oldIndex, dtable.getComponentWidths(), uiColumnIndexesToMove);
                final List<List<RuleAnnotationClauseText>> decisionRulesAnnotationEntries = dtable.getRule().stream().map(DecisionRule::getAnnotationEntry).collect(Collectors.toList());
                updateDecisionRules(relativeIndex, relativeOldIndex, decisionRulesAnnotationEntries, annotationClauseIndexesToMove);
                return GraphCommandResultBuilder.SUCCESS;
            } else {
                return GraphCommandResultBuilder.failed();
            }
        }

        private <T> void moveClauses(final int relativeIndex, final int relativeOldIndex, final List<T> clauses, final List<Integer> clauseIndexesToMove) {
            final List<T> clausesToMove = clauseIndexesToMove.stream().map(clauses::get).collect(Collectors.toList());
            clauses.removeAll(clausesToMove);
            if (relativeIndex < relativeOldIndex) {
                clauses.addAll(relativeIndex, clausesToMove);
            } else if (relativeIndex > relativeOldIndex) {
                clauses.addAll(relativeIndex - clausesToMove.size() + 1, clausesToMove);
            }
        }

        private <T> void updateDecisionRules(final int relativeIndex, final int relativeOldIndex, final List<List<T>> clauses, final List<Integer> clauseIndexesToMove) {
            clauses.forEach(row -> moveClauses(relativeIndex, relativeOldIndex, row, clauseIndexesToMove));
        }
    };
}
Also used : DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) DecisionTableUIModelMapperHelper(org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) VetoExecutionCommand(org.kie.workbench.common.dmn.client.commands.VetoExecutionCommand) CanvasCommandResultBuilder(org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) AbstractCanvasCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AbstractCanvasCommand) ArrayList(java.util.ArrayList) CommandUtils(org.kie.workbench.common.dmn.client.commands.util.CommandUtils) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) Command(org.kie.workbench.common.stunner.core.command.Command) GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) VetoUndoCommand(org.kie.workbench.common.dmn.client.commands.VetoUndoCommand) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult) DecisionTableSection(org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper.DecisionTableSection) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Collectors(java.util.stream.Collectors) AbstractCanvasGraphCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AbstractCanvasGraphCommand) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) List(java.util.List) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) DecisionTableSection(org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper.DecisionTableSection) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) ArrayList(java.util.ArrayList) List(java.util.List)

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