Search in sources :

Example 1 with DynamicBpmnService

use of org.activiti.engine.DynamicBpmnService in project Activiti by Activiti.

the class BpmnDeployer method createLocalizationValues.

protected void createLocalizationValues(String processDefinitionId, Process process) {
    if (process == null) {
        return;
    }
    CommandContext commandContext = Context.getCommandContext();
    DynamicBpmnService dynamicBpmnService = commandContext.getProcessEngineConfiguration().getDynamicBpmnService();
    ObjectNode infoNode = dynamicBpmnService.getProcessDefinitionInfo(processDefinitionId);
    boolean localizationValuesChanged = false;
    List<ExtensionElement> localizationElements = process.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 processId = process.getId();
                if (!isEqualToCurrentLocalizationValue(locale, processId, "name", name, infoNode)) {
                    dynamicBpmnService.changeLocalizationName(locale, processId, name, infoNode);
                    localizationValuesChanged = true;
                }
                if (documentation != null && !isEqualToCurrentLocalizationValue(locale, processId, "description", documentation, infoNode)) {
                    dynamicBpmnService.changeLocalizationDescription(locale, processId, documentation, infoNode);
                    localizationValuesChanged = true;
                }
                break;
            }
        }
    }
    boolean isFlowElementLocalizationChanged = localizeFlowElements(process.getFlowElements(), infoNode);
    boolean isDataObjectLocalizationChanged = localizeDataObjectElements(process.getDataObjects(), infoNode);
    if (isFlowElementLocalizationChanged || isDataObjectLocalizationChanged) {
        localizationValuesChanged = true;
    }
    if (localizationValuesChanged) {
        dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
    }
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DynamicBpmnService(org.activiti.engine.DynamicBpmnService) ExtensionElement(org.activiti.bpmn.model.ExtensionElement)

Example 2 with DynamicBpmnService

use of org.activiti.engine.DynamicBpmnService 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 3 with DynamicBpmnService

use of org.activiti.engine.DynamicBpmnService 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)3 DynamicBpmnService (org.activiti.engine.DynamicBpmnService)3 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 FlowElement (org.activiti.bpmn.model.FlowElement)1 SubProcess (org.activiti.bpmn.model.SubProcess)1 UserTask (org.activiti.bpmn.model.UserTask)1 ValuedDataObject (org.activiti.bpmn.model.ValuedDataObject)1