Search in sources :

Example 26 with FlowElement

use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.

the class ScopedConverterTest method validateModel.

private void validateModel(BpmnModel model) {
    FlowElement flowElement = model.getMainProcess().getFlowElement("outerSubProcess");
    assertNotNull(flowElement);
    assertTrue(flowElement instanceof SubProcess);
    assertEquals("outerSubProcess", flowElement.getId());
    SubProcess outerSubProcess = (SubProcess) flowElement;
    List<BoundaryEvent> eventList = outerSubProcess.getBoundaryEvents();
    assertEquals(1, eventList.size());
    BoundaryEvent boundaryEvent = eventList.get(0);
    assertEquals("outerBoundaryEvent", boundaryEvent.getId());
    FlowElement subElement = outerSubProcess.getFlowElement("innerSubProcess");
    assertNotNull(subElement);
    assertTrue(subElement instanceof SubProcess);
    assertEquals("innerSubProcess", subElement.getId());
    SubProcess innerSubProcess = (SubProcess) subElement;
    eventList = innerSubProcess.getBoundaryEvents();
    assertEquals(1, eventList.size());
    boundaryEvent = eventList.get(0);
    assertEquals("innerBoundaryEvent", boundaryEvent.getId());
    FlowElement taskElement = innerSubProcess.getFlowElement("usertask");
    assertNotNull(taskElement);
    assertTrue(taskElement instanceof UserTask);
    UserTask userTask = (UserTask) taskElement;
    assertEquals("usertask", userTask.getId());
    eventList = userTask.getBoundaryEvents();
    assertEquals(1, eventList.size());
    boundaryEvent = eventList.get(0);
    assertEquals("taskBoundaryEvent", boundaryEvent.getId());
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) FlowElement(org.activiti.bpmn.model.FlowElement) UserTask(org.activiti.bpmn.model.UserTask)

Example 27 with FlowElement

use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.

the class BpmnJsonConverter method convertToJson.

public ObjectNode convertToJson(BpmnModel model) {
    ObjectNode modelNode = objectMapper.createObjectNode();
    double maxX = 0.0;
    double maxY = 0.0;
    for (GraphicInfo flowInfo : model.getLocationMap().values()) {
        if ((flowInfo.getX() + flowInfo.getWidth()) > maxX) {
            maxX = flowInfo.getX() + flowInfo.getWidth();
        }
        if ((flowInfo.getY() + flowInfo.getHeight()) > maxY) {
            maxY = flowInfo.getY() + flowInfo.getHeight();
        }
    }
    maxX += 50;
    maxY += 50;
    if (maxX < 1485) {
        maxX = 1485;
    }
    if (maxY < 700) {
        maxY = 700;
    }
    modelNode.put("bounds", BpmnJsonConverterUtil.createBoundsNode(maxX, maxY, 0, 0));
    modelNode.put("resourceId", "canvas");
    ObjectNode stencilNode = objectMapper.createObjectNode();
    stencilNode.put("id", "BPMNDiagram");
    modelNode.put("stencil", stencilNode);
    ObjectNode stencilsetNode = objectMapper.createObjectNode();
    stencilsetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
    stencilsetNode.put("url", "../editor/stencilsets/bpmn2.0/bpmn2.0.json");
    modelNode.put("stencilset", stencilsetNode);
    ArrayNode shapesArrayNode = objectMapper.createArrayNode();
    Process mainProcess = null;
    if (model.getPools().size() > 0) {
        mainProcess = model.getProcess(model.getPools().get(0).getId());
    } else {
        mainProcess = model.getMainProcess();
    }
    ObjectNode propertiesNode = objectMapper.createObjectNode();
    if (StringUtils.isNotEmpty(mainProcess.getId())) {
        propertiesNode.put(PROPERTY_PROCESS_ID, mainProcess.getId());
    }
    if (StringUtils.isNotEmpty(mainProcess.getName())) {
        propertiesNode.put(PROPERTY_NAME, mainProcess.getName());
    }
    if (StringUtils.isNotEmpty(mainProcess.getDocumentation())) {
        propertiesNode.put(PROPERTY_DOCUMENTATION, mainProcess.getDocumentation());
    }
    if (mainProcess.isExecutable() == false) {
        propertiesNode.put(PROPERTY_PROCESS_EXECUTABLE, "No");
    }
    if (StringUtils.isNoneEmpty(model.getTargetNamespace())) {
        propertiesNode.put(PROPERTY_PROCESS_NAMESPACE, model.getTargetNamespace());
    }
    BpmnJsonConverterUtil.convertMessagesToJson(model.getMessages(), propertiesNode);
    BpmnJsonConverterUtil.convertListenersToJson(mainProcess.getExecutionListeners(), true, propertiesNode);
    BpmnJsonConverterUtil.convertEventListenersToJson(mainProcess.getEventListeners(), propertiesNode);
    BpmnJsonConverterUtil.convertSignalDefinitionsToJson(model, propertiesNode);
    BpmnJsonConverterUtil.convertMessagesToJson(model, propertiesNode);
    if (CollectionUtils.isNotEmpty(mainProcess.getDataObjects())) {
        BpmnJsonConverterUtil.convertDataPropertiesToJson(mainProcess.getDataObjects(), propertiesNode);
    }
    modelNode.put(EDITOR_SHAPE_PROPERTIES, propertiesNode);
    boolean poolHasDI = false;
    if (model.getPools().size() > 0) {
        for (Pool pool : model.getPools()) {
            GraphicInfo graphicInfo = model.getGraphicInfo(pool.getId());
            if (graphicInfo != null) {
                poolHasDI = true;
                break;
            }
        }
    }
    if (model.getPools().size() > 0 && poolHasDI) {
        for (Pool pool : model.getPools()) {
            GraphicInfo graphicInfo = model.getGraphicInfo(pool.getId());
            if (graphicInfo == null)
                continue;
            ObjectNode poolNode = BpmnJsonConverterUtil.createChildShape(pool.getId(), STENCIL_POOL, graphicInfo.getX() + graphicInfo.getWidth(), graphicInfo.getY() + graphicInfo.getHeight(), graphicInfo.getX(), graphicInfo.getY());
            shapesArrayNode.add(poolNode);
            ObjectNode poolPropertiesNode = objectMapper.createObjectNode();
            poolPropertiesNode.put(PROPERTY_OVERRIDE_ID, pool.getId());
            poolPropertiesNode.put(PROPERTY_PROCESS_ID, pool.getProcessRef());
            if (pool.isExecutable() == false) {
                poolPropertiesNode.put(PROPERTY_PROCESS_EXECUTABLE, PROPERTY_VALUE_NO);
            }
            if (StringUtils.isNotEmpty(pool.getName())) {
                poolPropertiesNode.put(PROPERTY_NAME, pool.getName());
            }
            poolNode.put(EDITOR_SHAPE_PROPERTIES, poolPropertiesNode);
            ArrayNode laneShapesArrayNode = objectMapper.createArrayNode();
            poolNode.put(EDITOR_CHILD_SHAPES, laneShapesArrayNode);
            ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
            poolNode.put("outgoing", outgoingArrayNode);
            Process process = model.getProcess(pool.getId());
            if (process != null) {
                Map<String, ArrayNode> laneMap = new HashMap<String, ArrayNode>();
                for (Lane lane : process.getLanes()) {
                    GraphicInfo laneGraphicInfo = model.getGraphicInfo(lane.getId());
                    if (laneGraphicInfo == null)
                        continue;
                    ObjectNode laneNode = BpmnJsonConverterUtil.createChildShape(lane.getId(), STENCIL_LANE, laneGraphicInfo.getX() + laneGraphicInfo.getWidth(), laneGraphicInfo.getY() + laneGraphicInfo.getHeight(), laneGraphicInfo.getX(), laneGraphicInfo.getY());
                    laneShapesArrayNode.add(laneNode);
                    ObjectNode lanePropertiesNode = objectMapper.createObjectNode();
                    lanePropertiesNode.put(PROPERTY_OVERRIDE_ID, lane.getId());
                    if (StringUtils.isNotEmpty(lane.getName())) {
                        lanePropertiesNode.put(PROPERTY_NAME, lane.getName());
                    }
                    laneNode.put(EDITOR_SHAPE_PROPERTIES, lanePropertiesNode);
                    ArrayNode elementShapesArrayNode = objectMapper.createArrayNode();
                    laneNode.put(EDITOR_CHILD_SHAPES, elementShapesArrayNode);
                    laneNode.put("outgoing", objectMapper.createArrayNode());
                    laneMap.put(lane.getId(), elementShapesArrayNode);
                }
                for (FlowElement flowElement : process.getFlowElements()) {
                    Lane laneForElement = null;
                    GraphicInfo laneGraphicInfo = null;
                    FlowElement lookForElement = null;
                    if (flowElement instanceof SequenceFlow) {
                        SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
                        lookForElement = model.getFlowElement(sequenceFlow.getSourceRef());
                    } else {
                        lookForElement = flowElement;
                    }
                    for (Lane lane : process.getLanes()) {
                        if (lane.getFlowReferences().contains(lookForElement.getId())) {
                            laneGraphicInfo = model.getGraphicInfo(lane.getId());
                            if (laneGraphicInfo != null) {
                                laneForElement = lane;
                            }
                            break;
                        }
                    }
                    if (flowElement instanceof SequenceFlow || laneForElement != null) {
                        processFlowElement(flowElement, process, model, laneMap.get(laneForElement.getId()), laneGraphicInfo.getX(), laneGraphicInfo.getY());
                    }
                }
                processArtifacts(process, model, shapesArrayNode, 0.0, 0.0);
            }
            for (MessageFlow messageFlow : model.getMessageFlows().values()) {
                if (messageFlow.getSourceRef().equals(pool.getId())) {
                    outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(messageFlow.getId()));
                }
            }
        }
        processMessageFlows(model, shapesArrayNode);
    } else {
        processFlowElements(model.getMainProcess(), model, shapesArrayNode, 0.0, 0.0);
        processMessageFlows(model, shapesArrayNode);
    }
    modelNode.put(EDITOR_CHILD_SHAPES, shapesArrayNode);
    return modelNode;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) Lane(org.activiti.bpmn.model.Lane) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) MessageFlow(org.activiti.bpmn.model.MessageFlow) FlowElement(org.activiti.bpmn.model.FlowElement) Pool(org.activiti.bpmn.model.Pool) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 28 with FlowElement

use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.

the class BpmnJsonConverter method convertToBpmnModel.

public BpmnModel convertToBpmnModel(JsonNode modelNode) {
    BpmnModel bpmnModel = new BpmnModel();
    bpmnModel.setTargetNamespace("http://activiti.org/test");
    Map<String, JsonNode> shapeMap = new HashMap<String, JsonNode>();
    Map<String, JsonNode> sourceRefMap = new HashMap<String, JsonNode>();
    Map<String, JsonNode> edgeMap = new HashMap<String, JsonNode>();
    Map<String, List<JsonNode>> sourceAndTargetMap = new HashMap<String, List<JsonNode>>();
    readShapeDI(modelNode, 0, 0, shapeMap, sourceRefMap, bpmnModel);
    filterAllEdges(modelNode, edgeMap, sourceAndTargetMap, shapeMap, sourceRefMap);
    readEdgeDI(edgeMap, sourceAndTargetMap, bpmnModel);
    ArrayNode shapesArrayNode = (ArrayNode) modelNode.get(EDITOR_CHILD_SHAPES);
    if (shapesArrayNode == null || shapesArrayNode.size() == 0)
        return bpmnModel;
    boolean nonEmptyPoolFound = false;
    Map<String, Lane> elementInLaneMap = new HashMap<String, Lane>();
    // first create the pool structure
    for (JsonNode shapeNode : shapesArrayNode) {
        String stencilId = BpmnJsonConverterUtil.getStencilId(shapeNode);
        if (STENCIL_POOL.equals(stencilId)) {
            Pool pool = new Pool();
            pool.setId(BpmnJsonConverterUtil.getElementId(shapeNode));
            pool.setName(JsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, shapeNode));
            pool.setProcessRef(JsonConverterUtil.getPropertyValueAsString(PROPERTY_PROCESS_ID, shapeNode));
            pool.setExecutable(JsonConverterUtil.getPropertyValueAsBoolean(PROPERTY_PROCESS_EXECUTABLE, shapeNode, true));
            bpmnModel.getPools().add(pool);
            Process process = new Process();
            process.setId(pool.getProcessRef());
            process.setName(pool.getName());
            process.setExecutable(pool.isExecutable());
            bpmnModel.addProcess(process);
            ArrayNode laneArrayNode = (ArrayNode) shapeNode.get(EDITOR_CHILD_SHAPES);
            for (JsonNode laneNode : laneArrayNode) {
                // should be a lane, but just check to be certain
                String laneStencilId = BpmnJsonConverterUtil.getStencilId(laneNode);
                if (STENCIL_LANE.equals(laneStencilId)) {
                    nonEmptyPoolFound = true;
                    Lane lane = new Lane();
                    lane.setId(BpmnJsonConverterUtil.getElementId(laneNode));
                    lane.setName(JsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, laneNode));
                    lane.setParentProcess(process);
                    process.getLanes().add(lane);
                    processJsonElements(laneNode.get(EDITOR_CHILD_SHAPES), modelNode, lane, shapeMap, bpmnModel);
                    if (CollectionUtils.isNotEmpty(lane.getFlowReferences())) {
                        for (String elementRef : lane.getFlowReferences()) {
                            elementInLaneMap.put(elementRef, lane);
                        }
                    }
                }
            }
        }
    }
    // Signal Definitions exist on the root level
    JsonNode signalDefinitionNode = BpmnJsonConverterUtil.getProperty(PROPERTY_SIGNAL_DEFINITIONS, modelNode);
    signalDefinitionNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(signalDefinitionNode);
    // no idea why this needs to be done twice ..
    signalDefinitionNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(signalDefinitionNode);
    if (signalDefinitionNode != null) {
        if (signalDefinitionNode instanceof ArrayNode) {
            ArrayNode signalDefinitionArrayNode = (ArrayNode) signalDefinitionNode;
            Iterator<JsonNode> signalDefinitionIterator = signalDefinitionArrayNode.iterator();
            while (signalDefinitionIterator.hasNext()) {
                JsonNode signalDefinitionJsonNode = signalDefinitionIterator.next();
                String signalId = signalDefinitionJsonNode.get(PROPERTY_SIGNAL_DEFINITION_ID).asText();
                String signalName = signalDefinitionJsonNode.get(PROPERTY_SIGNAL_DEFINITION_NAME).asText();
                String signalScope = signalDefinitionJsonNode.get(PROPERTY_SIGNAL_DEFINITION_SCOPE).asText();
                Signal signal = new Signal();
                signal.setId(signalId);
                signal.setName(signalName);
                signal.setScope((signalScope.toLowerCase().equals("processinstance")) ? Signal.SCOPE_PROCESS_INSTANCE : Signal.SCOPE_GLOBAL);
                bpmnModel.addSignal(signal);
            }
        }
    }
    if (nonEmptyPoolFound == false) {
        Process process = new Process();
        bpmnModel.getProcesses().add(process);
        process.setId(BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_PROCESS_ID, modelNode));
        process.setName(BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, modelNode));
        String namespace = BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_PROCESS_NAMESPACE, modelNode);
        if (StringUtils.isNotEmpty(namespace)) {
            bpmnModel.setTargetNamespace(namespace);
        }
        process.setDocumentation(BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_DOCUMENTATION, modelNode));
        JsonNode processExecutableNode = JsonConverterUtil.getProperty(PROPERTY_PROCESS_EXECUTABLE, modelNode);
        if (processExecutableNode != null && StringUtils.isNotEmpty(processExecutableNode.asText())) {
            process.setExecutable(JsonConverterUtil.getPropertyValueAsBoolean(PROPERTY_PROCESS_EXECUTABLE, modelNode));
        }
        BpmnJsonConverterUtil.convertJsonToMessages(modelNode, bpmnModel);
        BpmnJsonConverterUtil.convertJsonToListeners(modelNode, process);
        JsonNode eventListenersNode = BpmnJsonConverterUtil.getProperty(PROPERTY_EVENT_LISTENERS, modelNode);
        if (eventListenersNode != null) {
            eventListenersNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(eventListenersNode);
            BpmnJsonConverterUtil.parseEventListeners(eventListenersNode.get(PROPERTY_EVENTLISTENER_VALUE), process);
        }
        JsonNode processDataPropertiesNode = modelNode.get(EDITOR_SHAPE_PROPERTIES).get(PROPERTY_DATA_PROPERTIES);
        if (processDataPropertiesNode != null) {
            List<ValuedDataObject> dataObjects = BpmnJsonConverterUtil.convertJsonToDataProperties(processDataPropertiesNode, process);
            process.setDataObjects(dataObjects);
            process.getFlowElements().addAll(dataObjects);
        }
        processJsonElements(shapesArrayNode, modelNode, process, shapeMap, bpmnModel);
    } else {
        // sequence flows are on root level so need additional parsing for pools
        for (JsonNode shapeNode : shapesArrayNode) {
            if (STENCIL_SEQUENCE_FLOW.equalsIgnoreCase(BpmnJsonConverterUtil.getStencilId(shapeNode)) || STENCIL_ASSOCIATION.equalsIgnoreCase(BpmnJsonConverterUtil.getStencilId(shapeNode))) {
                String sourceRef = BpmnJsonConverterUtil.lookForSourceRef(shapeNode.get(EDITOR_SHAPE_ID).asText(), modelNode.get(EDITOR_CHILD_SHAPES));
                if (sourceRef != null) {
                    Lane lane = elementInLaneMap.get(sourceRef);
                    SequenceFlowJsonConverter flowConverter = new SequenceFlowJsonConverter();
                    if (lane != null) {
                        flowConverter.convertToBpmnModel(shapeNode, modelNode, this, lane, shapeMap, bpmnModel);
                    } else {
                        flowConverter.convertToBpmnModel(shapeNode, modelNode, this, bpmnModel.getProcesses().get(0), shapeMap, bpmnModel);
                    }
                }
            }
        }
    }
    // sequence flows are now all on root level
    Map<String, SubProcess> subShapesMap = new HashMap<String, SubProcess>();
    for (Process process : bpmnModel.getProcesses()) {
        for (FlowElement flowElement : process.findFlowElementsOfType(SubProcess.class)) {
            SubProcess subProcess = (SubProcess) flowElement;
            fillSubShapes(subShapesMap, subProcess);
        }
        if (subShapesMap.size() > 0) {
            List<String> removeSubFlowsList = new ArrayList<String>();
            for (FlowElement flowElement : process.findFlowElementsOfType(SequenceFlow.class)) {
                SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
                if (subShapesMap.containsKey(sequenceFlow.getSourceRef())) {
                    SubProcess subProcess = subShapesMap.get(sequenceFlow.getSourceRef());
                    if (subProcess.getFlowElement(sequenceFlow.getId()) == null) {
                        subProcess.addFlowElement(sequenceFlow);
                        removeSubFlowsList.add(sequenceFlow.getId());
                    }
                }
            }
            for (String flowId : removeSubFlowsList) {
                process.removeFlowElement(flowId);
            }
        }
    }
    Map<String, FlowWithContainer> allFlowMap = new HashMap<String, FlowWithContainer>();
    List<Gateway> gatewayWithOrderList = new ArrayList<Gateway>();
    // post handling of process elements
    for (Process process : bpmnModel.getProcesses()) {
        postProcessElements(process, process.getFlowElements(), edgeMap, bpmnModel, allFlowMap, gatewayWithOrderList);
    }
    // sort the sequence flows
    for (Gateway gateway : gatewayWithOrderList) {
        List<ExtensionElement> orderList = gateway.getExtensionElements().get("EDITOR_FLOW_ORDER");
        if (CollectionUtils.isNotEmpty(orderList)) {
            for (ExtensionElement orderElement : orderList) {
                String flowValue = orderElement.getElementText();
                if (StringUtils.isNotEmpty(flowValue)) {
                    if (allFlowMap.containsKey(flowValue)) {
                        FlowWithContainer flowWithContainer = allFlowMap.get(flowValue);
                        flowWithContainer.getFlowContainer().removeFlowElement(flowWithContainer.getSequenceFlow().getId());
                        flowWithContainer.getFlowContainer().addFlowElement(flowWithContainer.getSequenceFlow());
                    }
                }
            }
        }
        gateway.getExtensionElements().remove("EDITOR_FLOW_ORDER");
    }
    return bpmnModel;
}
Also used : ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) HashMap(java.util.HashMap) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) ArrayList(java.util.ArrayList) ExtensionElement(org.activiti.bpmn.model.ExtensionElement) JsonNode(com.fasterxml.jackson.databind.JsonNode) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) BpmnModel(org.activiti.bpmn.model.BpmnModel) Signal(org.activiti.bpmn.model.Signal) Gateway(org.activiti.bpmn.model.Gateway) ArrayList(java.util.ArrayList) List(java.util.List) Pool(org.activiti.bpmn.model.Pool) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) SubProcess(org.activiti.bpmn.model.SubProcess) Lane(org.activiti.bpmn.model.Lane) FlowElement(org.activiti.bpmn.model.FlowElement)

Example 29 with FlowElement

use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.

the class BpmnJsonConverterUtil method parseListeners.

protected static void parseListeners(JsonNode listenersNode, BaseElement element, boolean isTaskListener) {
    if (listenersNode == null)
        return;
    listenersNode = validateIfNodeIsTextual(listenersNode);
    for (JsonNode listenerNode : listenersNode) {
        listenerNode = validateIfNodeIsTextual(listenerNode);
        JsonNode eventNode = listenerNode.get(PROPERTY_LISTENER_EVENT);
        if (eventNode != null && eventNode.isNull() == false && StringUtils.isNotEmpty(eventNode.asText())) {
            ActivitiListener listener = new ActivitiListener();
            listener.setEvent(eventNode.asText());
            if (StringUtils.isNotEmpty(getValueAsString(PROPERTY_LISTENER_CLASS_NAME, listenerNode))) {
                listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);
                listener.setImplementation(getValueAsString(PROPERTY_LISTENER_CLASS_NAME, listenerNode));
            } else if (StringUtils.isNotEmpty(getValueAsString(PROPERTY_LISTENER_EXPRESSION, listenerNode))) {
                listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION);
                listener.setImplementation(getValueAsString(PROPERTY_LISTENER_EXPRESSION, listenerNode));
            } else if (StringUtils.isNotEmpty(getValueAsString(PROPERTY_LISTENER_DELEGATE_EXPRESSION, listenerNode))) {
                listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
                listener.setImplementation(getValueAsString(PROPERTY_LISTENER_DELEGATE_EXPRESSION, listenerNode));
            }
            JsonNode fieldsNode = listenerNode.get(PROPERTY_LISTENER_FIELDS);
            if (fieldsNode != null) {
                for (JsonNode fieldNode : fieldsNode) {
                    JsonNode nameNode = fieldNode.get(PROPERTY_FIELD_NAME);
                    if (nameNode != null && nameNode.isNull() == false && StringUtils.isNotEmpty(nameNode.asText())) {
                        FieldExtension fieldExtension = new FieldExtension();
                        fieldExtension.setFieldName(nameNode.asText());
                        fieldExtension.setStringValue(getValueAsString(PROPERTY_FIELD_STRING_VALUE, fieldNode));
                        if (StringUtils.isEmpty(fieldExtension.getStringValue())) {
                            fieldExtension.setStringValue(getValueAsString(PROPERTY_FIELD_STRING, fieldNode));
                        }
                        if (StringUtils.isEmpty(fieldExtension.getStringValue())) {
                            fieldExtension.setExpression(getValueAsString(PROPERTY_FIELD_EXPRESSION, fieldNode));
                        }
                        listener.getFieldExtensions().add(fieldExtension);
                    }
                }
            }
            if (element instanceof Process) {
                ((Process) element).getExecutionListeners().add(listener);
            } else if (element instanceof SequenceFlow) {
                ((SequenceFlow) element).getExecutionListeners().add(listener);
            } else if (element instanceof UserTask) {
                if (isTaskListener) {
                    ((UserTask) element).getTaskListeners().add(listener);
                } else {
                    ((UserTask) element).getExecutionListeners().add(listener);
                }
            } else if (element instanceof FlowElement) {
                ((FlowElement) element).getExecutionListeners().add(listener);
            }
        }
    }
}
Also used : FieldExtension(org.activiti.bpmn.model.FieldExtension) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) FlowElement(org.activiti.bpmn.model.FlowElement) UserTask(org.activiti.bpmn.model.UserTask) JsonNode(com.fasterxml.jackson.databind.JsonNode) Process(org.activiti.bpmn.model.Process) ActivitiListener(org.activiti.bpmn.model.ActivitiListener)

Example 30 with FlowElement

use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.

the class CatchEventConverterTest method validateModel.

private void validateModel(BpmnModel model) {
    FlowElement timerElement = model.getMainProcess().getFlowElement("timer_evt");
    EventDefinition timerEvent = extractEventDefinition(timerElement);
    assertTrue(timerEvent instanceof TimerEventDefinition);
    TimerEventDefinition ted = (TimerEventDefinition) timerEvent;
    assertEquals("PT5M", ted.getTimeDuration());
    FlowElement signalElement = model.getMainProcess().getFlowElement("signal_evt");
    EventDefinition signalEvent = extractEventDefinition(signalElement);
    assertTrue(signalEvent instanceof SignalEventDefinition);
    SignalEventDefinition sed = (SignalEventDefinition) signalEvent;
    assertEquals("signal_ref", sed.getSignalRef());
    FlowElement messageElement = model.getMainProcess().getFlowElement("message_evt");
    EventDefinition messageEvent = extractEventDefinition(messageElement);
    assertTrue(messageEvent instanceof MessageEventDefinition);
    MessageEventDefinition med = (MessageEventDefinition) messageEvent;
    assertEquals("message_ref", med.getMessageRef());
}
Also used : FlowElement(org.activiti.bpmn.model.FlowElement) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) EventDefinition(org.activiti.bpmn.model.EventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) TimerEventDefinition(org.activiti.bpmn.model.TimerEventDefinition) TimerEventDefinition(org.activiti.bpmn.model.TimerEventDefinition)

Aggregations

FlowElement (org.activiti.bpmn.model.FlowElement)75 SubProcess (org.activiti.bpmn.model.SubProcess)27 UserTask (org.activiti.bpmn.model.UserTask)25 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)24 StartEvent (org.activiti.bpmn.model.StartEvent)14 Process (org.activiti.bpmn.model.Process)13 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)11 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 ActivitiListener (org.activiti.bpmn.model.ActivitiListener)9 Activity (org.activiti.bpmn.model.Activity)9 ServiceTask (org.activiti.bpmn.model.ServiceTask)9 Gateway (org.activiti.bpmn.model.Gateway)8 GraphicInfo (org.activiti.bpmn.model.GraphicInfo)7 TimerEventDefinition (org.activiti.bpmn.model.TimerEventDefinition)7 Artifact (org.activiti.bpmn.model.Artifact)6 FlowNode (org.activiti.bpmn.model.FlowNode)6 SignalEventDefinition (org.activiti.bpmn.model.SignalEventDefinition)6 EventDefinition (org.activiti.bpmn.model.EventDefinition)5 ExclusiveGateway (org.activiti.bpmn.model.ExclusiveGateway)5