Search in sources :

Example 1 with EndCompensationEvent

use of org.kie.workbench.common.stunner.bpmn.definition.EndCompensationEvent in project kie-wb-common by kiegroup.

the class EndCompensationEventPostConverter method process.

@Override
public void process(ProcessPropertyWriter processWriter, BasePropertyWriter nodeWriter, Node<View<? extends BPMNViewDefinition>, ?> node) {
    final ThrowEvent throwEvent = (ThrowEvent) nodeWriter.getElement();
    final String activityRef = ((EndCompensationEvent) node.getContent().getDefinition()).getExecutionSet().getActivityRef().getValue();
    linkActivityRef(processWriter.getProcess(), throwEvent, activityRef);
}
Also used : ThrowEvent(org.eclipse.bpmn2.ThrowEvent) EndCompensationEvent(org.kie.workbench.common.stunner.bpmn.definition.EndCompensationEvent)

Example 2 with EndCompensationEvent

use of org.kie.workbench.common.stunner.bpmn.definition.EndCompensationEvent in project kie-wb-common by kiegroup.

the class EndEventConverter method compensationEvent.

private PropertyWriter compensationEvent(Node<View<EndCompensationEvent>, ?> n) {
    EndEvent event = bpmn2.createEndEvent();
    event.setId(n.getUUID());
    EndCompensationEvent definition = n.getContent().getDefinition();
    ThrowEventPropertyWriter p = propertyWriterFactory.of(event);
    BPMNGeneralSet general = definition.getGeneral();
    p.setName(general.getName().getValue());
    p.setDocumentation(general.getDocumentation().getValue());
    p.setMetaData(definition.getAdvancedData().getMetaDataAttributes());
    p.addCompensation();
    p.setAbsoluteBounds(n);
    return p;
}
Also used : BaseEndEvent(org.kie.workbench.common.stunner.bpmn.definition.BaseEndEvent) EndEvent(org.eclipse.bpmn2.EndEvent) BPMNGeneralSet(org.kie.workbench.common.stunner.bpmn.definition.property.general.BPMNGeneralSet) EndCompensationEvent(org.kie.workbench.common.stunner.bpmn.definition.EndCompensationEvent) ThrowEventPropertyWriter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.ThrowEventPropertyWriter)

Example 3 with EndCompensationEvent

use of org.kie.workbench.common.stunner.bpmn.definition.EndCompensationEvent in project kie-wb-common by kiegroup.

the class BPMNDirectDiagramMarshallerTest method testUnmarshallEndCompensationEvent.

@Test
@SuppressWarnings("unchecked")
public void testUnmarshallEndCompensationEvent() throws Exception {
    Diagram<Graph, Metadata> diagram = unmarshall(BPMN_ENDCOMPENSATIONEVENT);
    assertDiagram(diagram, 3);
    assertEquals("EndCompensationEvent", diagram.getMetadata().getTitle());
    Node<? extends Definition, ?> endEventNode = diagram.getGraph().getNode("_2AEA503B-26E5-4F11-A54D-3E275F8BFA6A");
    assertNotNull(endEventNode);
    EndCompensationEvent endCompensationEvent = (EndCompensationEvent) endEventNode.getContent().getDefinition();
    assertNotNull(endCompensationEvent.getGeneral());
    assertEquals("EndCompensationEventName", endCompensationEvent.getGeneral().getName().getValue());
    assertEquals("EndCompensationEventDocumentation", endCompensationEvent.getGeneral().getDocumentation().getValue());
    assertNotNull(endCompensationEvent.getExecutionSet());
    assertEquals("_7795AFA7-E602-4D90-B4B6-249639C4D965", endCompensationEvent.getExecutionSet().getActivityRef().getValue());
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) EndCompensationEvent(org.kie.workbench.common.stunner.bpmn.definition.EndCompensationEvent) Test(org.junit.Test)

Example 4 with EndCompensationEvent

use of org.kie.workbench.common.stunner.bpmn.definition.EndCompensationEvent in project kie-wb-common by kiegroup.

the class ProcessConverterDelegateTest method testPostConvertNodes.

@Test
@SuppressWarnings("unchecked")
public void testPostConvertNodes() {
    TestingGraphMockHandler graphTestHandler = new TestingGraphMockHandler();
    BPMNDiagramImpl bpmnDiagram = new BPMNDiagramImpl();
    StartNoneEvent level0StartNode = new StartNoneEvent();
    EndNoneEvent level0EndNode = new EndNoneEvent();
    UserTask level0Node1 = new UserTask();
    UserTask level0Node2 = new UserTask();
    EmbeddedSubprocess level1SubProcess1 = new EmbeddedSubprocess();
    ScriptTask level1Node1 = new ScriptTask();
    IntermediateSignalEventThrowing level1Node2 = new IntermediateSignalEventThrowing();
    AdHocSubprocess level2SubProcess1 = new AdHocSubprocess();
    BusinessRuleTask level2Node1 = new BusinessRuleTask();
    EndCompensationEvent level2Node2 = new EndCompensationEvent();
    TestingGraphInstanceBuilder2.Level2Graph level2Graph = TestingGraphInstanceBuilder2.buildLevel2Graph(graphTestHandler, bpmnDiagram, level0StartNode, level0Node1, level0Node2, level0EndNode, level1SubProcess1, level1Node1, level1Node2, level2SubProcess1, level2Node1, level2Node2);
    DefinitionsBuildingContext ctx = new DefinitionsBuildingContext(level2Graph.graph);
    PropertyWriterFactory writerFactory = new PropertyWriterFactory();
    ConverterFactory factory = spy(new ConverterFactory(ctx, writerFactory));
    FlowElementPostConverter flowElementPostConverter = mock(FlowElementPostConverter.class);
    when(factory.flowElementPostConverter()).thenReturn(flowElementPostConverter);
    MyProcessConverter abstractProcessConverter = new MyProcessConverter(factory);
    ProcessPropertyWriter processWriter = writerFactory.of(bpmn2.createProcess());
    abstractProcessConverter.postConvertChildNodes(processWriter, ctx);
    verify(flowElementPostConverter, times(10)).postConvert(anyObject(), anyObject(), nodeCaptor.capture());
    Map<String, BPMNViewDefinition> nodes = new HashMap<>();
    nodes.put(LEVEL0_START_NODE.uuid(), level0StartNode);
    nodes.put(LEVEL0_NODE1.uuid(), level0Node1);
    nodes.put(LEVEL0_NODE2.uuid(), level0Node2);
    nodes.put(LEVEL0_END_NODE.uuid(), level0EndNode);
    nodes.put(LEVEL1_SUB_PROCESS1.uuid(), level1SubProcess1);
    nodes.put(LEVEL1_NODE1.uuid(), level1Node1);
    nodes.put(LEVEL1_NODE2.uuid(), level1Node2);
    nodes.put(LEVEL2_SUB_PROCESS1.uuid(), level2SubProcess1);
    nodes.put(LEVEL2_NODE1.uuid(), level2Node1);
    nodes.put(LEVEL2_NODE2.uuid(), level2Node2);
    assertEquals(nodes.size(), nodeCaptor.getAllValues().size());
    nodes.entrySet().forEach(entry -> {
        Optional<Node<View<? extends BPMNViewDefinition>, ?>> processed = nodeCaptor.getAllValues().stream().filter(captured -> entry.getKey().equals(captured.getUUID())).findFirst();
        assertTrue("Node: " + entry.getKey() + " was not present in result", processed.isPresent());
        assertEquals(entry.getValue(), processed.get().getContent().getDefinition());
    });
}
Also used : IntermediateErrorEventCatching(org.kie.workbench.common.stunner.bpmn.definition.IntermediateErrorEventCatching) LEVEL2_SUB_PROCESS1(org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder2.NODES.LEVEL2_SUB_PROCESS1) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) UserTask(org.kie.workbench.common.stunner.bpmn.definition.UserTask) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) BPMNViewDefinition(org.kie.workbench.common.stunner.bpmn.definition.BPMNViewDefinition) Map(java.util.Map) ConverterFactory(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.ConverterFactory) NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) Factories.bpmn2(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.Factories.bpmn2) PropertyWriterFactory(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.PropertyWriterFactory) ArgumentMatchers.anyObject(org.mockito.ArgumentMatchers.anyObject) ScriptTask(org.kie.workbench.common.stunner.bpmn.definition.ScriptTask) LEVEL0_START_NODE(org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder2.NODES.LEVEL0_START_NODE) GraphImpl(org.kie.workbench.common.stunner.core.graph.impl.GraphImpl) EmbeddedSubprocess(org.kie.workbench.common.stunner.bpmn.definition.EmbeddedSubprocess) LEVEL1_NODE2(org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder2.NODES.LEVEL1_NODE2) Optional(java.util.Optional) Dock(org.kie.workbench.common.stunner.core.graph.content.relationship.Dock) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Node(org.kie.workbench.common.stunner.core.graph.Node) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) Mockito.mock(org.mockito.Mockito.mock) StartNoneEvent(org.kie.workbench.common.stunner.bpmn.definition.StartNoneEvent) ProcessPropertyWriter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.ProcessPropertyWriter) BusinessRuleTask(org.kie.workbench.common.stunner.bpmn.definition.BusinessRuleTask) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) LEVEL1_NODE1(org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder2.NODES.LEVEL1_NODE1) LEVEL1_SUB_PROCESS1(org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder2.NODES.LEVEL1_SUB_PROCESS1) Mockito.spy(org.mockito.Mockito.spy) Captor(org.mockito.Captor) FlowElementPostConverter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.FlowElementPostConverter) AdHocSubprocess(org.kie.workbench.common.stunner.bpmn.definition.AdHocSubprocess) View(org.kie.workbench.common.stunner.core.graph.content.view.View) TestingGraphInstanceBuilder2(org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder2) ArgumentCaptor(org.mockito.ArgumentCaptor) DefinitionsBuildingContext(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsBuildingContext) EndCompensationEvent(org.kie.workbench.common.stunner.bpmn.definition.EndCompensationEvent) IntermediateSignalEventThrowing(org.kie.workbench.common.stunner.bpmn.definition.IntermediateSignalEventThrowing) LEVEL2_NODE1(org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder2.NODES.LEVEL2_NODE1) LEVEL2_NODE2(org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder2.NODES.LEVEL2_NODE2) BPMNDiagramImpl(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagramImpl) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) LEVEL0_NODE2(org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder2.NODES.LEVEL0_NODE2) LEVEL0_END_NODE(org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder2.NODES.LEVEL0_END_NODE) LEVEL0_NODE1(org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder2.NODES.LEVEL0_NODE1) GraphNodeStoreImpl(org.kie.workbench.common.stunner.core.graph.store.GraphNodeStoreImpl) Assert.assertEquals(org.junit.Assert.assertEquals) EndNoneEvent(org.kie.workbench.common.stunner.bpmn.definition.EndNoneEvent) TestingGraphMockHandler(org.kie.workbench.common.stunner.core.TestingGraphMockHandler) HashMap(java.util.HashMap) Node(org.kie.workbench.common.stunner.core.graph.Node) BusinessRuleTask(org.kie.workbench.common.stunner.bpmn.definition.BusinessRuleTask) AdHocSubprocess(org.kie.workbench.common.stunner.bpmn.definition.AdHocSubprocess) FlowElementPostConverter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.FlowElementPostConverter) ConverterFactory(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.ConverterFactory) BPMNViewDefinition(org.kie.workbench.common.stunner.bpmn.definition.BPMNViewDefinition) PropertyWriterFactory(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.PropertyWriterFactory) EmbeddedSubprocess(org.kie.workbench.common.stunner.bpmn.definition.EmbeddedSubprocess) EndNoneEvent(org.kie.workbench.common.stunner.bpmn.definition.EndNoneEvent) BPMNDiagramImpl(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagramImpl) StartNoneEvent(org.kie.workbench.common.stunner.bpmn.definition.StartNoneEvent) IntermediateSignalEventThrowing(org.kie.workbench.common.stunner.bpmn.definition.IntermediateSignalEventThrowing) EndCompensationEvent(org.kie.workbench.common.stunner.bpmn.definition.EndCompensationEvent) TestingGraphInstanceBuilder2(org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder2) UserTask(org.kie.workbench.common.stunner.bpmn.definition.UserTask) DefinitionsBuildingContext(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsBuildingContext) TestingGraphMockHandler(org.kie.workbench.common.stunner.core.TestingGraphMockHandler) ProcessPropertyWriter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.ProcessPropertyWriter) ScriptTask(org.kie.workbench.common.stunner.bpmn.definition.ScriptTask) Test(org.junit.Test)

Example 5 with EndCompensationEvent

use of org.kie.workbench.common.stunner.bpmn.definition.EndCompensationEvent in project kie-wb-common by kiegroup.

the class ProcessCompensationRefProvider method getSelectorData.

@Override
@SuppressWarnings("unchecked")
public SelectorData getSelectorData(FormRenderingContext context) {
    final Diagram diagram = sessionManager.getCurrentSession().getCanvasHandler().getDiagram();
    final String rootUUID = diagram.getMetadata().getCanvasRootUUID();
    final Node<?, ? extends Edge> selectedNode = getSelectedNode(diagram, sessionManager.getCurrentSession());
    final Map<Object, String> values = new TreeMap<>(SafeComparator.TO_STRING_COMPARATOR);
    if (selectedNode != null) {
        Node<?, ? extends Edge> currentNode = selectedNode;
        final List<Node> compensableNodes = new ArrayList<>();
        Node<?, ? extends Edge> parentNode;
        int levels = 0;
        do {
            parentNode = GraphUtils.getParent(currentNode).asNode();
            compensableNodes.addAll(getCompensableNodes(parentNode));
            if (rootUUID.equals(parentNode.getUUID())) {
                levels = 2;
            } else if (isSubProcess(parentNode)) {
                currentNode = parentNode;
                levels++;
            } else if (isLane(parentNode)) {
                currentNode = parentNode;
            }
        } while (levels < 2);
        compensableNodes.stream().map(node -> buildPair(node.getUUID(), (BPMNDefinition) (((View) node.getContent()).getDefinition()))).forEach(pair -> values.put(pair.getK1(), pair.getK2()));
        ActivityRef currentActivityRef = null;
        if (isEndCompensationEvent(selectedNode)) {
            currentActivityRef = ((EndCompensationEvent) ((View) selectedNode.getContent()).getDefinition()).getExecutionSet().getActivityRef();
        } else if (isIntermediateCompensationEventThrowing(selectedNode)) {
            currentActivityRef = ((IntermediateCompensationEventThrowing) ((View) selectedNode.getContent()).getDefinition()).getExecutionSet().getActivityRef();
        }
        if (currentActivityRef != null && !isEmpty(currentActivityRef.getValue()) && !values.containsKey(currentActivityRef.getValue())) {
            Node configured = diagram.getGraph().getNode(currentActivityRef.getValue());
            if (configured != null) {
                Pair<Object, String> pair = buildPair(configured.getUUID(), (BPMNDefinition) ((View) configured.getContent()).getDefinition());
                values.put(pair.getK1(), pair.getK2());
            }
        }
    }
    return new SelectorData(values, null);
}
Also used : IntermediateCompensationEventThrowing(org.kie.workbench.common.stunner.bpmn.definition.IntermediateCompensationEventThrowing) Edge(org.kie.workbench.common.stunner.core.graph.Edge) SelectorDataProvider(org.kie.workbench.common.forms.dynamic.model.config.SelectorDataProvider) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ArrayList(java.util.ArrayList) IntermediateCompensationEvent(org.kie.workbench.common.stunner.bpmn.definition.IntermediateCompensationEvent) GraphUtils(org.kie.workbench.common.stunner.core.graph.util.GraphUtils) Inject(javax.inject.Inject) Map(java.util.Map) Lane(org.kie.workbench.common.stunner.bpmn.definition.Lane) EndCompensationEvent(org.kie.workbench.common.stunner.bpmn.definition.EndCompensationEvent) SessionManager(org.kie.workbench.common.stunner.core.client.api.SessionManager) Pair(org.uberfire.commons.data.Pair) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) SelectorData(org.kie.workbench.common.forms.dynamic.model.config.SelectorData) FormRenderingContext(org.kie.workbench.common.forms.dynamic.service.shared.FormRenderingContext) StringUtils.isEmpty(org.kie.workbench.common.stunner.core.util.StringUtils.isEmpty) BPMNDefinition(org.kie.workbench.common.stunner.bpmn.definition.BPMNDefinition) Collectors(java.util.stream.Collectors) BaseSubprocess(org.kie.workbench.common.stunner.bpmn.definition.BaseSubprocess) List(java.util.List) TreeMap(java.util.TreeMap) BaseTask(org.kie.workbench.common.stunner.bpmn.definition.BaseTask) ClientUtils.getSelectedNode(org.kie.workbench.common.stunner.core.client.util.ClientUtils.getSelectedNode) ActivityRef(org.kie.workbench.common.stunner.bpmn.definition.property.event.compensation.ActivityRef) SafeComparator(org.kie.workbench.common.stunner.core.util.SafeComparator) Node(org.kie.workbench.common.stunner.core.graph.Node) ClientUtils.getSelectedNode(org.kie.workbench.common.stunner.core.client.util.ClientUtils.getSelectedNode) Node(org.kie.workbench.common.stunner.core.graph.Node) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) SelectorData(org.kie.workbench.common.forms.dynamic.model.config.SelectorData) ActivityRef(org.kie.workbench.common.stunner.bpmn.definition.property.event.compensation.ActivityRef) EndCompensationEvent(org.kie.workbench.common.stunner.bpmn.definition.EndCompensationEvent)

Aggregations

EndCompensationEvent (org.kie.workbench.common.stunner.bpmn.definition.EndCompensationEvent)6 View (org.kie.workbench.common.stunner.core.graph.content.view.View)3 Map (java.util.Map)2 Test (org.junit.Test)2 ActivityRef (org.kie.workbench.common.stunner.bpmn.definition.property.event.compensation.ActivityRef)2 Edge (org.kie.workbench.common.stunner.core.graph.Edge)2 Node (org.kie.workbench.common.stunner.core.graph.Node)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 TreeMap (java.util.TreeMap)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Assertions.assertThatCode (org.assertj.core.api.Assertions.assertThatCode)1 EndEvent (org.eclipse.bpmn2.EndEvent)1 ThrowEvent (org.eclipse.bpmn2.ThrowEvent)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 RunWith (org.junit.runner.RunWith)1