Search in sources :

Example 16 with SubProcess

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

the class BpmnXMLConverter method processFlowElements.

private void processFlowElements(Collection<FlowElement> flowElementList, BaseElement parentScope) {
    for (FlowElement flowElement : flowElementList) {
        if (flowElement instanceof SequenceFlow) {
            SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
            FlowNode sourceNode = getFlowNodeFromScope(sequenceFlow.getSourceRef(), parentScope);
            if (sourceNode != null) {
                sourceNode.getOutgoingFlows().add(sequenceFlow);
            }
            FlowNode targetNode = getFlowNodeFromScope(sequenceFlow.getTargetRef(), parentScope);
            if (targetNode != null) {
                targetNode.getIncomingFlows().add(sequenceFlow);
            }
        } else if (flowElement instanceof BoundaryEvent) {
            BoundaryEvent boundaryEvent = (BoundaryEvent) flowElement;
            FlowElement attachedToElement = getFlowNodeFromScope(boundaryEvent.getAttachedToRefId(), parentScope);
            if (attachedToElement != null) {
                boundaryEvent.setAttachedToRef((Activity) attachedToElement);
                ((Activity) attachedToElement).getBoundaryEvents().add(boundaryEvent);
            }
        } else if (flowElement instanceof SubProcess) {
            SubProcess subProcess = (SubProcess) flowElement;
            processFlowElements(subProcess.getFlowElements(), subProcess);
        }
    }
}
Also used : EventSubProcess(org.activiti.bpmn.model.EventSubProcess) SubProcess(org.activiti.bpmn.model.SubProcess) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) FlowElement(org.activiti.bpmn.model.FlowElement) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) Activity(org.activiti.bpmn.model.Activity) FlowNode(org.activiti.bpmn.model.FlowNode)

Example 17 with SubProcess

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

the class BPMNDIExport method writeBPMNDI.

public static void writeBPMNDI(BpmnModel model, XMLStreamWriter xtw) throws Exception {
    // BPMN DI information
    xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_DIAGRAM, BPMNDI_NAMESPACE);
    String processId = null;
    if (!model.getPools().isEmpty()) {
        processId = "Collaboration";
    } else {
        processId = model.getMainProcess().getId();
    }
    xtw.writeAttribute(ATTRIBUTE_ID, "BPMNDiagram_" + processId);
    xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_PLANE, BPMNDI_NAMESPACE);
    xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, processId);
    xtw.writeAttribute(ATTRIBUTE_ID, "BPMNPlane_" + processId);
    for (String elementId : model.getLocationMap().keySet()) {
        if (model.getFlowElement(elementId) != null || model.getArtifact(elementId) != null || model.getPool(elementId) != null || model.getLane(elementId) != null) {
            xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_SHAPE, BPMNDI_NAMESPACE);
            xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, elementId);
            xtw.writeAttribute(ATTRIBUTE_ID, "BPMNShape_" + elementId);
            GraphicInfo graphicInfo = model.getGraphicInfo(elementId);
            FlowElement flowElement = model.getFlowElement(elementId);
            if (flowElement instanceof SubProcess && graphicInfo.getExpanded() != null) {
                xtw.writeAttribute(ATTRIBUTE_DI_IS_EXPANDED, String.valueOf(graphicInfo.getExpanded()));
            }
            xtw.writeStartElement(OMGDC_PREFIX, ELEMENT_DI_BOUNDS, OMGDC_NAMESPACE);
            xtw.writeAttribute(ATTRIBUTE_DI_HEIGHT, "" + graphicInfo.getHeight());
            xtw.writeAttribute(ATTRIBUTE_DI_WIDTH, "" + graphicInfo.getWidth());
            xtw.writeAttribute(ATTRIBUTE_DI_X, "" + graphicInfo.getX());
            xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + graphicInfo.getY());
            xtw.writeEndElement();
            xtw.writeEndElement();
        }
    }
    for (String elementId : model.getFlowLocationMap().keySet()) {
        if (model.getFlowElement(elementId) != null || model.getArtifact(elementId) != null || model.getMessageFlow(elementId) != null) {
            xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_EDGE, BPMNDI_NAMESPACE);
            xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, elementId);
            xtw.writeAttribute(ATTRIBUTE_ID, "BPMNEdge_" + elementId);
            List<GraphicInfo> graphicInfoList = model.getFlowLocationGraphicInfo(elementId);
            for (GraphicInfo graphicInfo : graphicInfoList) {
                xtw.writeStartElement(OMGDI_PREFIX, ELEMENT_DI_WAYPOINT, OMGDI_NAMESPACE);
                xtw.writeAttribute(ATTRIBUTE_DI_X, "" + graphicInfo.getX());
                xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + graphicInfo.getY());
                xtw.writeEndElement();
            }
            GraphicInfo labelGraphicInfo = model.getLabelGraphicInfo(elementId);
            FlowElement flowElement = model.getFlowElement(elementId);
            MessageFlow messageFlow = null;
            if (flowElement == null) {
                messageFlow = model.getMessageFlow(elementId);
            }
            boolean hasName = false;
            if (flowElement != null && StringUtils.isNotEmpty(flowElement.getName())) {
                hasName = true;
            } else if (messageFlow != null && StringUtils.isNotEmpty(messageFlow.getName())) {
                hasName = true;
            }
            if (labelGraphicInfo != null && hasName) {
                xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_LABEL, BPMNDI_NAMESPACE);
                xtw.writeStartElement(OMGDC_PREFIX, ELEMENT_DI_BOUNDS, OMGDC_NAMESPACE);
                xtw.writeAttribute(ATTRIBUTE_DI_HEIGHT, "" + labelGraphicInfo.getHeight());
                xtw.writeAttribute(ATTRIBUTE_DI_WIDTH, "" + labelGraphicInfo.getWidth());
                xtw.writeAttribute(ATTRIBUTE_DI_X, "" + labelGraphicInfo.getX());
                xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + labelGraphicInfo.getY());
                xtw.writeEndElement();
                xtw.writeEndElement();
            }
            xtw.writeEndElement();
        }
    }
    // end BPMN DI elements
    xtw.writeEndElement();
    xtw.writeEndElement();
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) FlowElement(org.activiti.bpmn.model.FlowElement) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) MessageFlow(org.activiti.bpmn.model.MessageFlow)

Example 18 with SubProcess

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

the class BpmnDeployer method localizeFlowElements.

protected boolean localizeFlowElements(Collection<FlowElement> flowElements, ObjectNode infoNode) {
    boolean localizationValuesChanged = false;
    if (flowElements == null)
        return localizationValuesChanged;
    CommandContext commandContext = Context.getCommandContext();
    DynamicBpmnService dynamicBpmnService = commandContext.getProcessEngineConfiguration().getDynamicBpmnService();
    for (FlowElement flowElement : flowElements) {
        if (flowElement instanceof UserTask || flowElement instanceof SubProcess) {
            List<ExtensionElement> localizationElements = flowElement.getExtensionElements().get("localization");
            if (localizationElements != null) {
                for (ExtensionElement localizationElement : localizationElements) {
                    if (BpmnXMLConstants.ACTIVITI_EXTENSIONS_PREFIX.equals(localizationElement.getNamespacePrefix())) {
                        String locale = localizationElement.getAttributeValue(null, "locale");
                        String name = localizationElement.getAttributeValue(null, "name");
                        String documentation = null;
                        List<ExtensionElement> documentationElements = localizationElement.getChildElements().get("documentation");
                        if (documentationElements != null) {
                            for (ExtensionElement documentationElement : documentationElements) {
                                documentation = StringUtils.trimToNull(documentationElement.getElementText());
                                break;
                            }
                        }
                        String flowElementId = flowElement.getId();
                        if (isEqualToCurrentLocalizationValue(locale, flowElementId, "name", name, infoNode) == false) {
                            dynamicBpmnService.changeLocalizationName(locale, flowElementId, name, infoNode);
                            localizationValuesChanged = true;
                        }
                        if (documentation != null && isEqualToCurrentLocalizationValue(locale, flowElementId, "description", documentation, infoNode) == false) {
                            dynamicBpmnService.changeLocalizationDescription(locale, flowElementId, documentation, infoNode);
                            localizationValuesChanged = true;
                        }
                        break;
                    }
                }
            }
            if (flowElement instanceof SubProcess) {
                SubProcess subprocess = (SubProcess) flowElement;
                boolean isFlowElementLocalizationChanged = localizeFlowElements(subprocess.getFlowElements(), infoNode);
                boolean isDataObjectLocalizationChanged = localizeDataObjectElements(subprocess.getDataObjects(), infoNode);
                if (isFlowElementLocalizationChanged || isDataObjectLocalizationChanged) {
                    localizationValuesChanged = true;
                }
            }
        }
    }
    return localizationValuesChanged;
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) DynamicBpmnService(org.activiti.engine.DynamicBpmnService) FlowElement(org.activiti.bpmn.model.FlowElement) UserTask(org.activiti.bpmn.model.UserTask) ExtensionElement(org.activiti.bpmn.model.ExtensionElement)

Example 19 with SubProcess

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

the class DataObjectValidator method executeValidation.

@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
    // Gather data objects
    List<ValuedDataObject> allDataObjects = new ArrayList<ValuedDataObject>();
    allDataObjects.addAll(process.getDataObjects());
    List<SubProcess> subProcesses = process.findFlowElementsOfType(SubProcess.class, true);
    for (SubProcess subProcess : subProcesses) {
        allDataObjects.addAll(subProcess.getDataObjects());
    }
    // Validate
    for (ValuedDataObject dataObject : allDataObjects) {
        if (StringUtils.isEmpty(dataObject.getName())) {
            addError(errors, Problems.DATA_OBJECT_MISSING_NAME, process, dataObject, "Name is mandatory for a data object");
        }
    }
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) ArrayList(java.util.ArrayList)

Example 20 with SubProcess

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

the class ValuedDataObjectConverterTest method validateModel.

private void validateModel(BpmnModel model) {
    FlowElement flowElement = model.getMainProcess().getFlowElement("start1");
    assertNotNull(flowElement);
    assertTrue(flowElement instanceof StartEvent);
    assertEquals("start1", flowElement.getId());
    // verify the main process data objects
    List<ValuedDataObject> dataObjects = model.getProcess(null).getDataObjects();
    assertEquals(7, dataObjects.size());
    Map<String, ValuedDataObject> objectMap = new HashMap<String, ValuedDataObject>();
    for (ValuedDataObject valueObj : dataObjects) {
        objectMap.put(valueObj.getId(), valueObj);
    }
    ValuedDataObject dataObj = objectMap.get("dObj1");
    assertEquals("dObj1", dataObj.getId());
    assertEquals("StringTest", dataObj.getName());
    assertEquals("xsd:string", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof String);
    assertEquals("Testing1&2&3", dataObj.getValue());
    dataObj = objectMap.get("dObj2");
    assertEquals("dObj2", dataObj.getId());
    assertEquals("BooleanTest", dataObj.getName());
    assertEquals("xsd:boolean", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof Boolean);
    assertEquals(new Boolean(true), dataObj.getValue());
    dataObj = objectMap.get("dObj3");
    assertEquals("dObj3", dataObj.getId());
    assertEquals("DateTest", dataObj.getName());
    assertEquals("xsd:datetime", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof Date);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    assertEquals("2013-09-16T11:23:00", sdf.format(dataObj.getValue()));
    dataObj = objectMap.get("dObj4");
    assertEquals("dObj4", dataObj.getId());
    assertEquals("DoubleTest", dataObj.getName());
    assertEquals("xsd:double", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof Double);
    assertEquals(new Double(123456789), dataObj.getValue());
    dataObj = objectMap.get("dObj5");
    assertEquals("dObj5", dataObj.getId());
    assertEquals("IntegerTest", dataObj.getName());
    assertEquals("xsd:int", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof Integer);
    assertEquals(new Integer(123), dataObj.getValue());
    dataObj = objectMap.get("dObj6");
    assertEquals("dObj6", dataObj.getId());
    assertEquals("LongTest", dataObj.getName());
    assertEquals("xsd:long", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof Long);
    assertEquals(new Long(-123456), dataObj.getValue());
    assertEquals(1, dataObj.getExtensionElements().size());
    List<ExtensionElement> testValues = dataObj.getExtensionElements().get("testvalue");
    assertNotNull(testValues);
    assertEquals(1, testValues.size());
    assertEquals("testvalue", testValues.get(0).getName());
    assertEquals("test", testValues.get(0).getElementText());
    dataObj = objectMap.get("NoData");
    assertEquals("NoData", dataObj.getId());
    assertEquals("NoData", dataObj.getName());
    assertEquals("xsd:datetime", dataObj.getItemSubjectRef().getStructureRef());
    assertNull(dataObj.getValue());
    flowElement = model.getMainProcess().getFlowElement("userTask1");
    assertNotNull(flowElement);
    assertTrue(flowElement instanceof UserTask);
    assertEquals("userTask1", flowElement.getId());
    UserTask userTask = (UserTask) flowElement;
    assertEquals("kermit", userTask.getAssignee());
    flowElement = model.getMainProcess().getFlowElement("subprocess1");
    assertNotNull(flowElement);
    assertTrue(flowElement instanceof SubProcess);
    assertEquals("subprocess1", flowElement.getId());
    SubProcess subProcess = (SubProcess) flowElement;
    assertEquals(11, subProcess.getFlowElements().size());
    // verify the sub process data objects
    dataObjects = subProcess.getDataObjects();
    assertEquals(6, dataObjects.size());
    objectMap = new HashMap<String, ValuedDataObject>();
    for (ValuedDataObject valueObj : dataObjects) {
        objectMap.put(valueObj.getId(), valueObj);
    }
    dataObj = objectMap.get("dObj7");
    assertEquals("dObj7", dataObj.getId());
    assertEquals("StringSubTest", dataObj.getName());
    assertEquals("xsd:string", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof String);
    assertEquals("Testing456", dataObj.getValue());
    dataObj = objectMap.get("dObj8");
    assertEquals("dObj8", dataObj.getId());
    assertEquals("BooleanSubTest", dataObj.getName());
    assertEquals("xsd:boolean", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof Boolean);
    assertEquals(new Boolean(false), dataObj.getValue());
    dataObj = objectMap.get("dObj9");
    assertEquals("dObj9", dataObj.getId());
    assertEquals("DateSubTest", dataObj.getName());
    assertEquals("xsd:datetime", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof Date);
    assertEquals("2013-11-11T22:00:00", sdf.format(dataObj.getValue()));
    dataObj = objectMap.get("dObj10");
    assertEquals("dObj10", dataObj.getId());
    assertEquals("DoubleSubTest", dataObj.getName());
    assertEquals("xsd:double", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof Double);
    assertEquals(new Double(678912345), dataObj.getValue());
    dataObj = objectMap.get("dObj11");
    assertEquals("dObj11", dataObj.getId());
    assertEquals("IntegerSubTest", dataObj.getName());
    assertEquals("xsd:int", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof Integer);
    assertEquals(new Integer(45), dataObj.getValue());
    dataObj = objectMap.get("dObj12");
    assertEquals("dObj12", dataObj.getId());
    assertEquals("LongSubTest", dataObj.getName());
    assertEquals("xsd:long", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof Long);
    assertEquals(new Long(456123), dataObj.getValue());
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) HashMap(java.util.HashMap) ExtensionElement(org.activiti.bpmn.model.ExtensionElement) UserTask(org.activiti.bpmn.model.UserTask) Date(java.util.Date) FlowElement(org.activiti.bpmn.model.FlowElement) StartEvent(org.activiti.bpmn.model.StartEvent) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

SubProcess (org.activiti.bpmn.model.SubProcess)32 FlowElement (org.activiti.bpmn.model.FlowElement)24 UserTask (org.activiti.bpmn.model.UserTask)10 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)8 StartEvent (org.activiti.bpmn.model.StartEvent)8 ValuedDataObject (org.activiti.bpmn.model.ValuedDataObject)8 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)7 EventSubProcess (org.activiti.bpmn.model.EventSubProcess)7 GraphicInfo (org.activiti.bpmn.model.GraphicInfo)7 Gateway (org.activiti.bpmn.model.Gateway)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Activity (org.activiti.bpmn.model.Activity)4 Artifact (org.activiti.bpmn.model.Artifact)4 ExtensionElement (org.activiti.bpmn.model.ExtensionElement)4 FlowNode (org.activiti.bpmn.model.FlowNode)4 Transaction (org.activiti.bpmn.model.Transaction)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 DataObject (org.activiti.bpmn.model.DataObject)3