Search in sources :

Example 66 with Edge

use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.

the class DMNMarshallerTest method setup.

@Before
public void setup() throws Exception {
    // Graph utils.
    when(definitionManager.adapters()).thenReturn(adapterManager);
    when(adapterManager.registry()).thenReturn(adapterRegistry);
    definitionUtils = new DefinitionUtils(definitionManager, applicationFactoryManager);
    testScopeModelFactory = new TestScopeModelFactory(new DMNDefinitionSet.DMNDefinitionSetBuilder().build());
    // Definition manager.
    final BackendDefinitionAdapter definitionAdapter = new BackendDefinitionAdapter(definitionUtils);
    final BackendDefinitionSetAdapter definitionSetAdapter = new BackendDefinitionSetAdapter(definitionAdapter);
    final BackendPropertySetAdapter propertySetAdapter = new BackendPropertySetAdapter();
    final BackendPropertyAdapter propertyAdapter = new BackendPropertyAdapter();
    when(adapterManager.forDefinitionSet()).thenReturn(definitionSetAdapter);
    when(adapterManager.forDefinition()).thenReturn(definitionAdapter);
    when(adapterManager.forPropertySet()).thenReturn(propertySetAdapter);
    when(adapterManager.forProperty()).thenReturn(propertyAdapter);
    when(adapterRegistry.getDefinitionSetAdapter(any(Class.class))).thenReturn(definitionSetAdapter);
    when(adapterRegistry.getDefinitionAdapter(any(Class.class))).thenReturn(definitionAdapter);
    when(adapterRegistry.getPropertySetAdapter(any(Class.class))).thenReturn(propertySetAdapter);
    when(adapterRegistry.getPropertyAdapter(any(Class.class))).thenReturn(propertyAdapter);
    commandManager = new GraphCommandManagerImpl(null, null, null);
    commandFactory = new GraphCommandFactory();
    connectionEdgeFactory = new EdgeFactoryImpl(definitionManager);
    viewNodeFactory = new NodeFactoryImpl(definitionUtils);
    dmnGraphFactory = new GraphFactoryImpl(definitionManager);
    doAnswer(invocationOnMock -> {
        String id = (String) invocationOnMock.getArguments()[0];
        return testScopeModelFactory.build(id);
    }).when(applicationFactoryManager).newDefinition(anyString());
    doAnswer(invocationOnMock -> {
        String uuid = (String) invocationOnMock.getArguments()[0];
        String id = (String) invocationOnMock.getArguments()[1];
        if (DMNDefinitionSet.class.getName().equals(id)) {
            // Emulate DMNGraphFactoryImpl, that adds a DMNDiagram to new Graphs
            // Please note this is different from the stunner jbpm test which this dmn test is based on
            Graph graph = (Graph) dmnGraphFactory.build(uuid, DMN_DEF_SET_ID);
            DMNDiagram model = new DMNDiagram.DMNDiagramBuilder().build();
            Node node = viewNodeFactory.build(uuid, model);
            graph.addNode(node);
            return graph;
        }
        Object model = testScopeModelFactory.accepts(id) ? testScopeModelFactory.build(id) : null;
        if (null != model) {
            Class<? extends ElementFactory> element = BackendDefinitionAdapter.getGraphFactory(model.getClass());
            if (element.isAssignableFrom(NodeFactory.class)) {
                Node node = viewNodeFactory.build(uuid, model);
                return node;
            } else if (element.isAssignableFrom(EdgeFactory.class)) {
                Edge edge = connectionEdgeFactory.build(uuid, model);
                return edge;
            }
        }
        return null;
    }).when(applicationFactoryManager).newElement(anyString(), anyString());
    doAnswer(invocationOnMock -> {
        String uuid = (String) invocationOnMock.getArguments()[0];
        Class type = (Class) invocationOnMock.getArguments()[1];
        String id = BindableAdapterUtils.getGenericClassName(type);
        if (DMNDefinitionSet.class.equals(type)) {
            Graph graph = (Graph) dmnGraphFactory.build(uuid, DMN_DEF_SET_ID);
            return graph;
        }
        Object model = testScopeModelFactory.accepts(id) ? testScopeModelFactory.build(id) : null;
        if (null != model) {
            Class<? extends ElementFactory> element = BackendDefinitionAdapter.getGraphFactory(model.getClass());
            if (element.isAssignableFrom(NodeFactory.class)) {
                Node node = viewNodeFactory.build(uuid, model);
                return node;
            } else if (element.isAssignableFrom(EdgeFactory.class)) {
                Edge edge = connectionEdgeFactory.build(uuid, model);
                return edge;
            }
        }
        return null;
    }).when(applicationFactoryManager).newElement(anyString(), any(Class.class));
    doAnswer(invocationOnMock -> {
        String uuid = (String) invocationOnMock.getArguments()[0];
        String defSetId = (String) invocationOnMock.getArguments()[1];
        final Graph graph = (Graph) applicationFactoryManager.newElement(uuid, defSetId);
        final DiagramImpl result = new DiagramImpl(uuid, new MetadataImpl.MetadataImplBuilder(defSetId).build());
        result.setGraph(graph);
        return result;
    }).when(applicationFactoryManager).newDiagram(anyString(), anyString(), any(Metadata.class));
    MappingContextSingleton.loadDynamicMarshallers();
}
Also used : BackendPropertyAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendPropertyAdapter) NodeFactoryImpl(org.kie.workbench.common.stunner.core.factory.impl.NodeFactoryImpl) BackendDefinitionAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendDefinitionAdapter) Node(org.kie.workbench.common.stunner.core.graph.Node) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) GraphFactoryImpl(org.kie.workbench.common.stunner.core.factory.impl.GraphFactoryImpl) Matchers.anyString(org.mockito.Matchers.anyString) BackendDefinitionSetAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendDefinitionSetAdapter) BackendPropertySetAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendPropertySetAdapter) DMNDiagram(org.kie.workbench.common.dmn.api.definition.v1_1.DMNDiagram) DiagramImpl(org.kie.workbench.common.stunner.core.diagram.DiagramImpl) DMNDefinitionSet(org.kie.workbench.common.dmn.api.DMNDefinitionSet) GraphCommandManagerImpl(org.kie.workbench.common.stunner.core.graph.command.GraphCommandManagerImpl) GraphCommandFactory(org.kie.workbench.common.stunner.core.graph.command.impl.GraphCommandFactory) TestScopeModelFactory(org.kie.workbench.common.stunner.backend.definition.factory.TestScopeModelFactory) Graph(org.kie.workbench.common.stunner.core.graph.Graph) EdgeFactoryImpl(org.kie.workbench.common.stunner.core.factory.impl.EdgeFactoryImpl) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) EdgeFactory(org.kie.workbench.common.stunner.core.factory.graph.EdgeFactory) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Before(org.junit.Before)

Example 67 with Edge

use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.

the class DMNEditBusinessKnowledgeModelToolboxAction method onMouseClick.

@Override
@SuppressWarnings("unchecked")
public ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler, final String uuid, final MouseClickEvent event) {
    // Notice the toolbox factory ensure this action is only being included
    // for BusinessKnowledgeModel definitions, next cast is safe.
    final Node<View<? extends BusinessKnowledgeModel>, Edge> bkmNode = (Node<View<? extends BusinessKnowledgeModel>, Edge>) AbstractToolboxAction.getElement(canvasHandler, uuid).asNode();
    final BusinessKnowledgeModel bkm = bkmNode.getContent().getDefinition();
    editExpressionEvent.fire(new EditExpressionEvent(sessionManager.getCurrentSession(), uuid, bkm.getEncapsulatedLogic(), Optional.of(bkm)));
    return this;
}
Also used : BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel) Node(org.kie.workbench.common.stunner.core.graph.Node) EditExpressionEvent(org.kie.workbench.common.dmn.client.events.EditExpressionEvent) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 68 with Edge

use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.

the class DMNEditDecisionToolboxAction method onMouseClick.

@Override
@SuppressWarnings("unchecked")
public ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler, final String uuid, final MouseClickEvent event) {
    // Notice the toolbox factory ensure this action is only being included
    // for Decision definitions, next cast is safe.
    final Node<View<? extends Decision>, Edge> decisionNode = (Node<View<? extends Decision>, Edge>) AbstractToolboxAction.getElement(canvasHandler, uuid).asNode();
    final Decision decision = decisionNode.getContent().getDefinition();
    editExpressionEvent.fire(new EditExpressionEvent(sessionManager.getCurrentSession(), uuid, decision, Optional.of(decision)));
    return this;
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) EditExpressionEvent(org.kie.workbench.common.dmn.client.events.EditExpressionEvent) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision)

Example 69 with Edge

use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.

the class DMNFlowActionsToolboxFactory method getActions.

@Override
@SuppressWarnings("unchecked")
public Collection<ToolboxAction<AbstractCanvasHandler>> getActions(final AbstractCanvasHandler canvasHandler, final Element<?> element) {
    final Set<ToolboxAction<AbstractCanvasHandler>> actions = new LinkedHashSet<>();
    final Node<Definition<Object>, Edge> node = (Node<Definition<Object>, Edge>) element;
    final Diagram diagram = canvasHandler.getDiagram();
    final String defSetId = diagram.getMetadata().getDefinitionSetId();
    // Look for the allowed connectors present in the Definition Set.
    final Set<String> allowedConnectorIds = commonLookups.getAllowedConnectors(defSetId, node, 0, 10);
    for (final String allowedConnectorId : allowedConnectorIds) {
        // Append a new action for each connector.
        actions.add(createConnectorActions.get().setEdgeId(allowedConnectorId));
        // Append a new action for each candidate target node (as from the current connector).
        commonLookups.getAllowedTargetDefinitions(defSetId, diagram.getGraph(), node, allowedConnectorId, 0, 10).forEach(def -> actions.add(createNodeActions.get().setEdgeId(allowedConnectorId).setNodeId(getDefinitionId(def))));
    }
    return actions;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ToolboxAction(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ToolboxAction) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram)

Example 70 with Edge

use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.

the class AbstractEdgeBuilder method buildControlPoints.

private void buildControlPoints(BuilderContext context, T edge, GraphCommandFactory commandFactory) {
    if (dockers.size() > 2) {
        Counter indexCounter = new Counter(0);
        ControlPoint[] controlPoints = dockers.subList(1, dockers.size() - 1).stream().sequential().map(docker -> (docker.length == 2 ? new Point2D(docker[0], docker[1]) : null)).filter(Objects::nonNull).map(point -> new ControlPointImpl(point, indexCounter.increment())).toArray(ControlPoint[]::new);
        CommandResult<RuleViolation> addControlPointsResult = context.execute(commandFactory.addControlPoint(edge, controlPoints));
        if (hasErrors(addControlPointsResult)) {
            throw new RuntimeException("Error building BPMN graph. Command 'AddControlPointCommand' execution failed." + addControlPointsResult);
        }
    }
}
Also used : AddControlPointCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AddControlPointCommand) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) BPMNDefinition(org.kie.workbench.common.stunner.bpmn.definition.BPMNDefinition) Edge(org.kie.workbench.common.stunner.core.graph.Edge) MutableIndex(org.kie.workbench.common.stunner.core.graph.processing.index.MutableIndex) Collectors(java.util.stream.Collectors) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Objects(java.util.Objects) GraphCommandFactory(org.kie.workbench.common.stunner.core.graph.command.impl.GraphCommandFactory) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) CommandUtils(org.kie.workbench.common.stunner.core.command.util.CommandUtils) Bpmn2OryxManager(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.Bpmn2OryxManager) Counter(org.kie.workbench.common.stunner.core.util.Counter) ControlPointImpl(org.kie.workbench.common.stunner.core.graph.content.view.ControlPointImpl) AddNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand) SetConnectionTargetNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.SetConnectionTargetNodeCommand) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) FactoryManager(org.kie.workbench.common.stunner.core.api.FactoryManager) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult) Node(org.kie.workbench.common.stunner.core.graph.Node) Counter(org.kie.workbench.common.stunner.core.util.Counter) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Objects(java.util.Objects) ControlPointImpl(org.kie.workbench.common.stunner.core.graph.content.view.ControlPointImpl) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation)

Aggregations

Edge (org.kie.workbench.common.stunner.core.graph.Edge)154 View (org.kie.workbench.common.stunner.core.graph.content.view.View)101 Node (org.kie.workbench.common.stunner.core.graph.Node)84 Test (org.junit.Test)45 Documentation (org.kie.workbench.common.stunner.bpmn.definition.property.general.Documentation)30 Name (org.kie.workbench.common.stunner.bpmn.definition.property.general.Name)30 Graph (org.kie.workbench.common.stunner.core.graph.Graph)28 BPMNGeneralSet (org.kie.workbench.common.stunner.bpmn.definition.property.general.BPMNGeneralSet)25 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)25 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)19 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)19 List (java.util.List)17 EventPropertyReader (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.EventPropertyReader)16 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)16 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)15 Element (org.kie.workbench.common.stunner.core.graph.Element)14 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)13 Child (org.kie.workbench.common.stunner.core.graph.content.relationship.Child)12 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)12 ArrayList (java.util.ArrayList)11