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();
}
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();
}
Aggregations