Search in sources :

Example 16 with IntermediateCompensationEventThrowing

use of org.kie.workbench.common.stunner.bpmn.definition.IntermediateCompensationEventThrowing 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

IntermediateCompensationEventThrowing (org.kie.workbench.common.stunner.bpmn.definition.IntermediateCompensationEventThrowing)16 Test (org.junit.Test)10 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)9 Graph (org.kie.workbench.common.stunner.core.graph.Graph)9 IntermediateThrowEvent (org.eclipse.bpmn2.IntermediateThrowEvent)3 CompensationEventExecutionSet (org.kie.workbench.common.stunner.bpmn.definition.property.event.compensation.CompensationEventExecutionSet)3 CompensateEventDefinition (org.eclipse.bpmn2.CompensateEventDefinition)2 ActivityRef (org.kie.workbench.common.stunner.bpmn.definition.property.event.compensation.ActivityRef)2 BPMNGeneralSet (org.kie.workbench.common.stunner.bpmn.definition.property.general.BPMNGeneralSet)2 Edge (org.kie.workbench.common.stunner.core.graph.Edge)2 Node (org.kie.workbench.common.stunner.core.graph.Node)2 View (org.kie.workbench.common.stunner.core.graph.content.view.View)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 ThrowEvent (org.eclipse.bpmn2.ThrowEvent)1 SelectorData (org.kie.workbench.common.forms.dynamic.model.config.SelectorData)1