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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations