Search in sources :

Example 86 with CommandContext

use of org.camunda.bpm.engine.impl.interceptor.CommandContext in project camunda-bpm-platform by camunda.

the class MultiTenancyProcessDefinitionSuspensionStateTest method tearDown.

@After
public void tearDown() throws Exception {
    CommandExecutor commandExecutor = engineRule.getProcessEngineConfiguration().getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Object>() {

        public Object execute(CommandContext commandContext) {
            commandContext.getHistoricJobLogManager().deleteHistoricJobLogsByHandlerType(TimerActivateProcessDefinitionHandler.TYPE);
            commandContext.getHistoricJobLogManager().deleteHistoricJobLogsByHandlerType(TimerSuspendProcessDefinitionHandler.TYPE);
            return null;
        }
    });
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) After(org.junit.After)

Example 87 with CommandContext

use of org.camunda.bpm.engine.impl.interceptor.CommandContext in project camunda-bpm-platform by camunda.

the class BpmnDeploymentTest method testDiagramCreationDisabled.

public void testDiagramCreationDisabled() {
    repositoryService.createDeployment().addClasspathResource("org/camunda/bpm/engine/test/bpmn/parse/BpmnParseTest.testParseDiagramInterchangeElements.bpmn20.xml").deploy();
    // Graphical information is not yet exposed publicly, so we need to do some plumbing
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    ProcessDefinitionEntity processDefinitionEntity = commandExecutor.execute(new Command<ProcessDefinitionEntity>() {

        @Override
        public ProcessDefinitionEntity execute(CommandContext commandContext) {
            return Context.getProcessEngineConfiguration().getDeploymentCache().findDeployedLatestProcessDefinitionByKey("myProcess");
        }
    });
    assertNotNull(processDefinitionEntity);
    assertEquals(7, processDefinitionEntity.getActivities().size());
    // Check that no diagram has been created
    List<String> resourceNames = repositoryService.getDeploymentResourceNames(processDefinitionEntity.getDeploymentId());
    assertEquals(1, resourceNames.size());
    repositoryService.deleteDeployment(repositoryService.createDeploymentQuery().singleResult().getId(), true);
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)

Example 88 with CommandContext

use of org.camunda.bpm.engine.impl.interceptor.CommandContext in project camunda-bpm-platform by camunda.

the class TaskListenerTest method testDeleteListenerByCaseInstanceDeletion.

@Deployment(resources = { "org/camunda/bpm/engine/test/cmmn/tasklistener/TaskListenerTest.testDeleteListenerByCaseInstanceDeletion.cmmn" })
public void testDeleteListenerByCaseInstanceDeletion() {
    TaskDeleteListener.clear();
    // given
    final String caseInstanceId = caseService.withCaseDefinitionByKey("case").create().getId();
    String humanTaskId = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult().getId();
    // when
    processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Void>() {

        @Override
        public Void execute(CommandContext commandContext) {
            commandContext.getCaseExecutionManager().deleteCaseInstance(caseInstanceId, null);
            return null;
        }
    });
    // then
    assertEquals(1, TaskDeleteListener.eventCounter);
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) Matchers.containsString(org.hamcrest.Matchers.containsString) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 89 with CommandContext

use of org.camunda.bpm.engine.impl.interceptor.CommandContext in project camunda-bpm-platform by camunda.

the class JtaTransactionContext method addTransactionListener.

public void addTransactionListener(TransactionState transactionState, final TransactionListener transactionListener) {
    Transaction transaction = getTransaction();
    CommandContext commandContext = Context.getCommandContext();
    try {
        transaction.registerSynchronization(new TransactionStateSynchronization(transactionState, transactionListener, commandContext));
    } catch (Exception e) {
        throw LOG.exceptionWhileInteractingWithTransaction("registering synchronization", e);
    }
}
Also used : Transaction(javax.transaction.Transaction) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) SystemException(javax.transaction.SystemException)

Example 90 with CommandContext

use of org.camunda.bpm.engine.impl.interceptor.CommandContext in project camunda-bpm-platform by camunda.

the class DefaultDelegateInterceptor method handleInvocationInContext.

protected void handleInvocationInContext(final DelegateInvocation invocation) throws Exception {
    CommandContext commandContext = Context.getCommandContext();
    boolean oldValue = commandContext.isAuthorizationCheckEnabled();
    BaseDelegateExecution contextExecution = invocation.getContextExecution();
    ProcessEngineConfigurationImpl configuration = Context.getProcessEngineConfiguration();
    boolean popExecutionContext = false;
    try {
        if (!configuration.isAuthorizationEnabledForCustomCode()) {
            // the custom code should be executed without authorization
            commandContext.disableAuthorizationCheck();
        }
        try {
            commandContext.disableUserOperationLog();
            try {
                if (contextExecution != null && !isCurrentContextExecution(contextExecution)) {
                    popExecutionContext = setExecutionContext(contextExecution);
                }
                invocation.proceed();
            } finally {
                if (popExecutionContext) {
                    Context.removeExecutionContext();
                }
            }
        } finally {
            commandContext.enableUserOperationLog();
        }
    } finally {
        if (oldValue) {
            commandContext.enableAuthorizationCheck();
        }
    }
}
Also used : BaseDelegateExecution(org.camunda.bpm.engine.delegate.BaseDelegateExecution) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)

Aggregations

CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)120 CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)31 List (java.util.List)17 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)17 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)11 Deployment (org.camunda.bpm.engine.test.Deployment)11 ArrayList (java.util.ArrayList)10 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)10 Date (java.util.Date)9 HistoricIncident (org.camunda.bpm.engine.history.HistoricIncident)8 DeploymentCache (org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache)8 JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)8 Command (org.camunda.bpm.engine.impl.interceptor.Command)6 HistoricIncidentEntity (org.camunda.bpm.engine.impl.persistence.entity.HistoricIncidentEntity)6 After (org.junit.After)6 ProcessApplicationReference (org.camunda.bpm.application.ProcessApplicationReference)5 RepositoryService (org.camunda.bpm.engine.RepositoryService)5 ProcessEngineImpl (org.camunda.bpm.engine.impl.ProcessEngineImpl)5 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)5 HistoricDecisionInstance (org.camunda.bpm.engine.history.HistoricDecisionInstance)4