Search in sources :

Example 31 with CommandContext

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

the class JobQueryTest method deleteJobInDatabase.

private void deleteJobInDatabase() {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            timerEntity.delete();
            commandContext.getHistoricJobLogManager().deleteHistoricJobLogByJobId(timerEntity.getId());
            List<HistoricIncident> historicIncidents = Context.getProcessEngineConfiguration().getHistoryService().createHistoricIncidentQuery().list();
            for (HistoricIncident historicIncident : historicIncidents) {
                commandContext.getDbEntityManager().delete((DbEntity) historicIncident);
            }
            return null;
        }
    });
}
Also used : HistoricIncident(org.camunda.bpm.engine.history.HistoricIncident) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) DbEntity(org.camunda.bpm.engine.impl.db.DbEntity) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) List(java.util.List)

Example 32 with CommandContext

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

the class JobQueryTest method setUp.

/**
 * Setup will create
 *   - 3 process instances, each with one timer, each firing at t1/t2/t3 + 1 hour (see process)
 *   - 1 message
 */
protected void setUp() throws Exception {
    super.setUp();
    this.commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    deploymentId = repositoryService.createDeployment().addClasspathResource("org/camunda/bpm/engine/test/api/mgmt/timerOnTask.bpmn20.xml").deploy().getId();
    // Create proc inst that has timer that will fire on t1 + 1 hour
    Calendar startTime = Calendar.getInstance();
    startTime.set(Calendar.MILLISECOND, 0);
    Date t1 = startTime.getTime();
    ClockUtil.setCurrentTime(t1);
    processInstanceIdOne = runtimeService.startProcessInstanceByKey("timerOnTask").getId();
    testStartTime = t1;
    timerOneFireTime = new Date(t1.getTime() + ONE_HOUR);
    // Create proc inst that has timer that will fire on t2 + 1 hour
    startTime.add(Calendar.HOUR_OF_DAY, 1);
    // t2 = t1 + 1 hour
    Date t2 = startTime.getTime();
    ClockUtil.setCurrentTime(t2);
    processInstanceIdTwo = runtimeService.startProcessInstanceByKey("timerOnTask").getId();
    timerTwoFireTime = new Date(t2.getTime() + ONE_HOUR);
    // Create proc inst that has timer that will fire on t3 + 1 hour
    startTime.add(Calendar.HOUR_OF_DAY, 1);
    // t3 = t2 + 1 hour
    Date t3 = startTime.getTime();
    ClockUtil.setCurrentTime(t3);
    processInstanceIdThree = runtimeService.startProcessInstanceByKey("timerOnTask").getId();
    timerThreeFireTime = new Date(t3.getTime() + ONE_HOUR);
    // Create one message
    messageId = commandExecutor.execute(new Command<String>() {

        public String execute(CommandContext commandContext) {
            MessageEntity message = new MessageEntity();
            commandContext.getJobManager().send(message);
            return message.getId();
        }
    });
}
Also used : MessageEntity(org.camunda.bpm.engine.impl.persistence.entity.MessageEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) Command(org.camunda.bpm.engine.impl.interceptor.Command) Calendar(java.util.Calendar) Date(java.util.Date)

Example 33 with CommandContext

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

the class JobQueryTest method createJobWithoutExceptionStacktrace.

private void createJobWithoutExceptionStacktrace() {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            JobManager jobManager = commandContext.getJobManager();
            timerEntity = new TimerEntity();
            timerEntity.setLockOwner(UUID.randomUUID().toString());
            timerEntity.setDuedate(new Date());
            timerEntity.setRetries(0);
            timerEntity.setExceptionMessage("I'm supposed to fail");
            jobManager.insert(timerEntity);
            assertNotNull(timerEntity.getId());
            return null;
        }
    });
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) TimerEntity(org.camunda.bpm.engine.impl.persistence.entity.TimerEntity) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager) Date(java.util.Date)

Example 34 with CommandContext

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

the class HistoryCleanupBatchWindowTest method clearDatabase.

@After
public void clearDatabase() {
    // reset configuration changes
    processEngineConfiguration.setHistoryCleanupBatchWindowStartTime(defaultStartTime);
    processEngineConfiguration.setHistoryCleanupBatchWindowEndTime(defaultEndTime);
    processEngineConfiguration.setHistoryCleanupBatchSize(defaultBatchSize);
    processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            List<Job> jobs = managementService.createJobQuery().list();
            if (jobs.size() > 0) {
                assertEquals(1, jobs.size());
                String jobId = jobs.get(0).getId();
                commandContext.getJobManager().deleteJob((JobEntity) jobs.get(0));
                commandContext.getHistoricJobLogManager().deleteHistoricJobLogByJobId(jobId);
            }
            List<HistoricIncident> historicIncidents = historyService.createHistoricIncidentQuery().list();
            for (HistoricIncident historicIncident : historicIncidents) {
                commandContext.getDbEntityManager().delete((HistoricIncidentEntity) historicIncident);
            }
            commandContext.getMeterLogManager().deleteAll();
            return null;
        }
    });
    List<HistoricProcessInstance> historicProcessInstances = historyService.createHistoricProcessInstanceQuery().list();
    for (HistoricProcessInstance historicProcessInstance : historicProcessInstances) {
        historyService.deleteHistoricProcessInstance(historicProcessInstance.getId());
    }
    List<HistoricDecisionInstance> historicDecisionInstances = historyService.createHistoricDecisionInstanceQuery().list();
    for (HistoricDecisionInstance historicDecisionInstance : historicDecisionInstances) {
        historyService.deleteHistoricDecisionInstanceByInstanceId(historicDecisionInstance.getId());
    }
    List<HistoricCaseInstance> historicCaseInstances = historyService.createHistoricCaseInstanceQuery().list();
    for (HistoricCaseInstance historicCaseInstance : historicCaseInstances) {
        historyService.deleteHistoricCaseInstance(historicCaseInstance.getId());
    }
    clearMetrics();
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) HistoricDecisionInstance(org.camunda.bpm.engine.history.HistoricDecisionInstance) JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) HistoricIncident(org.camunda.bpm.engine.history.HistoricIncident) HistoricIncidentEntity(org.camunda.bpm.engine.impl.persistence.entity.HistoricIncidentEntity) HistoricCaseInstance(org.camunda.bpm.engine.history.HistoricCaseInstance) List(java.util.List) After(org.junit.After)

Example 35 with CommandContext

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

the class HistoryCleanupTest method clearDatabase.

@After
public void clearDatabase() {
    // reset configuration changes
    processEngineConfiguration.setHistoryCleanupBatchWindowStartTime(defaultStartTime);
    processEngineConfiguration.setHistoryCleanupBatchWindowEndTime(defaultEndTime);
    processEngineConfiguration.setHistoryCleanupBatchSize(defaultBatchSize);
    processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            List<Job> jobs = managementService.createJobQuery().list();
            if (jobs.size() > 0) {
                assertEquals(1, jobs.size());
                String jobId = jobs.get(0).getId();
                commandContext.getJobManager().deleteJob((JobEntity) jobs.get(0));
                commandContext.getHistoricJobLogManager().deleteHistoricJobLogByJobId(jobId);
            }
            List<HistoricIncident> historicIncidents = historyService.createHistoricIncidentQuery().list();
            for (HistoricIncident historicIncident : historicIncidents) {
                commandContext.getDbEntityManager().delete((HistoricIncidentEntity) historicIncident);
            }
            commandContext.getMeterLogManager().deleteAll();
            return null;
        }
    });
    List<HistoricProcessInstance> historicProcessInstances = historyService.createHistoricProcessInstanceQuery().list();
    for (HistoricProcessInstance historicProcessInstance : historicProcessInstances) {
        historyService.deleteHistoricProcessInstance(historicProcessInstance.getId());
    }
    List<HistoricDecisionInstance> historicDecisionInstances = historyService.createHistoricDecisionInstanceQuery().list();
    for (HistoricDecisionInstance historicDecisionInstance : historicDecisionInstances) {
        historyService.deleteHistoricDecisionInstanceByInstanceId(historicDecisionInstance.getId());
    }
    List<HistoricCaseInstance> historicCaseInstances = historyService.createHistoricCaseInstanceQuery().list();
    for (HistoricCaseInstance historicCaseInstance : historicCaseInstances) {
        historyService.deleteHistoricCaseInstance(historicCaseInstance.getId());
    }
    clearMetrics();
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) HistoricDecisionInstance(org.camunda.bpm.engine.history.HistoricDecisionInstance) JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) HistoricIncident(org.camunda.bpm.engine.history.HistoricIncident) HistoricIncidentEntity(org.camunda.bpm.engine.impl.persistence.entity.HistoricIncidentEntity) HistoricCaseInstance(org.camunda.bpm.engine.history.HistoricCaseInstance) List(java.util.List) ArrayList(java.util.ArrayList) After(org.junit.After)

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