org.flowable.engine.HistoryService Java Examples

The following examples show how to use org.flowable.engine.HistoryService. 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 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 #2
Source File: ProcessTimeCalculatorTest.java    From multiapps-controller with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);

    Mockito.when(flowableFacade.getHistoricProcessById(DEFAULT_PROCESS_ID))
           .thenReturn(mockedProcessInstance);
    ProcessEngine processEngine = Mockito.mock(ProcessEngine.class);
    Mockito.when(flowableFacade.getProcessEngine())
           .thenReturn(processEngine);
    HistoryService historyServiceMock = Mockito.mock(HistoryService.class);
    Mockito.when(processEngine.getHistoryService())
           .thenReturn(historyServiceMock);
    Mockito.when(historyServiceMock.createHistoricActivityInstanceQuery())
           .thenReturn(historicActivityInstanceQueryMock);
    Mockito.when(historicActivityInstanceQueryMock.processInstanceId(DEFAULT_PROCESS_ID))
           .thenReturn(historicActivityInstanceQueryMock);

    processTimeCalculator = new ProcessTimeCalculator(flowableFacade);
}
 
Example #3
Source File: ServiceCacheTask.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
    ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
    RuntimeService runtimeService = processEngineConfiguration.getRuntimeService();
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(execution.getProcessInstanceId()).singleResult();
    if (processInstance != null && processInstance.getId().equals(execution.getProcessInstanceId())) {
        processInstanceId = processInstance.getId();
    }
    
    Execution queryExecution = runtimeService.createExecutionQuery().executionId(execution.getId()).singleResult();
    if (queryExecution != null && execution.getId().equals(queryExecution.getId())) {
        executionId = queryExecution.getId();
    }
    
    HistoryService historyService = processEngineConfiguration.getHistoryService();
    HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(execution.getProcessInstanceId()).singleResult();
    if (historicProcessInstance != null && historicProcessInstance.getId().equals(execution.getProcessInstanceId())) {
        historicProcessInstanceId = historicProcessInstance.getId();
    }
}
 
Example #4
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void queryForTaskLogEntriesByTasKId(TaskService taskService, HistoryService historyService,
        ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) {

    task = taskService.createTaskBuilder().
            assignee("testAssignee").
            create();
    Task anotherTask = taskService.createTaskBuilder().create();

    try {
        if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
            List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
            assertThat(logEntries).hasSize(1);
            assertThat(logEntries.get(0)).extracting(HistoricTaskLogEntry::getTaskId).isEqualTo(task.getId());

            assertThat(historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).count()).isEqualTo(1l);
        }

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

    HistoricTaskLogEntryBuilder historicTaskLogEntryBuilder = historyService.createHistoricTaskLogEntryBuilder(task);
    historicTaskLogEntryBuilder.userId("testUser");
    historicTaskLogEntryBuilder.type("customType");
    historicTaskLogEntryBuilder.data("testData");
    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.getTimeStamp()).isNotNull();
    }
}
 
Example #6
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 #7
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void changeDueDate(TaskService taskService, HistoryService historyService, ManagementService managementService,
        ProcessEngineConfiguration processEngineConfiguration) {
    task = taskService.createTaskBuilder().create();

    taskService.setDueDate(task.getId(), new Date());

    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_DUEDATE_CHANGED").list();
        assertThat(taskLogEntries).hasSize(1);
        assertThat(taskLogEntries.get(0).getData()).contains("\"newDueDate\"", "\"previousDueDate\":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_DUEDATE_CHANGED");
    }
}
 
Example #8
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void assertThatAuthenticatedUserIsSet(TaskService taskService, HistoryService historyService,
        Consumer<String> functionToAssert, ProcessEngineConfiguration processEngineConfiguration) {

    String previousUserId = Authentication.getAuthenticatedUserId();
    task = taskService.createTaskBuilder().
            assignee("testAssignee").
            create();
    Authentication.setAuthenticatedUserId("testUser");

    try {
        functionToAssert.accept(task.getId());

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

            taskLogsByTaskInstanceId = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).userId("testUser").list();
            assertThat(taskLogsByTaskInstanceId).hasSize(1);
        }

    } finally {
        Authentication.setAuthenticatedUserId(previousUserId);
    }
}
 
Example #9
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 #10
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void unclaimTaskEvent(TaskService taskService, HistoryService historyService, ProcessEngineConfiguration processEngineConfiguration) {
    task = taskService.createTaskBuilder().
            assignee("initialAssignee").
            create();

    taskService.unclaim(task.getId());

    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\":null", "\"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 #11
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void createTaskEventAsAuthenticatedUser(TaskService taskService, HistoryService historyService, ManagementService managementService,
        ProcessEngineConfiguration processEngineConfiguration) {
    String previousUserId = Authentication.getAuthenticatedUserId();
    Authentication.setAuthenticatedUserId("testUser");
    try {
        task = taskService.createTaskBuilder().
                assignee("testAssignee").
                create();

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

            assertThat(taskLogsByTaskInstanceId.get(0)).
                    extracting(HistoricTaskLogEntry::getUserId)
                    .isEqualTo("testUser");
        }

    } finally {
        Authentication.setAuthenticatedUserId(previousUserId);
    }
}
 
Example #12
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 #13
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 #14
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void deleteTaskEventLogEntry(TaskService taskService, HistoryService historyService, ManagementService managementService,
        ProcessEngineConfiguration processEngineConfiguration) {
    task = taskService.createTaskBuilder().
            assignee("testAssignee").
            create();

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

        historyService.deleteHistoricTaskLogEntry(taskLogsByTaskInstanceId.get(0).getLogNumber());

        HistoryTestHelper.waitForJobExecutorToProcessAllHistoryJobs(processEngineConfiguration, managementService, 5000, 200);
        taskLogsByTaskInstanceId = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
        assertThat(taskLogsByTaskInstanceId).isEmpty();
    }
}
 
Example #15
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 #16
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 #17
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 logAddGroup(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.addGroupIdentityLink(task.getId(), "newCandidateGroup", IdentityLinkType.PARTICIPANT);

        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\":\"participant\"",
                    "\"groupId\":\"newCandidateGroup\""
            );
        }

    } finally {
        taskService.complete(task.getId());
        deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, task.getId());
    }
}
 
Example #18
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 #19
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 logDeleteCandidateGroup(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();
    taskService.addCandidateGroup(task.getId(), "newCandidateGroup");
    try {
        taskService.deleteCandidateGroup(task.getId(), "newCandidateGroup");

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

            logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId())
                    .type("USER_TASK_IDENTITY_LINK_REMOVED")
                    .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 #20
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void queryForTaskLogEntriesBySubScopeId(TaskService taskService, HistoryService historyService,
        ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) {

    assertThatTaskLogIsFetched(taskService, historyService.createHistoricTaskLogEntryBuilder().subScopeId("testSubScopeId"),
            historyService.createHistoricTaskLogEntryQuery().subScopeId("testSubScopeId"), managementService, processEngineConfiguration);
}
 
Example #21
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 #22
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void queryForTaskLogEntriesByFromTimeStamp(TaskService taskService, HistoryService historyService,
        ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) {

    assertThatAllTaskLogIsFetched(taskService, historyService.createHistoricTaskLogEntryBuilder().timeStamp(getInsertDate()),
            historyService.createHistoricTaskLogEntryQuery().from(getCompareBeforeDate()), 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 queryForTaskLogEntriesByToTimeStamp(TaskService taskService, HistoryService historyService, ManagementService managementService,
        ProcessEngineConfiguration processEngineConfiguration) {
    
    HistoricTaskLogEntryBuilder historicTaskLogEntryBuilder = historyService.createHistoricTaskLogEntryBuilder().timeStamp(getInsertDate());
    HistoricTaskLogEntryQuery historicTaskLogEntryQuery = historyService.createHistoricTaskLogEntryQuery().to(getCompareAfterDate());

    task = taskService.createTaskBuilder().
            assignee("testAssignee").
            create();
    Task anotherTask = taskService.createTaskBuilder().create();
    historicTaskLogEntryBuilder.taskId(task.getId()).create();
    historicTaskLogEntryBuilder.taskId(task.getId()).create();
    historicTaskLogEntryBuilder.taskId(task.getId()).create();

    try {
        if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
            List<HistoricTaskLogEntry> logEntries = historicTaskLogEntryQuery.list();
            assertThat(logEntries).hasSize(3);
            assertThat(logEntries).extracting(HistoricTaskLogEntry::getTaskId)
                    .containsExactly(task.getId(), task.getId(), task.getId());

            assertThat(historicTaskLogEntryQuery.count()).isEqualTo(3);

            List<HistoricTaskLogEntry> pagedLogEntries = historicTaskLogEntryQuery.listPage(1, 1);
            assertThat(pagedLogEntries).hasSize(1);
            assertThat(pagedLogEntries.get(0)).isEqualToComparingFieldByField(logEntries.get(1));
        }

    } finally {
        deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, anotherTask.getId());
        taskService.deleteTask(anotherTask.getId(), true);
    }
}
 
Example #24
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void queryForTaskLogEntriesByFromToTimeStamp(TaskService taskService, HistoryService historyService,
        ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) {

    assertThatTaskLogIsFetched(taskService, historyService.createHistoricTaskLogEntryBuilder().timeStamp(getInsertDate()),
            historyService.createHistoricTaskLogEntryQuery().from(getCompareBeforeDate()).to(getCompareAfterDate()), managementService,
            processEngineConfiguration);
}
 
Example #25
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void queryForTaskLogEntriesByTenantId(TaskService taskService, HistoryService historyService,
        ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) {

    assertThatTaskLogIsFetched(taskService, historyService.createHistoricTaskLogEntryBuilder().timeStamp(getInsertDate()),
            historyService.createHistoricTaskLogEntryQuery().from(getCompareBeforeDate()).to(getCompareAfterDate()), managementService,
            processEngineConfiguration);
}
 
Example #26
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void queryForTaskLogEntriesByLogNumber(TaskService taskService, HistoryService historyService,
        ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) {

    task = taskService.createTaskBuilder().
            assignee("testAssignee").
            create();
    Task anotherTask = taskService.createTaskBuilder().create();

    try {
        if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
            HistoricTaskLogEntryBuilder historicTaskLogEntryBuilder = historyService.createHistoricTaskLogEntryBuilder();
            historicTaskLogEntryBuilder.taskId(task.getId()).create();
            historicTaskLogEntryBuilder.taskId(task.getId()).create();
            historicTaskLogEntryBuilder.taskId(task.getId()).create();

            HistoryTestHelper.waitForJobExecutorToProcessAllHistoryJobs(processEngineConfiguration, managementService, 10000, 200);
            List<HistoricTaskLogEntry> allLogEntries = historyService.createHistoricTaskLogEntryQuery().list();

            HistoricTaskLogEntryQuery historicTaskLogEntryQuery = historyService.createHistoricTaskLogEntryQuery().
                    fromLogNumber(allLogEntries.get(1).getLogNumber()).
                    toLogNumber(allLogEntries.get(allLogEntries.size() - 2).getLogNumber());
            List<HistoricTaskLogEntry> logEntries = historicTaskLogEntryQuery.
                    list();
            assertThat(logEntries).hasSize(3);
            assertThat(logEntries).extracting(HistoricTaskLogEntry::getLogNumber).containsExactly(
                    allLogEntries.get(1).getLogNumber(), allLogEntries.get(2).getLogNumber(), allLogEntries.get(3).getLogNumber()
            );

            assertThat(historicTaskLogEntryQuery.count()).isEqualTo(3l);

            List<HistoricTaskLogEntry> pagedLogEntries = historicTaskLogEntryQuery.listPage(1, 1);
            assertThat(pagedLogEntries).hasSize(1);
            assertThat(pagedLogEntries.get(0).getLogNumber()).isEqualTo(logEntries.get(1).getLogNumber());
        }
    } finally {
        deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, anotherTask.getId());
    }
}
 
Example #27
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 #28
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void queryForTaskLogOrderBy(TaskService taskService, HistoryService historyService, ManagementService managementService,
        ProcessEngineConfiguration processEngineConfiguration) {
    HistoricTaskLogEntryBuilder historicTaskLogEntryBuilder = historyService.createHistoricTaskLogEntryBuilder();
    historicTaskLogEntryBuilder.taskId("1").timeStamp(getInsertDate()).create();
    historicTaskLogEntryBuilder.taskId("2").timeStamp(getCompareAfterDate()).create();
    historicTaskLogEntryBuilder.taskId("3").timeStamp(getCompareBeforeDate()).create();

    try {

        if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
            List<HistoricTaskLogEntry> taskLogEntries = historyService.createHistoricTaskLogEntryQuery().list();
            assertThat(taskLogEntries).extracting(taskLogEntry -> taskLogEntry.getTaskId()).containsExactly("1", "2", "3");

            taskLogEntries = historyService.createHistoricTaskLogEntryQuery().orderByLogNumber().desc().list();
            assertThat(taskLogEntries).extracting(taskLogEntry -> taskLogEntry.getTaskId()).containsExactly("3", "2", "1");

            taskLogEntries = historyService.createHistoricTaskLogEntryQuery().orderByTimeStamp().desc().list();
            assertThat(taskLogEntries).extracting(taskLogEntry -> taskLogEntry.getTaskId()).containsExactly("2", "1", "3");
        }

    } finally {
        deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, "1");
        deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, "2");
        deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, "3");
    }
}
 
Example #29
Source File: ClientReleaser.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
public void releaseClientFor(HistoryService historyService, String processInstanceId) {
    String user = HistoryUtil.getVariableValue(historyService, processInstanceId, Variables.USER.getName());
    String organizationName = HistoryUtil.getVariableValue(historyService, processInstanceId, Variables.ORGANIZATION_NAME.getName());
    String spaceName = HistoryUtil.getVariableValue(historyService, processInstanceId, Variables.SPACE_NAME.getName());
    String spaceGuid = HistoryUtil.getVariableValue(historyService, processInstanceId, Variables.SPACE_GUID.getName());

    try {
        clientProvider.releaseClient(user, organizationName, spaceName);
        clientProvider.releaseClient(user, spaceGuid);
    } catch (SLException e) {
        LOGGER.warn(e.getMessage());
    }
}
 
Example #30
Source File: HistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void createCustomTaskEventLog(TaskService taskService, HistoryService historyService, ManagementService managementService,
        ProcessEngineConfiguration processEngineConfiguration) {
    task = taskService.createTaskBuilder().create();

    Date todayDate = new Date();
    HistoricTaskLogEntryBuilder historicTaskLogEntryBuilder = historyService.createHistoricTaskLogEntryBuilder(task);
    historicTaskLogEntryBuilder.timeStamp(todayDate);
    historicTaskLogEntryBuilder.userId("testUser");
    historicTaskLogEntryBuilder.type("customType");
    historicTaskLogEntryBuilder.data("testData");
    historicTaskLogEntryBuilder.create();

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

        logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("customType").list();
        assertThat(logEntries).hasSize(1);
        HistoricTaskLogEntry historicTaskLogEntry = logEntries.get(0);
        assertThat(historicTaskLogEntry.getLogNumber()).isNotNull();
        assertThat(historicTaskLogEntry.getUserId()).isEqualTo("testUser");
        assertThat(historicTaskLogEntry.getTaskId()).isEqualTo(task.getId());
        assertThat(historicTaskLogEntry.getType()).isEqualTo("customType");
        assertThat(simpleDateFormat.format(historicTaskLogEntry.getTimeStamp())).isEqualTo(simpleDateFormat.format(todayDate));
        assertThat(historicTaskLogEntry.getData()).isEqualTo("testData");
        historyService.deleteHistoricTaskLogEntry(historicTaskLogEntry.getLogNumber());
    }
}