本文整理汇总了Java中org.activiti.engine.impl.context.Context.setCommandContext方法的典型用法代码示例。如果您正苦于以下问题:Java Context.setCommandContext方法的具体用法?Java Context.setCommandContext怎么用?Java Context.setCommandContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.activiti.engine.impl.context.Context
的用法示例。
在下文中一共展示了Context.setCommandContext方法的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);
}
}
示例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;
}