Search in sources :

Example 1 with EventLogTransformer

use of org.activiti.crystalball.simulator.delegate.event.impl.EventLogTransformer in project Activiti by Activiti.

the class EventOverviewPanel method initProcessInstances.

protected void initProcessInstances() {
    HorizontalLayout instancesHeader = new HorizontalLayout();
    instancesHeader.setSpacing(false);
    instancesHeader.setMargin(false);
    instancesHeader.setWidth(100, UNITS_PERCENTAGE);
    instancesHeader.addStyleName(ExplorerLayout.STYLE_DETAIL_BLOCK);
    addDetailComponent(instancesHeader);
    initProcessInstanceTitle(instancesHeader);
    HorizontalLayout selectLayout = new HorizontalLayout();
    selectLayout.setSpacing(true);
    selectLayout.setMargin(true);
    selectLayout.setWidth(50, UNITS_PERCENTAGE);
    addDetailComponent(selectLayout);
    definitionSelect = new NativeSelect(i18nManager.getMessage(Messages.DEPLOYMENT_HEADER_DEFINITIONS));
    definitionSelect.setImmediate(true);
    for (ProcessDefinition definition : definitionList) {
        definitionSelect.addItem(definition.getId());
        definitionSelect.setItemCaption(definition.getId(), definition.getName());
    }
    definitionSelect.addListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            if (definitionSelect.getValue() != null) {
                String selectedDefinitionId = (String) definitionSelect.getValue();
                ExplorerApp.get().setCrystalBallCurrentDefinitionId(selectedDefinitionId);
                refreshInstances(selectedDefinitionId);
            }
        }
    });
    selectLayout.addComponent(definitionSelect);
    replayButton = new Button(i18nManager.getMessage(Messages.CRYSTALBALL_BUTTON_REPLAY));
    replayButton.setEnabled(false);
    replayButton.addListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            if (instanceTable.getValue() != null) {
                String processInstanceId = (String) instanceTable.getValue();
                ExplorerApp.get().setCrystalBallCurrentInstanceId(processInstanceId);
                List<EventLogEntry> eventLogEntries = managementService.getEventLogEntriesByProcessInstanceId(processInstanceId);
                if (eventLogEntries == null || eventLogEntries.isEmpty())
                    return;
                EventLogTransformer transformer = new EventLogTransformer(getTransformers());
                simulationEvents = transformer.transform(eventLogEntries);
                ExplorerApp.get().setCrystalBallSimulationEvents(simulationEvents);
                SimpleEventCalendar eventCalendar = new SimpleEventCalendar(ProcessEngines.getDefaultProcessEngine().getProcessEngineConfiguration().getClock(), new SimulationEventComparator());
                eventCalendar.addEvents(simulationEvents);
                // replay process instance run
                simulationDebugger = new ReplaySimulationRun(ProcessEngines.getDefaultProcessEngine(), eventCalendar, getReplayHandlers(processInstanceId));
                ExplorerApp.get().setCrystalBallSimulationDebugger(simulationDebugger);
                simulationDebugger.init(new NoExecutionVariableScope());
                simulationDebugger.step();
                // replay process was started
                List<HistoricProcessInstance> replayProcessInstanceList = historyService.createHistoricProcessInstanceQuery().processInstanceBusinessKey(SIMULATION_BUSINESS_KEY).orderByProcessInstanceStartTime().desc().list();
                if (replayProcessInstanceList != null && !replayProcessInstanceList.isEmpty()) {
                    replayHistoricInstance = replayProcessInstanceList.get(0);
                }
                refreshEvents();
            }
        }
    });
    selectLayout.addComponent(replayButton);
    selectLayout.setComponentAlignment(replayButton, Alignment.MIDDLE_LEFT);
    instanceLayout = new HorizontalLayout();
    instanceLayout.setWidth(100, UNITS_PERCENTAGE);
    addDetailComponent(instanceLayout);
    initInstancesTable();
}
Also used : ReplaySimulationRun(org.activiti.crystalball.simulator.ReplaySimulationRun) ClickEvent(com.vaadin.ui.Button.ClickEvent) SimpleEventCalendar(org.activiti.crystalball.simulator.SimpleEventCalendar) NoExecutionVariableScope(org.activiti.engine.impl.el.NoExecutionVariableScope) SimulationEventComparator(org.activiti.crystalball.simulator.SimulationEventComparator) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) EventLogTransformer(org.activiti.crystalball.simulator.delegate.event.impl.EventLogTransformer) HorizontalLayout(com.vaadin.ui.HorizontalLayout) ValueChangeEvent(com.vaadin.data.Property.ValueChangeEvent) ValueChangeListener(com.vaadin.data.Property.ValueChangeListener) Button(com.vaadin.ui.Button) NativeSelect(com.vaadin.ui.NativeSelect) ArrayList(java.util.ArrayList) List(java.util.List) ClickListener(com.vaadin.ui.Button.ClickListener)

Example 2 with EventLogTransformer

use of org.activiti.crystalball.simulator.delegate.event.impl.EventLogTransformer 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)

Aggregations

ReplaySimulationRun (org.activiti.crystalball.simulator.ReplaySimulationRun)2 SimpleEventCalendar (org.activiti.crystalball.simulator.SimpleEventCalendar)2 SimulationEventComparator (org.activiti.crystalball.simulator.SimulationEventComparator)2 EventLogTransformer (org.activiti.crystalball.simulator.delegate.event.impl.EventLogTransformer)2 NoExecutionVariableScope (org.activiti.engine.impl.el.NoExecutionVariableScope)2 ValueChangeEvent (com.vaadin.data.Property.ValueChangeEvent)1 ValueChangeListener (com.vaadin.data.Property.ValueChangeListener)1 Button (com.vaadin.ui.Button)1 ClickEvent (com.vaadin.ui.Button.ClickEvent)1 ClickListener (com.vaadin.ui.Button.ClickListener)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 NativeSelect (com.vaadin.ui.NativeSelect)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 SimulationDebugger (org.activiti.crystalball.simulator.SimulationDebugger)1 SimulationEvent (org.activiti.crystalball.simulator.SimulationEvent)1 HistoryService (org.activiti.engine.HistoryService)1 ManagementService (org.activiti.engine.ManagementService)1 RuntimeService (org.activiti.engine.RuntimeService)1