Search in sources :

Example 21 with ExtensionElement

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

the class BaseBpmnJsonConverter method convertToBpmnModel.

public void convertToBpmnModel(JsonNode elementNode, JsonNode modelNode, ActivityProcessor processor, BaseElement parentElement, Map<String, JsonNode> shapeMap, BpmnModel bpmnModel) {
    this.processor = processor;
    this.model = bpmnModel;
    BaseElement baseElement = convertJsonToElement(elementNode, modelNode, shapeMap);
    baseElement.setId(BpmnJsonConverterUtil.getElementId(elementNode));
    if (baseElement instanceof FlowElement) {
        FlowElement flowElement = (FlowElement) baseElement;
        flowElement.setName(getPropertyValueAsString(PROPERTY_NAME, elementNode));
        flowElement.setDocumentation(getPropertyValueAsString(PROPERTY_DOCUMENTATION, elementNode));
        BpmnJsonConverterUtil.convertJsonToListeners(elementNode, flowElement);
        if (baseElement instanceof Activity) {
            Activity activity = (Activity) baseElement;
            activity.setAsynchronous(getPropertyValueAsBoolean(PROPERTY_ASYNCHRONOUS, elementNode));
            activity.setNotExclusive(!getPropertyValueAsBoolean(PROPERTY_EXCLUSIVE, elementNode));
            String multiInstanceType = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_TYPE, elementNode);
            String multiInstanceCardinality = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_CARDINALITY, elementNode);
            String multiInstanceCollection = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_COLLECTION, elementNode);
            String multiInstanceCondition = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_CONDITION, elementNode);
            if (StringUtils.isNotEmpty(multiInstanceType) && !"none".equalsIgnoreCase(multiInstanceType)) {
                String multiInstanceVariable = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_VARIABLE, elementNode);
                MultiInstanceLoopCharacteristics multiInstanceObject = new MultiInstanceLoopCharacteristics();
                if ("sequential".equalsIgnoreCase(multiInstanceType)) {
                    multiInstanceObject.setSequential(true);
                } else {
                    multiInstanceObject.setSequential(false);
                }
                multiInstanceObject.setLoopCardinality(multiInstanceCardinality);
                multiInstanceObject.setInputDataItem(multiInstanceCollection);
                multiInstanceObject.setElementVariable(multiInstanceVariable);
                multiInstanceObject.setCompletionCondition(multiInstanceCondition);
                activity.setLoopCharacteristics(multiInstanceObject);
            }
        } else if (baseElement instanceof Gateway) {
            JsonNode flowOrderNode = getProperty(PROPERTY_SEQUENCEFLOW_ORDER, elementNode);
            if (flowOrderNode != null) {
                flowOrderNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(flowOrderNode);
                JsonNode orderArray = flowOrderNode.get("sequenceFlowOrder");
                if (orderArray != null && orderArray.size() > 0) {
                    for (JsonNode orderNode : orderArray) {
                        ExtensionElement orderElement = new ExtensionElement();
                        orderElement.setName("EDITOR_FLOW_ORDER");
                        orderElement.setElementText(orderNode.asText());
                        flowElement.addExtensionElement(orderElement);
                    }
                }
            }
        }
    }
    if (baseElement instanceof FlowElement) {
        FlowElement flowElement = (FlowElement) baseElement;
        if (flowElement instanceof SequenceFlow) {
            ExtensionElement idExtensionElement = new ExtensionElement();
            idExtensionElement.setName("EDITOR_RESOURCEID");
            idExtensionElement.setElementText(elementNode.get(EDITOR_SHAPE_ID).asText());
            flowElement.addExtensionElement(idExtensionElement);
        }
        if (parentElement instanceof Process) {
            ((Process) parentElement).addFlowElement(flowElement);
        } else if (parentElement instanceof SubProcess) {
            ((SubProcess) parentElement).addFlowElement(flowElement);
        } else if (parentElement instanceof Lane) {
            Lane lane = (Lane) parentElement;
            lane.getFlowReferences().add(flowElement.getId());
            lane.getParentProcess().addFlowElement(flowElement);
        }
    } else if (baseElement instanceof Artifact) {
        Artifact artifact = (Artifact) baseElement;
        if (parentElement instanceof Process) {
            ((Process) parentElement).addArtifact(artifact);
        } else if (parentElement instanceof SubProcess) {
            ((SubProcess) parentElement).addArtifact(artifact);
        } else if (parentElement instanceof Lane) {
            Lane lane = (Lane) parentElement;
            lane.getFlowReferences().add(artifact.getId());
            lane.getParentProcess().addArtifact(artifact);
        }
    }
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) ExtensionElement(org.activiti.bpmn.model.ExtensionElement) Lane(org.activiti.bpmn.model.Lane) Activity(org.activiti.bpmn.model.Activity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) Artifact(org.activiti.bpmn.model.Artifact) BaseElement(org.activiti.bpmn.model.BaseElement) MultiInstanceLoopCharacteristics(org.activiti.bpmn.model.MultiInstanceLoopCharacteristics) FlowElement(org.activiti.bpmn.model.FlowElement) Gateway(org.activiti.bpmn.model.Gateway)

Example 22 with ExtensionElement

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

the class ValuedDataObjectWithExtensionsConverterTest method getDataObjectAttributes.

protected Map<String, String> getDataObjectAttributes(BaseElement dObj) {
    Map<String, String> attributes = null;
    if (null != dObj) {
        List<ExtensionElement> attributesExtension = dObj.getExtensionElements().get(ELEMENT_DATA_ATTRIBUTES);
        if (null != attributesExtension && !attributesExtension.isEmpty()) {
            attributes = new HashMap<String, String>();
            List<ExtensionElement> attributeExtensions = attributesExtension.get(0).getChildElements().get(ELEMENT_DATA_ATTRIBUTE);
            for (ExtensionElement attributeExtension : attributeExtensions) {
                attributes.put(attributeExtension.getAttributeValue(YOURCO_EXTENSIONS_NAMESPACE, ATTRIBUTE_NAME), attributeExtension.getAttributeValue(YOURCO_EXTENSIONS_NAMESPACE, ATTRIBUTE_VALUE));
            }
        }
    }
    return attributes;
}
Also used : ExtensionElement(org.activiti.bpmn.model.ExtensionElement)

Example 23 with ExtensionElement

use of org.activiti.bpmn.model.ExtensionElement 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 24 with ExtensionElement

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

the class BpmnDeployer method localizeDataObjectElements.

protected boolean localizeDataObjectElements(List<ValuedDataObject> dataObjects, ObjectNode infoNode) {
    boolean localizationValuesChanged = false;
    CommandContext commandContext = Context.getCommandContext();
    DynamicBpmnService dynamicBpmnService = commandContext.getProcessEngineConfiguration().getDynamicBpmnService();
    for (ValuedDataObject dataObject : dataObjects) {
        List<ExtensionElement> localizationElements = dataObject.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;
                        }
                    }
                    if (name != null && isEqualToCurrentLocalizationValue(locale, dataObject.getId(), DynamicBpmnConstants.LOCALIZATION_NAME, name, infoNode) == false) {
                        dynamicBpmnService.changeLocalizationName(locale, dataObject.getId(), name, infoNode);
                        localizationValuesChanged = true;
                    }
                    if (documentation != null && isEqualToCurrentLocalizationValue(locale, dataObject.getId(), DynamicBpmnConstants.LOCALIZATION_DESCRIPTION, documentation, infoNode) == false) {
                        dynamicBpmnService.changeLocalizationDescription(locale, dataObject.getId(), documentation, infoNode);
                        localizationValuesChanged = true;
                    }
                }
            }
        }
    }
    return localizationValuesChanged;
}
Also used : ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) DynamicBpmnService(org.activiti.engine.DynamicBpmnService) ExtensionElement(org.activiti.bpmn.model.ExtensionElement)

Aggregations

ExtensionElement (org.activiti.bpmn.model.ExtensionElement)24 HashMap (java.util.HashMap)5 FlowElement (org.activiti.bpmn.model.FlowElement)5 SubProcess (org.activiti.bpmn.model.SubProcess)5 ValuedDataObject (org.activiti.bpmn.model.ValuedDataObject)5 List (java.util.List)4 ExtensionAttribute (org.activiti.bpmn.model.ExtensionAttribute)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 ArrayList (java.util.ArrayList)3 BpmnModel (org.activiti.bpmn.model.BpmnModel)3 Gateway (org.activiti.bpmn.model.Gateway)3 Lane (org.activiti.bpmn.model.Lane)3 Process (org.activiti.bpmn.model.Process)3 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)3 UserTask (org.activiti.bpmn.model.UserTask)3 DynamicBpmnService (org.activiti.engine.DynamicBpmnService)3 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 LinkedHashMap (java.util.LinkedHashMap)2