Search in sources :

Example 61 with CommandContext

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

the class AbstractCorrelateMessageCmd method checkAuthorization.

protected void checkAuthorization(CorrelationHandlerResult correlation) {
    CommandContext commandContext = Context.getCommandContext();
    for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
        if (MessageCorrelationResultType.Execution.equals(correlation.getResultType())) {
            ExecutionEntity execution = correlation.getExecutionEntity();
            checker.checkUpdateProcessInstanceById(execution.getProcessInstanceId());
        } else {
            ProcessDefinitionEntity definition = correlation.getProcessDefinitionEntity();
            checker.checkCreateProcessInstance(definition);
        }
    }
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker)

Example 62 with CommandContext

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

the class DeployCmd method getDeployedProcesses.

protected List<? extends ProcessDefinition> getDeployedProcesses(DeploymentEntity deployment) {
    List<? extends ProcessDefinition> deployedProcessDefinitions = deployment.getDeployedProcessDefinitions();
    if (deployedProcessDefinitions == null) {
        // existing deployment
        CommandContext commandContext = Context.getCommandContext();
        ProcessDefinitionManager manager = commandContext.getProcessDefinitionManager();
        deployedProcessDefinitions = manager.findProcessDefinitionsByDeploymentId(deployment.getId());
    }
    return deployedProcessDefinitions;
}
Also used : ProcessDefinitionManager(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionManager) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext)

Example 63 with CommandContext

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

the class MigrationBatchJobHandler method postProcessJob.

@Override
protected void postProcessJob(MigrationBatchConfiguration configuration, JobEntity job) {
    CommandContext commandContext = Context.getCommandContext();
    String sourceProcessDefinitionId = configuration.getMigrationPlan().getSourceProcessDefinitionId();
    ProcessDefinitionEntity processDefinition = getProcessDefinition(commandContext, sourceProcessDefinitionId);
    job.setDeploymentId(processDefinition.getDeploymentId());
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)

Example 64 with CommandContext

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

the class EntityManagerSessionImpl method getEntityManager.

public EntityManager getEntityManager() {
    if (entityManager == null) {
        entityManager = getEntityManagerFactory().createEntityManager();
        if (handleTransactions) {
            // Add transaction listeners, if transactions should be handled
            TransactionListener jpaTransactionCommitListener = new TransactionListener() {

                public void execute(CommandContext commandContext) {
                    if (isTransactionActive()) {
                        entityManager.getTransaction().commit();
                    }
                }
            };
            TransactionListener jpaTransactionRollbackListener = new TransactionListener() {

                public void execute(CommandContext commandContext) {
                    if (isTransactionActive()) {
                        entityManager.getTransaction().rollback();
                    }
                }
            };
            TransactionContext transactionContext = Context.getCommandContext().getTransactionContext();
            transactionContext.addTransactionListener(TransactionState.COMMITTED, jpaTransactionCommitListener);
            transactionContext.addTransactionListener(TransactionState.ROLLED_BACK, jpaTransactionRollbackListener);
            // Also, start a transaction, if one isn't started already
            if (!isTransactionActive()) {
                entityManager.getTransaction().begin();
            }
        }
    }
    return entityManager;
}
Also used : TransactionListener(org.camunda.bpm.engine.impl.cfg.TransactionListener) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) TransactionContext(org.camunda.bpm.engine.impl.cfg.TransactionContext)

Example 65 with CommandContext

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

the class ManagementServiceTest method testSetJobRetriesByDefinitionUnlocksInconsistentJobs.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/mgmt/ManagementServiceTest.testGetJobExceptionStacktrace.bpmn20.xml" })
public void testSetJobRetriesByDefinitionUnlocksInconsistentJobs() {
    // given a job definition
    final JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();
    // and an inconsistent job that is never again picked up by a job executor
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Void>() {

        @Override
        public Void execute(CommandContext commandContext) {
            JobManager jobManager = commandContext.getJobManager();
            MessageEntity job = new MessageEntity();
            job.setJobDefinitionId(jobDefinition.getId());
            job.setJobHandlerType("any");
            job.setLockOwner("owner");
            job.setLockExpirationTime(ClockUtil.getCurrentTime());
            job.setRetries(0);
            jobManager.send(job);
            return null;
        }
    });
    // when the job retries are reset
    managementService.setJobRetriesByJobDefinitionId(jobDefinition.getId(), 3);
    // then the job can be picked up again
    JobEntity job = (JobEntity) managementService.createJobQuery().singleResult();
    assertNotNull(job);
    assertNull(job.getLockOwner());
    assertNull(job.getLockExpirationTime());
    assertEquals(3, job.getRetries());
    deleteJobAndIncidents(job);
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) MessageEntity(org.camunda.bpm.engine.impl.persistence.entity.MessageEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager) JobDefinition(org.camunda.bpm.engine.management.JobDefinition) Deployment(org.camunda.bpm.engine.test.Deployment)

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