Search in sources :

Example 6 with Event

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

use of org.eclipse.bpmn2.Event 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)

Example 8 with Event

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

the class Bpmn2JsonUnmarshaller method applySubProcessProperties.

protected void applySubProcessProperties(SubProcess sp, Map<String, String> properties) {
    if (properties.get("name") != null) {
        sp.setName(StringEscapeUtils.escapeXml(properties.get("name")).replaceAll("\\r\\n|\\r|\\n", " "));
        // add unescaped and untouched name value as extension element as well
        Utils.setMetaDataExtensionValue(sp, "elementname", wrapInCDATABlock(properties.get("name").replaceAll("\\\\n", "\n")));
    } else {
        sp.setName("");
    }
    // process on-entry and on-exit actions as custom elements
    applyOnEntryActions(sp, properties);
    applyOnExitActions(sp, properties);
    // isAsync metadata
    if (properties.get("isasync") != null && properties.get("isasync").length() > 0 && properties.get("isasync").equals("true")) {
        Utils.setMetaDataExtensionValue(sp, "customAsync", wrapInCDATABlock(properties.get("isasync")));
    }
    if (sp.getIoSpecification() == null) {
        InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
        sp.setIoSpecification(iospec);
    }
    parseAssignmentsInfo(properties);
    // data input set
    applyDataInputProperties(sp, properties, new HashMap<String, DataInput>());
    // data output set
    applyDataOutputProperties(sp, properties);
    // assignments
    if (properties.get("assignments") != null && properties.get("assignments").length() > 0 && sp.getIoSpecification() != null) {
        String[] allAssignments = properties.get("assignments").split(",\\s*");
        for (String assignment : allAssignments) {
            if (assignment.contains("=")) {
                String[] assignmentParts = assignment.split("=\\s*");
                String fromPart = assignmentParts[0];
                if (fromPart.startsWith("[din]")) {
                    fromPart = fromPart.substring(5, fromPart.length());
                }
                DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
                if (sp.getIoSpecification() != null && sp.getIoSpecification().getDataOutputs() != null) {
                    List<DataInput> dataInputs = sp.getIoSpecification().getDataInputs();
                    for (DataInput di : dataInputs) {
                        if (di.getId().equals(sp.getId() + "_" + fromPart + "InputX")) {
                            dia.setTargetRef(di);
                            if (di.getName().equals("TaskName")) {
                                break;
                            }
                        }
                    }
                }
                Assignment a = Bpmn2Factory.eINSTANCE.createAssignment();
                FormalExpression fromExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
                if (assignmentParts.length > 1) {
                    String replacer = decodeAssociationValue(assignmentParts[1]);
                    fromExpression.setBody(wrapInCDATABlock(replacer));
                } else {
                    fromExpression.setBody("");
                }
                FormalExpression toExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
                toExpression.setBody(dia.getTargetRef().getId());
                a.setFrom(fromExpression);
                a.setTo(toExpression);
                dia.getAssignment().add(a);
                sp.getDataInputAssociations().add(dia);
            // } else if(assignment.contains("<->")) {
            // String[] assignmentParts = assignment.split( "<->\\s*" );
            // DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
            // DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
            // 
            // ItemAwareElement ie = Bpmn2Factory.eINSTANCE.createItemAwareElement();
            // ie.setId(assignmentParts[0]);
            // dia.getSourceRef().add(ie);
            // doa.setTargetRef(ie);
            // 
            // List<DataInput> dataInputs = sp.getIoSpecification().getDataInputs();
            // for(DataInput di : dataInputs) {
            // if(di.getId().equals(sp.getId() + "_" + assignmentParts[1] + "InputX")) {
            // dia.setTargetRef(di);
            // break;
            // }
            // }
            // List<DataOutput> dataOutputs = sp.getIoSpecification().getDataOutputs();
            // for(DataOutput dout : dataOutputs) {
            // if(dout.getId().equals(sp.getId() + "_" + assignmentParts[1] + "OutputX")) {
            // doa.getSourceRef().add(dout);
            // break;
            // }
            // }
            // 
            // sp.getDataInputAssociations().add(dia);
            // sp.getDataOutputAssociations().add(doa);
            } else if (assignment.contains("->")) {
                String[] assignmentParts = assignment.split("->\\s*");
                String fromPart = assignmentParts[0];
                boolean isDataInput = false;
                boolean isDataOutput = false;
                if (fromPart.startsWith("[din]")) {
                    fromPart = fromPart.substring(5, fromPart.length());
                    isDataInput = true;
                }
                if (fromPart.startsWith("[dout]")) {
                    fromPart = fromPart.substring(6, fromPart.length());
                    isDataOutput = true;
                }
                List<DataOutput> dataOutputs = sp.getIoSpecification().getDataOutputs();
                if (isDataOutput) {
                    DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
                    for (DataOutput dout : dataOutputs) {
                        if (dout.getId().equals(sp.getId() + "_" + fromPart + "OutputX")) {
                            doa.getSourceRef().add(dout);
                            break;
                        }
                    }
                    ItemAwareElement ie = Bpmn2Factory.eINSTANCE.createItemAwareElement();
                    ie.setId(assignmentParts[1]);
                    doa.setTargetRef(ie);
                    sp.getDataOutputAssociations().add(doa);
                } else if (isDataInput) {
                    DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
                    // association from process var to dataInput var
                    ItemAwareElement ie = Bpmn2Factory.eINSTANCE.createItemAwareElement();
                    ie.setId(fromPart);
                    dia.getSourceRef().add(ie);
                    List<DataInput> dataInputs = sp.getIoSpecification().getDataInputs();
                    for (DataInput di : dataInputs) {
                        if (di.getId().equals(sp.getId() + "_" + assignmentParts[1] + "InputX")) {
                            dia.setTargetRef(di);
                            break;
                        }
                    }
                    sp.getDataInputAssociations().add(dia);
                }
            } else {
            // TODO throw exception here?
            }
        }
    }
    // loop characteristics input
    if (properties.get("mitrigger") != null && properties.get("mitrigger").equals("true")) {
        if (properties.get("multipleinstancecollectioninput") != null && properties.get("multipleinstancecollectioninput").length() > 0) {
            String miDataInputStr = properties.get("multipleinstancedatainput");
            if (miDataInputStr == null || miDataInputStr.length() < 1) {
                miDataInputStr = "defaultDataInput";
            }
            if (sp.getIoSpecification() == null) {
                InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
                sp.setIoSpecification(iospec);
            } else {
                sp.getIoSpecification().getDataInputs().clear();
                sp.getIoSpecification().getDataOutputs().clear();
                sp.getDataInputAssociations().clear();
                sp.getDataOutputAssociations().clear();
            }
            InputSet inset = sp.getIoSpecification().getInputSets().get(0);
            DataInput multiInput = Bpmn2Factory.eINSTANCE.createDataInput();
            multiInput.setId(sp.getId() + "_" + "input");
            multiInput.setName(properties.get("multipleinstancecollectioninput"));
            sp.getIoSpecification().getDataInputs().add(multiInput);
            inset.getDataInputRefs().add(multiInput);
            DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
            ItemAwareElement ie = Bpmn2Factory.eINSTANCE.createItemAwareElement();
            ie.setId(properties.get("multipleinstancecollectioninput"));
            dia.getSourceRef().add(ie);
            dia.setTargetRef(multiInput);
            sp.getDataInputAssociations().add(dia);
            MultiInstanceLoopCharacteristics loopCharacteristics = Bpmn2Factory.eINSTANCE.createMultiInstanceLoopCharacteristics();
            loopCharacteristics.setLoopDataInputRef(multiInput);
            DataInput din = Bpmn2Factory.eINSTANCE.createDataInput();
            din.setId(miDataInputStr);
            ItemDefinition itemDef = Bpmn2Factory.eINSTANCE.createItemDefinition();
            itemDef.setId(sp.getId() + "_" + "multiInstanceItemType");
            din.setItemSubjectRef(itemDef);
            _subprocessItemDefs.put(itemDef.getId(), itemDef);
            loopCharacteristics.setInputDataItem(din);
            // loop characteristics output
            if (properties.get("multipleinstancecollectionoutput") != null && properties.get("multipleinstancecollectionoutput").length() > 0) {
                String miDataOutputStr = properties.get("multipleinstancedataoutput");
                if (miDataOutputStr == null || miDataOutputStr.length() < 1) {
                    miDataOutputStr = "defaultDataOutput";
                }
                OutputSet outset = sp.getIoSpecification().getOutputSets().get(0);
                DataOutput multiOutput = Bpmn2Factory.eINSTANCE.createDataOutput();
                multiOutput.setId(sp.getId() + "_" + "output");
                multiOutput.setName(properties.get("multipleinstancecollectionoutput"));
                sp.getIoSpecification().getDataOutputs().add(multiOutput);
                outset.getDataOutputRefs().add(multiOutput);
                DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
                ItemAwareElement ie2 = Bpmn2Factory.eINSTANCE.createItemAwareElement();
                ie2.setId(properties.get("multipleinstancecollectionoutput"));
                doa.getSourceRef().add(multiOutput);
                doa.setTargetRef(ie2);
                sp.getDataOutputAssociations().add(doa);
                loopCharacteristics.setLoopDataOutputRef(multiOutput);
                DataOutput don = Bpmn2Factory.eINSTANCE.createDataOutput();
                don.setId(miDataOutputStr);
                ItemDefinition itemDef2 = Bpmn2Factory.eINSTANCE.createItemDefinition();
                itemDef2.setId(sp.getId() + "_" + "multiInstanceItemType");
                don.setItemSubjectRef(itemDef2);
                _subprocessItemDefs.put(itemDef2.getId(), itemDef2);
                loopCharacteristics.setOutputDataItem(don);
            }
            // loop characteristics completion condition
            if (properties.get("multipleinstancecompletioncondition") != null && !properties.get("multipleinstancecompletioncondition").isEmpty()) {
                FormalExpression expr = Bpmn2Factory.eINSTANCE.createFormalExpression();
                expr.setBody(properties.get("multipleinstancecompletioncondition"));
                loopCharacteristics.setCompletionCondition(expr);
            }
            sp.setLoopCharacteristics(loopCharacteristics);
        } else {
            MultiInstanceLoopCharacteristics loopCharacteristics = Bpmn2Factory.eINSTANCE.createMultiInstanceLoopCharacteristics();
            sp.setLoopCharacteristics(loopCharacteristics);
        }
    }
    // properties
    if (properties.get("vardefs") != null && properties.get("vardefs").length() > 0) {
        String[] vardefs = properties.get("vardefs").split(",\\s*");
        for (String vardef : vardefs) {
            Property prop = Bpmn2Factory.eINSTANCE.createProperty();
            ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition();
            // check if we define a structure ref in the definition
            if (vardef.contains(":")) {
                String[] vardefParts = vardef.split(":\\s*");
                prop.setId(vardefParts[0]);
                itemdef.setId("_" + prop.getId() + "Item");
                boolean haveKPI = false;
                String kpiValue = "";
                if (vardefParts.length == 3) {
                    itemdef.setStructureRef(vardefParts[1]);
                    if (vardefParts[2].equals("true")) {
                        haveKPI = true;
                        kpiValue = vardefParts[2];
                    }
                }
                if (vardefParts.length == 2) {
                    if (vardefParts[1].equals("true") || vardefParts[1].equals("false")) {
                        if (vardefParts[1].equals("true")) {
                            haveKPI = true;
                            kpiValue = vardefParts[1];
                        }
                    } else {
                        itemdef.setStructureRef(vardefParts[1]);
                    }
                }
                if (haveKPI) {
                    Utils.setMetaDataExtensionValue(prop, "customKPI", wrapInCDATABlock(kpiValue));
                }
            } else {
                prop.setId(vardef);
                itemdef.setId("_" + prop.getId() + "Item");
            }
            prop.setItemSubjectRef(itemdef);
            sp.getProperties().add(prop);
            _subprocessItemDefs.put(itemdef.getId(), itemdef);
        }
    }
    // event subprocess
    if (sp instanceof EventSubprocess) {
        sp.setTriggeredByEvent(true);
    }
    // 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 not supported in bpsim 1.0
        // } else if(properties.get("distributiontype").equals("random")) {
        // RandomDistributionType randomDistributionType = BpsimFactory.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);
        }
        // }
        if (properties.get("waittime") != null) {
            Parameter waittimeParam = BpsimFactory.eINSTANCE.createParameter();
            FloatingParameterType waittimeParamValue = BpsimFactory.eINSTANCE.createFloatingParameterType();
            DecimalFormat twoDForm = new DecimalFormat("#.##");
            waittimeParamValue.setValue(Double.valueOf(twoDForm.format(Double.valueOf(properties.get("waittime")))));
            waittimeParam.getParameterValue().add(waittimeParamValue);
            timeParams.setWaitTime(waittimeParam);
        }
        timeParams.setProcessingTime(processingTimeParam);
        if (_simulationElementParameters.containsKey(sp.getId())) {
            _simulationElementParameters.get(sp.getId()).add(timeParams);
        } else {
            List<EObject> values = new ArrayList<EObject>();
            values.add(timeParams);
            _simulationElementParameters.put(sp.getId(), values);
        }
    }
    CostParameters costParameters = BpsimFactory.eINSTANCE.createCostParameters();
    if (properties.get("unitcost") != null && properties.get("unitcost").length() > 0) {
        Parameter unitcostParam = BpsimFactory.eINSTANCE.createParameter();
        FloatingParameterType unitCostParameterValue = BpsimFactory.eINSTANCE.createFloatingParameterType();
        unitCostParameterValue.setValue(new Double(properties.get("unitcost")));
        unitcostParam.getParameterValue().add(unitCostParameterValue);
        costParameters.setUnitCost(unitcostParam);
    }
    // }
    if (_simulationElementParameters.containsKey(sp.getId())) {
        _simulationElementParameters.get(sp.getId()).add(costParameters);
    } else {
        List<EObject> values = new ArrayList<EObject>();
        values.add(costParameters);
        _simulationElementParameters.put(sp.getId(), values);
    }
}
Also used : DataOutput(org.eclipse.bpmn2.DataOutput) CostParameters(bpsim.CostParameters) NormalDistributionType(bpsim.NormalDistributionType) DecimalFormat(java.text.DecimalFormat) ItemDefinition(org.eclipse.bpmn2.ItemDefinition) ArrayList(java.util.ArrayList) Assignment(org.eclipse.bpmn2.Assignment) MultiInstanceLoopCharacteristics(org.eclipse.bpmn2.MultiInstanceLoopCharacteristics) EventSubprocess(org.eclipse.bpmn2.EventSubprocess) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) List(java.util.List) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) Property(org.eclipse.bpmn2.Property) UniformDistributionType(bpsim.UniformDistributionType) OutputSet(org.eclipse.bpmn2.OutputSet) InputOutputSpecification(org.eclipse.bpmn2.InputOutputSpecification) ItemAwareElement(org.eclipse.bpmn2.ItemAwareElement) FormalExpression(org.eclipse.bpmn2.FormalExpression) FloatingParameterType(bpsim.FloatingParameterType) DataInput(org.eclipse.bpmn2.DataInput) InputSet(org.eclipse.bpmn2.InputSet) PoissonDistributionType(bpsim.PoissonDistributionType) Parameter(bpsim.Parameter) TimeParameters(bpsim.TimeParameters) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation)

Example 9 with Event

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

the class Bpmn2JsonUnmarshaller method revisitCatchEvents.

/**
 * Updates event definitions for all catch events.
 * @param def Definitions
 */
public void revisitCatchEvents(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) {
            setCatchEventsInfo((Process) root, def, toAddSignals, toAddErrors, toAddEscalations, toAddMessages, toAddItemDefinitions);
        }
    }
    for (Lane lane : _lanes) {
        setCatchEventsInfoForLanes(lane, def, 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)

Example 10 with Event

use of org.eclipse.bpmn2.Event 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

BPMNGeneralSet (org.kie.workbench.common.stunner.bpmn.definition.property.general.BPMNGeneralSet)28 Test (org.junit.Test)18 EventDefinition (org.eclipse.bpmn2.EventDefinition)15 CompensateEventDefinition (org.eclipse.bpmn2.CompensateEventDefinition)14 SignalEventDefinition (org.eclipse.bpmn2.SignalEventDefinition)14 ArrayList (java.util.ArrayList)13 List (java.util.List)13 ConditionalEventDefinition (org.eclipse.bpmn2.ConditionalEventDefinition)13 ErrorEventDefinition (org.eclipse.bpmn2.ErrorEventDefinition)13 EscalationEventDefinition (org.eclipse.bpmn2.EscalationEventDefinition)13 MessageEventDefinition (org.eclipse.bpmn2.MessageEventDefinition)13 ThrowEventPropertyWriter (org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.ThrowEventPropertyWriter)13 TimerEventDefinition (org.eclipse.bpmn2.TimerEventDefinition)12 Event (io.requery.test.model3.Event)9 UUID (java.util.UUID)9 EndEvent (org.eclipse.bpmn2.EndEvent)9 CatchEventPropertyWriter (org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.CatchEventPropertyWriter)9 CatchEvent (org.eclipse.bpmn2.CatchEvent)8 DataIOSet (org.kie.workbench.common.stunner.bpmn.definition.property.dataio.DataIOSet)8 MessageRef (org.kie.workbench.common.stunner.bpmn.definition.property.event.message.MessageRef)8