use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression in project kie-wb-common by kiegroup.
the class DeleteRelationColumnCommandTest method testCanvasCommandExecuteWithRows.
@Test
public void testCanvasCommandExecuteWithRows() {
final List rowList = new List();
relation.getRow().add(rowList);
relation.getRow().get(0).getExpression().add(HasExpression.wrap(rowList, new LiteralExpression()));
uiModel.appendRow(new BaseGridRow());
uiModelMapper.fromDMNModel(0, 0);
uiModelMapper.fromDMNModel(0, 1);
makeCommand();
final Command<AbstractCanvasHandler, CanvasViolation> cc = command.newCanvasCommand(handler);
assertEquals(CanvasCommandResultBuilder.SUCCESS, cc.execute(handler));
assertEquals(1, uiModel.getColumnCount());
assertEquals(uiRowNumberColumn, uiModel.getColumns().get(0));
assertEquals(1, uiModel.getRowCount());
assertEquals(1, uiModel.getRows().get(0).getCells().size());
assertEquals(1, uiModel.getCell(0, 0).getValue().getValue());
verify(command).updateParentInformation();
verify(executeCanvasOperation).execute();
}
use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression in project kie-wb-common by kiegroup.
the class DeleteRelationColumnCommandTest method testGraphCommandExecuteDeleteMiddleWithRows.
@Test
public void testGraphCommandExecuteDeleteMiddleWithRows() {
final List rowList = new List();
uiModel.appendColumn(mock(RelationColumn.class));
uiModel.appendColumn(mock(RelationColumn.class));
relation.getColumn().add(new InformationItem());
relation.getColumn().add(new InformationItem());
relation.getRow().add(rowList);
final LiteralExpression firstExpression = new LiteralExpression();
final LiteralExpression lastExpression = new LiteralExpression();
relation.getRow().get(0).getExpression().add(HasExpression.wrap(rowList, firstExpression));
relation.getRow().get(0).getExpression().add(HasExpression.wrap(rowList, new LiteralExpression()));
relation.getRow().get(0).getExpression().add(HasExpression.wrap(rowList, lastExpression));
makeCommand(2);
final Command<GraphCommandExecutionContext, RuleViolation> c = command.newGraphCommand(handler);
assertEquals(GraphCommandResultBuilder.SUCCESS, c.execute(gce));
assertEquals(2, relation.getColumn().size());
assertEquals(1, relation.getRow().size());
assertEquals(2, relation.getRow().get(0).getExpression().size());
assertEquals(firstExpression, relation.getRow().get(0).getExpression().get(0).getExpression());
assertEquals(lastExpression, relation.getRow().get(0).getExpression().get(1).getExpression());
}
use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression in project kie-wb-common by kiegroup.
the class RegisterNodeCommandTest method testExecuteWithBusinessKnowledgeModelNodeWhenNodeIsNotNew.
@Test
public void testExecuteWithBusinessKnowledgeModelNodeWhenNodeIsNotNew() {
final FunctionDefinition functionDefinition = new FunctionDefinition();
final LiteralExpression literalExpression = makeLiteralExpression("123");
when(candidateContent.getDefinition()).thenReturn(businessKnowledgeModel);
doReturn(functionDefinition).when(businessKnowledgeModel).getEncapsulatedLogic();
functionDefinition.setExpression(literalExpression);
literalExpression.setParent(functionDefinition);
assertThat(command.execute(graphCommandExecutionContext).getType()).isEqualTo(CommandResult.Type.INFO);
final FunctionDefinition encapsulatedLogic = businessKnowledgeModel.getEncapsulatedLogic();
final Expression expression = encapsulatedLogic.getExpression();
assertThat(expression).isEqualTo(makeLiteralExpression("123"));
assertThat(expression.getParent()).isEqualTo(encapsulatedLogic);
assertThat(KindUtilities.getKind(encapsulatedLogic)).isEqualTo(FunctionDefinition.Kind.FEEL);
}
use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricher method enrichInputClauses.
@SuppressWarnings("unchecked")
void enrichInputClauses(final String uuid, final DecisionTable dtable) {
final Graph<?, Node> graph = sessionManager.getCurrentSession().getCanvasHandler().getDiagram().getGraph();
final Node<?, Edge> node = graph.getNode(uuid);
if (Objects.isNull(node)) {
return;
}
// Get all Decision nodes feeding into this DecisionTable
final List<Decision> decisionSet = node.getInEdges().stream().map(Edge::getSourceNode).map(Node::getContent).filter(content -> content instanceof Definition).map(content -> (Definition) content).map(Definition::getDefinition).filter(definition -> definition instanceof Decision).map(definition -> (Decision) definition).collect(Collectors.toList());
// Get all InputData nodes feeding into this DecisionTable
final List<InputData> inputDataSet = node.getInEdges().stream().map(Edge::getSourceNode).map(Node::getContent).filter(content -> content instanceof Definition).map(content -> (Definition) content).map(Definition::getDefinition).filter(definition -> definition instanceof InputData).map(definition -> (InputData) definition).collect(Collectors.toList());
if (decisionSet.isEmpty() && inputDataSet.isEmpty()) {
return;
}
// Extract individual components of InputData TypeRefs
final Definitions definitions = dmnGraphUtils.getModelDefinitions();
final List<ClauseRequirement> inputClauseRequirements = new ArrayList<>();
decisionSet.forEach(decision -> addInputClauseRequirement(decision.getVariable().getTypeRef(), definitions, inputClauseRequirements, decision.getName().getValue()));
inputDataSet.forEach(inputData -> addInputClauseRequirement(inputData.getVariable().getTypeRef(), definitions, inputClauseRequirements, inputData.getName().getValue()));
// Add InputClause columns for each InputData TypeRef component, sorted alphabetically
dtable.getInput().clear();
dtable.getRule().stream().forEach(decisionRule -> decisionRule.getInputEntry().clear());
inputClauseRequirements.stream().sorted(Comparator.comparing(inputClauseRequirement -> inputClauseRequirement.text)).forEach(inputClauseRequirement -> {
final InputClause inputClause = new InputClause();
final InputClauseLiteralExpression literalExpression = new InputClauseLiteralExpression();
literalExpression.getText().setValue(inputClauseRequirement.text);
literalExpression.setTypeRef(inputClauseRequirement.typeRef);
inputClause.setInputExpression(literalExpression);
dtable.getInput().add(inputClause);
dtable.getRule().stream().forEach(decisionRule -> {
final UnaryTests decisionRuleUnaryTest = new UnaryTests();
decisionRuleUnaryTest.getText().setValue(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT);
decisionRule.getInputEntry().add(decisionRuleUnaryTest);
decisionRuleUnaryTest.setParent(decisionRule);
});
inputClause.setParent(dtable);
literalExpression.setParent(inputClause);
});
}
use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression in project kie-wb-common by kiegroup.
the class DecisionRuleFactory method makeDecisionRule.
public static DecisionRule makeDecisionRule(final DecisionTable dtable) {
final DecisionRule rule = new DecisionRule();
for (int ie = 0; ie < dtable.getInput().size(); ie++) {
final UnaryTests ut = new UnaryTests();
ut.getText().setValue(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT);
rule.getInputEntry().add(ut);
ut.setParent(rule);
}
for (int oe = 0; oe < dtable.getOutput().size(); oe++) {
final LiteralExpression le = new LiteralExpression();
le.getText().setValue(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT);
rule.getOutputEntry().add(le);
le.setParent(rule);
}
for (int index = 0; index < dtable.getAnnotations().size(); index++) {
final RuleAnnotationClauseText ruleAnnotationClauseText = new RuleAnnotationClauseText();
ruleAnnotationClauseText.getText().setValue(DecisionTableDefaultValueUtilities.RULE_ANNOTATION_CLAUSE_EXPRESSION_TEXT);
rule.getAnnotationEntry().add(ruleAnnotationClauseText);
ruleAnnotationClauseText.setParent(rule);
}
rule.setParent(dtable);
return rule;
}
Aggregations