Search in sources :

Example 11 with FlowElement

use of org.eclipse.bpmn2.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.eclipse.bpmn2.FlowElement in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method setDefaultGateway.

private void setDefaultGateway(FlowElement fe, List<SequenceFlow> sqList) {
    Iterator<FeatureMap.Entry> iter = fe.getAnyAttribute().iterator();
    while (iter.hasNext()) {
        FeatureMap.Entry entry = iter.next();
        if (entry.getEStructuralFeature().getName().equals("dg")) {
            for (SequenceFlow newFlow : sqList) {
                String entryValue = (String) entry.getValue();
                String entryValueId = "";
                String[] entryValueParts = entryValue.split(" : ");
                if (entryValueParts.length == 1) {
                    entryValueId = entryValueParts[0];
                } else if (entryValueParts.length > 1) {
                    entryValueId = entryValueParts[1];
                }
                if (newFlow.getId().equals(entryValueId)) {
                    if (fe instanceof ExclusiveGateway) {
                        ((ExclusiveGateway) fe).setDefault(newFlow);
                    } else if (fe instanceof InclusiveGateway) {
                        ((InclusiveGateway) fe).setDefault(newFlow);
                    }
                    if (newFlow.getConditionExpression() == null) {
                        FormalExpression expr = Bpmn2Factory.eINSTANCE.createFormalExpression();
                        expr.setBody("");
                        newFlow.setConditionExpression(expr);
                    }
                }
            }
        }
    }
}
Also used : FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) ExclusiveGateway(org.eclipse.bpmn2.ExclusiveGateway) Entry(java.util.Map.Entry) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) InclusiveGateway(org.eclipse.bpmn2.InclusiveGateway) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) FormalExpression(org.eclipse.bpmn2.FormalExpression)

Example 13 with FlowElement

use of org.eclipse.bpmn2.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 14 with FlowElement

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

the class Bpmn2JsonUnmarshallerTest method testUpdateIDs.

@Test
public void testUpdateIDs() {
    Definitions defs = mock(Definitions.class);
    Process process = mock(Process.class);
    DataObject flowElement = mock(DataObject.class);
    final Value<String> processId = new Value<>("Project:Bad Id");
    final Value<String> flowElementId = new Value<>("Bad Flow Id!");
    when(process.getId()).thenAnswer((m) -> processId.get());
    doAnswer((m) -> {
        processId.set(m.getArgumentAt(0, String.class));
        return null;
    }).when(process).setId(anyString());
    when(flowElement.getId()).thenAnswer((m) -> flowElementId.get());
    when(flowElement.getName()).thenAnswer((m) -> flowElementId.get());
    doAnswer((m) -> {
        flowElementId.set(m.getArgumentAt(0, String.class));
        return null;
    }).when(flowElement).setId(anyString());
    when(process.getFlowElements()).thenReturn(Arrays.asList(flowElement));
    when(defs.getRootElements()).thenReturn(Arrays.asList(process));
    tested.updateIDs(defs);
    assertEquals("Project:BadId", processId.get());
    assertEquals("BadFlowId", flowElementId.get());
}
Also used : DataObject(org.eclipse.bpmn2.DataObject) Definitions(org.eclipse.bpmn2.Definitions) Process(org.eclipse.bpmn2.Process) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 15 with FlowElement

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

the class Bpmn2JsonUnmarshaller method revisitTaskAssociations.

public void revisitTaskAssociations(Definitions def) {
    List<RootElement> rootElements = def.getRootElements();
    for (RootElement root : rootElements) {
        if (root instanceof Process) {
            Process process = (Process) root;
            List<FlowElement> flowElements = process.getFlowElements();
            for (FlowElement fe : flowElements) {
                if (fe instanceof Task) {
                    Task t = (Task) fe;
                    if (t.getDataInputAssociations() != null) {
                        List<DataInputAssociation> inputList = t.getDataInputAssociations();
                        if (inputList != null) {
                            for (DataInputAssociation input : inputList) {
                                List<ItemAwareElement> sourceRef = input.getSourceRef();
                                if (sourceRef != null) {
                                    for (ItemAwareElement iae : sourceRef) {
                                        String[] iaeParts = iae.getId().split("\\.");
                                        if (iaeParts.length > 1) {
                                        // FormalExpression dataInputTransformationExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
                                        // dataInputTransformationExpression.setBody(iae.getId());
                                        // input.setTransformation(dataInputTransformationExpression);
                                        // iae.setId(iaeParts[0]);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (t.getDataOutputAssociations() != null) {
                        List<DataOutputAssociation> outputList = t.getDataOutputAssociations();
                        if (outputList != null) {
                            for (DataOutputAssociation output : outputList) {
                                ItemAwareElement targetEle = output.getTargetRef();
                                if (targetEle != null) {
                                    String[] targetEleParts = targetEle.getId().split("\\.");
                                    if (targetEleParts.length > 1) {
                                    // FormalExpression dataOutputTransformationExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
                                    // dataOutputTransformationExpression.setBody(targetEle.getId());
                                    // output.setTransformation(dataOutputTransformationExpression);
                                    // targetEle.setId(targetEleParts[0]);
                                    }
                                }
                            }
                        }
                    }
                    if (t.getIoSpecification() != null) {
                        InputOutputSpecification ios = t.getIoSpecification();
                        if (ios.getInputSets() == null || ios.getInputSets().size() < 1) {
                            InputSet inset = Bpmn2Factory.eINSTANCE.createInputSet();
                            ios.getInputSets().add(inset);
                        }
                        if (ios.getOutputSets() == null) {
                            if (ios.getOutputSets() == null || ios.getOutputSets().size() < 1) {
                                OutputSet outset = Bpmn2Factory.eINSTANCE.createOutputSet();
                                ios.getOutputSets().add(outset);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : OutputSet(org.eclipse.bpmn2.OutputSet) ServiceTask(org.eclipse.bpmn2.ServiceTask) ReceiveTask(org.eclipse.bpmn2.ReceiveTask) SendTask(org.eclipse.bpmn2.SendTask) GlobalTask(org.eclipse.bpmn2.GlobalTask) BusinessRuleTask(org.eclipse.bpmn2.BusinessRuleTask) Task(org.eclipse.bpmn2.Task) ScriptTask(org.eclipse.bpmn2.ScriptTask) UserTask(org.eclipse.bpmn2.UserTask) InputOutputSpecification(org.eclipse.bpmn2.InputOutputSpecification) ItemAwareElement(org.eclipse.bpmn2.ItemAwareElement) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Process(org.eclipse.bpmn2.Process) InputSet(org.eclipse.bpmn2.InputSet) RootElement(org.eclipse.bpmn2.RootElement) FlowElement(org.eclipse.bpmn2.FlowElement) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation)

Aggregations

FlowElement (org.eclipse.bpmn2.FlowElement)27 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)19 SubProcess (org.eclipse.bpmn2.SubProcess)19 Process (org.eclipse.bpmn2.Process)16 FlowElementsContainer (org.eclipse.bpmn2.FlowElementsContainer)14 RootElement (org.eclipse.bpmn2.RootElement)14 FeatureMap (org.eclipse.emf.ecore.util.FeatureMap)13 ArrayList (java.util.ArrayList)12 Entry (java.util.Map.Entry)12 SimpleFeatureMapEntry (org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry)12 CallActivity (org.eclipse.bpmn2.CallActivity)8 DataObject (org.eclipse.bpmn2.DataObject)8 SequenceFlow (org.eclipse.bpmn2.SequenceFlow)8 Activity (org.eclipse.bpmn2.Activity)7 FlowNode (org.eclipse.bpmn2.FlowNode)7 Bounds (org.eclipse.dd.dc.Bounds)7 Artifact (org.eclipse.bpmn2.Artifact)6 BoundaryEvent (org.eclipse.bpmn2.BoundaryEvent)6 DataInputAssociation (org.eclipse.bpmn2.DataInputAssociation)6 DataOutputAssociation (org.eclipse.bpmn2.DataOutputAssociation)6