Search in sources :

Example 1 with ExtensionAttribute

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

the class BpmnXMLUtil method writeExtensionElement.

protected static void writeExtensionElement(ExtensionElement extensionElement, Map<String, String> namespaceMap, XMLStreamWriter xtw) throws Exception {
    if (StringUtils.isNotEmpty(extensionElement.getName())) {
        Map<String, String> localNamespaceMap = new HashMap<String, String>();
        if (StringUtils.isNotEmpty(extensionElement.getNamespace())) {
            if (StringUtils.isNotEmpty(extensionElement.getNamespacePrefix())) {
                xtw.writeStartElement(extensionElement.getNamespacePrefix(), extensionElement.getName(), extensionElement.getNamespace());
                if (namespaceMap.containsKey(extensionElement.getNamespacePrefix()) == false || namespaceMap.get(extensionElement.getNamespacePrefix()).equals(extensionElement.getNamespace()) == false) {
                    xtw.writeNamespace(extensionElement.getNamespacePrefix(), extensionElement.getNamespace());
                    namespaceMap.put(extensionElement.getNamespacePrefix(), extensionElement.getNamespace());
                    localNamespaceMap.put(extensionElement.getNamespacePrefix(), extensionElement.getNamespace());
                }
            } else {
                xtw.writeStartElement(extensionElement.getNamespace(), extensionElement.getName());
            }
        } else {
            xtw.writeStartElement(extensionElement.getName());
        }
        for (List<ExtensionAttribute> attributes : extensionElement.getAttributes().values()) {
            for (ExtensionAttribute attribute : attributes) {
                if (StringUtils.isNotEmpty(attribute.getName()) && attribute.getValue() != null) {
                    if (StringUtils.isNotEmpty(attribute.getNamespace())) {
                        if (StringUtils.isNotEmpty(attribute.getNamespacePrefix())) {
                            if (namespaceMap.containsKey(attribute.getNamespacePrefix()) == false || namespaceMap.get(attribute.getNamespacePrefix()).equals(attribute.getNamespace()) == false) {
                                xtw.writeNamespace(attribute.getNamespacePrefix(), attribute.getNamespace());
                                namespaceMap.put(attribute.getNamespacePrefix(), attribute.getNamespace());
                            }
                            xtw.writeAttribute(attribute.getNamespacePrefix(), attribute.getNamespace(), attribute.getName(), attribute.getValue());
                        } else {
                            xtw.writeAttribute(attribute.getNamespace(), attribute.getName(), attribute.getValue());
                        }
                    } else {
                        xtw.writeAttribute(attribute.getName(), attribute.getValue());
                    }
                }
            }
        }
        if (extensionElement.getElementText() != null) {
            xtw.writeCData(extensionElement.getElementText());
        } else {
            for (List<ExtensionElement> childElements : extensionElement.getChildElements().values()) {
                for (ExtensionElement childElement : childElements) {
                    writeExtensionElement(childElement, namespaceMap, xtw);
                }
            }
        }
        for (String prefix : localNamespaceMap.keySet()) {
            namespaceMap.remove(prefix);
        }
        xtw.writeEndElement();
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ExtensionElement(org.activiti.bpmn.model.ExtensionElement) ExtensionAttribute(org.activiti.bpmn.model.ExtensionAttribute)

Example 2 with ExtensionAttribute

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

the class BpmnXMLUtil method parseExtensionElement.

public static ExtensionElement parseExtensionElement(XMLStreamReader xtr) throws Exception {
    ExtensionElement extensionElement = new ExtensionElement();
    extensionElement.setName(xtr.getLocalName());
    if (StringUtils.isNotEmpty(xtr.getNamespaceURI())) {
        extensionElement.setNamespace(xtr.getNamespaceURI());
    }
    if (StringUtils.isNotEmpty(xtr.getPrefix())) {
        extensionElement.setNamespacePrefix(xtr.getPrefix());
    }
    for (int i = 0; i < xtr.getAttributeCount(); i++) {
        ExtensionAttribute extensionAttribute = new ExtensionAttribute();
        extensionAttribute.setName(xtr.getAttributeLocalName(i));
        extensionAttribute.setValue(xtr.getAttributeValue(i));
        if (StringUtils.isNotEmpty(xtr.getAttributeNamespace(i))) {
            extensionAttribute.setNamespace(xtr.getAttributeNamespace(i));
        }
        if (StringUtils.isNotEmpty(xtr.getAttributePrefix(i))) {
            extensionAttribute.setNamespacePrefix(xtr.getAttributePrefix(i));
        }
        extensionElement.addAttribute(extensionAttribute);
    }
    boolean readyWithExtensionElement = false;
    while (readyWithExtensionElement == false && xtr.hasNext()) {
        xtr.next();
        if (xtr.isCharacters() || XMLStreamReader.CDATA == xtr.getEventType()) {
            if (StringUtils.isNotEmpty(xtr.getText().trim())) {
                extensionElement.setElementText(xtr.getText().trim());
            }
        } else if (xtr.isStartElement()) {
            ExtensionElement childExtensionElement = parseExtensionElement(xtr);
            extensionElement.addChildElement(childExtensionElement);
        } else if (xtr.isEndElement() && extensionElement.getName().equalsIgnoreCase(xtr.getLocalName())) {
            readyWithExtensionElement = true;
        }
    }
    return extensionElement;
}
Also used : ExtensionElement(org.activiti.bpmn.model.ExtensionElement) ExtensionAttribute(org.activiti.bpmn.model.ExtensionAttribute)

Example 3 with ExtensionAttribute

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

the class CustomExtensionsConverterTest method validateModel.

private void validateModel(BpmnModel model) {
    Process process = model.getMainProcess();
    assertThat(process.getAttributes()).isNotNull();
    assertThat(process.getAttributes()).hasSize(1);
    List<ExtensionAttribute> attributes = process.getAttributes().get("version");
    assertThat(attributes).isNotNull();
    assertThat(attributes).hasSize(1);
    ExtensionAttribute attribute = attributes.get(0);
    // custom:version = "9"
    assertThat(attribute).isNotNull();
    assertThat(attribute.getNamespace()).isEqualTo("http://custom.org/bpmn");
    assertThat(attribute.getNamespacePrefix()).isEqualTo("custom");
    assertThat(attribute.getName()).isEqualTo("version");
    assertThat(attribute.getValue()).isEqualTo("9");
    List<ActivitiListener> listeners = model.getMainProcess().getExecutionListeners();
    validateExecutionListeners(listeners);
    Map<String, List<ExtensionElement>> extensionElementMap = model.getMainProcess().getExtensionElements();
    validateExtensionElements(extensionElementMap);
    FlowElement flowElement = model.getMainProcess().getFlowElement("servicetask");
    assertThat(flowElement).isNotNull();
    assertThat(flowElement).isInstanceOf(ServiceTask.class);
    assertThat(flowElement.getId()).isEqualTo("servicetask");
    ServiceTask serviceTask = (ServiceTask) flowElement;
    assertThat(serviceTask.getId()).isEqualTo("servicetask");
    assertThat(serviceTask.getName()).isEqualTo("Service task");
    List<FieldExtension> fields = serviceTask.getFieldExtensions();
    assertThat(fields).hasSize(2);
    FieldExtension field = (FieldExtension) fields.get(0);
    assertThat(field.getFieldName()).isEqualTo("testField");
    assertThat(field.getStringValue()).isEqualTo("test");
    field = (FieldExtension) fields.get(1);
    assertThat(field.getFieldName()).isEqualTo("testField2");
    assertThat(field.getExpression()).isEqualTo("${test}");
    listeners = serviceTask.getExecutionListeners();
    validateExecutionListeners(listeners);
    extensionElementMap = serviceTask.getExtensionElements();
    validateExtensionElements(extensionElementMap);
    assertThat(serviceTask.getBoundaryEvents()).hasSize(1);
    BoundaryEvent boundaryEvent = serviceTask.getBoundaryEvents().get(0);
    assertThat(boundaryEvent.getId()).isEqualTo("timerEvent");
    assertThat(boundaryEvent.getEventDefinitions()).hasSize(1);
    assertThat(boundaryEvent.getEventDefinitions().get(0)).isInstanceOf(TimerEventDefinition.class);
    extensionElementMap = boundaryEvent.getEventDefinitions().get(0).getExtensionElements();
    validateExtensionElements(extensionElementMap);
}
Also used : ServiceTask(org.activiti.bpmn.model.ServiceTask) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) Process(org.activiti.bpmn.model.Process) ActivitiListener(org.activiti.bpmn.model.ActivitiListener) ExtensionAttribute(org.activiti.bpmn.model.ExtensionAttribute) FlowElement(org.activiti.bpmn.model.FlowElement) FieldExtension(org.activiti.bpmn.model.FieldExtension) List(java.util.List)

Example 4 with ExtensionAttribute

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

the class CustomExtensionsConverterTest method validateExtensionElements.

protected void validateExtensionElements(Map<String, List<ExtensionElement>> extensionElementMap) {
    assertThat(extensionElementMap).hasSize(1);
    List<ExtensionElement> extensionElements = extensionElementMap.get("test");
    assertThat(extensionElements).hasSize(2);
    ExtensionElement extensionElement = extensionElements.get(0);
    assertThat(extensionElement).isNotNull();
    assertThat(extensionElement.getName()).isEqualTo("test");
    assertThat(extensionElement.getNamespacePrefix()).isEqualTo("custom");
    assertThat(extensionElement.getNamespace()).isEqualTo("http://custom.org/bpmn");
    assertThat(extensionElement.getAttributes()).hasSize(2);
    List<ExtensionAttribute> attributes = extensionElement.getAttributes().get("id");
    assertThat(attributes).hasSize(1);
    ExtensionAttribute attribute = attributes.get(0);
    assertThat(attribute).isNotNull();
    assertThat(attribute.getName()).isEqualTo("id");
    assertThat(attribute.getValue()).isEqualTo("test");
    assertThat(attribute.getNamespace()).isNull();
    assertThat(attribute.getNamespacePrefix()).isNull();
    attributes = extensionElement.getAttributes().get("name");
    assertThat(attributes).hasSize(1);
    attribute = attributes.get(0);
    assertThat(attribute).isNotNull();
    assertThat(attribute.getName()).isEqualTo("name");
    assertThat(attribute.getValue()).isEqualTo("test");
    assertThat(extensionElement.getChildElements()).hasSize(2);
    List<ExtensionElement> childExtensions = extensionElement.getChildElements().get("name");
    assertThat(childExtensions).hasSize(2);
    ExtensionElement childExtension = childExtensions.get(0);
    assertThat(childExtension).isNotNull();
    assertThat(childExtension.getName()).isEqualTo("name");
    assertThat(childExtension.getNamespacePrefix()).isEqualTo("custom");
    assertThat(childExtension.getNamespace()).isEqualTo("http://custom.org/bpmn");
    assertThat(childExtension.getAttributes()).hasSize(0);
    assertThat(childExtension.getChildElements()).hasSize(1);
    List<ExtensionElement> subChildExtensions = childExtension.getChildElements().get("test");
    assertThat(subChildExtensions).hasSize(1);
    childExtension = subChildExtensions.get(0);
    assertThat(childExtension).isNotNull();
    assertThat(childExtension.getName()).isEqualTo("test");
    assertThat(childExtension.getNamespacePrefix()).isEqualTo("custom");
    assertThat(childExtension.getNamespace()).isEqualTo("http://custom.org/bpmn");
    assertThat(childExtension.getAttributes()).hasSize(0);
    assertThat(childExtension.getChildElements()).hasSize(0);
    assertThat(childExtension.getElementText()).isEqualTo("test");
    childExtensions = extensionElement.getChildElements().get("description");
    assertThat(childExtensions).hasSize(1);
    childExtension = childExtensions.get(0);
    assertThat(childExtension).isNotNull();
    assertThat(childExtension.getName()).isEqualTo("description");
    assertThat(childExtension.getAttributes()).hasSize(1);
    attributes = childExtension.getAttributes().get("id");
    attribute = attributes.get(0);
    assertThat(attribute).isNotNull();
    assertThat(attribute.getName()).isEqualTo("id");
    assertThat(attribute.getValue()).isEqualTo("test");
    assertThat(attribute.getNamespacePrefix()).isEqualTo("custom2");
    assertThat(attribute.getNamespace()).isEqualTo("http://custom2.org/bpmn");
    extensionElement = extensionElements.get(1);
    assertThat(extensionElement).isNotNull();
    assertThat(extensionElement.getName()).isEqualTo("test");
    assertThat(extensionElement.getNamespacePrefix()).isEqualTo("custom");
    assertThat(extensionElement.getNamespace()).isEqualTo("http://custom.org/bpmn");
    assertThat(extensionElement.getAttributes()).hasSize(2);
    attributes = extensionElement.getAttributes().get("id");
    assertThat(attributes).hasSize(1);
    attribute = attributes.get(0);
    assertThat(attribute).isNotNull();
    assertThat(attribute.getName()).isEqualTo("id");
    assertThat(attribute.getValue()).isEqualTo("test2");
    assertThat(attribute.getNamespace()).isNull();
    assertThat(attribute.getNamespacePrefix()).isNull();
    attributes = extensionElement.getAttributes().get("name");
    assertThat(attributes).hasSize(1);
    attribute = attributes.get(0);
    assertThat(attribute).isNotNull();
    assertThat(attribute.getName()).isEqualTo("name");
    assertThat(attribute.getValue()).isEqualTo("test2");
}
Also used : ExtensionElement(org.activiti.bpmn.model.ExtensionElement) ExtensionAttribute(org.activiti.bpmn.model.ExtensionAttribute)

Example 5 with ExtensionAttribute

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

the class CustomNamespaceAttributeConverterTest method validateModel.

private void validateModel(BpmnModel model) {
    Process process = model.getMainProcess();
    assertThat(process.getAttributes()).isNotNull();
    assertThat(process.getAttributes()).hasSize(1);
    List<ExtensionAttribute> attributes = process.getAttributes().get("version");
    assertThat(attributes).isNotNull();
    assertThat(attributes).hasSize(1);
    ExtensionAttribute attribute = attributes.get(0);
    // custom:version = "9"
    assertThat(attribute).isNotNull();
    assertThat(attribute.getNamespace()).isEqualTo("http://custom.org/bpmn");
    assertThat(attribute.getNamespacePrefix()).isEqualTo("custom");
    assertThat(attribute.getName()).isEqualTo("version");
    assertThat(attribute.getValue()).isEqualTo("9");
    FlowElement flowElement = model.getMainProcess().getFlowElement("usertask");
    assertThat(flowElement).isNotNull();
    assertThat(flowElement).isInstanceOf(UserTask.class);
    assertThat(flowElement.getId()).isEqualTo("usertask");
    UserTask userTask = (UserTask) flowElement;
    assertThat(userTask.getId()).isEqualTo("usertask");
    assertThat(userTask.getName()).isEqualTo("User Task");
    Map<String, List<ExtensionAttribute>> attributesMap = userTask.getAttributes();
    assertThat(attributesMap).isNotNull();
    assertThat(attributesMap).hasSize(2);
    attributes = attributesMap.get("id");
    assertThat(attributes).isNotNull();
    assertThat(attributes).hasSize(1);
    ExtensionAttribute a = attributes.get(0);
    assertThat(a).isNotNull();
    assertThat(a.getName()).isEqualTo("id");
    assertThat(a.getValue()).isEqualTo("test");
    assertThat(a.getNamespacePrefix()).isEqualTo("custom2");
    assertThat(a.getNamespace()).isEqualTo("http://custom2.org/bpmn");
    attributes = attributesMap.get("attr");
    assertThat(attributes).isNotNull();
    assertThat(attributes).hasSize(1);
    a = attributes.get(0);
    assertThat(a).isNotNull();
    assertThat(a.getName()).isEqualTo("attr");
    assertThat(a.getValue()).isEqualTo("attrValue");
    assertThat(a.getNamespacePrefix()).isEqualTo("custom2");
    assertThat(a.getNamespace()).isEqualTo("http://custom2.org/bpmn");
}
Also used : FlowElement(org.activiti.bpmn.model.FlowElement) UserTask(org.activiti.bpmn.model.UserTask) Process(org.activiti.bpmn.model.Process) List(java.util.List) ExtensionAttribute(org.activiti.bpmn.model.ExtensionAttribute)

Aggregations

ExtensionAttribute (org.activiti.bpmn.model.ExtensionAttribute)12 ExtensionElement (org.activiti.bpmn.model.ExtensionElement)4 List (java.util.List)3 FlowElement (org.activiti.bpmn.model.FlowElement)2 Process (org.activiti.bpmn.model.Process)2 Arrays.asList (java.util.Arrays.asList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 ActivitiListener (org.activiti.bpmn.model.ActivitiListener)1 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)1 BpmnModel (org.activiti.bpmn.model.BpmnModel)1 Event (org.activiti.bpmn.model.Event)1 FieldExtension (org.activiti.bpmn.model.FieldExtension)1 MessageEventDefinition (org.activiti.bpmn.model.MessageEventDefinition)1 ServiceTask (org.activiti.bpmn.model.ServiceTask)1 UserTask (org.activiti.bpmn.model.UserTask)1 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)1