Search in sources :

Example 1 with EventLogEntry

use of org.activiti.engine.event.EventLogEntry in project Activiti by Activiti.

the class EventOverviewPanel method getTransformers.

protected List<Function<EventLogEntry, SimulationEvent>> getTransformers() {
    List<Function<EventLogEntry, SimulationEvent>> transformers = new ArrayList<Function<EventLogEntry, SimulationEvent>>();
    transformers.add(new EventLogProcessInstanceCreateTransformer(PROCESS_INSTANCE_START_EVENT_TYPE, PROCESS_DEFINITION_ID_KEY, SIMULATION_BUSINESS_KEY, VARIABLES_KEY));
    transformers.add(new EventLogUserTaskCompleteTransformer(USER_TASK_COMPLETED_EVENT_TYPE));
    return transformers;
}
Also used : Function(org.activiti.crystalball.simulator.delegate.event.Function) EventLogEntry(org.activiti.engine.event.EventLogEntry) EventLogProcessInstanceCreateTransformer(org.activiti.crystalball.simulator.delegate.event.impl.EventLogProcessInstanceCreateTransformer) ArrayList(java.util.ArrayList) EventLogUserTaskCompleteTransformer(org.activiti.crystalball.simulator.delegate.event.impl.EventLogUserTaskCompleteTransformer) SimulationEvent(org.activiti.crystalball.simulator.SimulationEvent)

Example 2 with EventLogEntry

use of org.activiti.engine.event.EventLogEntry in project Activiti by Activiti.

the class ReplayEventLogTest method testProcessInstanceStartEvents.

@Test
public void testProcessInstanceStartEvents() throws Exception {
    ProcessEngineImpl processEngine = initProcessEngine();
    TaskService taskService = processEngine.getTaskService();
    RuntimeService runtimeService = processEngine.getRuntimeService();
    ManagementService managementService = processEngine.getManagementService();
    HistoryService historyService = processEngine.getHistoryService();
    // record events
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put(TEST_VARIABLE, TEST_VALUE);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(USERTASK_PROCESS, BUSINESS_KEY, variables);
    Task task = taskService.createTaskQuery().taskDefinitionKey("userTask").singleResult();
    TimeUnit.MILLISECONDS.sleep(50);
    variables = new HashMap<String, Object>();
    variables.put(TASK_TEST_VARIABLE, TASK_TEST_VALUE);
    taskService.complete(task.getId(), variables);
    // transform log events
    List<EventLogEntry> eventLogEntries = managementService.getEventLogEntries(null, null);
    EventLogTransformer transformer = new EventLogTransformer(getTransformers());
    List<SimulationEvent> simulationEvents = transformer.transform(eventLogEntries);
    SimpleEventCalendar eventCalendar = new SimpleEventCalendar(processEngine.getProcessEngineConfiguration().getClock(), new SimulationEventComparator());
    eventCalendar.addEvents(simulationEvents);
    // replay process instance run
    final SimulationDebugger simRun = new ReplaySimulationRun(processEngine, eventCalendar, getReplayHandlers(processInstance.getId()));
    simRun.init(new NoExecutionVariableScope());
    // original process is finished - there should not be any running process instance/task
    assertEquals(0, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count());
    assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("userTask").count());
    simRun.step();
    // replay process was started
    ProcessInstance replayProcessInstance = runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).singleResult();
    assertNotNull(replayProcessInstance);
    assertTrue(replayProcessInstance.getId().equals(processInstance.getId()) == false);
    assertEquals(TEST_VALUE, runtimeService.getVariable(replayProcessInstance.getId(), TEST_VARIABLE));
    // there should be one task
    assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("userTask").count());
    simRun.step();
    // userTask was completed - replay process was finished
    assertEquals(0, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count());
    assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("userTask").count());
    HistoricVariableInstance variableInstance = historyService.createHistoricVariableInstanceQuery().processInstanceId(replayProcessInstance.getId()).variableName(TASK_TEST_VARIABLE).singleResult();
    assertNotNull(variableInstance);
    assertEquals(TASK_TEST_VALUE, variableInstance.getValue());
    // close simulation
    simRun.close();
    processEngine.close();
    ProcessEngines.destroy();
}
Also used : ReplaySimulationRun(org.activiti.crystalball.simulator.ReplaySimulationRun) Task(org.activiti.engine.task.Task) RuntimeService(org.activiti.engine.RuntimeService) HashMap(java.util.HashMap) TaskService(org.activiti.engine.TaskService) EventLogEntry(org.activiti.engine.event.EventLogEntry) SimpleEventCalendar(org.activiti.crystalball.simulator.SimpleEventCalendar) NoExecutionVariableScope(org.activiti.engine.impl.el.NoExecutionVariableScope) HistoryService(org.activiti.engine.HistoryService) SimulationEventComparator(org.activiti.crystalball.simulator.SimulationEventComparator) EventLogTransformer(org.activiti.crystalball.simulator.delegate.event.impl.EventLogTransformer) ManagementService(org.activiti.engine.ManagementService) SimulationDebugger(org.activiti.crystalball.simulator.SimulationDebugger) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) SimulationEvent(org.activiti.crystalball.simulator.SimulationEvent) ProcessEngineImpl(org.activiti.engine.impl.ProcessEngineImpl) Test(org.junit.Test)

Example 3 with EventLogEntry

use of org.activiti.engine.event.EventLogEntry in project Activiti by Activiti.

the class DatabaseEventLoggerTest method testStandaloneTaskEvents.

public void testStandaloneTaskEvents() throws JsonParseException, JsonMappingException, IOException {
    Task task = taskService.newTask();
    task.setAssignee("kermit");
    task.setTenantId("myTenant");
    taskService.saveTask(task);
    List<EventLogEntry> events = managementService.getEventLogEntries(null, null);
    assertEquals(2, events.size());
    assertEquals("TASK_CREATED", events.get(0).getType());
    assertEquals("TASK_ASSIGNED", events.get(1).getType());
    for (EventLogEntry eventLogEntry : events) {
        Map<String, Object> data = objectMapper.readValue(eventLogEntry.getData(), new TypeReference<HashMap<String, Object>>() {
        });
        assertEquals("myTenant", data.get(Fields.TENANT_ID));
    }
    // Cleanup
    taskService.deleteTask(task.getId(), true);
    for (EventLogEntry eventLogEntry : managementService.getEventLogEntries(null, null)) {
        managementService.deleteEventLogEntry(eventLogEntry.getLogNumber());
    }
}
Also used : Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) EventLogEntry(org.activiti.engine.event.EventLogEntry)

Example 4 with EventLogEntry

use of org.activiti.engine.event.EventLogEntry in project Activiti by Activiti.

the class ActivityEventsTest method assertDatabaseEventPresent.

protected void assertDatabaseEventPresent(ActivitiEventType eventType) {
    String eventTypeString = eventType.name();
    List<EventLogEntry> eventLogEntries = managementService.getEventLogEntries(0L, 100000L);
    boolean found = false;
    for (EventLogEntry entry : eventLogEntries) {
        if (entry.getType().equals(eventTypeString)) {
            found = true;
        }
    }
    assertTrue(found);
}
Also used : EventLogEntry(org.activiti.engine.event.EventLogEntry)

Example 5 with EventLogEntry

use of org.activiti.engine.event.EventLogEntry in project Activiti by Activiti.

the class ActivityEventsTest method tearDown.

@Override
protected void tearDown() throws Exception {
    if (listener != null) {
        listener.clearEventsReceived();
        processEngineConfiguration.getEventDispatcher().removeEventListener(listener);
    }
    // Remove entries
    for (EventLogEntry eventLogEntry : managementService.getEventLogEntries(null, null)) {
        managementService.deleteEventLogEntry(eventLogEntry.getLogNumber());
    }
    // Database event logger teardown
    runtimeService.removeEventListener(databaseEventLogger);
    super.tearDown();
}
Also used : EventLogEntry(org.activiti.engine.event.EventLogEntry)

Aggregations

EventLogEntry (org.activiti.engine.event.EventLogEntry)9 HashMap (java.util.HashMap)4 SimulationEvent (org.activiti.crystalball.simulator.SimulationEvent)3 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)3 Task (org.activiti.engine.task.Task)3 ArrayList (java.util.ArrayList)2 Function (org.activiti.crystalball.simulator.delegate.event.Function)2 EventLogProcessInstanceCreateTransformer (org.activiti.crystalball.simulator.delegate.event.impl.EventLogProcessInstanceCreateTransformer)2 EventLogUserTaskCompleteTransformer (org.activiti.crystalball.simulator.delegate.event.impl.EventLogUserTaskCompleteTransformer)2 Map (java.util.Map)1 ReplaySimulationRun (org.activiti.crystalball.simulator.ReplaySimulationRun)1 SimpleEventCalendar (org.activiti.crystalball.simulator.SimpleEventCalendar)1 SimulationDebugger (org.activiti.crystalball.simulator.SimulationDebugger)1 SimulationEventComparator (org.activiti.crystalball.simulator.SimulationEventComparator)1 EventLogTransformer (org.activiti.crystalball.simulator.delegate.event.impl.EventLogTransformer)1 HistoryService (org.activiti.engine.HistoryService)1 ManagementService (org.activiti.engine.ManagementService)1 RuntimeService (org.activiti.engine.RuntimeService)1 TaskService (org.activiti.engine.TaskService)1 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)1