Search in sources :

Example 1 with CatchEvent

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

the class Bpmn2JsonMarshaller method setCatchEventProperties.

private void setCatchEventProperties(CatchEvent event, Map<String, Object> properties, Definitions def) {
    if (event.getOutputSet() != null) {
        List<DataOutput> dataOutputs = event.getOutputSet().getDataOutputRefs();
        StringBuffer doutbuff = new StringBuffer();
        for (DataOutput dout : dataOutputs) {
            doutbuff.append(dout.getName());
            String dtype = getAnyAttributeValue(dout, "dtype");
            if (dtype != null && !dtype.isEmpty()) {
                doutbuff.append(":").append(dtype);
            }
            doutbuff.append(",");
        }
        if (doutbuff.length() > 0) {
            doutbuff.setLength(doutbuff.length() - 1);
        }
        String dataoutput = doutbuff.toString();
        properties.put(DATAOUTPUT, dataoutput);
        List<DataOutputAssociation> outputAssociations = event.getDataOutputAssociation();
        StringBuffer doutassociationbuff = new StringBuffer();
        for (DataOutputAssociation doa : outputAssociations) {
            String doaName = ((DataOutput) doa.getSourceRef().get(0)).getName();
            if (doaName != null && doaName.length() > 0) {
                doutassociationbuff.append("[dout]" + ((DataOutput) doa.getSourceRef().get(0)).getName());
                doutassociationbuff.append("->");
                doutassociationbuff.append(doa.getTargetRef().getId());
                doutassociationbuff.append(",");
            }
        }
        if (doutassociationbuff.length() > 0) {
            doutassociationbuff.setLength(doutassociationbuff.length() - 1);
        }
        String assignments = doutassociationbuff.toString();
        properties.put(DATAOUTPUTASSOCIATIONS, assignments);
        setAssignmentsInfoProperty(null, null, dataoutput, null, assignments, properties);
    }
    // event definitions
    List<EventDefinition> eventdefs = event.getEventDefinitions();
    for (EventDefinition ed : eventdefs) {
        if (ed instanceof TimerEventDefinition) {
            setTimerEventProperties((TimerEventDefinition) ed, properties);
        } else if (ed instanceof SignalEventDefinition) {
            if (((SignalEventDefinition) ed).getSignalRef() != null) {
                // find signal with the corresponding id
                boolean foundSignalRef = false;
                List<RootElement> rootElements = def.getRootElements();
                for (RootElement re : rootElements) {
                    if (re instanceof Signal) {
                        if (re.getId().equals(((SignalEventDefinition) ed).getSignalRef())) {
                            properties.put("signalref", ((Signal) re).getName());
                            foundSignalRef = true;
                        }
                    }
                }
                if (!foundSignalRef) {
                    properties.put(SIGNALREF, "");
                }
            } else {
                properties.put(SIGNALREF, "");
            }
        } else if (ed instanceof ErrorEventDefinition) {
            if (((ErrorEventDefinition) ed).getErrorRef() != null && ((ErrorEventDefinition) ed).getErrorRef().getErrorCode() != null) {
                properties.put(ERRORREF, ((ErrorEventDefinition) ed).getErrorRef().getErrorCode());
            } else {
                properties.put(ERRORREF, "");
            }
        } else if (ed instanceof ConditionalEventDefinition) {
            FormalExpression conditionalExp = (FormalExpression) ((ConditionalEventDefinition) ed).getCondition();
            if (conditionalExp != null) {
                setConditionExpressionProperties(conditionalExp, properties, "drools");
            }
        } else if (ed instanceof EscalationEventDefinition) {
            if (((EscalationEventDefinition) ed).getEscalationRef() != null) {
                Escalation esc = ((EscalationEventDefinition) ed).getEscalationRef();
                if (esc.getEscalationCode() != null && esc.getEscalationCode().length() > 0) {
                    properties.put(ESCALATIONCODE, esc.getEscalationCode());
                } else {
                    properties.put(ESCALATIONCODE, "");
                }
            }
        } else if (ed instanceof MessageEventDefinition) {
            if (((MessageEventDefinition) ed).getMessageRef() != null) {
                Message msg = ((MessageEventDefinition) ed).getMessageRef();
                properties.put(MESSAGEREF, msg.getName());
            }
        } else if (ed instanceof CompensateEventDefinition) {
            if (((CompensateEventDefinition) ed).getActivityRef() != null) {
                Activity act = ((CompensateEventDefinition) ed).getActivityRef();
                properties.put(ACTIVITYREF, act.getName());
            }
        }
    }
}
Also used : DataOutput(org.eclipse.bpmn2.DataOutput) Message(org.eclipse.bpmn2.Message) Escalation(org.eclipse.bpmn2.Escalation) Activity(org.eclipse.bpmn2.Activity) CallActivity(org.eclipse.bpmn2.CallActivity) EventDefinition(org.eclipse.bpmn2.EventDefinition) ConditionalEventDefinition(org.eclipse.bpmn2.ConditionalEventDefinition) EscalationEventDefinition(org.eclipse.bpmn2.EscalationEventDefinition) TerminateEventDefinition(org.eclipse.bpmn2.TerminateEventDefinition) ErrorEventDefinition(org.eclipse.bpmn2.ErrorEventDefinition) CancelEventDefinition(org.eclipse.bpmn2.CancelEventDefinition) MessageEventDefinition(org.eclipse.bpmn2.MessageEventDefinition) SignalEventDefinition(org.eclipse.bpmn2.SignalEventDefinition) CompensateEventDefinition(org.eclipse.bpmn2.CompensateEventDefinition) TimerEventDefinition(org.eclipse.bpmn2.TimerEventDefinition) FormalExpression(org.eclipse.bpmn2.FormalExpression) Signal(org.eclipse.bpmn2.Signal) RootElement(org.eclipse.bpmn2.RootElement) EscalationEventDefinition(org.eclipse.bpmn2.EscalationEventDefinition) ErrorEventDefinition(org.eclipse.bpmn2.ErrorEventDefinition) SignalEventDefinition(org.eclipse.bpmn2.SignalEventDefinition) ConditionalEventDefinition(org.eclipse.bpmn2.ConditionalEventDefinition) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) ArrayList(java.util.ArrayList) List(java.util.List) EList(org.eclipse.emf.common.util.EList) MessageEventDefinition(org.eclipse.bpmn2.MessageEventDefinition) TimerEventDefinition(org.eclipse.bpmn2.TimerEventDefinition) CompensateEventDefinition(org.eclipse.bpmn2.CompensateEventDefinition)

Example 2 with CatchEvent

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

the class Bpmn2JsonUnmarshaller method revisitCatchEVentsConvertToBoundaryExecute.

private void revisitCatchEVentsConvertToBoundaryExecute(Process process, FlowElementsContainer subContainer, List<CatchEvent> catchEventsToRemove, Map<BoundaryEvent, List<String>> boundaryEventsToAdd) {
    FlowElementsContainer container = subContainer != null ? subContainer : process;
    List<FlowElement> flowElements = container.getFlowElements();
    for (FlowElement fe : flowElements) {
        if (fe instanceof CatchEvent) {
            // check if we have an outgoing connection to this catch event from an activity
            for (Entry<Object, List<String>> entry : _outgoingFlows.entrySet()) {
                for (String flowId : entry.getValue()) {
                    if (entry.getKey() instanceof Activity && flowId.equals(fe.getId())) {
                        CatchEvent ce = (CatchEvent) fe;
                        EventDefinition ed = null;
                        if (ce.getEventDefinitions() != null && ce.getEventDefinitions().size() > 0) {
                            ed = ce.getEventDefinitions().get(0);
                        }
                        BoundaryEvent be = Bpmn2Factory.eINSTANCE.createBoundaryEvent();
                        if (ed != null && ed instanceof ErrorEventDefinition) {
                            be.setCancelActivity(true);
                        } else {
                            Iterator<FeatureMap.Entry> iter = ce.getAnyAttribute().iterator();
                            while (iter.hasNext()) {
                                FeatureMap.Entry entry2 = iter.next();
                                if (entry2.getEStructuralFeature().getName().equals("boundaryca")) {
                                    String boundaryceVal = (String) entry2.getValue();
                                    be.setCancelActivity(Boolean.parseBoolean(boundaryceVal));
                                }
                            }
                        }
                        if (ce.getDataOutputs() != null) {
                            be.getDataOutputs().addAll(ce.getDataOutputs());
                        }
                        if (ce.getDataOutputAssociation() != null) {
                            be.getDataOutputAssociation().addAll(ce.getDataOutputAssociation());
                        }
                        if (ce.getOutputSet() != null) {
                            be.setOutputSet(ce.getOutputSet());
                        }
                        if (ce.getEventDefinitions() != null) {
                            be.getEventDefinitions().addAll(ce.getEventDefinitions());
                        }
                        if (ce.getEventDefinitionRefs() != null) {
                            be.getEventDefinitionRefs().addAll(ce.getEventDefinitionRefs());
                        }
                        if (ce.getProperties() != null) {
                            be.getProperties().addAll(ce.getProperties());
                        }
                        if (ce.getAnyAttribute() != null) {
                            be.getAnyAttribute().addAll(ce.getAnyAttribute());
                        }
                        if (ce.getOutgoing() != null) {
                            be.getOutgoing().addAll(ce.getOutgoing());
                        }
                        if (ce.getIncoming() != null) {
                            be.getIncoming().addAll(ce.getIncoming());
                        }
                        if (ce.getProperties() != null) {
                            be.getProperties().addAll(ce.getProperties());
                        }
                        be.getDocumentation().addAll(ce.getDocumentation());
                        be.setName(ce.getName());
                        String ceElementName = Utils.getMetaDataValue(ce.getExtensionValues(), "elementname");
                        if (ceElementName != null) {
                            Utils.setMetaDataExtensionValue(be, "elementname", ceElementName);
                        }
                        be.setId(ce.getId());
                        be.setAttachedToRef(((Activity) entry.getKey()));
                        ((Activity) entry.getKey()).getBoundaryEventRefs().add(be);
                        catchEventsToRemove.add(ce);
                        boundaryEventsToAdd.put(be, _outgoingFlows.get(ce));
                    }
                }
            }
        } else if (fe instanceof FlowElementsContainer) {
            revisitCatchEVentsConvertToBoundaryExecute(process, (FlowElementsContainer) fe, catchEventsToRemove, boundaryEventsToAdd);
        }
    }
    if (catchEventsToRemove.size() > 0) {
        for (CatchEvent ce : catchEventsToRemove) {
            boolean removed = container.getFlowElements().remove(ce);
            _outgoingFlows.remove(ce);
        }
    }
    if (boundaryEventsToAdd.size() > 0) {
        Iterator<BoundaryEvent> boundaryToAddIterator = boundaryEventsToAdd.keySet().iterator();
        while (boundaryToAddIterator.hasNext()) {
            BoundaryEvent bToAdd = boundaryToAddIterator.next();
            container.getFlowElements().add(bToAdd);
            _outgoingFlows.put(bToAdd, boundaryEventsToAdd.get(bToAdd));
        }
    }
}
Also used : BoundaryEvent(org.eclipse.bpmn2.BoundaryEvent) FlowElementsContainer(org.eclipse.bpmn2.FlowElementsContainer) Activity(org.eclipse.bpmn2.Activity) CallActivity(org.eclipse.bpmn2.CallActivity) 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) Entry(java.util.Map.Entry) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) FlowElement(org.eclipse.bpmn2.FlowElement) ErrorEventDefinition(org.eclipse.bpmn2.ErrorEventDefinition) EObject(org.eclipse.emf.ecore.EObject) DataObject(org.eclipse.bpmn2.DataObject) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with CatchEvent

use of org.eclipse.bpmn2.CatchEvent 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 4 with CatchEvent

use of org.eclipse.bpmn2.CatchEvent 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 5 with CatchEvent

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

the class Bpmn2JsonUnmarshaller method applyCatchEventProperties.

protected void applyCatchEventProperties(CatchEvent event, Map<String, String> properties) {
    parseAssignmentsInfo(properties);
    if (properties.get("dataoutput") != null && !"".equals(properties.get("dataoutput"))) {
        String[] allDataOutputs = properties.get("dataoutput").split(",\\s*");
        OutputSet outSet = Bpmn2Factory.eINSTANCE.createOutputSet();
        for (String dataOutput : allDataOutputs) {
            if (dataOutput.trim().length() > 0) {
                DataOutput nextOutput = Bpmn2Factory.eINSTANCE.createDataOutput();
                String[] doutputParts = dataOutput.split(":\\s*");
                if (doutputParts.length == 2) {
                    nextOutput.setId(event.getId() + "_" + doutputParts[0]);
                    nextOutput.setName(doutputParts[0]);
                    ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
                    EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "dtype", false, false);
                    SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, doutputParts[1]);
                    nextOutput.getAnyAttribute().add(extensionEntry);
                } else {
                    nextOutput.setId(event.getId() + "_" + dataOutput);
                    nextOutput.setName(dataOutput);
                    ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
                    EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "dtype", false, false);
                    SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, "Object");
                    nextOutput.getAnyAttribute().add(extensionEntry);
                }
                event.getDataOutputs().add(nextOutput);
                outSet.getDataOutputRefs().add(nextOutput);
            }
        }
        event.setOutputSet(outSet);
    }
    if (properties.get("boundarycancelactivity") != null) {
        ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
        EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "boundaryca", false, false);
        SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("boundarycancelactivity"));
        event.getAnyAttribute().add(extensionEntry);
    }
    // data output associations
    if (properties.get("dataoutputassociations") != null && !"".equals(properties.get("dataoutputassociations"))) {
        String[] allAssociations = properties.get("dataoutputassociations").split(",\\s*");
        for (String association : allAssociations) {
            // data outputs are uni-directional
            String[] associationParts = association.split("->\\s*");
            String fromPart = associationParts[0];
            if (fromPart.startsWith("[dout]")) {
                fromPart = fromPart.substring(6, fromPart.length());
            }
            DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
            // for source refs we loop through already defined data outputs
            List<DataOutput> dataOutputs = event.getDataOutputs();
            if (dataOutputs != null) {
                for (DataOutput ddo : dataOutputs) {
                    if (ddo.getId().equals(event.getId() + "_" + fromPart)) {
                        doa.getSourceRef().add(ddo);
                    }
                }
            }
            // since we dont have the process vars defined yet..need to improvise
            ItemAwareElement e = Bpmn2Factory.eINSTANCE.createItemAwareElement();
            e.setId(associationParts[1]);
            doa.setTargetRef(e);
            event.getDataOutputAssociation().add(doa);
        }
    }
    try {
        if (event.getEventDefinitions() != null && event.getEventDefinitions().size() > 0) {
            EventDefinition ed = event.getEventDefinitions().get(0);
            if (ed instanceof TimerEventDefinition) {
                applyTimerEventProperties((TimerEventDefinition) ed, properties);
            } else if (ed instanceof SignalEventDefinition) {
                if (properties.get("signalref") != null && !"".equals(properties.get("signalref"))) {
                    ((SignalEventDefinition) ed).setSignalRef(properties.get("signalref"));
                // ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
                // EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature(
                // "http://www.jboss.org/drools", "signalrefname", false, false);
                // EStructuralFeatureImpl.SimpleFeatureMapEntry extensionEntry = new EStructuralFeatureImpl.SimpleFeatureMapEntry(extensionAttribute,
                // properties.get("signalref"));
                // ((SignalEventDefinition) event.getEventDefinitions().get(0)).getAnyAttribute().add(extensionEntry);
                }
            } else if (ed instanceof ErrorEventDefinition) {
                if (properties.get("errorref") != null && !"".equals(properties.get("errorref"))) {
                    ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
                    EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "erefname", false, false);
                    SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("errorref"));
                    ((ErrorEventDefinition) event.getEventDefinitions().get(0)).getAnyAttribute().add(extensionEntry);
                }
            } else if (ed instanceof ConditionalEventDefinition) {
                applyConditionalEventProperties((ConditionalEventDefinition) ed, properties);
            } else if (ed instanceof EscalationEventDefinition) {
                if (properties.get("escalationcode") != null && !"".equals(properties.get("escalationcode"))) {
                    ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
                    EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "esccode", false, false);
                    SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("escalationcode"));
                    ((EscalationEventDefinition) event.getEventDefinitions().get(0)).getAnyAttribute().add(extensionEntry);
                }
            } else if (ed instanceof MessageEventDefinition) {
                if (properties.get("messageref") != null && !"".equals(properties.get("messageref"))) {
                    ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
                    EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "msgref", false, false);
                    SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("messageref"));
                    ((MessageEventDefinition) event.getEventDefinitions().get(0)).getAnyAttribute().add(extensionEntry);
                }
            } else if (ed instanceof CompensateEventDefinition) {
                if (properties.get("activityref") != null && !"".equals(properties.get("activityref"))) {
                    ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
                    EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "actrefname", false, false);
                    SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("activityref"));
                    ((CompensateEventDefinition) event.getEventDefinitions().get(0)).getAnyAttribute().add(extensionEntry);
                }
            }
        }
    } catch (Exception e) {
        _logger.warn(e.getMessage());
    }
    // simulation
    if (properties.get("distributiontype") != null && properties.get("distributiontype").length() > 0) {
        TimeParameters timeParams = BpsimFactory.eINSTANCE.createTimeParameters();
        Parameter processingTimeParam = BpsimFactory.eINSTANCE.createParameter();
        if (properties.get("distributiontype").equals("normal")) {
            NormalDistributionType normalDistributionType = BpsimFactory.eINSTANCE.createNormalDistributionType();
            normalDistributionType.setStandardDeviation(Double.valueOf(properties.get("standarddeviation")));
            normalDistributionType.setMean(Double.valueOf(properties.get("mean")));
            processingTimeParam.getParameterValue().add(normalDistributionType);
        } else if (properties.get("distributiontype").equals("uniform")) {
            UniformDistributionType uniformDistributionType = BpsimFactory.eINSTANCE.createUniformDistributionType();
            uniformDistributionType.setMax(Double.valueOf(properties.get("max")));
            uniformDistributionType.setMin(Double.valueOf(properties.get("min")));
            processingTimeParam.getParameterValue().add(uniformDistributionType);
        // random distribution type not supported in bpsim 1.0
        // } else if(properties.get("distributiontype").equals("random")) {
        // RandomDistributionType randomDistributionType = DroolsFactory.eINSTANCE.createRandomDistributionType();
        // randomDistributionType.setMax(Double.valueOf(properties.get("max")));
        // randomDistributionType.setMin(Double.valueOf(properties.get("min")));
        // processingTimeParam.getParameterValue().add(randomDistributionType);
        } else if (properties.get("distributiontype").equals("poisson")) {
            PoissonDistributionType poissonDistributionType = BpsimFactory.eINSTANCE.createPoissonDistributionType();
            poissonDistributionType.setMean(Double.valueOf(properties.get("mean")));
            processingTimeParam.getParameterValue().add(poissonDistributionType);
        }
        // no specific time unit available in 1.0 bpsim - use global
        // if(properties.get("timeunit") != null) {
        // timeParams.setTimeUnit(TimeUnit.getByName(properties.get("timeunit")));
        // }
        timeParams.setProcessingTime(processingTimeParam);
        if (_simulationElementParameters.containsKey(event.getId())) {
            _simulationElementParameters.get(event.getId()).add(timeParams);
        } else {
            List<EObject> values = new ArrayList<EObject>();
            values.add(timeParams);
            _simulationElementParameters.put(event.getId(), values);
        }
    }
    if (properties.get("probability") != null && properties.get("probability").length() > 0) {
        ControlParameters controlParams = BpsimFactory.eINSTANCE.createControlParameters();
        Parameter probParam = BpsimFactory.eINSTANCE.createParameter();
        FloatingParameterType probParamValueParam = BpsimFactory.eINSTANCE.createFloatingParameterType();
        DecimalFormat twoDForm = new DecimalFormat("#.##");
        probParamValueParam.setValue(Double.valueOf(twoDForm.format(Double.valueOf(properties.get("probability")))));
        probParam.getParameterValue().add(probParamValueParam);
        controlParams.setProbability(probParam);
        if (_simulationElementParameters.containsKey(event.getId())) {
            _simulationElementParameters.get(event.getId()).add(controlParams);
        } else {
            List<EObject> values = new ArrayList<EObject>();
            values.add(controlParams);
            _simulationElementParameters.put(event.getId(), values);
        }
    }
}
Also used : DataOutput(org.eclipse.bpmn2.DataOutput) NormalDistributionType(bpsim.NormalDistributionType) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) 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) EAttributeImpl(org.eclipse.emf.ecore.impl.EAttributeImpl) EObject(org.eclipse.emf.ecore.EObject) SignalEventDefinition(org.eclipse.bpmn2.SignalEventDefinition) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) TimerEventDefinition(org.eclipse.bpmn2.TimerEventDefinition) UniformDistributionType(bpsim.UniformDistributionType) OutputSet(org.eclipse.bpmn2.OutputSet) ItemAwareElement(org.eclipse.bpmn2.ItemAwareElement) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FloatingParameterType(bpsim.FloatingParameterType) PoissonDistributionType(bpsim.PoissonDistributionType) EscalationEventDefinition(org.eclipse.bpmn2.EscalationEventDefinition) ErrorEventDefinition(org.eclipse.bpmn2.ErrorEventDefinition) ControlParameters(bpsim.ControlParameters) ConditionalEventDefinition(org.eclipse.bpmn2.ConditionalEventDefinition) Parameter(bpsim.Parameter) MessageEventDefinition(org.eclipse.bpmn2.MessageEventDefinition) ExtendedMetaData(org.eclipse.emf.ecore.util.ExtendedMetaData) CompensateEventDefinition(org.eclipse.bpmn2.CompensateEventDefinition) TimeParameters(bpsim.TimeParameters)

Aggregations

CompensateEventDefinition (org.eclipse.bpmn2.CompensateEventDefinition)6 ConditionalEventDefinition (org.eclipse.bpmn2.ConditionalEventDefinition)6 ErrorEventDefinition (org.eclipse.bpmn2.ErrorEventDefinition)6 EscalationEventDefinition (org.eclipse.bpmn2.EscalationEventDefinition)6 EventDefinition (org.eclipse.bpmn2.EventDefinition)6 MessageEventDefinition (org.eclipse.bpmn2.MessageEventDefinition)6 SignalEventDefinition (org.eclipse.bpmn2.SignalEventDefinition)6 ArrayList (java.util.ArrayList)5 Activity (org.eclipse.bpmn2.Activity)5 CallActivity (org.eclipse.bpmn2.CallActivity)5 CatchEvent (org.eclipse.bpmn2.CatchEvent)5 RootElement (org.eclipse.bpmn2.RootElement)5 TimerEventDefinition (org.eclipse.bpmn2.TimerEventDefinition)5 List (java.util.List)4 Entry (java.util.Map.Entry)4 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)4 FlowElement (org.eclipse.bpmn2.FlowElement)4 Process (org.eclipse.bpmn2.Process)4 SubProcess (org.eclipse.bpmn2.SubProcess)4 SimpleFeatureMapEntry (org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry)4