Search in sources :

Example 31 with CommandContext

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

the class BpmnDeploymentTest method testDiagramCreationDisabled.

public void testDiagramCreationDisabled() {
    // disable diagram generation
    processEngineConfiguration.setCreateDiagramOnDeploy(false);
    try {
        repositoryService.createDeployment().addClasspathResource("org/activiti/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.getCommandExecutor();
        ProcessDefinitionEntity processDefinitionEntity = commandExecutor.execute(new Command<ProcessDefinitionEntity>() {

            public ProcessDefinitionEntity execute(CommandContext commandContext) {
                return Context.getProcessEngineConfiguration().getDeploymentManager().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);
    } finally {
        processEngineConfiguration.setCreateDiagramOnDeploy(true);
    }
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)

Example 32 with CommandContext

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

the class CustomMybatisMapperConfigurationTest method executeCustomMybatisXmlQuery.

@Test
public void executeCustomMybatisXmlQuery() throws Exception {
    AnnotationConfigApplicationContext applicationContext = this.context(Application.class);
    ManagementService managementService = applicationContext.getBean(ManagementService.class);
    String processDefinitionDeploymentId = managementService.executeCommand(new Command<String>() {

        @Override
        public String execute(CommandContext commandContext) {
            return (String) commandContext.getDbSqlSession().selectOne("selectProcessDefinitionDeploymentIdByKey", "waiter");
        }
    });
    Assert.assertNotNull("the processDefinitionDeploymentId should not be null!", processDefinitionDeploymentId);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ManagementService(org.activiti.engine.ManagementService) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) Test(org.junit.Test)

Example 33 with CommandContext

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

the class CustomMybatisXMLMapperTest method testSelectOneTask.

public void testSelectOneTask() {
    // Create test data
    for (int i = 0; i < 4; i++) {
        createTask(i + "", null, null, 0);
    }
    final String taskId = createTask("4", null, null, 0);
    CustomTask customTask = managementService.executeCommand(new Command<CustomTask>() {

        @Override
        public CustomTask execute(CommandContext commandContext) {
            return (CustomTask) commandContext.getDbSqlSession().selectOne("selectOneCustomTask", taskId);
        }
    });
    assertEquals("4", customTask.getName());
    // test default query as well
    List<Task> tasks = taskService.createTaskQuery().list();
    assertEquals(5, tasks.size());
    Task task = taskService.createTaskQuery().taskName("2").singleResult();
    assertEquals("2", task.getName());
    // Cleanup
    deleteTasks(taskService.createTaskQuery().list());
}
Also used : Task(org.activiti.engine.task.Task) CommandContext(org.activiti.engine.impl.interceptor.CommandContext)

Example 34 with CommandContext

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

the class AbstractActivitiTestCase method assertAndEnsureCleanDb.

/** Each test is assumed to clean up all DB content it entered.
   * After a test method executed, this method scans all tables to see if the DB is completely clean. 
   * It throws AssertionFailed in case the DB is not clean.
   * If the DB is not clean, it is cleaned by performing a create a drop. */
protected void assertAndEnsureCleanDb() throws Throwable {
    log.debug("verifying that db is clean after test");
    Map<String, Long> tableCounts = managementService.getTableCount();
    StringBuilder outputMessage = new StringBuilder();
    for (String tableName : tableCounts.keySet()) {
        String tableNameWithoutPrefix = tableName.replace(processEngineConfiguration.getDatabaseTablePrefix(), "");
        if (!TABLENAMES_EXCLUDED_FROM_DB_CLEAN_CHECK.contains(tableNameWithoutPrefix)) {
            Long count = tableCounts.get(tableName);
            if (count != 0L) {
                outputMessage.append("  ").append(tableName).append(": ").append(count).append(" record(s) ");
            }
        }
    }
    if (outputMessage.length() > 0) {
        outputMessage.insert(0, "DB NOT CLEAN: \n");
        log.error(EMPTY_LINE);
        log.error(outputMessage.toString());
        log.info("dropping and recreating db");
        CommandExecutor commandExecutor = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getCommandExecutor();
        CommandConfig config = new CommandConfig().transactionNotSupported();
        commandExecutor.execute(config, new Command<Object>() {

            public Object execute(CommandContext commandContext) {
                DbSqlSession session = commandContext.getSession(DbSqlSession.class);
                session.dbSchemaDrop();
                session.dbSchemaCreate();
                return null;
            }
        });
        if (exception != null) {
            throw exception;
        } else {
            Assert.fail(outputMessage.toString());
        }
    } else {
        log.info("database was clean");
    }
}
Also used : CommandConfig(org.activiti.engine.impl.interceptor.CommandConfig) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) DbSqlSession(org.activiti.engine.impl.db.DbSqlSession)

Example 35 with CommandContext

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

the class BpmnDeployer method removeExistingMessageEventSubscriptions.

protected void removeExistingMessageEventSubscriptions(ProcessDefinitionEntity processDefinition, ProcessDefinitionEntity latestProcessDefinition) {
    if (latestProcessDefinition != null) {
        CommandContext commandContext = Context.getCommandContext();
        List<EventSubscriptionEntity> subscriptionsToDisable = commandContext.getEventSubscriptionEntityManager().findEventSubscriptionsByTypeAndProcessDefinitionId(MessageEventHandler.EVENT_HANDLER_TYPE, latestProcessDefinition.getId(), latestProcessDefinition.getTenantId());
        for (EventSubscriptionEntity eventSubscriptionEntity : subscriptionsToDisable) {
            eventSubscriptionEntity.delete();
        }
    }
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity) MessageEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity) EventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity)

Aggregations

CommandContext (org.activiti.engine.impl.interceptor.CommandContext)72 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)18 DbSqlSession (org.activiti.engine.impl.db.DbSqlSession)13 SignalEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity)8 Date (java.util.Date)7 ActivitiException (org.activiti.engine.ActivitiException)7 CommandConfig (org.activiti.engine.impl.interceptor.CommandConfig)7 EventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity)7 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)7 MessageEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity)6 HashMap (java.util.HashMap)4 TimerEntity (org.activiti.engine.impl.persistence.entity.TimerEntity)4 Job (org.activiti.engine.runtime.Job)4 Deployment (org.activiti.engine.test.Deployment)4 ArrayList (java.util.ArrayList)3 GregorianCalendar (java.util.GregorianCalendar)3 List (java.util.List)3 ExtensionElement (org.activiti.bpmn.model.ExtensionElement)3 DynamicBpmnService (org.activiti.engine.DynamicBpmnService)3 JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)3