Search in sources :

Example 11 with FlowElement

use of org.osate.aadl2.FlowElement in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method setCatchEventsInfoForLanes.

public void setCatchEventsInfoForLanes(Lane lane, Definitions def, List<Signal> toAddSignals, Set<Error> toAddErrors, Set<Escalation> toAddEscalations, Set<Message> toAddMessages, Set<ItemDefinition> toAddItemDefinitions) {
    List<FlowNode> laneFlowNodes = lane.getFlowNodeRefs();
    for (FlowElement fe : laneFlowNodes) {
        if (fe instanceof CatchEvent) {
            if (((CatchEvent) fe).getEventDefinitions().size() > 0) {
                EventDefinition ed = ((CatchEvent) fe).getEventDefinitions().get(0);
                if (ed instanceof SignalEventDefinition) {
                    SignalEventDefinition sed = (SignalEventDefinition) ed;
                    if (sed.getSignalRef() != null && sed.getSignalRef().length() > 0) {
                        String signalRef = sed.getSignalRef();
                        boolean shouldAddSignal = true;
                        List<RootElement> rootElements = def.getRootElements();
                        for (RootElement re : rootElements) {
                            if (re instanceof Signal) {
                                if (((Signal) re).getName().equals(signalRef)) {
                                    shouldAddSignal = false;
                                    break;
                                }
                            }
                        }
                        if (toAddSignals != null) {
                            for (Signal s : toAddSignals) {
                                if (s.getName().equals(signalRef)) {
                                    shouldAddSignal = false;
                                    break;
                                }
                            }
                        }
                        if (shouldAddSignal) {
                            Signal signal = Bpmn2Factory.eINSTANCE.createSignal();
                            signal.setName(signalRef);
                            toAddSignals.add(signal);
                        }
                    }
                } else if (ed instanceof ErrorEventDefinition) {
                    String errorCode = null;
                    String errorId = null;
                    Iterator<FeatureMap.Entry> iter = ed.getAnyAttribute().iterator();
                    while (iter.hasNext()) {
                        FeatureMap.Entry entry = iter.next();
                        if (entry.getEStructuralFeature().getName().equals("erefname")) {
                            errorId = (String) entry.getValue();
                            errorCode = (String) entry.getValue();
                        }
                    }
                    Error err = this._errors.get(errorCode);
                    if (err == null) {
                        err = Bpmn2Factory.eINSTANCE.createError();
                        err.setId(errorId);
                        err.setErrorCode(errorCode);
                        this._errors.put(errorCode, err);
                    }
                    toAddErrors.add(err);
                    ((ErrorEventDefinition) ed).setErrorRef(err);
                } else if (ed instanceof EscalationEventDefinition) {
                    String escalationCode = null;
                    Iterator<FeatureMap.Entry> iter = ed.getAnyAttribute().iterator();
                    while (iter.hasNext()) {
                        FeatureMap.Entry entry = iter.next();
                        if (entry.getEStructuralFeature().getName().equals("esccode")) {
                            escalationCode = (String) entry.getValue();
                            break;
                        }
                    }
                    Escalation escalation = this._escalations.get(escalationCode);
                    if (escalation == null) {
                        escalation = Bpmn2Factory.eINSTANCE.createEscalation();
                        escalation.setEscalationCode(escalationCode);
                        this._escalations.put(escalationCode, escalation);
                    }
                    toAddEscalations.add(escalation);
                    ((EscalationEventDefinition) ed).setEscalationRef(escalation);
                } else if (ed instanceof MessageEventDefinition) {
                    ((MessageEventDefinition) ed).setMessageRef(extractMessage(ed, toAddMessages, toAddItemDefinitions));
                } else if (ed instanceof CompensateEventDefinition) {
                    Iterator<FeatureMap.Entry> iter = ed.getAnyAttribute().iterator();
                    while (iter.hasNext()) {
                        FeatureMap.Entry entry = iter.next();
                        if (entry.getEStructuralFeature().getName().equals("actrefname")) {
                            String activityNameRef = (String) entry.getValue();
                            // we have to iterate again through all flow elements
                            // in order to find our activity name
                            List<RootElement> re = def.getRootElements();
                            for (RootElement r : re) {
                                if (r instanceof Process) {
                                    Process p = (Process) r;
                                    List<FlowElement> fes = p.getFlowElements();
                                    for (FlowElement f : fes) {
                                        if (f instanceof Activity && ((Activity) f).getName().equals(activityNameRef)) {
                                            ((CompensateEventDefinition) ed).setActivityRef((Activity) f);
                                            ((Activity) f).setIsForCompensation(true);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } else if (fe instanceof FlowElementsContainer) {
            setCatchEventsInfo((FlowElementsContainer) fe, def, toAddSignals, toAddErrors, toAddEscalations, toAddMessages, toAddItemDefinitions);
        }
    }
}
Also used : Escalation(org.eclipse.bpmn2.Escalation) Activity(org.eclipse.bpmn2.Activity) CallActivity(org.eclipse.bpmn2.CallActivity) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Process(org.eclipse.bpmn2.Process) CatchEvent(org.eclipse.bpmn2.CatchEvent) EventDefinition(org.eclipse.bpmn2.EventDefinition) ConditionalEventDefinition(org.eclipse.bpmn2.ConditionalEventDefinition) EscalationEventDefinition(org.eclipse.bpmn2.EscalationEventDefinition) MessageEventDefinition(org.eclipse.bpmn2.MessageEventDefinition) ErrorEventDefinition(org.eclipse.bpmn2.ErrorEventDefinition) SignalEventDefinition(org.eclipse.bpmn2.SignalEventDefinition) CompensateEventDefinition(org.eclipse.bpmn2.CompensateEventDefinition) TimerEventDefinition(org.eclipse.bpmn2.TimerEventDefinition) Signal(org.eclipse.bpmn2.Signal) Entry(java.util.Map.Entry) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) Iterator(java.util.Iterator) SignalEventDefinition(org.eclipse.bpmn2.SignalEventDefinition) Error(org.eclipse.bpmn2.Error) FlowElementsContainer(org.eclipse.bpmn2.FlowElementsContainer) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) RootElement(org.eclipse.bpmn2.RootElement) EscalationEventDefinition(org.eclipse.bpmn2.EscalationEventDefinition) FlowElement(org.eclipse.bpmn2.FlowElement) ErrorEventDefinition(org.eclipse.bpmn2.ErrorEventDefinition) MessageEventDefinition(org.eclipse.bpmn2.MessageEventDefinition) CompensateEventDefinition(org.eclipse.bpmn2.CompensateEventDefinition) FlowNode(org.eclipse.bpmn2.FlowNode)

Example 12 with FlowElement

use of org.osate.aadl2.FlowElement in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method updateShapeBounds.

public void updateShapeBounds(Definitions def, BPMNPlane plane, BaseElement ele) {
    if (ele instanceof Lane) {
        Lane nextLane = (Lane) ele;
        Bounds laneBounds = getBoundsForElement(nextLane, plane);
        updateShapeBoundsInLanes(plane, ele, nextLane, laneBounds.getX(), laneBounds.getY());
    } else {
        List<RootElement> rootElements = def.getRootElements();
        for (RootElement root : rootElements) {
            if (root instanceof Process) {
                Process process = (Process) root;
                List<FlowElement> flowElements = process.getFlowElements();
                boolean foundAsTopLevel = false;
                for (FlowElement fe : flowElements) {
                    if (fe.getId().equals(ele.getId())) {
                        foundAsTopLevel = true;
                        break;
                    }
                }
                if (!foundAsTopLevel) {
                    for (FlowElement fe : flowElements) {
                        if (fe instanceof SubProcess) {
                            SubProcess sp = (SubProcess) fe;
                            // process if this subprocess is not in a lane already. otherwise we already updated it
                            if (sp.getLanes().size() < 1) {
                                // find the subprocess bounds
                                Bounds subprocessBounds = getBoundsForElement(fe, plane);
                                if (subprocessBounds != null) {
                                    updateShapeBoundsInSubprocess(plane, ele, (SubProcess) fe, subprocessBounds.getX(), subprocessBounds.getY());
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) RootElement(org.eclipse.bpmn2.RootElement) FlowElement(org.eclipse.bpmn2.FlowElement) Bounds(org.eclipse.dd.dc.Bounds) Lane(org.eclipse.bpmn2.Lane) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Process(org.eclipse.bpmn2.Process)

Example 13 with FlowElement

use of org.osate.aadl2.FlowElement in project kie-wb-common by kiegroup.

the class IntermediateLinkEventPostConverter method getCatchLinkEventWithSameName.

LinkEventDefinition getCatchLinkEventWithSameName(FlowElementsContainer container, String linkName) {
    for (FlowElement flowElement : container.getFlowElements()) {
        if (flowElement instanceof CatchEvent) {
            CatchEvent event = (CatchEvent) flowElement;
            List<EventDefinition> definitions = event.getEventDefinitions();
            if (definitions == null || definitions.isEmpty()) {
                continue;
            }
            EventDefinition definition = definitions.get(0);
            if (definition instanceof LinkEventDefinition) {
                LinkEventDefinition linkDefinition = (LinkEventDefinition) definition;
                if (linkName.equals(linkDefinition.getName())) {
                    return linkDefinition;
                }
            }
        }
    }
    return null;
}
Also used : LinkEventDefinition(org.eclipse.bpmn2.LinkEventDefinition) FlowElement(org.eclipse.bpmn2.FlowElement) CatchEvent(org.eclipse.bpmn2.CatchEvent) EventDefinition(org.eclipse.bpmn2.EventDefinition) LinkEventDefinition(org.eclipse.bpmn2.LinkEventDefinition)

Example 14 with FlowElement

use of org.osate.aadl2.FlowElement in project kie-wb-common by kiegroup.

the class AbstractCompensationEventPostConverter method findActivity.

protected Activity findActivity(FlowElementsContainer container, String uuid) {
    final List<FlowElementsContainer> subContainers = new ArrayList<>();
    for (FlowElement flowElement : container.getFlowElements()) {
        if (flowElement instanceof Activity) {
            if (flowElement.getId().equals(uuid)) {
                return (Activity) flowElement;
            } else if (flowElement instanceof SubProcess) {
                subContainers.add((SubProcess) flowElement);
            }
        }
    }
    Activity result;
    for (FlowElementsContainer subContainer : subContainers) {
        result = findActivity(subContainer, uuid);
        if (result != null) {
            return result;
        }
    }
    return null;
}
Also used : SubProcess(org.eclipse.bpmn2.SubProcess) FlowElement(org.eclipse.bpmn2.FlowElement) ArrayList(java.util.ArrayList) FlowElementsContainer(org.eclipse.bpmn2.FlowElementsContainer) Activity(org.eclipse.bpmn2.Activity)

Example 15 with FlowElement

use of org.osate.aadl2.FlowElement in project kie-wb-common by kiegroup.

the class SubProcessPropertyWriterTest method addChildElement.

@Test
public void addChildElement() {
    SubProcess process = (SubProcess) propertyWriter.getElement();
    List<FlowElement> flowElements = new ArrayList<>();
    when(process.getFlowElements()).thenReturn(flowElements);
    BoundaryEventPropertyWriter boundaryEventPropertyWriter = new BoundaryEventPropertyWriter(bpmn2.createBoundaryEvent(), variableScope, new HashSet<>());
    UserTaskPropertyWriter userTaskPropertyWriter = new UserTaskPropertyWriter(bpmn2.createUserTask(), variableScope, new HashSet<>());
    propertyWriter.addChildElement(boundaryEventPropertyWriter);
    propertyWriter.addChildElement(userTaskPropertyWriter);
    // boundary event should always occur after other nodes (compat with old marshallers)
    assertThat(process.getFlowElements().get(0)).isEqualTo(userTaskPropertyWriter.getFlowElement());
    assertThat(process.getFlowElements().get(1)).isEqualTo(boundaryEventPropertyWriter.getFlowElement());
}
Also used : SubProcess(org.eclipse.bpmn2.SubProcess) FlowElement(org.eclipse.bpmn2.FlowElement) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

FlowElement (org.eclipse.bpmn2.FlowElement)57 SubProcess (org.eclipse.bpmn2.SubProcess)27 ArrayList (java.util.ArrayList)26 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)22 Process (org.eclipse.bpmn2.Process)21 FlowElementsContainer (org.eclipse.bpmn2.FlowElementsContainer)19 RootElement (org.eclipse.bpmn2.RootElement)19 SequenceFlow (org.eclipse.bpmn2.SequenceFlow)16 Activity (org.eclipse.bpmn2.Activity)12 FeatureMap (org.eclipse.emf.ecore.util.FeatureMap)12 Entry (java.util.Map.Entry)11 SimpleFeatureMapEntry (org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry)11 List (java.util.List)10 EventDefinition (org.eclipse.bpmn2.EventDefinition)10 BoundaryEvent (org.eclipse.bpmn2.BoundaryEvent)9 CompensateEventDefinition (org.eclipse.bpmn2.CompensateEventDefinition)9 ErrorEventDefinition (org.eclipse.bpmn2.ErrorEventDefinition)9 MessageEventDefinition (org.eclipse.bpmn2.MessageEventDefinition)9 SignalEventDefinition (org.eclipse.bpmn2.SignalEventDefinition)9 CallActivity (org.eclipse.bpmn2.CallActivity)8