Search in sources :

Example 11 with RuleAnnotationClauseText

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

the class AddRuleAnnotationClauseCommand 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) {
            decisionTable.getComponentWidths().add(uiColumnIndex, null);
            final int clauseIndex = getClauseIndex();
            decisionTable.getAnnotations().add(clauseIndex, ruleAnnotationClause);
            ruleAnnotationClause.getName().setValue(getName());
            decisionTable.getRule().forEach(rule -> {
                final RuleAnnotationClauseText ruleAnnotationClauseText = new RuleAnnotationClauseText();
                ruleAnnotationClauseText.getText().setValue(DecisionTableDefaultValueUtilities.RULE_ANNOTATION_CLAUSE_EXPRESSION_TEXT);
                rule.getAnnotationEntry().add(clauseIndex, ruleAnnotationClauseText);
                ruleAnnotationClauseText.setParent(rule);
            });
            ruleAnnotationClause.setParent(decisionTable);
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) {
            decisionTable.getComponentWidths().remove(uiColumnIndex);
            final int clauseIndex = decisionTable.getAnnotations().indexOf(ruleAnnotationClause);
            decisionTable.getRule().forEach(rule -> rule.getAnnotationEntry().remove(clauseIndex));
            decisionTable.getAnnotations().remove(ruleAnnotationClause);
            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) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation)

Example 12 with RuleAnnotationClauseText

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

the class DeleteRuleAnnotationClauseCommand 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) {
            getDecisionTable().getComponentWidths().remove(getUiColumnIndex());
            final int clauseIndex = getRuleAnnotationClauseIndex();
            getDecisionTable().getRule().forEach(row -> row.getAnnotationEntry().remove(clauseIndex));
            getDecisionTable().getAnnotations().remove(clauseIndex);
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext gce) {
            getDecisionTable().getComponentWidths().add(getUiColumnIndex(), getOldUiModelColumn().getWidth());
            final int clauseIndex = getRuleAnnotationClauseIndex();
            getDecisionTable().getAnnotations().add(clauseIndex, getOldRuleClause());
            IntStream.range(0, getDecisionTable().getRule().size()).forEach(rowIndex -> {
                final RuleAnnotationClauseText value = getOldColumnData().get(rowIndex);
                getDecisionTable().getRule().get(rowIndex).getAnnotationEntry().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) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation)

Example 13 with RuleAnnotationClauseText

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

the class DecisionRulePropertyConverterTest method createWbRuleAnnotation.

private RuleAnnotationClauseText createWbRuleAnnotation(final String text) {
    final RuleAnnotationClauseText annotation = new RuleAnnotationClauseText();
    annotation.getText().setValue(text);
    return annotation;
}
Also used : RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)

Example 14 with RuleAnnotationClauseText

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

the class RuleAnnotationClauseTextConverterTest method testDmnFromWB.

@Test
public void testDmnFromWB() {
    final String text = "text";
    final Text textObject = new Text(text);
    when(ruleAnnotationClauseText.getText()).thenReturn(textObject);
    final RuleAnnotation converted = RuleAnnotationClauseTextConverter.dmnFromWB(ruleAnnotationClauseText);
    assertEquals(text, converted.getText());
}
Also used : RuleAnnotation(org.kie.dmn.model.api.RuleAnnotation) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) Test(org.junit.Test)

Example 15 with RuleAnnotationClauseText

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

the class RuleAnnotationClauseTextConverterTest method testWbFromDMN.

@Test
public void testWbFromDMN() {
    final String text = "text";
    when(ruleAnnotation.getText()).thenReturn(text);
    final RuleAnnotationClauseText converted = RuleAnnotationClauseTextConverter.wbFromDMN(ruleAnnotation);
    assertEquals(text, converted.getText().getValue());
}
Also used : RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) Test(org.junit.Test)

Aggregations

RuleAnnotationClauseText (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)25 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)14 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)12 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)11 Test (org.junit.Test)10 List (java.util.List)5 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)5 RuleAnnotationClause (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause)5 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)5 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)5 Before (org.junit.Before)3 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)3 Text (org.kie.workbench.common.dmn.api.property.dmn.Text)3 DMNGridData (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData)3 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)3 AbstractGraphCommand (org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand)3 OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)2 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)2 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)2 JSITDecisionRule (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionRule)2