/** * Does not returns labels not being used on the graph, * even if included in the <code>filter</code>. */ @SuppressWarnings("unchecked") public static Map<String, Integer> getLabelsCount(final Graph<?, ? extends Node> target, final Set<String> filter) { final Map<String, Integer> labels = new LinkedHashMap<>(); target.nodes().forEach(node -> { final Set<String> nodeRoles = node.getLabels(); if (null != nodeRoles) { nodeRoles .stream() .filter(role -> null == filter || filter.contains(role)) .forEach(role -> { final Integer i = labels.get(role); labels.put(role, null != i ? i + 1 : 1); }); } }); return labels; }
@Override public Set<String> execute(final DomainLookupContext context) { final DomainLookupsCache cache = context.getCache(); final Set<String> labels = sourceNode.getLabels(); final Set<String> allowedTargetConnectors = context.getCache() .getConnectionRules() .stream() .filter(rule -> isSourceConnectionAllowed(rule, labels)) .map(CanConnect::getRole) .collect(Collectors.toSet()); final Set<String> result = new LinkedHashSet<>(); for (final String allowedConnector : allowedTargetConnectors) { final int outEdgeCount = countOutgoingEdges(context, sourceNode, allowedConnector); final RuleViolations outEdgeCardinalityResult = context.getRuleManager() .evaluate(cache.getRuleSet(), edgeCardinality(sourceNode.getLabels(), allowedConnector, outEdgeCount, EdgeCardinalityContext.Direction.OUTGOING, Optional.of(CardinalityContext.Operation.ADD))); if (isValid(outEdgeCardinalityResult)) { result.add(allowedConnector); } } return result; } }
@SuppressWarnings("unchecked") protected Node mockNode(String id, Set<String> labels) { Node e = mock(Node.class); View v = mock(View.class); Object d = mock(Object.class); when(e.getContent()).thenReturn(v); when(v.getDefinition()).thenReturn(d); when(definitionAdapter.getId(eq(d))).thenReturn(DefinitionId.build(id)); when(definitionAdapter.getLabels(eq(d))).thenReturn(labels); when(e.getLabels()).thenReturn(labels); return e; }
@Test public void testBuild() { when(testingkHelper.definitionAdapter.getId(eq(definition))).thenReturn(DefinitionId.build(DEF_ID)); final Node<Definition<Object>, Edge> node = tested.build(UUID, definition); assertNotNull(node); assertEquals(UUID, node.getUUID()); assertEquals(3, node.getLabels().size()); assertTrue(node.getLabels().contains(DEF_ID)); assertTrue(node.getLabels().contains("label1")); assertTrue(node.getLabels().contains("label2")); }
public void setup() throws Exception { MockitoAnnotations.initMocks(this); when(definitionManager.adapters()).thenReturn(adapterManager); when(adapterManager.forDefinition()).thenReturn(definitionAdapter); when(element.getContent()).thenReturn(elementContent); when(element.getLabels()).thenReturn(DEFINITION_LABELS); when(elementContent.getDefinition()).thenReturn(elementDefinition); when(definitionAdapter.getId(eq(elementDefinition))).thenReturn(DefinitionId.build(DEFINITION_ID)); when(definitionAdapter.getLabels(eq(elementDefinition))).thenReturn(DEFINITION_LABELS); when(candidate.getContent()).thenReturn(candidateContent); when(candidate.getLabels()).thenReturn(CANDIDATE_LABELS); when(candidateContent.getDefinition()).thenReturn(candidateDefinition); when(parent.getContent()).thenReturn(parentContent); when(parent.getLabels()).thenReturn(PARENT_LABELS); when(parentContent.getDefinition()).thenReturn(parentDefinition); when(definitionAdapter.getId(eq(candidateDefinition))).thenReturn(DefinitionId.build(CANDIDATE_ID)); when(definitionAdapter.getLabels(eq(candidateDefinition))).thenReturn(CANDIDATE_LABELS); when(definitionAdapter.getId(eq(parentDefinition))).thenReturn(DefinitionId.build(PARENT_ID)); when(definitionAdapter.getLabels(eq(parentDefinition))).thenReturn(PARENT_LABELS); }
@Test public void testBuildDynamicDefinition() { when(testingkHelper.definitionAdapter.getId(eq(definition))).thenReturn(DefinitionId.build(DEF_TYPE_ID, DEF_ID)); final Node<Definition<Object>, Edge> node = tested.build(UUID, definition); assertNotNull(node); assertEquals(UUID, node.getUUID()); assertEquals(4, node.getLabels().size()); assertTrue(node.getLabels().contains(DefinitionId.generateId(DEF_TYPE_ID, DEF_ID))); assertTrue(node.getLabels().contains(DEF_TYPE_ID)); assertTrue(node.getLabels().contains("label1")); assertTrue(node.getLabels().contains("label2")); } }
@Before @SuppressWarnings("unchecked") public void setup() throws Exception { super.init(); this.tested = new MorphNodeCommand(candidate, morphDefinition, CURRENT_DEFINITION_ID); when(candidate.getLabels()).thenReturn(labels); when(candidate.getContent()).thenReturn(content); when(content.getDefinition()).thenReturn(CURRENT_DEFINITION); when(adapterRegistry.getMorphAdapter(any(Class.class))).thenReturn(morphAdaptor); when(definitionAdapter.getId(CURRENT_DEFINITION)).thenReturn(DefinitionId.build(CURRENT_DEFINITION_ID)); when(definitionAdapter.getLabels(CURRENT_DEFINITION)).thenReturn(Collections.emptySet()); when(morphAdaptor.morph(CURRENT_DEFINITION, morphDefinition, CURRENT_DEFINITION_ID)).thenReturn(NEW_DEFINITION); when(definitionAdapter.getId(NEW_DEFINITION)).thenReturn(DefinitionId.build(NEW_DEFINITION_ID)); when(definitionAdapter.getLabels(NEW_DEFINITION)).thenReturn(Collections.singleton(NEW_DEFINITION_LABEL)); when(morphAdaptor.morph(NEW_DEFINITION, morphDefinition, CURRENT_DEFINITION_ID)).thenReturn(CURRENT_DEFINITION); }
protected ParentAssignment getParentAssignment(final Node<View<?>, Edge> parent, final Object definition) { Objects.requireNonNull(definition); final Set<String> labels = clientDefinitionManager.adapters().forDefinition().getLabels(definition); final RuleSet ruleSet = canvasHandler.getRuleSet(); // Check containment rules. if (null != parent) { final Set<String> parentLabels = parent.getLabels(); final RuleViolations dockingViolations = ruleManager.evaluate(ruleSet, RuleContextBuilder.DomainContexts.docking(parentLabels, labels)); if (isValid(dockingViolations)) { return ParentAssignment.DOCKING; } final RuleViolations containmentViolations = ruleManager.evaluate(ruleSet, RuleContextBuilder.DomainContexts.containment(parentLabels, labels)); if (isValid(containmentViolations)) { return ParentAssignment.CONTAINMENT; } } return ParentAssignment.NONE; }
@Override public Set<String> execute(final DomainLookupContext context) { final DomainLookupsCache cache = context.getCache(); final int outEdgeCount = countOutgoingEdges(context, sourceNode, edgeId); final RuleViolations outEdgeCardinalityResult = context.getRuleManager() .evaluate(cache.getRuleSet(), edgeCardinality(sourceNode.getLabels(), edgeId, outEdgeCount, EdgeCardinalityContext.Direction.OUTGOING, Optional.of(CardinalityContext.Operation.ADD))); if (isValid(outEdgeCardinalityResult)) { final String defId = context.getDefinitionManager() .adapters() .forDefinition() .getId(sourceNode.getContent().getDefinition()) .value(); return new LookupConnectionTargetRoles(edgeId, defId) .execute(context); } return Collections.emptySet(); } }
View<CaseManagementDiagram> rootContent = new ViewImpl<>(root, Bounds.create(0.0, 0.0, 2800.0, 1400.0)); Node<View<CaseManagementDiagram>, Edge> rootNode = new NodeImpl<>("_0E761372-8B3C-4BE1-88BC-808D647D9EFF"); rootNode.getLabels().addAll(root.getLabels()); rootNode.getLabels().add("org.kie.workbench.common.stunner.cm.definition.CaseManagementDiagram"); rootNode.setContent(rootContent); View<AdHocSubprocess> stage1Content = new ViewImpl<>(stage1, Bounds.create(0.0, 0.0, 175.0, 50.0)); Node<View<AdHocSubprocess>, Edge> stage1Node = new NodeImpl<>("_F0A19BD0-3F42-493A-9A2D-2F4C24ED75D9"); stage1Node.getLabels().addAll(stage1.getLabels()); stage1Node.getLabels().add("org.kie.workbench.common.stunner.cm.definition.AdHocSubprocess"); stage1Node.setContent(stage1Content); View<UserTask> task1Content = new ViewImpl<>(task1, Bounds.create(0.0, 0.0, 153.0, 103.0)); Node<View<UserTask>, Edge> task1Node = new NodeImpl<>("_E95AD08A-4595-4FA4-8948-3318D8BE7941"); task1Node.getLabels().addAll(task1.getLabels()); task1Node.getLabels().add("org.kie.workbench.common.stunner.bpmn.definition.UserTask"); task1Node.setContent(task1Content); View<CaseReusableSubprocess> case1Content = new ViewImpl<>(case1, Bounds.create(0.0, 0.0, 153.0, 103.0)); Node<View<CaseReusableSubprocess>, Edge> case1Node = new NodeImpl<>("_C468418F-A1EE-470A-BC30-D85888DF3DF7"); case1Node.getLabels().addAll(case1.getLabels()); case1Node.getLabels().add("org.kie.workbench.common.stunner.cm.definition.CaseReusableSubprocess"); case1Node.setContent(case1Content); View<AdHocSubprocess> stage2Content = new ViewImpl<>(stage2, Bounds.create(0.0, 0.0, 175.0, 50.0)); Node<View<AdHocSubprocess>, Edge> stage2Node = new NodeImpl<>("_BCD8C7E1-9833-407D-9833-E12763A9A63D"); stage2Node.getLabels().addAll(stage2.getLabels()); stage2Node.getLabels().add("org.kie.workbench.common.stunner.cm.definition.AdHocSubprocess"); stage2Node.setContent(stage2Content);
@Override @SuppressWarnings("unchecked") public RuleViolations evaluate(final EdgeOccurrences rule, final ConnectorCardinalityContext context) { final DefaultRuleViolations result = new DefaultRuleViolations(); final Node<? extends View<?>, ? extends Edge> candidate = (Node<? extends View<?>, ? extends Edge>) context.getCandidate(); final Edge<? extends View<?>, Node> edge = context.getEdge(); final Optional<CardinalityContext.Operation> operation = context.getOperation(); final EdgeCardinalityContext.Direction direction = context.getDirection(); final List<? extends Edge> edges = isIncoming(direction) ? candidate.getInEdges() : candidate.getOutEdges(); final String edgeId = evalUtils.getElementDefinitionId(edge); final int count = evalUtils.countEdges(edgeId, edges); // Delegate to the domain model cardinality rule manager. result.addViolations( edgeCardinalityEvaluationHandler .evaluate(rule, RuleContextBuilder.DomainContexts.edgeCardinality(candidate.getLabels(), edgeId, count, rule.getDirection(), operation)) ); return GraphEvaluationHandlerUtils.addViolationsSourceUUID(edge.getUUID(), result); }
rootNode.getLabels().addAll(root.getLabels()); rootNode.getLabels().add("org.kie.workbench.common.stunner.cm.definition.CaseManagementDiagram"); rootNode.setContent(rootContent); stageNode.getLabels().addAll(stage.getLabels()); stageNode.getLabels().add("org.kie.workbench.common.stunner.cm.definition.AdHocSubprocess"); stageNode.setContent(stageContent); subcaseNode.getLabels().addAll(subcase.getLabels()); subcaseNode.getLabels().add("org.kie.workbench.common.stunner.cm.definition.CaseReusableSubprocess"); subcaseNode.setContent(subcaseContent);
rootNode.getLabels().addAll(root.getLabels()); rootNode.getLabels().add("org.kie.workbench.common.stunner.cm.definition.CaseManagementDiagram"); rootNode.setContent(rootContent); stageNode.getLabels().addAll(stage.getLabels()); stageNode.getLabels().add("org.kie.workbench.common.stunner.cm.definition.AdHocSubprocess"); stageNode.setContent(stageContent); subprocessNode.getLabels().addAll(subprocess.getLabels()); subprocessNode.getLabels().add("org.kie.workbench.common.stunner.cm.definition.ProcessReusableSubprocess"); subprocessNode.setContent(subprocessContent);
rootNode.getLabels().addAll(root.getLabels()); rootNode.getLabels().add("org.kie.workbench.common.stunner.cm.definition.CaseManagementDiagram"); rootNode.setContent(rootContent); stageNode.getLabels().addAll(stage.getLabels()); stageNode.getLabels().add("org.kie.workbench.common.stunner.cm.definition.AdHocSubprocess"); stageNode.setContent(stageContent);
rootNode.getLabels().addAll(root.getLabels()); rootNode.getLabels().add("org.kie.workbench.common.stunner.cm.definition.CaseManagementDiagram"); rootNode.setContent(rootContent); stageNode.getLabels().addAll(stage.getLabels()); stageNode.getLabels().add("org.kie.workbench.common.stunner.cm.definition.AdHocSubprocess"); stageNode.setContent(stageContent); taskNode.getLabels().addAll(task.getLabels()); taskNode.getLabels().add("org.kie.workbench.common.stunner.bpmn.definition.UserTask"); taskNode.setContent(taskContent);