org.flowable.engine.ProcessEngineConfiguration Java Examples

The following examples show how to use org.flowable.engine.ProcessEngineConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void taskAssigneeEvent(TaskService taskService, HistoryService historyService, ProcessEngineConfiguration processEngineConfiguration) {
    task = taskService.createTaskBuilder().
            assignee("initialAssignee").
            create();

    taskService.setAssignee(task.getId(), "newAssignee");

    if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
        List<HistoricTaskLogEntry> taskLogEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
        assertThat(taskLogEntries).hasSize(2);

        taskLogEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_ASSIGNEE_CHANGED").list();
        assertThat(taskLogEntries).hasSize(1);
        assertThat(taskLogEntries.get(0).getData()).contains("\"newAssigneeId\":\"newAssignee\"", "\"previousAssigneeId\":\"initialAssignee\"");
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getTimeStamp).isNotNull();
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getTaskId).isEqualTo(task.getId());
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getUserId).isNull();
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getType).isEqualTo("USER_TASK_ASSIGNEE_CHANGED");
    }
}
 
Example #2
Source File: BpmnDeploymentHelper.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the most recent persisted process definition that matches this one for tenant and key. If none is found, returns null. This method assumes that the tenant and key are properly set on the
 * process definition entity.
 */
public ProcessDefinitionEntity getMostRecentVersionOfProcessDefinition(ProcessDefinitionEntity processDefinition) {
    String key = processDefinition.getKey();
    String tenantId = processDefinition.getTenantId();
    ProcessDefinitionEntityManager processDefinitionManager = CommandContextUtil.getProcessEngineConfiguration().getProcessDefinitionEntityManager();

    ProcessDefinitionEntity existingDefinition = null;

    if (tenantId != null && !tenantId.equals(ProcessEngineConfiguration.NO_TENANT_ID)) {
        existingDefinition = processDefinitionManager.findLatestProcessDefinitionByKeyAndTenantId(key, tenantId);
    } else {
        existingDefinition = processDefinitionManager.findLatestProcessDefinitionByKey(key);
    }

    return existingDefinition;
}
 
Example #3
Source File: ProcessEngineAutoConfigurationTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void processEngineWithCustomIdGenerator() {
    contextRunner.withUserConfiguration(CustomIdGeneratorConfiguration.class)
        .run(context -> {
            assertThat(context).as("Process engine").hasSingleBean(ProcessEngine.class);
            assertThat(context).as("IdGenerator").doesNotHaveBean(IdGenerator.class);

            ProcessEngine processEngine = context.getBean(ProcessEngine.class);

            ProcessEngineConfiguration engineConfiguration = processEngine.getProcessEngineConfiguration();
            assertThat(engineConfiguration.getIdGenerator())
                .isInstanceOfSatisfying(DbIdGenerator.class, dbIdGenerator -> {
                    assertThat(dbIdGenerator.getIdBlockSize()).isEqualTo(engineConfiguration.getIdBlockSize());
                    assertThat(dbIdGenerator.getCommandExecutor()).isEqualTo(engineConfiguration.getCommandExecutor());
                    assertThat(dbIdGenerator.getCommandConfig())
                        .isEqualToComparingFieldByField(engineConfiguration.getDefaultCommandConfig().transactionRequiresNew());
                });
        });
}
 
Example #4
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void changePriority(TaskService taskService, HistoryService historyService, ProcessEngineConfiguration processEngineConfiguration) {
    task = taskService.createTaskBuilder().create();
    taskService.setPriority(task.getId(), Integer.MAX_VALUE);

    if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
        List<HistoricTaskLogEntry> taskLogEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
        assertThat(taskLogEntries).hasSize(2);

        taskLogEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_PRIORITY_CHANGED").list();
        assertThat(taskLogEntries).hasSize(1);
        assertThat(taskLogEntries.get(0).getData()).
                contains("\"newPriority\":2147483647", "\"previousPriority\":50}");
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getTimeStamp).isNotNull();
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getTaskId).isEqualTo(task.getId());
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getUserId).isNull();
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getType).isEqualTo("USER_TASK_PRIORITY_CHANGED");
    }
}
 
Example #5
Source File: ContentEngineConfiguratorTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws Exception{
    if (processEngine == null) {
        processEngine = ProcessEngineConfiguration
            .createProcessEngineConfigurationFromResource("flowable.cfg.xml")
            .buildProcessEngine();
        contentEngineConfiguration = (ContentEngineConfiguration) processEngine.getProcessEngineConfiguration()
            .getEngineConfigurations().get(EngineConfigurationConstants.KEY_CONTENT_ENGINE_CONFIG);
        contentService = contentEngineConfiguration.getContentService();
    }

    wiser = new Wiser();
    wiser.setPort(5025);
    try {
        wiser.start();
    } catch (RuntimeException e) { // Fix for slow port-closing Jenkins
        if (e.getMessage().toLowerCase().contains("bindexception")) {
            Thread.sleep(250L);
        }
    }
}
 
Example #6
Source File: ProcessWithFormTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void completeTaskWithoutValidationOnConfiguration(ProcessEngineConfiguration processEngineConfiguration, RuntimeService runtimeService, TaskService taskService) {
    ((ProcessEngineConfigurationImpl) processEngineConfiguration).setFormFieldValidationEnabled(false);
    try {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskWithFormSideEffectProcess");
        assertThat(SideEffectExecutionListener.getSideEffect()).isEqualTo(1);
        SideEffectExecutionListener.reset();

        Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

        FormRepositoryService formRepositoryService = FormEngines.getDefaultFormEngine().getFormRepositoryService();
        FormDefinition formDefinition = formRepositoryService.createFormDefinitionQuery().formDefinitionKey("form1").singleResult();

        taskService.completeTaskWithForm(task.getId(), formDefinition.getId(), "__COMPLETE", Collections.singletonMap("initiator", "someInitiator"));

        assertThat(SideEffectExecutionListener.getSideEffect()).isEqualTo(1);
    } finally {
        ((ProcessEngineConfigurationImpl) processEngineConfiguration).setFormFieldValidationEnabled(true);
    }
}
 
Example #7
Source File: JobTestHelper.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public static void executeJobExecutorForTime(ProcessEngineConfiguration processEngineConfiguration, long maxMillisToWait, long intervalMillis) {
    AsyncExecutor asyncExecutor = processEngineConfiguration.getAsyncExecutor();
    asyncExecutor.start();

    try {
        Timer timer = new Timer();
        InterruptTask task = new InterruptTask(Thread.currentThread());
        timer.schedule(task, maxMillisToWait);
        try {
            while (!task.isTimeLimitExceeded()) {
                Thread.sleep(intervalMillis);
            }
        } catch (InterruptedException e) {
            // ignore
        } finally {
            timer.cancel();
        }

    } finally {
        asyncExecutor.shutdown();
    }
}
 
Example #8
Source File: BpmnDeploymentHelper.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the persisted version of the already-deployed process definition. Note that this is different from {@link #getMostRecentVersionOfProcessDefinition} as it looks specifically for a process
 * definition that is already persisted and attached to a particular deployment, rather than the latest version across all deployments.
 */
public ProcessDefinitionEntity getPersistedInstanceOfProcessDefinition(ProcessDefinitionEntity processDefinition) {
    String deploymentId = processDefinition.getDeploymentId();
    if (StringUtils.isEmpty(processDefinition.getDeploymentId())) {
        throw new IllegalStateException("Provided process definition must have a deployment id.");
    }

    ProcessDefinitionEntityManager processDefinitionManager = CommandContextUtil.getProcessEngineConfiguration().getProcessDefinitionEntityManager();
    ProcessDefinitionEntity persistedProcessDefinition = null;
    if (processDefinition.getTenantId() == null || ProcessEngineConfiguration.NO_TENANT_ID.equals(processDefinition.getTenantId())) {
        persistedProcessDefinition = processDefinitionManager.findProcessDefinitionByDeploymentAndKey(deploymentId, processDefinition.getKey());
    } else {
        persistedProcessDefinition = processDefinitionManager.findProcessDefinitionByDeploymentAndKeyAndTenantId(deploymentId, processDefinition.getKey(), processDefinition.getTenantId());
    }

    return persistedProcessDefinition;
}
 
Example #9
Source File: CdiCamelBehavior.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
protected void setAppropriateCamelContext(DelegateExecution execution) {
    String camelContextValue = getStringFromField(camelContext, execution);
    if (StringUtils.isEmpty(camelContextValue) && camelContextObj != null) {
        // already set no further processing needed
    } else {
        ProcessEngineConfiguration engineConfiguration = org.flowable.engine.impl.context.Context.getProcessEngineConfiguration();
        if (StringUtils.isEmpty(camelContextValue) && camelContextObj == null) {
            camelContextValue = engineConfiguration.getDefaultCamelContext();
        }
    	
        camelContextObj = get(camelContextValue);
        
    	if(camelContextObj == null && camelContextValue.equals(engineConfiguration.getDefaultCamelContext())) {
    		// Camel CDI's default context is not named, so lookup as class if no named ones could be found
    		// See org.flowable.camel.cdi.named.CdiContextFactory to create a named context 
        	// lookup default context in CDI container so that 
        	camelContextObj = ProgrammaticBeanLookup.lookup(CamelContext.class);
        }
    }
}
 
Example #10
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void queryForNullTaskLogEntries_returnsAll(TaskService taskService, HistoryService historyService,
        ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) {

    Task taskA = taskService.createTaskBuilder().create();
    Task taskB = taskService.createTaskBuilder().create();
    Task taskC = taskService.createTaskBuilder().create();

    try {
        if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
            List<HistoricTaskLogEntry> taskLogsByTaskInstanceId = historyService.createHistoricTaskLogEntryQuery().taskId(null).list();
            assertThat(taskLogsByTaskInstanceId).hasSize(3);
        }

    } finally {
        deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, taskC.getId());
        deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, taskB.getId());
        deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, taskA.getId());
    }
}
 
Example #11
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void claimTaskEvent(TaskService taskService, HistoryService historyService, ManagementService managementService,
        ProcessEngineConfiguration processEngineConfiguration) {
    task = taskService.createTaskBuilder().create();

    taskService.claim(task.getId(), "testUser");

    if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
        List<HistoricTaskLogEntry> taskLogEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
        assertThat(taskLogEntries).hasSize(2);

        taskLogEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_ASSIGNEE_CHANGED").list();
        assertThat(taskLogEntries).hasSize(1);
        assertThat(taskLogEntries.get(0).getData()).contains("\"newAssigneeId\":\"testUser\"", "\"previousAssigneeId\":null");
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getTimeStamp).isNotNull();
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getTaskId).isEqualTo(task.getId());
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getUserId).isNull();
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getType).isEqualTo("USER_TASK_ASSIGNEE_CHANGED");
    }
}
 
Example #12
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void createCustomTaskEventLog_taskIdIsEnoughToCreateTaskLogEntry(TaskService taskService, HistoryService historyService,
        ProcessEngineConfiguration processEngineConfiguration) {
    task = taskService.createTaskBuilder().create();

    HistoricTaskLogEntryBuilder historicTaskLogEntryBuilder = historyService.createHistoricTaskLogEntryBuilder(task);
    historicTaskLogEntryBuilder.create();

    if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
        List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();

        assertThat(logEntries).hasSize(2);
        HistoricTaskLogEntry historicTaskLogEntry = logEntries.get(1);
        assertThat(historicTaskLogEntry.getLogNumber()).isNotNull();
        assertThat(historicTaskLogEntry.getUserId()).isNull();
        assertThat(historicTaskLogEntry.getTaskId()).isEqualTo(task.getId());
        assertThat(historicTaskLogEntry.getType()).isNull();
        assertThat(historicTaskLogEntry.getTimeStamp()).isNotNull();
        assertThat(historicTaskLogEntry.getData()).isNull();
    }
}
 
Example #13
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void deleteTaskWithLogEntries(TaskService taskService, ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration,
        String taskId) {
    taskService.deleteTask(taskId, true);
    managementService.executeCommand(new Command<Void>() {

        @Override
        public Void execute(CommandContext commandContext) {
            HistoricTaskLogEntryEntityManager historicTaskLogEntryEntityManager = CommandContextUtil.getTaskServiceConfiguration(commandContext)
                    .getHistoricTaskLogEntryEntityManager();
            List<HistoricTaskLogEntry> taskLogEntries = historicTaskLogEntryEntityManager
                    .findHistoricTaskLogEntriesByQueryCriteria(new HistoricTaskLogEntryQueryImpl(processEngineConfiguration.getCommandExecutor()));
            for (HistoricTaskLogEntry historicTaskLogEntry : taskLogEntries) {
                historicTaskLogEntryEntityManager.deleteHistoricTaskLogEntry(historicTaskLogEntry.getLogNumber());
            }

            HistoryJobService historyJobService = CommandContextUtil.getHistoryJobService(commandContext);
            List<HistoryJob> jobs = historyJobService.findHistoryJobsByQueryCriteria(new HistoryJobQueryImpl(commandContext));
            for (HistoryJob historyJob : jobs) {
                historyJobService.deleteHistoryJob((HistoryJobEntity) historyJob);
            }

            return null;
        }
    });
}
 
Example #14
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void taskOwnerEvent(TaskService taskService, HistoryService historyService, ManagementService managementService,
        ProcessEngineConfiguration processEngineConfiguration) {
    task = taskService.createTaskBuilder().
            assignee("initialAssignee").
            create();

    taskService.setOwner(task.getId(), "newOwner");

    if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
        List<HistoricTaskLogEntry> taskLogEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
        assertThat(taskLogEntries).hasSize(2);

        taskLogEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_OWNER_CHANGED").list();
        assertThat(taskLogEntries).hasSize(1);
        assertThat(taskLogEntries.get(0).getData()).
                contains("\"previousOwnerId\":null", "\"newOwnerId\":\"newOwner\"");
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getTimeStamp).isNotNull();
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getTaskId).isEqualTo(task.getId());
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getUserId).isNull();
        assertThat(taskLogEntries.get(0)).extracting(HistoricTaskLogEntry::getType).isEqualTo("USER_TASK_OWNER_CHANGED");
    }
}
 
Example #15
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void saveTask(TaskService taskService, HistoryService historyService, ProcessEngineConfiguration configuration) {
    task = taskService.createTaskBuilder().
            create();

    task.setName("newTaskName");
    task.setAssignee("newAssignee");
    task.setOwner("newOwner");
    task.setPriority(Integer.MAX_VALUE);
    task.setDueDate(new Date());
    taskService.saveTask(task);

    if (HistoryTestHelper.isHistoricTaskLoggingEnabled(configuration)) {
        List<HistoricTaskLogEntry> taskLogEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
        assertThat(taskLogEntries).as("The only event is user task created").hasSize(1);
    }
}
 
Example #16
Source File: SendEventTaskActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected EventModel getEventModel(CommandContext commandContext, DelegateExecution execution) {
    EventModel eventModel = null;
    if (Objects.equals(ProcessEngineConfiguration.NO_TENANT_ID, execution.getTenantId())) {
        eventModel = CommandContextUtil.getEventRepositoryService(commandContext)
            .getEventModelByKey(sendEventServiceTask.getEventType());
    } else {
        eventModel = CommandContextUtil.getEventRepositoryService(commandContext)
            .getEventModelByKey(sendEventServiceTask.getEventType(), execution.getTenantId());
    }

    if (eventModel == null) {
        throw new FlowableException("No event definition found for event key " + sendEventServiceTask.getEventType());
    }
    return eventModel;
}
 
Example #17
Source File: SpringProcessEngineConfiguration.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public ProcessEngineConfiguration setDataSource(DataSource dataSource) {
    if (dataSource instanceof TransactionAwareDataSourceProxy) {
        return super.setDataSource(dataSource);
    } else {
        // Wrap datasource in Transaction-aware proxy
        DataSource proxiedDataSource = new TransactionAwareDataSourceProxy(dataSource);
        return super.setDataSource(proxiedDataSource);
    }
}
 
Example #18
Source File: ProcessStepHelper.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
public ProcessStepHelper(ProgressMessageService progressMessageService, StepLogger stepLogger,
                         ProcessLogsPersister processLogsPersister, ProcessEngineConfiguration processEngineConfigurationSupplier) {
    this.progressMessageService = progressMessageService;
    this.stepLogger = stepLogger;
    this.processLogsPersister = processLogsPersister;
    this.processEngineConfiguration = processEngineConfigurationSupplier;
}
 
Example #19
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void queryForTaskLogEntriesByScopeType(TaskService taskService, HistoryService historyService,
        ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) {

    assertThatTaskLogIsFetched(taskService, historyService.createHistoricTaskLogEntryBuilder().scopeType("testScopeType"),
            historyService.createHistoricTaskLogEntryQuery().scopeType("testScopeType"), managementService, processEngineConfiguration);
}
 
Example #20
Source File: DeploymentEntityManagerImpl.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected ProcessDefinition findNewLatestProcessDefinitionAfterRemovalOf(ProcessDefinition processDefinitionToBeRemoved) {

        // The latest process definition is not necessarily the one with 'version -1' (some versions could have been deleted)
        // Hence, the following logic

        ProcessDefinitionQueryImpl query = new ProcessDefinitionQueryImpl();
        query.processDefinitionKey(processDefinitionToBeRemoved.getKey());

        if (processDefinitionToBeRemoved.getTenantId() != null
                && !ProcessEngineConfiguration.NO_TENANT_ID.equals(processDefinitionToBeRemoved.getTenantId())) {
            query.processDefinitionTenantId(processDefinitionToBeRemoved.getTenantId());
        } else {
            query.processDefinitionWithoutTenantId();
        }

        if (processDefinitionToBeRemoved.getVersion() > 0) {
            query.processDefinitionVersionLowerThan(processDefinitionToBeRemoved.getVersion());
        }
        query.orderByProcessDefinitionVersion().desc();

        query.setFirstResult(0);
        query.setMaxResults(1);
        List<ProcessDefinition> processDefinitions = getProcessDefinitionEntityManager().findProcessDefinitionsByQueryCriteria(query);
        if (processDefinitions != null && processDefinitions.size() > 0) {
            return processDefinitions.get(0);
        }
        return null;
    }
 
Example #21
Source File: EngineServiceUtil.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public static FormRepositoryService getFormRepositoryService(ProcessEngineConfiguration processEngineConfiguration) {
    FormRepositoryService formRepositoryService = null;
    FormEngineConfigurationApi formEngineConfiguration = getFormEngineConfiguration(processEngineConfiguration);
    if (formEngineConfiguration != null) {
        formRepositoryService = formEngineConfiguration.getFormRepositoryService();
    }
    
    return formRepositoryService;
}
 
Example #22
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void queryForTaskLogEntriesByType(TaskService taskService, HistoryService historyService,
        ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) {

    assertThatTaskLogIsFetched(taskService, historyService.createHistoricTaskLogEntryBuilder().type("testType"),
            historyService.createHistoricTaskLogEntryQuery().type("testType"), managementService, processEngineConfiguration);
}
 
Example #23
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void queryForTaskLogEntriesByNativeQuery(TaskService taskService, HistoryService historyService, ManagementService managementService,
        ProcessEngineConfiguration processEngineConfiguration) {
    assertThat(managementService.getTableName(HistoricTaskLogEntryEntity.class, false)).isEqualTo("ACT_HI_TSK_LOG");
    assertThat(managementService.getTableName(HistoricTaskLogEntry.class, false)).isEqualTo("ACT_HI_TSK_LOG");
    HistoricTaskLogEntryBuilder historicTaskLogEntryBuilder = historyService.createHistoricTaskLogEntryBuilder();
    historicTaskLogEntryBuilder.taskId("1").create();
    historicTaskLogEntryBuilder.taskId("2").create();
    historicTaskLogEntryBuilder.taskId("3").create();

    if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
        try {
            assertThat(historyService.createNativeHistoricTaskLogEntryQuery()
                    .sql("SELECT * FROM " + managementService.getTableName(HistoricTaskLogEntry.class)).list()).hasSize(3);
            assertThat(historyService.createNativeHistoricTaskLogEntryQuery()
                    .sql("SELECT count(*) FROM " + managementService.getTableName(HistoricTaskLogEntry.class)).count()).isEqualTo(3);

            assertThat(historyService.createNativeHistoricTaskLogEntryQuery().parameter("taskId", "1").
                    sql("SELECT count(*) FROM " + managementService.getTableName(HistoricTaskLogEntry.class) + " WHERE TASK_ID_ = #{taskId}").list())
                    .hasSize(1);
            assertThat(historyService.createNativeHistoricTaskLogEntryQuery().parameter("taskId", "1").
                    sql("SELECT count(*) FROM " + managementService.getTableName(HistoricTaskLogEntry.class) + " WHERE TASK_ID_ = #{taskId}").count())
                    .isEqualTo(1);
        } finally {
            deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, "1");
            deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, "2");
            deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, "3");
        }
    }
}
 
Example #24
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void logAddCandidateGroup(RuntimeService runtimeService, TaskService taskService, HistoryService historyService,
        ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) {

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    assertThat(processInstance).isNotNull();
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(task).isNotNull();

    try {
        taskService.addCandidateGroup(task.getId(), "newCandidateGroup");

        if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
            List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
            assertThat(logEntries).hasSize(2);

            logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId())
                    .type("USER_TASK_IDENTITY_LINK_ADDED")
                    .list();
            assertThat(logEntries).hasSize(1);
            assertThat(logEntries.get(0).getData()).contains(
                    "\"type\":\"candidate\"",
                    "\"groupId\":\"newCandidateGroup\""
            );
        }

    } finally {
        taskService.complete(task.getId());
        deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, task.getId());
    }
}
 
Example #25
Source File: DeploymentEntityManagerImpl.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected ProcessDefinitionEntity findLatestProcessDefinition(ProcessDefinition processDefinition) {
    ProcessDefinitionEntity latestProcessDefinition = null;
    if (processDefinition.getTenantId() != null && !ProcessEngineConfiguration.NO_TENANT_ID.equals(processDefinition.getTenantId())) {
        latestProcessDefinition = getProcessDefinitionEntityManager()
                .findLatestProcessDefinitionByKeyAndTenantId(processDefinition.getKey(), processDefinition.getTenantId());
    } else {
        latestProcessDefinition = getProcessDefinitionEntityManager()
                .findLatestProcessDefinitionByKey(processDefinition.getKey());
    }
    return latestProcessDefinition;
}
 
Example #26
Source File: ProcessEngineAutoConfigurationTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void processEngineWithMultipleCustomIdGeneratorsAsBean() {
    contextRunner.withUserConfiguration(
        CustomBeanIdGeneratorConfiguration.class,
        SecondCustomBeanIdGeneratorConfiguration.class
    ).run(context -> {
        assertThat(context)
            .as("Process engine").hasSingleBean(ProcessEngine.class)
            .as("Custom Id generator").hasBean("customIdGenerator")
            .as("Second Custom Id generator").hasBean("secondCustomIdGenerator");

        Map<String, IdGenerator> idGenerators = context.getBeansOfType(IdGenerator.class);
        assertThat(idGenerators).containsOnlyKeys("customIdGenerator", "secondCustomIdGenerator");

        IdGenerator customIdGenerator = idGenerators.get("customIdGenerator");
        assertThat(customIdGenerator).isInstanceOf(DbIdGenerator.class);

        IdGenerator secondCustomIdGenerator = idGenerators.get("secondCustomIdGenerator");
        assertThat(secondCustomIdGenerator).isInstanceOf(StrongUuidGenerator.class);

        ProcessEngine processEngine = context.getBean(ProcessEngine.class);

        ProcessEngineConfiguration engineConfiguration = processEngine.getProcessEngineConfiguration();
        assertThat(engineConfiguration.getIdGenerator())
            .isInstanceOf(StrongUuidGenerator.class)
            .isNotEqualTo(customIdGenerator)
            .isNotEqualTo(secondCustomIdGenerator);
    });
}
 
Example #27
Source File: ProcessWithFormTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void completeTaskWithoutValidationOnModelLevelBadExpression(ProcessEngineConfiguration processEngineConfiguration, RuntimeService runtimeService,
    TaskService taskService, RepositoryService repositoryService) {

    repositoryService.createDeployment().
        addString("oneTaskWithFormKeySideEffectProcess.bpmn20.xml",
            ONE_TASK_PROCESS.
                replace("START_EVENT_VALIDATION", "true").
                replace("USER_TASK_VALIDATION", "${BAD_EXPRESSION}")
        ).
        deploy();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(
        "oneTaskWithFormSideEffectProcess",
        Collections.emptyMap()
    );
    SideEffectExecutionListener.reset();

    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

    FormRepositoryService formRepositoryService = FormEngines.getDefaultFormEngine().getFormRepositoryService();
    FormDefinition formDefinition = formRepositoryService.createFormDefinitionQuery().formDefinitionKey("form1").singleResult();

    assertThatThrownBy(() -> taskService.completeTaskWithForm(task.getId(), formDefinition.getId(), "__COMPLETE", Collections.singletonMap("initiator", "someInitiator")))
            .isInstanceOf(FlowableException.class)
            .hasMessage("Unknown property used in expression: ${BAD_EXPRESSION}");
    assertThat(SideEffectExecutionListener.getSideEffect()).isZero();
}
 
Example #28
Source File: ConnectionPoolTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void testMyBatisConnectionPoolProperlyConfigured() {
    ProcessEngineConfigurationImpl config = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration
            .createProcessEngineConfigurationFromResource("org/activiti/engine/test/db/connection-pool.flowable.cfg.xml");

    config.buildProcessEngine();

    // Expected values
    int maxActive = 25;
    int maxIdle = 10;
    int maxCheckoutTime = 30000;
    int maxWaitTime = 25000;

    assertEquals(maxActive, config.getJdbcMaxActiveConnections());
    assertEquals(maxIdle, config.getJdbcMaxIdleConnections());
    assertEquals(maxCheckoutTime, config.getJdbcMaxCheckoutTime());
    assertEquals(maxWaitTime, config.getJdbcMaxWaitTime());

    // Verify that these properties are correctly set in the MyBatis datasource
    DataSource datasource = config.getDbSqlSessionFactory().getSqlSessionFactory().getConfiguration().getEnvironment().getDataSource();
    assertTrue(datasource instanceof PooledDataSource);

    PooledDataSource pooledDataSource = (PooledDataSource) datasource;
    assertEquals(maxActive, pooledDataSource.getPoolMaximumActiveConnections());
    assertEquals(maxIdle, pooledDataSource.getPoolMaximumIdleConnections());
    assertEquals(maxCheckoutTime, pooledDataSource.getPoolMaximumCheckoutTime());
    assertEquals(maxWaitTime, pooledDataSource.getPoolTimeToWait());
}
 
Example #29
Source File: NoDbConnectionTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void testNoDbConnection() {
    try {
        ProcessEngineConfiguration
                .createProcessEngineConfigurationFromResource("org/activiti/standalone/initialization/nodbconnection.flowable.cfg.xml")
                .buildProcessEngine();
        fail("expected exception");
    } catch (RuntimeException e) {
        assertTrue(containsSqlException(e));
    }
}
 
Example #30
Source File: DatabaseTablePrefixTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected ProcessEngine createProcessEngine(String schema) {
    return ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration()
            .setJdbcUrl("jdbc:h2:mem:flowable-db-table-prefix-test;DB_CLOSE_DELAY=-1;SCHEMA=" + schema)
            .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE)
            .setTablePrefixIsSchema(true)
            .setDatabaseTablePrefix(schema + ".")
            .buildProcessEngine();
}