Search in sources :

Example 1 with FlowElement

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

the class Bpmn2JsonMarshaller method marshallProcess.

protected void marshallProcess(Process process, Definitions def, JsonGenerator generator, String preProcessingData) throws JsonGenerationException, IOException {
    BPMNPlane plane = null;
    for (BPMNDiagram d : def.getDiagrams()) {
        if (d != null) {
            BPMNPlane p = d.getPlane();
            if (p != null) {
                if (p.getBpmnElement() == process) {
                    plane = p;
                    break;
                }
            }
        }
    }
    if (plane == null) {
        throw new IllegalArgumentException("Could not find BPMNDI information");
    }
    generator.writeArrayFieldStart("childShapes");
    List<String> laneFlowElementsIds = new ArrayList<String>();
    for (LaneSet laneSet : process.getLaneSets()) {
        for (Lane lane : laneSet.getLanes()) {
            // we only want to marshall lanes if we have the bpmndi info for them!
            if (findDiagramElement(plane, lane) != null) {
                laneFlowElementsIds.addAll(marshallLanes(lane, plane, generator, 0, 0, preProcessingData, def));
            }
        }
    }
    for (FlowElement flowElement : process.getFlowElements()) {
        if (!laneFlowElementsIds.contains(flowElement.getId())) {
            marshallFlowElement(flowElement, plane, generator, 0, 0, preProcessingData, def);
        }
    }
    for (Artifact artifact : process.getArtifacts()) {
        marshallArtifact(artifact, plane, generator, 0, 0, preProcessingData, def);
    }
    generator.writeEndArray();
}
Also used : BPMNDiagram(org.eclipse.bpmn2.di.BPMNDiagram) FlowElement(org.eclipse.bpmn2.FlowElement) ArrayList(java.util.ArrayList) Lane(org.eclipse.bpmn2.Lane) LaneSet(org.eclipse.bpmn2.LaneSet) BPMNPlane(org.eclipse.bpmn2.di.BPMNPlane) Artifact(org.eclipse.bpmn2.Artifact)

Example 2 with FlowElement

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

the class Bpmn2JsonMarshaller method linkSequenceFlows.

private void linkSequenceFlows(List<FlowElement> flowElements) {
    Map<String, FlowNode> nodes = new HashMap<String, FlowNode>();
    for (FlowElement flowElement : flowElements) {
        if (flowElement instanceof FlowNode) {
            nodes.put(flowElement.getId(), (FlowNode) flowElement);
            if (flowElement instanceof SubProcess) {
                linkSequenceFlows(((SubProcess) flowElement).getFlowElements());
            }
        }
    }
    for (FlowElement flowElement : flowElements) {
        if (flowElement instanceof SequenceFlow) {
            SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
            if (sequenceFlow.getSourceRef() == null && sequenceFlow.getTargetRef() == null) {
                String id = sequenceFlow.getId();
                try {
                    String[] subids = id.split("-_");
                    String id1 = subids[0];
                    String id2 = "_" + subids[1];
                    FlowNode source = nodes.get(id1);
                    if (source != null) {
                        sequenceFlow.setSourceRef(source);
                    }
                    FlowNode target = nodes.get(id2);
                    if (target != null) {
                        sequenceFlow.setTargetRef(target);
                    }
                } catch (Throwable t) {
                // Do nothing
                }
            }
        }
    }
}
Also used : AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) FlowElement(org.eclipse.bpmn2.FlowElement) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) FlowNode(org.eclipse.bpmn2.FlowNode)

Example 3 with FlowElement

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

the class Bpmn2JsonUnmarshaller method revisitBoundaryEventsPositions.

protected void revisitBoundaryEventsPositions(Definitions def) {
    for (RootElement root : def.getRootElements()) {
        if (root instanceof Process) {
            Process process = (Process) root;
            List<BoundaryEvent> toRemove = new ArrayList();
            for (FlowElement fe : process.getFlowElements()) {
                if (fe instanceof BoundaryEvent) {
                    BoundaryEvent be = (BoundaryEvent) fe;
                    FlowElementsContainer container = findContainerForBoundaryEvent(process, be);
                    if (container != null && !(container instanceof Process)) {
                        BoundaryEvent beCopy = copyBoundaryEvent(be);
                        container.getFlowElements().add(beCopy);
                        _outgoingFlows.put(beCopy, _outgoingFlows.get(be));
                        toRemove.add(be);
                        _outgoingFlows.remove(be);
                    }
                }
            }
            for (BoundaryEvent be : toRemove) {
                process.getFlowElements().remove(be);
            }
        }
    }
    reconnectFlows();
}
Also used : RootElement(org.eclipse.bpmn2.RootElement) BoundaryEvent(org.eclipse.bpmn2.BoundaryEvent) FlowElement(org.eclipse.bpmn2.FlowElement) ArrayList(java.util.ArrayList) FlowElementsContainer(org.eclipse.bpmn2.FlowElementsContainer) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Process(org.eclipse.bpmn2.Process)

Example 4 with FlowElement

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

the class Bpmn2JsonUnmarshaller method updateIDs.

public void updateIDs(Definitions def) {
    // data object id update
    List<RootElement> rootElements = def.getRootElements();
    for (RootElement root : rootElements) {
        if (root instanceof Process) {
            Process process = (Process) root;
            if (process.getId() != null) {
                String processId = process.getId().trim();
                processId = processId.replaceAll("\\s", "");
                process.setId(processId);
            }
            List<FlowElement> flowElements = process.getFlowElements();
            for (FlowElement fe : flowElements) {
                if (fe instanceof DataObject) {
                    DataObject da = (DataObject) fe;
                    if (da.getName() != null) {
                        String daId = da.getName().trim();
                        daId = daId.replaceAll("\\W", "");
                        da.setId(daId);
                    }
                }
            }
        }
    }
}
Also used : RootElement(org.eclipse.bpmn2.RootElement) DataObject(org.eclipse.bpmn2.DataObject) FlowElement(org.eclipse.bpmn2.FlowElement) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Process(org.eclipse.bpmn2.Process)

Example 5 with FlowElement

use of org.osate.aadl2.FlowElement 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)

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