当前位置: 首页>>代码示例>>Java>>正文


Java Context.removeCommandContext方法代码示例

本文整理汇总了Java中org.activiti.engine.impl.context.Context.removeCommandContext方法的典型用法代码示例。如果您正苦于以下问题:Java Context.removeCommandContext方法的具体用法?Java Context.removeCommandContext怎么用?Java Context.removeCommandContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.activiti.engine.impl.context.Context的用法示例。


在下文中一共展示了Context.removeCommandContext方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startWorkflow

import org.activiti.engine.impl.context.Context; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public WorkflowPath startWorkflow(String workflowDefinitionId, Map<QName, Serializable> parameters)
{
    try
    {
        String currentUserName = AuthenticationUtil.getFullyAuthenticatedUser();
        Authentication.setAuthenticatedUserId(currentUserName);
        
        String processDefId = createLocalId(workflowDefinitionId);
        
        // Set start task properties. This should be done before instance is started, since it's id will be used
        Map<String, Object> variables = propertyConverter.getStartVariables(processDefId, parameters);
        variables.put(WorkflowConstants.PROP_CANCELLED, Boolean.FALSE);
        
        // Add company home
        Object companyHome = nodeConverter.convertNode(getCompanyHome());
        variables.put(WorkflowConstants.PROP_COMPANY_HOME, companyHome);
         
        // Add the initiator
        NodeRef initiator = getPersonNodeRef(currentUserName);
        if (initiator != null)
        {
            variables.put(WorkflowConstants.PROP_INITIATOR, nodeConverter.convertNode(initiator));
            // Also add the initiator home reference, if one exists
            NodeRef initiatorHome = (NodeRef) nodeService.getProperty(initiator, ContentModel.PROP_HOMEFOLDER);
            if (initiatorHome != null)
            {
                variables.put(WorkflowConstants.PROP_INITIATOR_HOME, nodeConverter.convertNode(initiatorHome));
            }
        }
        
        // Start the process-instance
        CommandContext context = Context.getCommandContext();
        boolean isContextSuspended = false;
        if (context != null && context.getException() == null)
        {
            // MNT-11926: push null context to stack to avoid context reusage when new instance is not flushed
            Context.setCommandContext(null);
            isContextSuspended = true;
        }
        try
        {
            ProcessInstance instance = runtimeService.startProcessInstanceById(processDefId, variables);
            if (instance.isEnded())
            {
                return typeConverter.buildCompletedPath(instance.getId(), instance.getId());
            }
            else
            {
                WorkflowPath path = typeConverter.convert((Execution) instance);
                endStartTaskAutomatically(path, instance);
                return path;
            }
        }
        finally
        {
            if (isContextSuspended)
            {
                // pop null context out of stack
                Context.removeCommandContext();
            }
        }
    }
    catch (ActivitiException ae)
    {
        String msg = messageService.getMessage(ERR_START_WORKFLOW, workflowDefinitionId);
        if(logger.isDebugEnabled())
        {
        	logger.debug(msg, ae);
        }
        throw new WorkflowException(msg, ae);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:76,代码来源:ActivitiWorkflowEngine.java

示例2: execute

import org.activiti.engine.impl.context.Context; //导入方法依赖的package包/类
@Override
public <T> T execute(CommandConfig config, Command<T> command) {
    CommandContext context = Context.getCommandContext();

    boolean contextReused = false;
    // We need to check the exception, because the transaction can be in a rollback state,
    // and some other command is being fired to compensate (eg. decrementing job retries)
    if (!config.isContextReusePossible() || context == null || context.getException() != null) {
        context = commandContextFactory.createCommandContext(command);
    } else {
        LOGGER.debug("Valid context found. Reusing it for the current command '{}'", command.getClass().getCanonicalName());
        contextReused = true;
    }

    try {
        // Push on stack
        Context.setCommandContext(context);
        Context.setProcessEngineConfiguration(processEngineConfiguration);
        Flowable5CompatibilityContext.setFallbackFlowable5CompatibilityHandler(processEngineConfiguration.getFlowable5CompatibilityHandler());

        return next.execute(config, command);

    } catch (Exception e) {

        context.exception(e);

    } finally {
        try {
            if (!contextReused) {
                context.close();
            }
        } finally {
            // Pop from stack
            Context.removeCommandContext();
            Context.removeProcessEngineConfiguration();
            Context.removeBpmnOverrideContext();
            // don't remove the fallback because it's needed in Activiti 6 code like the Camel module
            // org.activiti.engine.impl.context.Context.removeFallbackcompatibilityHandler();
        }
    }

    return null;
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:44,代码来源:CommandContextInterceptor.java


注:本文中的org.activiti.engine.impl.context.Context.removeCommandContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。