Search in sources :

Example 11 with DataInput

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

the class BPMNDiagramMarshallerTest method testMarshallUserTaskAssignments.

@Test
public void testMarshallUserTaskAssignments() throws Exception {
    Diagram<Graph, Metadata> diagram = unmarshall(BPMN_USERTASKASSIGNMENTS);
    JBPMBpmn2ResourceImpl resource = tested.marshallToBpmn2Resource(diagram);
    String result = tested.marshall(diagram);
    assertDiagram(result, 1, 7, 7);
    Definitions definitions = (Definitions) resource.getContents().get(0);
    assertNotNull(definitions);
    Process process = getProcess(definitions);
    assertNotNull(process);
    org.eclipse.bpmn2.UserTask userTask = (org.eclipse.bpmn2.UserTask) getNamedFlowElement(process, org.eclipse.bpmn2.UserTask.class, "Self Evaluation");
    assertNotNull(userTask);
    DataInput dataInput = (DataInput) getDataInput(userTask, "reason");
    validateDataInputOrOutput(dataInput, "_reasonInputX", "com.test.Reason", "_reasonInputXItem");
    DataOutput dataOutput = (DataOutput) getDataOutput(userTask, "performance");
    validateDataInputOrOutput(dataOutput, "_performanceOutputX", "Object", "_performanceOutputXItem");
    ItemAwareElement sourceRef = getDataInputAssociationSourceRef(userTask, "reason");
    assertNotNull(sourceRef);
    ItemAwareElement targetRef = getDataInputAssociationTargetRef(userTask, "_reasonInputX");
    assertNotNull(targetRef);
    sourceRef = getDataOutputAssociationSourceRef(userTask, "_performanceOutputX");
    assertNotNull(sourceRef);
    targetRef = getDataOutputAssociationTargetRef(userTask, "performance");
    assertNotNull(targetRef);
}
Also used : DataOutput(org.eclipse.bpmn2.DataOutput) JBPMBpmn2ResourceImpl(org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceImpl) Definitions(org.eclipse.bpmn2.Definitions) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) UserTask(org.kie.workbench.common.stunner.bpmn.definition.UserTask) ItemAwareElement(org.eclipse.bpmn2.ItemAwareElement) Process(org.eclipse.bpmn2.Process) Matchers.anyString(org.mockito.Matchers.anyString) DataInput(org.eclipse.bpmn2.DataInput) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Test(org.junit.Test)

Example 12 with DataInput

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

the class Bpmn2JsonUnmarshaller method setItemDefinitionsForActivitiesIoSpec.

public void setItemDefinitionsForActivitiesIoSpec(FlowElementsContainer container, Definitions def, List<ItemDefinition> toAddItemDefinitions) {
    List<FlowElement> flowElements = container.getFlowElements();
    for (FlowElement fe : flowElements) {
        if (fe instanceof Activity) {
            Activity ac = (Activity) fe;
            if (ac.getIoSpecification() != null) {
                if (ac.getIoSpecification().getDataInputs() != null) {
                    List<DataInput> dataInputs = ac.getIoSpecification().getDataInputs();
                    for (DataInput din : dataInputs) {
                        Iterator<FeatureMap.Entry> iter = din.getAnyAttribute().iterator();
                        while (iter.hasNext()) {
                            FeatureMap.Entry entry = iter.next();
                            if (entry.getEStructuralFeature().getName().equals("dtype")) {
                                String dinType = (String) entry.getValue();
                                if (dinType != null && dinType.length() > 0) {
                                    ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition();
                                    itemdef.setId("_" + din.getId() + "Item");
                                    itemdef.setStructureRef(dinType);
                                    toAddItemDefinitions.add(itemdef);
                                    din.setItemSubjectRef(itemdef);
                                }
                            }
                        }
                    }
                }
                if (ac.getIoSpecification().getDataOutputs() != null) {
                    List<DataOutput> dataOutputs = ac.getIoSpecification().getDataOutputs();
                    for (DataOutput dout : dataOutputs) {
                        Iterator<FeatureMap.Entry> iter = dout.getAnyAttribute().iterator();
                        while (iter.hasNext()) {
                            FeatureMap.Entry entry = iter.next();
                            if (entry.getEStructuralFeature().getName().equals("dtype")) {
                                String doutType = (String) entry.getValue();
                                if (doutType != null && doutType.length() > 0) {
                                    ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition();
                                    itemdef.setId("_" + dout.getId() + "Item");
                                    itemdef.setStructureRef(doutType);
                                    toAddItemDefinitions.add(itemdef);
                                    dout.setItemSubjectRef(itemdef);
                                }
                            }
                        }
                    }
                }
            }
        } else if (fe instanceof FlowElementsContainer) {
            setItemDefinitionsForActivitiesIoSpec((FlowElementsContainer) fe, def, toAddItemDefinitions);
        }
    }
}
Also used : DataOutput(org.eclipse.bpmn2.DataOutput) ItemDefinition(org.eclipse.bpmn2.ItemDefinition) Activity(org.eclipse.bpmn2.Activity) CallActivity(org.eclipse.bpmn2.CallActivity) FlowElementsContainer(org.eclipse.bpmn2.FlowElementsContainer) DataInput(org.eclipse.bpmn2.DataInput) 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)

Example 13 with DataInput

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

the class Bpmn2JsonUnmarshaller method revisitMultiInstanceTasks.

public void revisitMultiInstanceTasks(Definitions def) {
    try {
        List<RootElement> rootElements = def.getRootElements();
        for (RootElement root : rootElements) {
            if (root instanceof Process) {
                Process process = (Process) root;
                List<FlowElement> flowElements = process.getFlowElements();
                for (FlowElement fe : flowElements) {
                    if (fe instanceof Task) {
                        Task task = (Task) fe;
                        Iterator<FeatureMap.Entry> iter = task.getAnyAttribute().iterator();
                        while (iter.hasNext()) {
                            FeatureMap.Entry entry = iter.next();
                            if (entry.getEStructuralFeature().getName().equals("mitask")) {
                                String multiValue = (String) entry.getValue();
                                String[] multiValueParts = multiValue.split("@");
                                if (multiValueParts != null && multiValueParts.length == 5) {
                                    String miCollectionInput = (multiValueParts[0].equals(" ") ? "" : multiValueParts[0]);
                                    String miCollectionOutput = (multiValueParts[1].equals(" ") ? "" : multiValueParts[1]);
                                    String miDataInput = (multiValueParts[2].equals(" ") ? "" : multiValueParts[2]);
                                    String miDataOutput = (multiValueParts[3].equals(" ") ? "" : multiValueParts[3]);
                                    String miCompletionCondition = (multiValueParts[4].equals(" ") ? "" : multiValueParts[4]);
                                    MultiInstanceLoopCharacteristics loopCharacteristics = Bpmn2Factory.eINSTANCE.createMultiInstanceLoopCharacteristics();
                                    if (miCollectionInput != null && miCollectionInput.length() > 0) {
                                        List<Property> properties = process.getProperties();
                                        for (Property prop : properties) {
                                            if (prop.getId() != null && prop.getId().equals(miCollectionInput)) {
                                                DataInput miCollectionInputDI = Bpmn2Factory.eINSTANCE.createDataInput();
                                                miCollectionInputDI.setName("miinputCollection");
                                                ItemDefinition miCollectionInputDIItemDefinition = this.getMessageItemDefinition(def.getRootElements(), prop.getId());
                                                miCollectionInputDI.setItemSubjectRef(miCollectionInputDIItemDefinition);
                                                task.getIoSpecification().getDataInputs().add(miCollectionInputDI);
                                                if (task.getIoSpecification().getInputSets() == null || task.getIoSpecification().getInputSets().size() < 1) {
                                                    InputSet inset = Bpmn2Factory.eINSTANCE.createInputSet();
                                                    task.getIoSpecification().getInputSets().add(inset);
                                                }
                                                task.getIoSpecification().getInputSets().get(0).getDataInputRefs().add(miCollectionInputDI);
                                                loopCharacteristics.setLoopDataInputRef(miCollectionInputDI);
                                                DataInputAssociation miCollectionInputDataInputAssociation = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
                                                miCollectionInputDataInputAssociation.getSourceRef().add(prop);
                                                miCollectionInputDataInputAssociation.setTargetRef(miCollectionInputDI);
                                                task.getDataInputAssociations().add(miCollectionInputDataInputAssociation);
                                                break;
                                            }
                                        }
                                    }
                                    if (miCollectionOutput != null && miCollectionOutput.length() > 0) {
                                        List<Property> properties = process.getProperties();
                                        for (Property prop : properties) {
                                            if (prop.getId() != null && prop.getId().equals(miCollectionOutput)) {
                                                DataOutput miCollectionOutputDI = Bpmn2Factory.eINSTANCE.createDataOutput();
                                                miCollectionOutputDI.setName("mioutputCollection");
                                                ItemDefinition miCollectionOutputDIItemDefinition = this.getMessageItemDefinition(def.getRootElements(), prop.getId());
                                                miCollectionOutputDI.setItemSubjectRef(miCollectionOutputDIItemDefinition);
                                                task.getIoSpecification().getDataOutputs().add(miCollectionOutputDI);
                                                if (task.getIoSpecification().getOutputSets() == null || task.getIoSpecification().getOutputSets().size() < 1) {
                                                    OutputSet outset = Bpmn2Factory.eINSTANCE.createOutputSet();
                                                    task.getIoSpecification().getOutputSets().add(outset);
                                                }
                                                task.getIoSpecification().getOutputSets().get(0).getDataOutputRefs().add(miCollectionOutputDI);
                                                loopCharacteristics.setLoopDataOutputRef(miCollectionOutputDI);
                                                DataOutputAssociation miCollectionInputDataOutputAssociation = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
                                                miCollectionInputDataOutputAssociation.setTargetRef(prop);
                                                miCollectionInputDataOutputAssociation.getSourceRef().add(miCollectionOutputDI);
                                                task.getDataOutputAssociations().add(miCollectionInputDataOutputAssociation);
                                                break;
                                            }
                                        }
                                    }
                                    if (miDataInput != null && miDataInput.length() > 0) {
                                        List<DataInput> dins = task.getIoSpecification().getDataInputs();
                                        for (DataInput di : dins) {
                                            if (di.getName().equals(miDataInput)) {
                                                DataInput inputDataItemObj = Bpmn2Factory.eINSTANCE.createDataInput();
                                                inputDataItemObj.setId("miDataInputX");
                                                inputDataItemObj.setItemSubjectRef(di.getItemSubjectRef());
                                                loopCharacteristics.setInputDataItem(inputDataItemObj);
                                                break;
                                            }
                                        }
                                    }
                                    if (miDataOutput != null && miDataOutput.length() > 0) {
                                        List<DataOutput> douts = task.getIoSpecification().getDataOutputs();
                                        for (DataOutput dout : douts) {
                                            if (dout.getName().equals(miDataOutput)) {
                                                DataOutput outputDataItemObj = Bpmn2Factory.eINSTANCE.createDataOutput();
                                                outputDataItemObj.setId("miDataOutputX");
                                                outputDataItemObj.setItemSubjectRef(dout.getItemSubjectRef());
                                                loopCharacteristics.setOutputDataItem(outputDataItemObj);
                                                break;
                                            }
                                        }
                                    }
                                    if (miCompletionCondition != null && !miCompletionCondition.isEmpty()) {
                                        FormalExpression expr = Bpmn2Factory.eINSTANCE.createFormalExpression();
                                        expr.setBody(miCompletionCondition);
                                        loopCharacteristics.setCompletionCondition(expr);
                                    }
                                    task.setLoopCharacteristics(loopCharacteristics);
                                    if (miDataInput != null && miDataInput.length() > 0 && ((MultiInstanceLoopCharacteristics) task.getLoopCharacteristics()).getInputDataItem() != null) {
                                        DataInputAssociation dias = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
                                        dias.getSourceRef().add(((MultiInstanceLoopCharacteristics) task.getLoopCharacteristics()).getInputDataItem());
                                        List<DataInput> dins = task.getIoSpecification().getDataInputs();
                                        for (DataInput di : dins) {
                                            if (di.getName().equals(miDataInput)) {
                                                dias.setTargetRef(di);
                                                task.getDataInputAssociations().add(dias);
                                                break;
                                            }
                                        }
                                    }
                                    if (miDataOutput != null && miDataOutput.length() > 0 && ((MultiInstanceLoopCharacteristics) task.getLoopCharacteristics()).getOutputDataItem() != null) {
                                        DataOutputAssociation dout = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
                                        dout.setTargetRef(((MultiInstanceLoopCharacteristics) task.getLoopCharacteristics()).getOutputDataItem());
                                        List<DataOutput> douts = task.getIoSpecification().getDataOutputs();
                                        for (DataOutput dou : douts) {
                                            if (dou.getName().equals(miDataOutput)) {
                                                dout.getSourceRef().add(dou);
                                                task.getDataOutputAssociations().add(dout);
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
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) ItemDefinition(org.eclipse.bpmn2.ItemDefinition) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Process(org.eclipse.bpmn2.Process) Entry(java.util.Map.Entry) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) MultiInstanceLoopCharacteristics(org.eclipse.bpmn2.MultiInstanceLoopCharacteristics) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) Property(org.eclipse.bpmn2.Property) OutputSet(org.eclipse.bpmn2.OutputSet) FormalExpression(org.eclipse.bpmn2.FormalExpression) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) DataInput(org.eclipse.bpmn2.DataInput) InputSet(org.eclipse.bpmn2.InputSet) RootElement(org.eclipse.bpmn2.RootElement) FlowElement(org.eclipse.bpmn2.FlowElement) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation)

Example 14 with DataInput

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

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

the class Bpmn2JsonUnmarshaller method applyThrowEventProperties.

protected void applyThrowEventProperties(ThrowEvent event, Map<String, String> properties) {
    parseAssignmentsInfo(properties);
    if (properties.get("datainput") != null && properties.get("datainput").trim().length() > 0) {
        String[] allDataInputs = properties.get("datainput").split(",\\s*");
        InputSet inset = Bpmn2Factory.eINSTANCE.createInputSet();
        for (String dataInput : allDataInputs) {
            if (dataInput.trim().length() > 0) {
                DataInput nextInput = Bpmn2Factory.eINSTANCE.createDataInput();
                String[] dataInputParts = dataInput.split(":\\s*");
                if (dataInputParts.length == 2) {
                    nextInput.setId(event.getId() + "_" + dataInputParts[0] + (dataInputParts[0].endsWith("InputX") ? "" : "InputX"));
                    nextInput.setName(dataInputParts[0]);
                    ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
                    EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "dtype", false, false);
                    SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, dataInputParts[1]);
                    nextInput.getAnyAttribute().add(extensionEntry);
                } else {
                    nextInput.setId(event.getId() + "_" + dataInput + (dataInput.endsWith("InputX") ? "" : "InputX"));
                    nextInput.setName(dataInput);
                    ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
                    EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "dtype", false, false);
                    SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, "Object");
                    nextInput.getAnyAttribute().add(extensionEntry);
                }
                event.getDataInputs().add(nextInput);
                inset.getDataInputRefs().add(nextInput);
            }
        }
        event.setInputSet(inset);
    }
    if (properties.get("datainputassociations") != null && properties.get("datainputassociations").length() > 0) {
        String[] allAssignments = properties.get("datainputassociations").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 (event.getInputSet() != null) {
                    List<DataInput> dataInputs = event.getInputSet().getDataInputRefs();
                    for (DataInput di : dataInputs) {
                        if (di.getId().equals(event.getId() + "_" + fromPart + (fromPart.endsWith("InputX") ? "" : "InputX"))) {
                            dia.setTargetRef(di);
                        }
                    }
                }
                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);
                event.getDataInputAssociation().add(dia);
            } 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 (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 = event.getInputSet().getDataInputRefs();
                    for (DataInput di : dataInputs) {
                        if (di.getId().equals(event.getId() + "_" + assignmentParts[1] + (assignmentParts[1].endsWith("InputX") ? "" : "InputX"))) {
                            dia.setTargetRef(di);
                            break;
                        }
                    }
                    event.getDataInputAssociation().add(dia);
                }
            } else {
            // TODO throw exception here?
            }
        }
    }
    // signal scope metadata
    if (properties.get("signalscope") != null && properties.get("signalscope").length() > 0 && !properties.get("signalscope").equals("default")) {
        Utils.setMetaDataExtensionValue(event, "customScope", wrapInCDATABlock(properties.get("signalscope")));
    }
    try {
        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 (IndexOutOfBoundsException e) {
    // TODO we dont want to barf here as test for example do not define event definitions in the bpmn2....
    }
    // 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);
        }
    }
}
Also used : NormalDistributionType(bpsim.NormalDistributionType) 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) Assignment(org.eclipse.bpmn2.Assignment) 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) ArrayList(java.util.ArrayList) List(java.util.List) TimerEventDefinition(org.eclipse.bpmn2.TimerEventDefinition) UniformDistributionType(bpsim.UniformDistributionType) ItemAwareElement(org.eclipse.bpmn2.ItemAwareElement) FormalExpression(org.eclipse.bpmn2.FormalExpression) InputSet(org.eclipse.bpmn2.InputSet) DataInput(org.eclipse.bpmn2.DataInput) PoissonDistributionType(bpsim.PoissonDistributionType) EscalationEventDefinition(org.eclipse.bpmn2.EscalationEventDefinition) ErrorEventDefinition(org.eclipse.bpmn2.ErrorEventDefinition) 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) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation)

Aggregations

DataInput (org.eclipse.bpmn2.DataInput)20 DataInputAssociation (org.eclipse.bpmn2.DataInputAssociation)15 DataOutput (org.eclipse.bpmn2.DataOutput)12 FormalExpression (org.eclipse.bpmn2.FormalExpression)10 ArrayList (java.util.ArrayList)9 InputSet (org.eclipse.bpmn2.InputSet)9 ItemAwareElement (org.eclipse.bpmn2.ItemAwareElement)9 DataOutputAssociation (org.eclipse.bpmn2.DataOutputAssociation)8 SimpleFeatureMapEntry (org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry)8 List (java.util.List)7 Assignment (org.eclipse.bpmn2.Assignment)7 Parameter (bpsim.Parameter)5 InputOutputSpecification (org.eclipse.bpmn2.InputOutputSpecification)5 NormalDistributionType (bpsim.NormalDistributionType)4 PoissonDistributionType (bpsim.PoissonDistributionType)4 TimeParameters (bpsim.TimeParameters)4 UniformDistributionType (bpsim.UniformDistributionType)4 Entry (java.util.Map.Entry)4 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)4 FlowElement (org.eclipse.bpmn2.FlowElement)4