Search in sources :

Example 16 with RuleAnnotationClauseText

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

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

Example 18 with RuleAnnotationClauseText

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

the class DecisionRulePropertyConverter method wbFromDMN.

public static DecisionRule wbFromDMN(final org.kie.dmn.model.api.DecisionRule dmn) {
    final Id id = new Id(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final DecisionRule result = new DecisionRule();
    result.setId(id);
    if (!(dmn instanceof org.kie.dmn.model.v1_1.TDecisionRule)) {
        for (final org.kie.dmn.model.api.RuleAnnotation ruleAnnotation : dmn.getAnnotationEntry()) {
            final RuleAnnotationClauseText annotationEntryConverted = RuleAnnotationClauseTextConverter.wbFromDMN(ruleAnnotation);
            if (annotationEntryConverted != null) {
                annotationEntryConverted.setParent(result);
            }
            result.getAnnotationEntry().add(annotationEntryConverted);
        }
    }
    if (result.getAnnotationEntry().isEmpty()) {
        // If it's empty, then there is none RuleAnnotation and the description was not converted yet to RuleAnnotation.
        final RuleAnnotationClauseText annotationEntryText = new RuleAnnotationClauseText();
        annotationEntryText.getText().setValue(description.getValue());
        annotationEntryText.setParent(result);
        result.getAnnotationEntry().add(annotationEntryText);
    }
    for (final org.kie.dmn.model.api.UnaryTests ie : dmn.getInputEntry()) {
        final UnaryTests inputEntryConverted = UnaryTestsPropertyConverter.wbFromDMN(ie);
        if (inputEntryConverted != null) {
            inputEntryConverted.setParent(result);
        }
        result.getInputEntry().add(inputEntryConverted);
    }
    for (final org.kie.dmn.model.api.LiteralExpression oe : dmn.getOutputEntry()) {
        final LiteralExpression outputEntryConverted = LiteralExpressionPropertyConverter.wbFromDMN(oe);
        if (outputEntryConverted != null) {
            outputEntryConverted.setParent(result);
        }
        result.getOutputEntry().add(outputEntryConverted);
    }
    return result;
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests)

Example 19 with RuleAnnotationClauseText

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

the class RuleAnnotationClauseTextConverter method wbFromDMN.

public static RuleAnnotationClauseText wbFromDMN(final RuleAnnotation ruleAnnotation) {
    if (ruleAnnotation == null) {
        return null;
    }
    final RuleAnnotationClauseText text = new RuleAnnotationClauseText();
    text.setText(new Text(ruleAnnotation.getText()));
    return text;
}
Also used : RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)

Example 20 with RuleAnnotationClauseText

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

the class AddRuleAnnotationClauseCommandTest method testNewGraphCommandExecute.

@Test
public void testNewGraphCommandExecute() {
    final AbstractCanvasHandler context = mock(AbstractCanvasHandler.class);
    final GraphCommandExecutionContext executionContext = mock(GraphCommandExecutionContext.class);
    final DecisionRule rule1 = mock(DecisionRule.class);
    final DecisionRule rule2 = mock(DecisionRule.class);
    final List<DecisionRule> rules = Arrays.asList(rule1, rule2);
    final int clauseIndex = 2;
    final Name ruleAnnotationClauseName = mock(Name.class);
    final List rule1AnnotationEntries = mock(List.class);
    final List rule2AnnotationEntries = mock(List.class);
    doReturn(clauseIndex).when(command).getClauseIndex();
    when(rule1.getAnnotationEntry()).thenReturn(rule1AnnotationEntries);
    when(rule2.getAnnotationEntry()).thenReturn(rule2AnnotationEntries);
    when(ruleAnnotationClause.getName()).thenReturn(ruleAnnotationClauseName);
    when(decisionTable.getRule()).thenReturn(rules);
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(context);
    final CommandResult<RuleViolation> commandResult = graphCommand.execute(executionContext);
    verify(rule1AnnotationEntries).add(eq(clauseIndex), clauseTextCaptor.capture());
    verify(rule2AnnotationEntries).add(eq(clauseIndex), clauseTextCaptor.capture());
    verify(componentsWidths).add(uiColumnIndex, null);
    verify(annotations).add(clauseIndex, ruleAnnotationClause);
    verify(ruleAnnotationClause).setParent(decisionTable);
    final List<RuleAnnotationClauseText> capturedValues = clauseTextCaptor.getAllValues();
    assertEquals(2, capturedValues.size());
    assertEquals(DecisionTableDefaultValueUtilities.RULE_ANNOTATION_CLAUSE_EXPRESSION_TEXT, capturedValues.get(0).getText().getValue());
    assertEquals(DecisionTableDefaultValueUtilities.RULE_ANNOTATION_CLAUSE_EXPRESSION_TEXT, capturedValues.get(1).getText().getValue());
    assertEquals(rule1, capturedValues.get(0).getParent());
    assertEquals(rule2, capturedValues.get(1).getParent());
    assertEquals(GraphCommandResultBuilder.SUCCESS, commandResult);
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) List(java.util.List) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) 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