Search in sources :

Example 11 with RootElement

use of org.eclipse.bpmn2.RootElement in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method setThrowEventsInfoForLanes.

public void setThrowEventsInfoForLanes(Lane lane, Definitions def, List<RootElement> rootElements, List<Signal> toAddSignals, Set<Error> toAddErrors, Set<Escalation> toAddEscalations, Set<Message> toAddMessages, Set<ItemDefinition> toAddItemDefinitions) {
    List<FlowNode> laneFlowNodes = lane.getFlowNodeRefs();
    for (FlowNode fe : laneFlowNodes) {
        if (fe instanceof ThrowEvent) {
            if (((ThrowEvent) fe).getEventDefinitions().size() > 0) {
                EventDefinition ed = ((ThrowEvent) 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;
                        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) {
            setThrowEventsInfo((FlowElementsContainer) fe, def, rootElements, 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) 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) ThrowEvent(org.eclipse.bpmn2.ThrowEvent) 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 RootElement

use of org.eclipse.bpmn2.RootElement in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method setCatchEventsInfo.

public void setCatchEventsInfo(FlowElementsContainer container, Definitions def, List<Signal> toAddSignals, Set<Error> toAddErrors, Set<Escalation> toAddEscalations, Set<Message> toAddMessages, Set<ItemDefinition> toAddItemDefinitions) {
    List<FlowElement> flowElements = container.getFlowElements();
    for (FlowElement fe : flowElements) {
        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) Error(org.eclipse.bpmn2.Error) Activity(org.eclipse.bpmn2.Activity) CallActivity(org.eclipse.bpmn2.CallActivity) FlowElementsContainer(org.eclipse.bpmn2.FlowElementsContainer) 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) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) Signal(org.eclipse.bpmn2.Signal) Entry(java.util.Map.Entry) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) RootElement(org.eclipse.bpmn2.RootElement) EscalationEventDefinition(org.eclipse.bpmn2.EscalationEventDefinition) FlowElement(org.eclipse.bpmn2.FlowElement) ErrorEventDefinition(org.eclipse.bpmn2.ErrorEventDefinition) Iterator(java.util.Iterator) SignalEventDefinition(org.eclipse.bpmn2.SignalEventDefinition) MessageEventDefinition(org.eclipse.bpmn2.MessageEventDefinition) CompensateEventDefinition(org.eclipse.bpmn2.CompensateEventDefinition)

Example 13 with RootElement

use of org.eclipse.bpmn2.RootElement in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method revisitLanes.

public void revisitLanes(Definitions def) {
    List<RootElement> rootElements = def.getRootElements();
    for (RootElement root : rootElements) {
        if (root instanceof Process) {
            Process process = (Process) root;
            if ((process.getLaneSets() == null || process.getLaneSets().size() < 1) && _lanes.size() > 0) {
                LaneSet ls = Bpmn2Factory.eINSTANCE.createLaneSet();
                for (Lane lane : _lanes) {
                    ls.getLanes().add(lane);
                    List<FlowNode> laneFlowNodes = lane.getFlowNodeRefs();
                    for (FlowNode fl : laneFlowNodes) {
                        process.getFlowElements().add(fl);
                    }
                }
                process.getLaneSets().add(ls);
            }
        }
    }
}
Also used : RootElement(org.eclipse.bpmn2.RootElement) Lane(org.eclipse.bpmn2.Lane) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Process(org.eclipse.bpmn2.Process) LaneSet(org.eclipse.bpmn2.LaneSet) FlowNode(org.eclipse.bpmn2.FlowNode)

Example 14 with RootElement

use of org.eclipse.bpmn2.RootElement in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method revisitServiceTasks.

private void revisitServiceTasks(Definitions def) {
    List<RootElement> rootElements = def.getRootElements();
    List<Interface> toAddInterfaces = new ArrayList<Interface>();
    List<Message> toAddMessages = new ArrayList<Message>();
    List<ItemDefinition> toAddDefinitions = new ArrayList<ItemDefinition>();
    for (RootElement root : rootElements) {
        if (root instanceof Process) {
            revisitServiceTasksExecute((Process) root, rootElements, toAddInterfaces, toAddMessages, toAddDefinitions);
        }
    }
    for (Lane lane : _lanes) {
        revisitServiceTasksExecuteForLanes(lane, def, rootElements, toAddInterfaces, toAddMessages, toAddDefinitions);
    }
    for (ItemDefinition id : toAddDefinitions) {
        def.getRootElements().add(id);
    }
    for (Message m : toAddMessages) {
        def.getRootElements().add(m);
    }
    for (Interface i : toAddInterfaces) {
        def.getRootElements().add(i);
    }
}
Also used : RootElement(org.eclipse.bpmn2.RootElement) Message(org.eclipse.bpmn2.Message) ArrayList(java.util.ArrayList) ItemDefinition(org.eclipse.bpmn2.ItemDefinition) Lane(org.eclipse.bpmn2.Lane) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Process(org.eclipse.bpmn2.Process) Interface(org.eclipse.bpmn2.Interface)

Example 15 with RootElement

use of org.eclipse.bpmn2.RootElement in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method revisitThrowEvents.

/**
 * Updates event definitions for all throwing events.
 * @param def Definitions
 */
public void revisitThrowEvents(Definitions def) {
    List<RootElement> rootElements = def.getRootElements();
    List<Signal> toAddSignals = new ArrayList<Signal>();
    Set<Error> toAddErrors = new HashSet<Error>();
    Set<Escalation> toAddEscalations = new HashSet<Escalation>();
    Set<Message> toAddMessages = new HashSet<Message>();
    Set<ItemDefinition> toAddItemDefinitions = new HashSet<ItemDefinition>();
    for (RootElement root : rootElements) {
        if (root instanceof Process) {
            setThrowEventsInfo((Process) root, def, rootElements, toAddSignals, toAddErrors, toAddEscalations, toAddMessages, toAddItemDefinitions);
        }
    }
    for (Lane lane : _lanes) {
        setThrowEventsInfoForLanes(lane, def, rootElements, toAddSignals, toAddErrors, toAddEscalations, toAddMessages, toAddItemDefinitions);
    }
    for (Signal s : toAddSignals) {
        def.getRootElements().add(s);
    }
    for (Error er : toAddErrors) {
        def.getRootElements().add(er);
    }
    for (Escalation es : toAddEscalations) {
        def.getRootElements().add(es);
    }
    for (ItemDefinition idef : toAddItemDefinitions) {
        def.getRootElements().add(idef);
    }
    for (Message msg : toAddMessages) {
        def.getRootElements().add(msg);
    }
}
Also used : Message(org.eclipse.bpmn2.Message) Escalation(org.eclipse.bpmn2.Escalation) ArrayList(java.util.ArrayList) ItemDefinition(org.eclipse.bpmn2.ItemDefinition) Lane(org.eclipse.bpmn2.Lane) Error(org.eclipse.bpmn2.Error) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Process(org.eclipse.bpmn2.Process) Signal(org.eclipse.bpmn2.Signal) RootElement(org.eclipse.bpmn2.RootElement) HashSet(java.util.HashSet)

Aggregations

RootElement (org.eclipse.bpmn2.RootElement)34 Process (org.eclipse.bpmn2.Process)27 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)24 SubProcess (org.eclipse.bpmn2.SubProcess)24 ArrayList (java.util.ArrayList)17 FlowElement (org.eclipse.bpmn2.FlowElement)14 ItemDefinition (org.eclipse.bpmn2.ItemDefinition)13 Entry (java.util.Map.Entry)11 Message (org.eclipse.bpmn2.Message)11 FeatureMap (org.eclipse.emf.ecore.util.FeatureMap)11 SimpleFeatureMapEntry (org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry)10 CallActivity (org.eclipse.bpmn2.CallActivity)8 FlowElementsContainer (org.eclipse.bpmn2.FlowElementsContainer)8 List (java.util.List)7 Activity (org.eclipse.bpmn2.Activity)7 Escalation (org.eclipse.bpmn2.Escalation)7 FlowNode (org.eclipse.bpmn2.FlowNode)7 Signal (org.eclipse.bpmn2.Signal)7 CompensateEventDefinition (org.eclipse.bpmn2.CompensateEventDefinition)6 ConditionalEventDefinition (org.eclipse.bpmn2.ConditionalEventDefinition)6