use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.
the class AbstractDMNDiagramFactory method build.
@Override
public D build(final String name, final M metadata, final Graph<DefinitionSet, ?> graph) {
final D diagram = doBuild(name, metadata, graph);
final Node<Definition<DMNDiagram>, ?> diagramNode = diagramProvider.apply(graph);
if (null == diagramNode) {
throw new IllegalStateException("A DMNDiagram is expected to be present on DMN Diagram graphs.");
}
updateProperties(diagramNode, metadata);
updateDefaultNameSpaces(diagramNode);
updateName(diagramNode, name);
return diagram;
}
use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition 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.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.
the class ExpressionEditor method handleCanvasElementUpdated.
@Override
public void handleCanvasElementUpdated(final CanvasElementUpdatedEvent event) {
final Element<?> element = event.getElement();
if ((element instanceof Node)) {
if (element.getContent() instanceof Definition) {
final Definition definition = (Definition) element.getContent();
final Optional<Definitions> definitions = Optional.ofNullable(dmnGraphUtils.getModelDefinitions());
definitions.ifPresent(d -> {
if (Objects.equals(d, definition.getDefinition())) {
view.setReturnToLinkText(returnToLinkTextSupplier.get());
}
});
hasExpression.ifPresent(e -> {
if (Objects.equals(e.asDMNModelInstrumentedBase(), definition.getDefinition())) {
view.setExpressionNameText(Optional.ofNullable((HasName) definition.getDefinition()));
view.refresh();
}
});
}
}
}
use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.
the class DMNGraphProcessorTest method createNode.
private Node createNode(final Object definition, final String nodeId) {
final Node node = mock(Node.class);
when(node.getUUID()).thenReturn(nodeId);
final Definition content = mock(Definition.class);
when(node.getContent()).thenReturn(content);
when(content.getDefinition()).thenReturn(definition);
return node;
}
use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.
the class DMNIncludedModelHandler method buildUpdateCommand.
CompositeCommand<AbstractCanvasHandler, CanvasViolation> buildUpdateCommand(final DRGElement drgElement, final String newName) {
final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> commandBuilder = new CompositeCommand.Builder<>();
final Node node = getNode(drgElement);
if (node.getContent() instanceof Definition) {
final Definition definition = (Definition) node.getContent();
final String nameId = definitionUtils.getNameIdentifier(definition.getDefinition());
if (nameId != null) {
commandBuilder.addCommand(canvasCommandFactory.updatePropertyValue(node, nameId, new Name(newName)));
}
}
return commandBuilder.build();
}
Aggregations