Search in sources :

Example 26 with CommandExecutor

use of org.activiti.engine.impl.interceptor.CommandExecutor in project Activiti by Activiti.

the class ManagementServiceTest method testDeleteJobThatWasAlreadyAcquired.

@Deployment(resources = { "org/activiti/engine/test/api/mgmt/timerOnTask.bpmn20.xml" })
public void testDeleteJobThatWasAlreadyAcquired() {
    processEngineConfiguration.getClock().setCurrentTime(new Date());
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerOnTask");
    Job timerJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    // We need to move time at least one hour to make the timer executable
    processEngineConfiguration.getClock().setCurrentTime(new Date(processEngineConfiguration.getClock().getCurrentTime().getTime() + 7200000L));
    // Acquire job by running the acquire command manually
    ProcessEngineImpl processEngineImpl = (ProcessEngineImpl) processEngine;
    AcquireTimerJobsCmd acquireJobsCmd = new AcquireTimerJobsCmd("testLockOwner", 60000, 5);
    CommandExecutor commandExecutor = processEngineImpl.getProcessEngineConfiguration().getCommandExecutor();
    commandExecutor.execute(acquireJobsCmd);
    // Try to delete the job. This should fail.
    try {
        managementService.deleteJob(timerJob.getId());
        fail();
    } catch (ActivitiException e) {
    // Exception is expected
    }
    // Clean up
    managementService.executeJob(timerJob.getId());
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Job(org.activiti.engine.runtime.Job) Date(java.util.Date) ProcessEngineImpl(org.activiti.engine.impl.ProcessEngineImpl) AcquireTimerJobsCmd(org.activiti.engine.impl.cmd.AcquireTimerJobsCmd) Deployment(org.activiti.engine.test.Deployment)

Example 27 with CommandExecutor

use of org.activiti.engine.impl.interceptor.CommandExecutor in project Activiti by Activiti.

the class JobQueryTest method deleteJobInDatabase.

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

        public Void execute(CommandContext commandContext) {
            timerEntity.delete();
            return null;
        }
    });
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor)

Example 28 with CommandExecutor

use of org.activiti.engine.impl.interceptor.CommandExecutor in project Activiti by Activiti.

the class JobQueryTest method createJobWithoutExceptionStacktrace.

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

        public Void execute(CommandContext commandContext) {
            JobEntityManager jobManager = commandContext.getJobEntityManager();
            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 : JobEntityManager(org.activiti.engine.impl.persistence.entity.JobEntityManager) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) TimerEntity(org.activiti.engine.impl.persistence.entity.TimerEntity) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) Date(java.util.Date)

Example 29 with CommandExecutor

use of org.activiti.engine.impl.interceptor.CommandExecutor in project Activiti by Activiti.

the class ProcessInstanceMigrationTest method testSetProcessDefinitionVersionActivityMissing.

@Deployment(resources = { TEST_PROCESS })
public void testSetProcessDefinitionVersionActivityMissing() {
    // start process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("receiveTask");
    // check that receive task has been reached
    Execution execution = runtimeService.createExecutionQuery().activityId("waitState1").singleResult();
    assertNotNull(execution);
    // deploy new version of the process definition
    org.activiti.engine.repository.Deployment deployment = repositoryService.createDeployment().addClasspathResource(TEST_PROCESS_ACTIVITY_MISSING).deploy();
    assertEquals(2, repositoryService.createProcessDefinitionQuery().count());
    // migrate process instance to new process definition version
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
    SetProcessDefinitionVersionCmd setProcessDefinitionVersionCmd = new SetProcessDefinitionVersionCmd(pi.getId(), 2);
    try {
        commandExecutor.execute(setProcessDefinitionVersionCmd);
        fail("ActivitiException expected");
    } catch (ActivitiException ae) {
        assertTextPresent("The new process definition (key = 'receiveTask') does not contain the current activity (id = 'waitState1') of the process instance (id = '", ae.getMessage());
    }
    // undeploy "manually" deployed process definition
    repositoryService.deleteDeployment(deployment.getId(), true);
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) Execution(org.activiti.engine.runtime.Execution) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) SetProcessDefinitionVersionCmd(org.activiti.engine.impl.cmd.SetProcessDefinitionVersionCmd) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 30 with CommandExecutor

use of org.activiti.engine.impl.interceptor.CommandExecutor in project Activiti by Activiti.

the class BpmnParseTest method testParseNamespaceInConditionExpressionType.

@Deployment
public void testParseNamespaceInConditionExpressionType() {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
    ProcessDefinitionEntity processDefinitionEntity = commandExecutor.execute(new Command<ProcessDefinitionEntity>() {

        public ProcessDefinitionEntity execute(CommandContext commandContext) {
            return Context.getProcessEngineConfiguration().getDeploymentManager().findDeployedLatestProcessDefinitionByKey("resolvableNamespacesProcess");
        }
    });
    // Test that the process definition has been deployed
    assertNotNull(processDefinitionEntity);
    ActivityImpl activity = processDefinitionEntity.findActivity("ExclusiveGateway_1");
    assertNotNull(activity);
    // Test that the conditions has been resolved
    for (PvmTransition transition : activity.getOutgoingTransitions()) {
        if (transition.getDestination().getId().equals("Task_2")) {
            assertTrue(transition.getProperty("conditionText").equals("#{approved}"));
        } else if (transition.getDestination().getId().equals("Task_3")) {
            assertTrue(transition.getProperty("conditionText").equals("#{!approved}"));
        } else {
            fail("Something went wrong");
        }
    }
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition) Deployment(org.activiti.engine.test.Deployment)

Aggregations

CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)36 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)18 Deployment (org.activiti.engine.test.Deployment)11 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)10 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)8 SetProcessDefinitionVersionCmd (org.activiti.engine.impl.cmd.SetProcessDefinitionVersionCmd)8 CommandConfig (org.activiti.engine.impl.interceptor.CommandConfig)7 Date (java.util.Date)6 Execution (org.activiti.engine.runtime.Execution)6 DbSqlSession (org.activiti.engine.impl.db.DbSqlSession)5 JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)5 TimerEntity (org.activiti.engine.impl.persistence.entity.TimerEntity)5 ActivitiOptimisticLockingException (org.activiti.engine.ActivitiOptimisticLockingException)4 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)4 ActivitiException (org.activiti.engine.ActivitiException)3 ProcessEngineImpl (org.activiti.engine.impl.ProcessEngineImpl)3 AcquireTimerJobsCmd (org.activiti.engine.impl.cmd.AcquireTimerJobsCmd)3 JobEntityManager (org.activiti.engine.impl.persistence.entity.JobEntityManager)3 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)3 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)2