use of org.kie.workbench.common.dmn.api.definition.model.UnaryTests 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.UnaryTests in project kie-wb-common by kiegroup.
the class ItemDefinitionPropertyConverter method setUnaryTests.
static void setUnaryTests(final ItemDefinition wb, final JSITItemDefinition dmn) {
final JSITUnaryTests dmnAllowedValues = dmn.getAllowedValues();
final Optional<UnaryTests> wbUnaryTests = ofNullable(UnaryTestsPropertyConverter.wbFromDMN(dmnAllowedValues));
wbUnaryTests.ifPresent(unaryTests -> {
wb.setAllowedValues(unaryTests);
unaryTests.setParent(wb);
});
}
use of org.kie.workbench.common.dmn.api.definition.model.UnaryTests in project kie-wb-common by kiegroup.
the class AddInputClauseCommandTest method testGraphCommandExecuteInsertMiddle.
@Test
public void testGraphCommandExecuteInsertMiddle() throws Exception {
makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT + 1);
final String ruleInputOne = "rule in 1";
final String ruleInputTwo = "rule in 2";
dtable.getInput().add(new InputClause());
dtable.getInput().add(new InputClause());
addRuleWithInputClauseValues(ruleInputOne, ruleInputTwo);
assertEquals(2, dtable.getInput().size());
// Graph command will insert new InputClause at index 1 of the InputEntries
final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
assertEquals(3, dtable.getInput().size());
assertNotNull(dtable.getInput().get(0).getInputExpression());
assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "1", dtable.getInput().get(1).getInputExpression().getText().getValue());
assertNotNull(dtable.getInput().get(2).getInputExpression());
final List<UnaryTests> ruleInputs = dtable.getRule().get(0).getInputEntry();
// first rule
assertEquals(3, ruleInputs.size());
assertEquals(ruleInputOne, ruleInputs.get(0).getText().getValue());
assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT, ruleInputs.get(1).getText().getValue());
assertEquals(dtable.getRule().get(0), ruleInputs.get(1).getParent());
assertEquals(ruleInputTwo, ruleInputs.get(2).getText().getValue());
assertEquals(dtable, inputClause.getParent());
}
use of org.kie.workbench.common.dmn.api.definition.model.UnaryTests in project kie-wb-common by kiegroup.
the class AddInputClauseCommandTest method testGraphCommandExecute.
@Test
public void testGraphCommandExecute() throws Exception {
makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT);
dtable.getRule().add(new DecisionRule());
dtable.getRule().add(new DecisionRule());
assertEquals(0, dtable.getInput().size());
final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
// one new input column
assertEquals(1, dtable.getInput().size());
assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "1", dtable.getInput().get(0).getInputExpression().getText().getValue());
// first rule
final List<UnaryTests> inputEntriesRuleOne = dtable.getRule().get(0).getInputEntry();
assertEquals(1, inputEntriesRuleOne.size());
assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT, inputEntriesRuleOne.get(0).getText().getValue());
assertEquals(dtable.getRule().get(0), inputEntriesRuleOne.get(0).getParent());
// second rule
final List<UnaryTests> inputEntriesRuleTwo = dtable.getRule().get(1).getInputEntry();
assertEquals(1, inputEntriesRuleTwo.size());
assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT, inputEntriesRuleTwo.get(0).getText().getValue());
assertEquals(dtable.getRule().get(1), inputEntriesRuleTwo.get(0).getParent());
assertEquals(dtable, inputClause.getParent());
}
use of org.kie.workbench.common.dmn.api.definition.model.UnaryTests in project kie-wb-common by kiegroup.
the class ItemDefinitionUpdateHandlerTest method testMakeAllowedValuesWhenDataTypeAndItemDefinitionConstraintAreEqual.
@Test
public void testMakeAllowedValuesWhenDataTypeAndItemDefinitionConstraintAreEqual() {
final DataType dataType = mock(DataType.class);
final ItemDefinition itemDefinition = mock(ItemDefinition.class);
final UnaryTests expectedAllowedValues = mock(UnaryTests.class);
final String expectedText = "(1..20)";
final ConstraintType expectedConstraintType = ConstraintType.RANGE;
when(itemDefinition.getAllowedValues()).thenReturn(expectedAllowedValues);
when(expectedAllowedValues.getConstraintType()).thenReturn(expectedConstraintType);
when(expectedAllowedValues.getText()).thenReturn(new Text(expectedText));
when(dataType.getConstraint()).thenReturn(expectedText);
final UnaryTests actualAllowedValues = handler.makeAllowedValues(dataType, itemDefinition);
assertEquals(expectedAllowedValues, actualAllowedValues);
assertEquals(expectedConstraintType, actualAllowedValues.getConstraintType());
}
Aggregations