Search in sources :

Example 6 with CatchEvent

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

the class Bpmn2JsonUnmarshaller method revisitDataObjects.

public void revisitDataObjects(Definitions def) {
    List<RootElement> rootElements = def.getRootElements();
    List<ItemDefinition> itemDefinitionsToAddUnfiltered = new ArrayList<ItemDefinition>();
    List<ItemDefinition> itemDefinitionsToAddFiltered = new ArrayList<ItemDefinition>();
    for (RootElement root : rootElements) {
        if (root instanceof Process) {
            Process process = (Process) root;
            List<FlowElement> flowElements = process.getFlowElements();
            for (FlowElement fe : flowElements) {
                if (fe instanceof DataObject) {
                    DataObject da = (DataObject) fe;
                    ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition();
                    itemdef.setId("_" + da.getId() + "Item");
                    Iterator<FeatureMap.Entry> iter = da.getAnyAttribute().iterator();
                    while (iter.hasNext()) {
                        FeatureMap.Entry entry = iter.next();
                        if (entry.getEStructuralFeature().getName().equals("datype")) {
                            String typeValue = (String) entry.getValue();
                            if (typeValue != null && !typeValue.equals("None")) {
                                itemdef.setStructureRef((String) entry.getValue());
                            }
                        }
                    }
                    da.setItemSubjectRef(itemdef);
                    itemDefinitionsToAddUnfiltered.add(itemdef);
                }
            }
        }
    }
    for (ItemDefinition itemDef : itemDefinitionsToAddUnfiltered) {
        boolean foundItemDef = false;
        for (RootElement ele : rootElements) {
            if (ele instanceof ItemDefinition) {
                ItemDefinition idef = (ItemDefinition) ele;
                if (idef.getId().equals(itemDef.getId())) {
                    foundItemDef = true;
                    break;
                }
            }
        }
        if (!foundItemDef) {
            itemDefinitionsToAddFiltered.add(itemDef);
        }
    }
    for (ItemDefinition itemDefFil : itemDefinitionsToAddFiltered) {
        def.getRootElements().add(itemDefFil);
    }
    for (RootElement root : rootElements) {
        if (root instanceof Process) {
            Process process = (Process) root;
            List<Artifact> artifactElements = process.getArtifacts();
            for (Artifact af : artifactElements) {
                if (af instanceof Association) {
                    Association as = (Association) af;
                    if (as.getSourceRef() != null && as.getSourceRef() instanceof DataObject && as.getTargetRef() != null && (as.getTargetRef() instanceof Task || as.getTargetRef() instanceof ThrowEvent)) {
                        DataObject da = (DataObject) as.getSourceRef();
                        if (as.getTargetRef() instanceof Task) {
                            Task task = (Task) as.getTargetRef();
                            if (task.getIoSpecification() == null) {
                                InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
                                task.setIoSpecification(iospec);
                            }
                            if (task.getIoSpecification().getInputSets() == null || task.getIoSpecification().getInputSets().size() < 1) {
                                InputSet inset = Bpmn2Factory.eINSTANCE.createInputSet();
                                task.getIoSpecification().getInputSets().add(inset);
                            }
                            InputSet inSet = task.getIoSpecification().getInputSets().get(0);
                            boolean foundDataInput = false;
                            for (DataInput dataInput : inSet.getDataInputRefs()) {
                                if (dataInput.getId().equals(task.getId() + "_" + da.getId() + "InputX")) {
                                    foundDataInput = true;
                                }
                            }
                            if (!foundDataInput) {
                                DataInput d = Bpmn2Factory.eINSTANCE.createDataInput();
                                d.setId(task.getId() + "_" + da.getId() + "InputX");
                                d.setName(da.getId() + "InputX");
                                task.getIoSpecification().getDataInputs().add(d);
                                task.getIoSpecification().getInputSets().get(0).getDataInputRefs().add(d);
                                DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
                                dia.setTargetRef(d);
                                dia.getSourceRef().add(da);
                                task.getDataInputAssociations().add(dia);
                            }
                        } else if (as.getTargetRef() instanceof ThrowEvent) {
                            ThrowEvent te = (ThrowEvent) as.getTargetRef();
                            // update throw event data input and add data input association
                            boolean foundDataInput = false;
                            List<DataInput> dataInputs = te.getDataInputs();
                            for (DataInput din : dataInputs) {
                                if (din.getId().equals(te.getId() + "_" + da.getId() + "InputX")) {
                                    foundDataInput = true;
                                }
                            }
                            if (!foundDataInput) {
                                DataInput datain = Bpmn2Factory.eINSTANCE.createDataInput();
                                datain.setId(te.getId() + "_" + da.getId() + "InputX");
                                datain.setName(da.getId() + "InputX");
                                te.getDataInputs().add(datain);
                                if (te.getInputSet() == null) {
                                    InputSet inset = Bpmn2Factory.eINSTANCE.createInputSet();
                                    te.setInputSet(inset);
                                }
                                te.getInputSet().getDataInputRefs().add(datain);
                                DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
                                dia.setTargetRef(datain);
                                dia.getSourceRef().add(da);
                                te.getDataInputAssociation().add(dia);
                            }
                        }
                    }
                    if (as.getTargetRef() != null && as.getTargetRef() instanceof DataObject && as.getSourceRef() != null && (as.getSourceRef() instanceof Task || as.getSourceRef() instanceof CatchEvent)) {
                        DataObject da = (DataObject) as.getTargetRef();
                        if (as.getSourceRef() instanceof Task) {
                            Task task = (Task) as.getSourceRef();
                            if (task.getIoSpecification() == null) {
                                InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
                                task.setIoSpecification(iospec);
                            }
                            if (task.getIoSpecification().getOutputSets() == null || task.getIoSpecification().getOutputSets().size() < 1) {
                                OutputSet outSet = Bpmn2Factory.eINSTANCE.createOutputSet();
                                task.getIoSpecification().getOutputSets().add(outSet);
                            }
                            boolean foundDataOutput = false;
                            OutputSet outSet = task.getIoSpecification().getOutputSets().get(0);
                            for (DataOutput dataOut : outSet.getDataOutputRefs()) {
                                if (dataOut.getId().equals(task.getId() + "_" + da.getId() + "OutputX")) {
                                    foundDataOutput = true;
                                }
                            }
                            if (!foundDataOutput) {
                                DataOutput d = Bpmn2Factory.eINSTANCE.createDataOutput();
                                d.setId(task.getId() + "_" + da.getId() + "OutputX");
                                d.setName(da.getId() + "OutputX");
                                task.getIoSpecification().getDataOutputs().add(d);
                                task.getIoSpecification().getOutputSets().get(0).getDataOutputRefs().add(d);
                                DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
                                doa.getSourceRef().add(d);
                                doa.setTargetRef(da);
                                task.getDataOutputAssociations().add(doa);
                            }
                        } else if (as.getSourceRef() instanceof CatchEvent) {
                            CatchEvent ce = (CatchEvent) as.getSourceRef();
                            // update catch event data output and add data output association
                            boolean foundDataOutput = false;
                            List<DataOutput> dataOutputs = ce.getDataOutputs();
                            for (DataOutput dout : dataOutputs) {
                                if (dout.getId().equals(ce.getId() + "_" + da.getId() + "OutputX")) {
                                    foundDataOutput = true;
                                }
                            }
                            if (!foundDataOutput) {
                                DataOutput dataout = Bpmn2Factory.eINSTANCE.createDataOutput();
                                dataout.setId(ce.getId() + "_" + da.getId() + "OutputX");
                                dataout.setName(da.getId() + "OutputX");
                                ce.getDataOutputs().add(dataout);
                                if (ce.getOutputSet() == null) {
                                    OutputSet outset = Bpmn2Factory.eINSTANCE.createOutputSet();
                                    ce.setOutputSet(outset);
                                }
                                ce.getOutputSet().getDataOutputRefs().add(dataout);
                                DataOutputAssociation dia = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
                                dia.setTargetRef(da);
                                dia.getSourceRef().add(dataout);
                                ce.getDataOutputAssociation().add(dia);
                            }
                        }
                    }
                    if (as.getSourceRef() != null && as.getSourceRef() instanceof DataObject && as.getTargetRef() != null && (as.getTargetRef() instanceof SequenceFlow)) {
                        SequenceFlow sf = (SequenceFlow) as.getTargetRef();
                        if (sf.getSourceRef() != null && sf.getSourceRef() instanceof Activity && sf.getTargetRef() != null && sf.getTargetRef() instanceof Activity) {
                            Activity sourceElement = (Activity) sf.getSourceRef();
                            Activity targetElement = (Activity) sf.getTargetRef();
                            DataObject da = (DataObject) as.getSourceRef();
                            if (targetElement.getIoSpecification() == null) {
                                InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
                                targetElement.setIoSpecification(iospec);
                            }
                            if (targetElement.getIoSpecification().getInputSets() == null || targetElement.getIoSpecification().getInputSets().size() < 1) {
                                InputSet inset = Bpmn2Factory.eINSTANCE.createInputSet();
                                targetElement.getIoSpecification().getInputSets().add(inset);
                            }
                            InputSet inSet = targetElement.getIoSpecification().getInputSets().get(0);
                            boolean foundDataInput = false;
                            for (DataInput dataInput : inSet.getDataInputRefs()) {
                                if (dataInput.getId().equals(targetElement.getId() + "_" + da.getId() + "InputX")) {
                                    foundDataInput = true;
                                }
                            }
                            if (!foundDataInput) {
                                DataInput d = Bpmn2Factory.eINSTANCE.createDataInput();
                                d.setId(targetElement.getId() + "_" + da.getId() + "InputX");
                                d.setName(da.getId() + "InputX");
                                targetElement.getIoSpecification().getDataInputs().add(d);
                                targetElement.getIoSpecification().getInputSets().get(0).getDataInputRefs().add(d);
                                DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
                                dia.setTargetRef(d);
                                dia.getSourceRef().add(da);
                                targetElement.getDataInputAssociations().add(dia);
                            }
                            if (sourceElement.getIoSpecification() == null) {
                                InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
                                sourceElement.setIoSpecification(iospec);
                            }
                            if (sourceElement.getIoSpecification().getOutputSets() == null || sourceElement.getIoSpecification().getOutputSets().size() < 1) {
                                OutputSet outSet = Bpmn2Factory.eINSTANCE.createOutputSet();
                                sourceElement.getIoSpecification().getOutputSets().add(outSet);
                            }
                            boolean foundDataOutput = false;
                            OutputSet outSet = sourceElement.getIoSpecification().getOutputSets().get(0);
                            for (DataOutput dataOut : outSet.getDataOutputRefs()) {
                                if (dataOut.getId().equals(sourceElement.getId() + "_" + da.getId() + "OutputX")) {
                                    foundDataOutput = true;
                                }
                            }
                            if (!foundDataOutput) {
                                DataOutput d = Bpmn2Factory.eINSTANCE.createDataOutput();
                                d.setId(sourceElement.getId() + "_" + da.getId() + "OutputX");
                                d.setName(da.getId() + "OutputX");
                                sourceElement.getIoSpecification().getDataOutputs().add(d);
                                sourceElement.getIoSpecification().getOutputSets().get(0).getDataOutputRefs().add(d);
                                DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
                                doa.getSourceRef().add(d);
                                doa.setTargetRef(da);
                                sourceElement.getDataOutputAssociations().add(doa);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : DataOutput(org.eclipse.bpmn2.DataOutput) 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) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) ItemDefinition(org.eclipse.bpmn2.ItemDefinition) ArrayList(java.util.ArrayList) 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) Entry(java.util.Map.Entry) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) Association(org.eclipse.bpmn2.Association) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation) ArrayList(java.util.ArrayList) List(java.util.List) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) ThrowEvent(org.eclipse.bpmn2.ThrowEvent) OutputSet(org.eclipse.bpmn2.OutputSet) InputOutputSpecification(org.eclipse.bpmn2.InputOutputSpecification) Artifact(org.eclipse.bpmn2.Artifact) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) InputSet(org.eclipse.bpmn2.InputSet) DataInput(org.eclipse.bpmn2.DataInput) RootElement(org.eclipse.bpmn2.RootElement) DataObject(org.eclipse.bpmn2.DataObject) FlowElement(org.eclipse.bpmn2.FlowElement) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation)

Example 7 with CatchEvent

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

the class Bpmn2JsonUnmarshaller method revisitCatchEventsConvertToBoundary.

protected void revisitCatchEventsConvertToBoundary(Definitions def) {
    List<CatchEvent> catchEventsToRemove = new ArrayList<>();
    Map<BoundaryEvent, List<String>> boundaryEventsToAdd = new HashMap<>();
    List<RootElement> rootElements = def.getRootElements();
    for (RootElement root : rootElements) {
        if (root instanceof Process) {
            Process process = (Process) root;
            revisitCatchEVentsConvertToBoundaryExecute(process, null, catchEventsToRemove, boundaryEventsToAdd);
        }
    }
    reconnectFlows();
}
Also used : RootElement(org.eclipse.bpmn2.RootElement) BoundaryEvent(org.eclipse.bpmn2.BoundaryEvent) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Process(org.eclipse.bpmn2.Process) CatchEvent(org.eclipse.bpmn2.CatchEvent)

Example 8 with CatchEvent

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

the class Bpmn2JsonMarshaller method marshallIntermediateCatchEvent.

protected void marshallIntermediateCatchEvent(IntermediateCatchEvent catchEvent, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, Map<String, Object> properties) throws JsonGenerationException, IOException {
    List<EventDefinition> eventDefinitions = catchEvent.getEventDefinitions();
    // simulation properties
    setSimulationProperties(catchEvent.getId(), properties);
    if (eventDefinitions.size() == 1) {
        EventDefinition eventDefinition = eventDefinitions.get(0);
        if (eventDefinition instanceof SignalEventDefinition) {
            marshallNode(catchEvent, properties, "IntermediateSignalEventCatching", plane, generator, xOffset, yOffset);
        } else if (eventDefinition instanceof MessageEventDefinition) {
            marshallNode(catchEvent, properties, "IntermediateMessageEventCatching", plane, generator, xOffset, yOffset);
        } else if (eventDefinition instanceof TimerEventDefinition) {
            marshallNode(catchEvent, properties, "IntermediateTimerEvent", plane, generator, xOffset, yOffset);
        } else if (eventDefinition instanceof ConditionalEventDefinition) {
            marshallNode(catchEvent, properties, "IntermediateConditionalEvent", plane, generator, xOffset, yOffset);
        } else if (eventDefinition instanceof ErrorEventDefinition) {
            marshallNode(catchEvent, properties, "IntermediateErrorEvent", plane, generator, xOffset, yOffset);
        } else if (eventDefinition instanceof EscalationEventDefinition) {
            marshallNode(catchEvent, properties, "IntermediateEscalationEvent", plane, generator, xOffset, yOffset);
        } else if (eventDefinition instanceof CompensateEventDefinition) {
            marshallNode(catchEvent, properties, "IntermediateCompensationEventCatching", plane, generator, xOffset, yOffset);
        } else {
            throw new UnsupportedOperationException("Event definition not supported: " + eventDefinition);
        }
    } else {
        throw new UnsupportedOperationException("Intermediate catch event does not have event definition.");
    }
}
Also used : EscalationEventDefinition(org.eclipse.bpmn2.EscalationEventDefinition) ErrorEventDefinition(org.eclipse.bpmn2.ErrorEventDefinition) SignalEventDefinition(org.eclipse.bpmn2.SignalEventDefinition) ConditionalEventDefinition(org.eclipse.bpmn2.ConditionalEventDefinition) MessageEventDefinition(org.eclipse.bpmn2.MessageEventDefinition) 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) TimerEventDefinition(org.eclipse.bpmn2.TimerEventDefinition) CompensateEventDefinition(org.eclipse.bpmn2.CompensateEventDefinition)

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