use of org.kie.workbench.common.dmn.api.definition.model.InputClause in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenTopLevelDecisionTableWithInputDataAndRecursiveCustomType.
@Test
@SuppressWarnings("unchecked")
public void testModelEnrichmentWhenTopLevelDecisionTableWithInputDataAndRecursiveCustomType() {
setupGraphWithDiagram();
setupGraphWithInputData();
final Definitions definitions = diagram.getDefinitions();
final String tSmurfName = "tSmurf";
final String tDateOfBirthName = "tDateOfBirth";
final String tIsBlueName = "tIsBlue";
final String tParentName = "tParent";
final QName dateBuiltInType = new QName(QName.NULL_NS_URI, BuiltInType.DATE.getName());
final QName booleanBuiltInType = new QName(QName.NULL_NS_URI, BuiltInType.BOOLEAN.getName());
final QName parentCustomType = new QName(QName.NULL_NS_URI, tSmurfName);
final ItemDefinition tSmurfCustomDataType = new ItemDefinition();
tSmurfCustomDataType.setName(new Name(tSmurfName));
tSmurfCustomDataType.getItemComponent().add(new ItemDefinition() {
{
setName(new Name(tDateOfBirthName));
setTypeRef(dateBuiltInType);
}
});
tSmurfCustomDataType.getItemComponent().add(new ItemDefinition() {
{
setName(new Name(tIsBlueName));
setTypeRef(booleanBuiltInType);
}
});
tSmurfCustomDataType.getItemComponent().add(new ItemDefinition() {
{
setName(new Name(tParentName));
setTypeRef(parentCustomType);
}
});
definitions.getItemDefinition().add(tSmurfCustomDataType);
final QName inputData1TypeRef = new QName(QName.NULL_NS_URI, tSmurfName);
inputData1.getVariable().setTypeRef(inputData1TypeRef);
final Optional<DecisionTable> oModel = definition.getModelClass();
definition.enrich(Optional.of(NODE_UUID), decision, oModel);
final DecisionTable model = oModel.get();
assertBasicEnrichment(model);
final List<InputClause> input = model.getInput();
assertThat(input.size()).isEqualTo(4);
assertThat(input.get(0).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
assertThat(input.get(0).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_2);
assertThat(input.get(0).getInputExpression().getTypeRef()).isEqualTo(INPUT_DATA_QNAME_2);
assertThat(input.get(1).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
assertThat(input.get(1).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + "." + tDateOfBirthName);
assertThat(input.get(1).getInputExpression().getTypeRef()).isEqualTo(dateBuiltInType);
assertThat(input.get(2).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
assertThat(input.get(2).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + "." + tIsBlueName);
assertThat(input.get(2).getInputExpression().getTypeRef()).isEqualTo(booleanBuiltInType);
assertThat(input.get(3).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
assertThat(input.get(3).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + "." + tParentName);
assertThat(input.get(3).getInputExpression().getTypeRef()).isEqualTo(parentCustomType);
assertStandardOutputClauseEnrichment(model);
assertStandardDecisionRuleEnrichment(model);
assertParentHierarchyEnrichment(model);
}
use of org.kie.workbench.common.dmn.api.definition.model.InputClause in project kie-wb-common by kiegroup.
the class DecisionTablePropertyConverter method wbFromDMN.
public static DecisionTable wbFromDMN(final JSITDecisionTable dmn) {
final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
final DecisionTable result = new DecisionTable();
result.setId(id);
result.setDescription(description);
result.setTypeRef(typeRef);
final List<JSITRuleAnnotationClause> jsiRuleAnnotationClauses = dmn.getAnnotation();
if (jsiRuleAnnotationClauses.isEmpty()) {
final RuleAnnotationClause ruleAnnotationClause = new RuleAnnotationClause();
ruleAnnotationClause.setParent(result);
result.getAnnotations().add(ruleAnnotationClause);
} else {
for (int i = 0; i < jsiRuleAnnotationClauses.size(); i++) {
final JSITRuleAnnotationClause ruleAnnotationClause = Js.uncheckedCast(jsiRuleAnnotationClauses.get(i));
final RuleAnnotationClause converted = RuleAnnotationClausePropertyConverter.wbFromDMN(ruleAnnotationClause);
if (Objects.nonNull(converted)) {
converted.setParent(result);
result.getAnnotations().add(converted);
}
}
}
final List<JSITInputClause> jsiInputClauses = dmn.getInput();
for (int i = 0; i < jsiInputClauses.size(); i++) {
final JSITInputClause input = Js.uncheckedCast(jsiInputClauses.get(i));
final InputClause inputClauseConverted = InputClausePropertyConverter.wbFromDMN(input);
if (Objects.nonNull(inputClauseConverted)) {
inputClauseConverted.setParent(result);
result.getInput().add(inputClauseConverted);
}
}
final List<JSITOutputClause> jsiOutputClauses = dmn.getOutput();
for (int i = 0; i < jsiOutputClauses.size(); i++) {
final JSITOutputClause output = Js.uncheckedCast(jsiOutputClauses.get(i));
final OutputClause outputClauseConverted = OutputClausePropertyConverter.wbFromDMN(output);
if (Objects.nonNull(outputClauseConverted)) {
outputClauseConverted.setParent(result);
result.getOutput().add(outputClauseConverted);
}
}
if (result.getOutput().size() == 1) {
final OutputClause outputClause = result.getOutput().get(0);
// DROOLS-3281
outputClause.setName(null);
// DROOLS-5178
outputClause.setTypeRef(BuiltInType.UNDEFINED.asQName());
}
final List<JSITDecisionRule> jsiDecisionRules = dmn.getRule();
for (int i = 0; i < jsiDecisionRules.size(); i++) {
final JSITDecisionRule dr = Js.uncheckedCast(jsiDecisionRules.get(i));
final DecisionRule decisionRuleConverted = DecisionRulePropertyConverter.wbFromDMN(dr);
if (Objects.nonNull(decisionRuleConverted)) {
decisionRuleConverted.setParent(result);
}
result.getRule().add(decisionRuleConverted);
}
// JSITHitPolicy is a String JSO so convert into the real type
final String hitPolicy = Js.uncheckedCast(dmn.getHitPolicy());
if (Objects.nonNull(hitPolicy)) {
result.setHitPolicy(HitPolicy.fromValue(hitPolicy));
}
// JSITBuiltinAggregator is a String JSO so convert into the real type
final String aggregation = Js.uncheckedCast(dmn.getAggregation());
if (Objects.nonNull(aggregation)) {
result.setAggregation(BuiltinAggregator.fromValue(aggregation));
}
// JSITDecisionTableOrientation is a String JSO so convert into the real type
final String orientation = Js.uncheckedCast(dmn.getPreferredOrientation());
if (Objects.nonNull(orientation)) {
result.setPreferredOrientation(DecisionTableOrientation.fromValue(orientation));
}
result.setOutputLabel(dmn.getOutputLabel());
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.InputClause in project kie-wb-common by kiegroup.
the class AddInputClauseCommandTest method testGraphCommandUndoJustLastInputClauseColumn.
@Test
public void testGraphCommandUndoJustLastInputClauseColumn() throws Exception {
makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT);
final String ruleOneOldInput = "old rule 1";
final String ruleTwoOldInput = "old rule 2";
dtable.getInput().add(new InputClause());
addRuleWithInputClauseValues(ruleOneOldInput);
addRuleWithInputClauseValues(ruleTwoOldInput);
assertEquals(1, dtable.getInput().size());
final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.undo(graphCommandExecutionContext));
assertEquals(1, dtable.getInput().size());
// first rule
assertEquals(1, dtable.getRule().get(0).getInputEntry().size());
assertEquals(ruleOneOldInput, dtable.getRule().get(0).getInputEntry().get(0).getText().getValue());
// second rule
assertEquals(1, dtable.getRule().get(1).getInputEntry().size());
assertEquals(ruleTwoOldInput, dtable.getRule().get(1).getInputEntry().get(0).getText().getValue());
}
use of org.kie.workbench.common.dmn.api.definition.model.InputClause in project kie-wb-common by kiegroup.
the class AddInputClauseCommandTest method testGraphCommandExecuteExistingNotAffected.
@Test
public void testGraphCommandExecuteExistingNotAffected() throws Exception {
makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT);
final String ruleOneOldInput = "old rule 1";
final String ruleTwoOldInput = "old rule 2";
dtable.getInput().add(new InputClause());
addRuleWithInputClauseValues(ruleOneOldInput);
addRuleWithInputClauseValues(ruleTwoOldInput);
assertEquals(1, dtable.getInput().size());
// Graph command will insert new InputClause at index 0 of the InputEntries
final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
assertEquals(2, dtable.getInput().size());
assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "1", dtable.getInput().get(0).getInputExpression().getText().getValue());
assertNotNull(dtable.getInput().get(1).getInputExpression());
// first rule
final List<UnaryTests> inputEntriesRuleOne = dtable.getRule().get(0).getInputEntry();
assertEquals(2, inputEntriesRuleOne.size());
assertEquals(ruleOneOldInput, inputEntriesRuleOne.get(1).getText().getValue());
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(2, inputEntriesRuleTwo.size());
assertEquals(ruleTwoOldInput, inputEntriesRuleTwo.get(1).getText().getValue());
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.InputClause in project kie-wb-common by kiegroup.
the class DeleteInputClauseCommandTest method testGraphCommandExecuteRemoveMiddle.
@Test
public void testGraphCommandExecuteRemoveMiddle() {
final InputClause firstInput = mock(InputClause.class);
final InputClause lastInput = mock(InputClause.class);
dtable.getInput().add(0, firstInput);
dtable.getInput().add(lastInput);
final UnaryTests inputOneValue = mock(UnaryTests.class);
final UnaryTests inputTwoValue = mock(UnaryTests.class);
final UnaryTests inputThreeValue = mock(UnaryTests.class);
final DecisionRule rule = new DecisionRule();
rule.getInputEntry().add(inputOneValue);
rule.getInputEntry().add(inputTwoValue);
rule.getInputEntry().add(inputThreeValue);
dtable.getRule().add(rule);
makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT + 1);
final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
assertEquals(2, dtable.getInput().size());
assertEquals(firstInput, dtable.getInput().get(0));
assertEquals(lastInput, dtable.getInput().get(1));
assertEquals(2, dtable.getRule().get(0).getInputEntry().size());
assertEquals(inputOneValue, dtable.getRule().get(0).getInputEntry().get(0));
assertEquals(inputThreeValue, dtable.getRule().get(0).getInputEntry().get(1));
}
Aggregations