Search in sources :

Example 36 with CommandContext

use of org.activiti.engine.impl.interceptor.CommandContext 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 37 with CommandContext

use of org.activiti.engine.impl.interceptor.CommandContext 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.getName(), DynamicBpmnConstants.LOCALIZATION_NAME, name, infoNode) == false) {
                        dynamicBpmnService.changeLocalizationName(locale, dataObject.getName(), name, infoNode);
                        localizationValuesChanged = true;
                    }
                    if (documentation != null && isEqualToCurrentLocalizationValue(locale, dataObject.getName(), DynamicBpmnConstants.LOCALIZATION_DESCRIPTION, documentation, infoNode) == false) {
                        dynamicBpmnService.changeLocalizationDescription(locale, dataObject.getName(), 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)

Example 38 with CommandContext

use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.

the class BpmnDeployer method removeExistingSignalEventSubScription.

protected void removeExistingSignalEventSubScription(ProcessDefinitionEntity processDefinition, ProcessDefinitionEntity latestProcessDefinition) {
    if (latestProcessDefinition != null) {
        CommandContext commandContext = Context.getCommandContext();
        List<EventSubscriptionEntity> subscriptionsToDisable = commandContext.getEventSubscriptionEntityManager().findEventSubscriptionsByTypeAndProcessDefinitionId(SignalEventHandler.EVENT_HANDLER_TYPE, latestProcessDefinition.getId(), latestProcessDefinition.getTenantId());
        for (EventSubscriptionEntity eventSubscriptionEntity : subscriptionsToDisable) {
            eventSubscriptionEntity.delete();
        }
    }
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity) MessageEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity) EventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 39 with CommandContext

use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.

the class SpringTransactionContext method addTransactionListener.

public void addTransactionListener(final TransactionState transactionState, final TransactionListener transactionListener) {
    if (transactionState.equals(TransactionState.COMMITTING)) {
        TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {

            @Override
            public void beforeCommit(boolean readOnly) {
                transactionListener.execute(commandContext);
            }
        });
    } else if (transactionState.equals(TransactionState.COMMITTED)) {
        TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {

            @Override
            public void afterCommit() {
                CommandExecutor commandExecutor = commandContext.getProcessEngineConfiguration().getCommandExecutor();
                CommandConfig commandConfig = new CommandConfig(false, TransactionPropagation.REQUIRES_NEW);
                commandExecutor.execute(commandConfig, new Command<Void>() {

                    public Void execute(CommandContext commandContext) {
                        transactionListener.execute(commandContext);
                        return null;
                    }
                });
            }
        });
    } else if (transactionState.equals(TransactionState.ROLLINGBACK)) {
        TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {

            @Override
            public void beforeCompletion() {
                transactionListener.execute(commandContext);
            }
        });
    } else if (transactionState.equals(TransactionState.ROLLED_BACK)) {
        TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {

            @Override
            public void afterCompletion(int status) {
                if (TransactionSynchronization.STATUS_ROLLED_BACK == status) {
                    CommandExecutor commandExecutor = commandContext.getProcessEngineConfiguration().getCommandExecutor();
                    CommandConfig commandConfig = new CommandConfig(false, TransactionPropagation.REQUIRES_NEW);
                    commandExecutor.execute(commandConfig, new Command<Void>() {

                        public Void execute(CommandContext commandContext) {
                            transactionListener.execute(commandContext);
                            return null;
                        }
                    });
                }
            }
        });
    }
}
Also used : CommandConfig(org.activiti.engine.impl.interceptor.CommandConfig) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor)

Example 40 with CommandContext

use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.

the class EventSubscriptionQueryTest method testQueryByEventType.

public void testQueryByEventType() {
    processEngineConfiguration.getCommandExecutor().execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            MessageEventSubscriptionEntity messageEventSubscriptionEntity1 = new MessageEventSubscriptionEntity();
            messageEventSubscriptionEntity1.setEventName("messageName");
            messageEventSubscriptionEntity1.insert();
            MessageEventSubscriptionEntity messageEventSubscriptionEntity2 = new MessageEventSubscriptionEntity();
            messageEventSubscriptionEntity2.setEventName("messageName");
            messageEventSubscriptionEntity2.insert();
            SignalEventSubscriptionEntity signalEventSubscriptionEntity3 = new SignalEventSubscriptionEntity();
            signalEventSubscriptionEntity3.setEventName("messageName2");
            signalEventSubscriptionEntity3.insert();
            return null;
        }
    });
    List<EventSubscriptionEntity> list = newEventSubscriptionQuery().eventType("signal").list();
    assertEquals(1, list.size());
    list = newEventSubscriptionQuery().eventType("message").list();
    assertEquals(2, list.size());
    cleanDb();
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) MessageEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity) MessageEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity) EventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity)

Aggregations

CommandContext (org.activiti.engine.impl.interceptor.CommandContext)72 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)18 DbSqlSession (org.activiti.engine.impl.db.DbSqlSession)13 SignalEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity)8 Date (java.util.Date)7 ActivitiException (org.activiti.engine.ActivitiException)7 CommandConfig (org.activiti.engine.impl.interceptor.CommandConfig)7 EventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity)7 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)7 MessageEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity)6 HashMap (java.util.HashMap)4 TimerEntity (org.activiti.engine.impl.persistence.entity.TimerEntity)4 Job (org.activiti.engine.runtime.Job)4 Deployment (org.activiti.engine.test.Deployment)4 ArrayList (java.util.ArrayList)3 GregorianCalendar (java.util.GregorianCalendar)3 List (java.util.List)3 ExtensionElement (org.activiti.bpmn.model.ExtensionElement)3 DynamicBpmnService (org.activiti.engine.DynamicBpmnService)3 JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)3