use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.
the class NodeConnectorTest method testConnectEdgeToNodesWhenDMNDIIsPresentAndNodeIsNotConnectedWithEdge.
@Test
public void testConnectEdgeToNodesWhenDMNDIIsPresentAndNodeIsNotConnectedWithEdge() {
final JSIDMNEdge existingEdge = mock(JSIDMNEdge.class);
final Definition definition = mock(Definition.class);
final DRGElement drgElement = mock(DRGElement.class);
final String id = "789";
final String contentDefinitionId = "123";
final List<NodeEntry> list = singletonList(nodeEntry);
when(jsiDMNElementReference.getHref()).thenReturn("#123");
when(jsiDMNElement.getId()).thenReturn(id);
when(existingEdge.getDmnElementRef()).thenReturn(new QName("", id));
when(definition.getDefinition()).thenReturn(drgElement);
when(currentNode.getContent()).thenReturn(definition);
when(drgElement.getContentDefinitionId()).thenReturn(contentDefinitionId);
doReturn(false).when(nodeConnector).isEdgeConnectedWithNode(eq(existingEdge), eq(currentNode), eq(list));
doReturn(Optional.of(requiredNode)).when(nodeConnector).getSourceNode(eq(existingEdge), any());
doNothing().when(nodeConnector).connectWbEdge(any(), any(), any(), any(), any(), any());
entriesById.put(contentDefinitionId, list);
edges.add(existingEdge);
isDMNDIPresent = true;
nodeConnector.connectEdgeToNodes(connectorTypeId, jsiDMNElement, jsiDMNElementReference, entriesById, diagramId, edges, isDMNDIPresent, currentNode);
verify(nodeConnector, never()).connectWbEdge(eq(connectorTypeId), eq(diagramId), eq(currentNode), eq(requiredNode), eq(existingEdge), eq("789"));
verify(nodeConnector).isEdgeConnectedWithNode(eq(existingEdge), eq(currentNode), eq(list));
}
use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.
the class DeleteNodeConfirmationImpl method isReferredInAnotherGraph.
boolean isReferredInAnotherGraph(final Element element) {
if (element.getContent() instanceof Definition) {
final Definition def = (Definition) element.getContent();
if (def.getDefinition() instanceof HasContentDefinitionId) {
final HasContentDefinitionId hasContentDefinitionId = (HasContentDefinitionId) def.getDefinition();
final String contentId = hasContentDefinitionId.getContentDefinitionId();
final List<Graph> graphs = getGraphsProvider().getNonGlobalGraphs();
return graphs.stream().anyMatch(graph -> containsNodeWithContentId(graph, contentId));
}
}
return false;
}
use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.
the class ConnectorParentsMatchContainmentHandler method evaluateContainment.
@SuppressWarnings("unchecked")
private RuleViolations evaluateContainment(final RuleExtension rule, final NodeContainmentContext context) {
final DefaultRuleViolations result = new DefaultRuleViolations();
final Collection<Node<? extends Definition<?>, ? extends Edge>> candidates = context.getCandidates();
candidates.forEach(candidate -> evaluateSingleContainment(result, rule, context, candidate));
return result;
}
use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.
the class NodeContainmentEvaluationHandler method evaluate.
@Override
@SuppressWarnings("unchecked")
public RuleViolations evaluate(final CanContain rule, final NodeContainmentContext context) {
final Element<? extends Definition<?>> parent = context.getParent();
final Set<String> parentLabels = evalUtils.getLabels(parent);
final DefaultRuleViolations result = new DefaultRuleViolations();
final Collection<Node<? extends Definition<?>, ? extends Edge>> candidates = context.getCandidates();
candidates.forEach(candidate -> result.addViolations(evaluate(rule, candidate.getUUID(), evalUtils.getLabels(candidate), parentLabels)));
return result;
}
use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.
the class GraphUtils method computeGraphHashCode.
@SuppressWarnings("all")
public static int computeGraphHashCode(GraphImpl graph) {
final int[] result = { 0 };
new TreeWalkTraverseProcessorImpl().traverse(graph, new AbstractTreeTraverseCallback<Graph, Node, Edge>() {
@Override
public boolean startEdgeTraversal(final Edge edge) {
super.startEdgeTraversal(edge);
final Object content = edge.getContent();
result[0] = combineHashCodes(result[0], content.hashCode());
if (edge.getContent() instanceof ViewConnector) {
Optional<Connection> sourceConnection = ((ViewConnector) edge.getContent()).getSourceConnection();
sourceConnection.ifPresent(c -> result[0] = combineHashCodes(result[0], c.hashCode()));
Optional<Connection> targetConnection = ((ViewConnector) edge.getContent()).getTargetConnection();
targetConnection.ifPresent(c -> result[0] = combineHashCodes(result[0], c.hashCode()));
}
return true;
}
@Override
public boolean startNodeTraversal(final Node node) {
super.startNodeTraversal(node);
result[0] = combineHashCodes(result[0], node.hashCode());
if (!(node.getContent() instanceof DefinitionSet) && node.getContent() instanceof Definition) {
Object def = ((Definition) (node.getContent())).getDefinition();
result[0] = combineHashCodes(result[0], def.hashCode());
}
if (node.getContent() instanceof HasBounds) {
Bounds bounds = ((HasBounds) node.getContent()).getBounds();
result[0] = combineHashCodes(result[0], bounds.hashCode());
}
return true;
}
});
return result[0];
}
Aggregations