Search in sources :

Example 56 with Definitions

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

the class Bpmn2JsonUnmarshallerTest method testUpdateIDs.

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

Example 57 with Definitions

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

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

the class Bpmn2JsonUnmarshaller method revisitTaskAssociations.

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

Example 59 with Definitions

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

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

Aggregations

Process (org.eclipse.bpmn2.Process)40 RootElement (org.eclipse.bpmn2.RootElement)35 ArrayList (java.util.ArrayList)27 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)26 SubProcess (org.eclipse.bpmn2.SubProcess)26 Definitions (org.eclipse.bpmn2.Definitions)25 Definitions (org.kie.dmn.model.v1_1.Definitions)22 List (java.util.List)21 Test (org.junit.Test)20 FlowElement (org.eclipse.bpmn2.FlowElement)18 FeatureMap (org.eclipse.emf.ecore.util.FeatureMap)16 ItemDefinition (org.eclipse.bpmn2.ItemDefinition)15 Entry (java.util.Map.Entry)14 CompensateEventDefinition (org.eclipse.bpmn2.CompensateEventDefinition)13 ErrorEventDefinition (org.eclipse.bpmn2.ErrorEventDefinition)13 EscalationEventDefinition (org.eclipse.bpmn2.EscalationEventDefinition)13 EventDefinition (org.eclipse.bpmn2.EventDefinition)13 MessageEventDefinition (org.eclipse.bpmn2.MessageEventDefinition)13 SignalEventDefinition (org.eclipse.bpmn2.SignalEventDefinition)13 ConditionalEventDefinition (org.eclipse.bpmn2.ConditionalEventDefinition)12