Search in sources :

Example 41 with FlowElement

use of org.osate.aadl2.FlowElement in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method setUserTaskInfo.

private void setUserTaskInfo(FlowElementsContainer container) {
    List<FlowElement> flowElements = container.getFlowElements();
    for (FlowElement fe : flowElements) {
        // Set name and metaData "elementname" to "Task_n" if empty
        if (fe instanceof UserTask) {
            UserTask task = (UserTask) fe;
            String name = task.getName();
            if (name == null || name.length() == 0) {
                LastUserTaskID++;
                String newName = DEFAULT_USERTASK_NAME_PREFIX + LastUserTaskID;
                task.setName(newName);
                if (task.getExtensionValues() != null && task.getExtensionValues().size() > 0) {
                    for (ExtensionAttributeValue extattrval : task.getExtensionValues()) {
                        FeatureMap extensionElements = extattrval.getValue();
                        List<MetaDataType> metadataExtensions = (List<MetaDataType>) extensionElements.get(DroolsPackage.Literals.DOCUMENT_ROOT__META_DATA, true);
                        for (MetaDataType eleMetadata : metadataExtensions) {
                            if (eleMetadata.getName() != null && eleMetadata.getName().equals("elementname")) {
                                eleMetadata.setMetaValue(wrapInCDATABlock(newName));
                            }
                        }
                    }
                }
            }
        }
        if (fe instanceof FlowElementsContainer) {
            setUserTaskInfo((FlowElementsContainer) fe);
        }
    }
}
Also used : FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) MetaDataType(org.jboss.drools.MetaDataType) FlowElement(org.eclipse.bpmn2.FlowElement) UserTask(org.eclipse.bpmn2.UserTask) FlowElementsContainer(org.eclipse.bpmn2.FlowElementsContainer) ArrayList(java.util.ArrayList) List(java.util.List) ExtensionAttributeValue(org.eclipse.bpmn2.ExtensionAttributeValue)

Example 42 with FlowElement

use of org.osate.aadl2.FlowElement in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method setSendReceiveTasksInfo.

public void setSendReceiveTasksInfo(FlowElementsContainer container, Definitions def, List<Message> toAddMessages, List<ItemDefinition> toAddItemDefinitions) {
    List<FlowElement> flowElements = container.getFlowElements();
    for (FlowElement fe : flowElements) {
        if (fe instanceof ReceiveTask) {
            ReceiveTask rt = (ReceiveTask) fe;
            rt.setMessageRef(extractMessage(rt, toAddMessages, toAddItemDefinitions));
        } else if (fe instanceof SendTask) {
            SendTask st = (SendTask) fe;
            st.setMessageRef(extractMessage(st, toAddMessages, toAddItemDefinitions));
        } else if (fe instanceof FlowElementsContainer) {
            setSendReceiveTasksInfo((FlowElementsContainer) fe, def, toAddMessages, toAddItemDefinitions);
        }
    }
}
Also used : ReceiveTask(org.eclipse.bpmn2.ReceiveTask) FlowElement(org.eclipse.bpmn2.FlowElement) SendTask(org.eclipse.bpmn2.SendTask) FlowElementsContainer(org.eclipse.bpmn2.FlowElementsContainer)

Example 43 with FlowElement

use of org.osate.aadl2.FlowElement in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method createDiagram.

private void createDiagram(Definitions def) {
    for (RootElement rootElement : def.getRootElements()) {
        if (rootElement instanceof Process) {
            Process process = (Process) rootElement;
            BpmnDiFactory factory = BpmnDiFactory.eINSTANCE;
            BPMNDiagram diagram = factory.createBPMNDiagram();
            BPMNPlane plane = factory.createBPMNPlane();
            plane.setBpmnElement(process);
            diagram.setPlane(plane);
            // first process flowNodes
            for (FlowElement flowElement : process.getFlowElements()) {
                if (flowElement instanceof FlowNode) {
                    createBpmnShapeForElement(factory, plane, flowElement);
                    if (flowElement instanceof BoundaryEvent) {
                        createDockersForBoundaryEvent((BoundaryEvent) flowElement);
                    }
                    // check if its a subprocess
                    if (flowElement instanceof SubProcess) {
                        createSubProcessDiagram(plane, flowElement, factory);
                    }
                } else if (flowElement instanceof DataObject) {
                    createBpmnShapeForElement(factory, plane, flowElement);
                } else if (flowElement instanceof SequenceFlow) {
                    createBpmnEdgeForSequenceFlow(factory, plane, (SequenceFlow) flowElement);
                }
            }
            // then process artifacts
            if (process.getArtifacts() != null) {
                List<Association> incompleteAssociations = new ArrayList<Association>();
                for (Artifact artifact : process.getArtifacts()) {
                    // if (artifact instanceof TextAnnotation || artifact instanceof Group) {
                    if (artifact instanceof Group) {
                        createBpmnShapeForElement(factory, plane, artifact);
                    }
                    if (artifact instanceof Association) {
                        Association association = (Association) artifact;
                        if (association.getSourceRef() != null && association.getTargetRef() != null) {
                            createBpmnEdgeForAssociation(factory, plane, association);
                        } else {
                            incompleteAssociations.add(association);
                        }
                    }
                }
                if (!incompleteAssociations.isEmpty()) {
                    for (Association incompleteAssociation : incompleteAssociations) {
                        process.getArtifacts().remove(incompleteAssociation);
                    }
                }
            }
            // finally process lanes
            if (process.getLaneSets() != null && process.getLaneSets().size() > 0) {
                for (LaneSet ls : process.getLaneSets()) {
                    for (Lane lane : ls.getLanes()) {
                        createBpmnShapeForElement(factory, plane, lane);
                    }
                }
            }
            def.getDiagrams().add(diagram);
        }
    }
}
Also used : AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Group(org.eclipse.bpmn2.Group) BoundaryEvent(org.eclipse.bpmn2.BoundaryEvent) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) ArrayList(java.util.ArrayList) Lane(org.eclipse.bpmn2.Lane) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Process(org.eclipse.bpmn2.Process) LaneSet(org.eclipse.bpmn2.LaneSet) BpmnDiFactory(org.eclipse.bpmn2.di.BpmnDiFactory) Artifact(org.eclipse.bpmn2.Artifact) BPMNDiagram(org.eclipse.bpmn2.di.BPMNDiagram) RootElement(org.eclipse.bpmn2.RootElement) DataObject(org.eclipse.bpmn2.DataObject) Association(org.eclipse.bpmn2.Association) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation) FlowElement(org.eclipse.bpmn2.FlowElement) BPMNPlane(org.eclipse.bpmn2.di.BPMNPlane) FlowNode(org.eclipse.bpmn2.FlowNode)

Example 44 with FlowElement

use of org.osate.aadl2.FlowElement in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method setGatewayInfo.

private void setGatewayInfo(FlowElementsContainer container) {
    List<FlowElement> flowElements = container.getFlowElements();
    for (FlowElement fe : flowElements) {
        if (fe instanceof Gateway) {
            Gateway gateway = (Gateway) fe;
            int incoming = gateway.getIncoming() == null ? 0 : gateway.getIncoming().size();
            int outgoing = gateway.getOutgoing() == null ? 0 : gateway.getOutgoing().size();
            if (incoming <= 1 && outgoing > 1) {
                gateway.setGatewayDirection(GatewayDirection.DIVERGING);
            } else if (incoming > 1 && outgoing <= 1) {
                gateway.setGatewayDirection(GatewayDirection.CONVERGING);
            } else // temp. removing support for mixed gateway direction (not supported by runtime yet)
            // else if (incoming > 1 && outgoing > 1) {
            // gateway.setGatewayDirection(GatewayDirection.MIXED);
            // }
            // else if (incoming == 1 && outgoing == 1) {
            // // this handles the 1:1 case of the diverging gateways
            // }
            {
                gateway.setGatewayDirection(GatewayDirection.UNSPECIFIED);
            }
        }
        if (fe instanceof InclusiveGateway) {
            InclusiveGateway ig = (InclusiveGateway) fe;
            List<SequenceFlow> sqList = new ArrayList<SequenceFlow>();
            if (ig.getIncoming() != null) {
                sqList.addAll(ig.getIncoming());
            }
            if (ig.getOutgoing() != null) {
                sqList.addAll(ig.getOutgoing());
            }
            setDefaultGateway(fe, sqList);
        }
        if (fe instanceof ExclusiveGateway) {
            ExclusiveGateway eg = (ExclusiveGateway) fe;
            List<SequenceFlow> sqList = new ArrayList<SequenceFlow>();
            if (eg.getIncoming() != null) {
                sqList.addAll(eg.getIncoming());
            }
            if (eg.getOutgoing() != null) {
                sqList.addAll(eg.getOutgoing());
            }
            setDefaultGateway(fe, sqList);
        }
        if (fe instanceof FlowElementsContainer) {
            setGatewayInfo((FlowElementsContainer) fe);
        }
    }
}
Also used : ExclusiveGateway(org.eclipse.bpmn2.ExclusiveGateway) InclusiveGateway(org.eclipse.bpmn2.InclusiveGateway) FlowElement(org.eclipse.bpmn2.FlowElement) ExclusiveGateway(org.eclipse.bpmn2.ExclusiveGateway) Gateway(org.eclipse.bpmn2.Gateway) InclusiveGateway(org.eclipse.bpmn2.InclusiveGateway) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) ArrayList(java.util.ArrayList) FlowElementsContainer(org.eclipse.bpmn2.FlowElementsContainer) Point(org.eclipse.dd.dc.Point)

Example 45 with FlowElement

use of org.osate.aadl2.FlowElement in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method revisitServiceTasksExecuteForLanes.

private void revisitServiceTasksExecuteForLanes(Lane lane, Definitions def, List<RootElement> rootElements, List<Interface> toAddInterfaces, List<Message> toAddMessages, List<ItemDefinition> toAddDefinitions) {
    List<FlowNode> laneFlowNodes = lane.getFlowNodeRefs();
    for (FlowElement fe : laneFlowNodes) {
        if (fe instanceof ServiceTask) {
            Iterator<FeatureMap.Entry> iter = fe.getAnyAttribute().iterator();
            String serviceImplementation = null;
            String serviceInterface = null;
            String serviceOperation = null;
            EStructuralFeature serviceInterfaceFeature = null;
            EStructuralFeature serviceOperationFeature = null;
            while (iter.hasNext()) {
                FeatureMap.Entry entry = iter.next();
                if (entry.getEStructuralFeature().getName().equals("serviceimplementation")) {
                    serviceImplementation = (String) entry.getValue();
                }
                if (entry.getEStructuralFeature().getName().equals("serviceoperation")) {
                    serviceOperation = (String) entry.getValue();
                    serviceOperationFeature = entry.getEStructuralFeature();
                }
                if (entry.getEStructuralFeature().getName().equals("serviceinterface")) {
                    serviceInterface = (String) entry.getValue();
                    serviceInterfaceFeature = entry.getEStructuralFeature();
                }
            }
            boolean foundInterface = false;
            Interface touseInterface = null;
            if (serviceImplementation != null && serviceImplementation.equals("Java")) {
                for (RootElement iroot : rootElements) {
                    if (iroot instanceof Interface && ((Interface) iroot).getName().equals(serviceInterface)) {
                        foundInterface = true;
                        touseInterface = (Interface) iroot;
                        break;
                    }
                }
                if (!foundInterface) {
                    for (Interface toadd : toAddInterfaces) {
                        if (toadd.getName() != null && toadd.getName().equals(serviceInterface)) {
                            foundInterface = true;
                            touseInterface = toadd;
                            break;
                        }
                    }
                }
            } else if (serviceImplementation != null && serviceImplementation.equals("##WebService")) {
                for (RootElement iroot : rootElements) {
                    if (iroot instanceof Interface && ((Interface) iroot).getImplementationRef().equals(serviceInterface)) {
                        foundInterface = true;
                        touseInterface = (Interface) iroot;
                        break;
                    }
                }
                if (!foundInterface) {
                    for (Interface toadd : toAddInterfaces) {
                        if (toadd.getImplementationRef().equals(serviceInterface)) {
                            foundInterface = true;
                            touseInterface = toadd;
                            break;
                        }
                    }
                }
            }
            if (!foundInterface) {
                touseInterface = Bpmn2Factory.eINSTANCE.createInterface();
                if (serviceInterface == null || serviceInterface.length() == 0) {
                    serviceInterface = fe.getId() + "_ServiceInterface";
                    if (serviceInterfaceFeature != null) {
                        fe.getAnyAttribute().set(serviceInterfaceFeature, serviceInterface);
                    }
                }
                touseInterface.setName(serviceInterface);
                touseInterface.setImplementationRef(serviceInterface);
                touseInterface.setId(fe.getId() + "_ServiceInterface");
                toAddInterfaces.add(touseInterface);
            }
            if (serviceOperation != null) {
                boolean foundOperation = false;
                for (Operation oper : touseInterface.getOperations()) {
                    if (serviceImplementation != null && serviceImplementation.equals("Java")) {
                        if (oper.getName().equals(serviceOperation)) {
                            foundOperation = true;
                            break;
                        }
                    } else if (serviceImplementation != null && serviceImplementation.equals("##WebService")) {
                        if (oper.getImplementationRef().equals(serviceOperation)) {
                            foundOperation = true;
                            break;
                        }
                    }
                }
                if (!foundOperation) {
                    Operation touseOperation = Bpmn2Factory.eINSTANCE.createOperation();
                    if (serviceOperation == null || serviceOperation.length() == 0) {
                        serviceOperation = fe.getId() + "_ServiceOperation";
                        if (serviceOperationFeature != null) {
                            fe.getAnyAttribute().set(serviceOperationFeature, serviceOperation);
                        }
                    }
                    touseOperation.setId(fe.getId() + "_ServiceOperation");
                    touseOperation.setName(serviceOperation);
                    touseOperation.setImplementationRef(serviceOperation);
                    Message message = Bpmn2Factory.eINSTANCE.createMessage();
                    message.setId(fe.getId() + "_InMessage");
                    ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition();
                    itemdef.setId(message.getId() + "Type");
                    message.setItemRef(itemdef);
                    toAddDefinitions.add(itemdef);
                    toAddMessages.add(message);
                    touseOperation.setInMessageRef(message);
                    touseInterface.getOperations().add(touseOperation);
                    ((ServiceTask) fe).setOperationRef(touseOperation);
                }
            }
        } else if (fe instanceof FlowElementsContainer) {
            revisitServiceTasksExecute((FlowElementsContainer) fe, rootElements, toAddInterfaces, toAddMessages, toAddDefinitions);
        }
    }
}
Also used : ServiceTask(org.eclipse.bpmn2.ServiceTask) Message(org.eclipse.bpmn2.Message) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) ItemDefinition(org.eclipse.bpmn2.ItemDefinition) FlowElementsContainer(org.eclipse.bpmn2.FlowElementsContainer) Operation(org.eclipse.bpmn2.Operation) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) Entry(java.util.Map.Entry) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) RootElement(org.eclipse.bpmn2.RootElement) FlowElement(org.eclipse.bpmn2.FlowElement) Interface(org.eclipse.bpmn2.Interface) FlowNode(org.eclipse.bpmn2.FlowNode)

Aggregations

FlowElement (org.eclipse.bpmn2.FlowElement)57 SubProcess (org.eclipse.bpmn2.SubProcess)27 ArrayList (java.util.ArrayList)26 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)22 Process (org.eclipse.bpmn2.Process)21 FlowElementsContainer (org.eclipse.bpmn2.FlowElementsContainer)19 RootElement (org.eclipse.bpmn2.RootElement)19 SequenceFlow (org.eclipse.bpmn2.SequenceFlow)16 Activity (org.eclipse.bpmn2.Activity)12 FeatureMap (org.eclipse.emf.ecore.util.FeatureMap)12 Entry (java.util.Map.Entry)11 SimpleFeatureMapEntry (org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry)11 List (java.util.List)10 EventDefinition (org.eclipse.bpmn2.EventDefinition)10 BoundaryEvent (org.eclipse.bpmn2.BoundaryEvent)9 CompensateEventDefinition (org.eclipse.bpmn2.CompensateEventDefinition)9 ErrorEventDefinition (org.eclipse.bpmn2.ErrorEventDefinition)9 MessageEventDefinition (org.eclipse.bpmn2.MessageEventDefinition)9 SignalEventDefinition (org.eclipse.bpmn2.SignalEventDefinition)9 CallActivity (org.eclipse.bpmn2.CallActivity)8