use of org.kie.workbench.common.dmn.api.definition.model.Decision 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.Decision in project kie-wb-common by kiegroup.
the class DMNIncludedModelHandlerTest method makeDecision.
private Decision makeDecision(final String name, final String type, final boolean allowOnlyVisualChange) {
final Decision decision = new Decision();
setName(decision, name);
setType(decision, type);
decision.setAllowOnlyVisualChange(allowOnlyVisualChange);
return decision;
}
use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.
the class DMNIncludedModelHandlerTest method testBuildUpdateCommand.
@Test
public void testBuildUpdateCommand() {
final Decision drgElement = makeDecision("model1.tUUID", "string", true);
final String newName = "model2.tUUID";
final String nameId = "nameId";
final AbstractCanvasHandler context = mock(AbstractCanvasHandler.class);
final Node node = mock(Node.class);
final Definition definition = mock(Definition.class);
final Object definitionObject = mock(Object.class);
when(node.getContent()).thenReturn(definition);
when(definition.getDefinition()).thenReturn(definitionObject);
when(definitionUtils.getNameIdentifier(definitionObject)).thenReturn(nameId);
when(canvasCommandFactory.updatePropertyValue(eq(node), eq(nameId), any(Name.class))).thenReturn(canvasCommand);
doReturn(node).when(handler).getNode(drgElement);
final Command<AbstractCanvasHandler, CanvasViolation> command = handler.buildUpdateCommand(drgElement, newName).getCommands().get(0);
command.execute(context);
assertEquals(canvasCommand, command);
}
use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.
the class DMNIncludedModelHandlerTest method testDestroy.
@Test
public void testDestroy() {
final Decision drgElement1 = makeDecision("model1.tUUID", "string", true);
final Decision drgElement2 = makeDecision("model1.imported person", "model1.tPerson", true);
final InputData drgElement3 = makeInputData("local person", "model1.tPerson", false);
final InputData drgElement4 = makeInputData("regular DRG Element", "boolean", false);
final List<DRGElement> drgElements = asList(drgElement1, drgElement2, drgElement3, drgElement4);
doNothing().when(handler).deleteDRGElement(any());
when(dmnGraphUtils.getModelDRGElements()).thenReturn(drgElements);
handler.destroy("model1");
verify(handler).deleteDRGElement(drgElement1);
verify(handler).deleteDRGElement(drgElement2);
}
use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.
the class DMNGraphProcessorTest method testGetNodes.
@Test
public void testGetNodes() {
final DMNGraphProcessor processor = new DMNGraphProcessor();
final Graph graph = mock(Graph.class);
final Decision decision1 = mock(Decision.class);
final Decision decision2 = mock(Decision.class);
final Node node1 = createNode(decision1, "id1");
final Node node2 = createNode(decision2, "id2");
final List<Node> graphNodes = createGraphNodes(node1, node2);
when(graph.nodes()).thenReturn(graphNodes);
final Iterable<? extends Node> nodes = processor.getNodes(graph);
for (final Node node : nodes) {
assertTrue(graphNodes.contains(node));
assertFalse(processor.isReplacedByAnotherNode(node.getUUID()));
}
}
Aggregations