use of org.activiti.crystalball.simulator.SimulationEvent in project Activiti by Activiti.
the class UserTaskCompleteTransformer method apply.
@Override
public SimulationEvent apply(ActivitiEvent event) {
if (ActivitiEventType.TASK_COMPLETED.equals(event.getType())) {
Task task = (Task) ((ActivitiEntityEvent) event).getEntity();
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("taskId", task.getId());
properties.put(TASK_DEFINITION_KEY, task.getTaskDefinitionKey());
properties.put(PROCESS_INSTANCE_ID, task.getProcessInstanceId());
properties.put(TASK_VARIABLES, task.getProcessVariables());
return new SimulationEvent.Builder(this.simulationEventType).simulationTime(Context.getProcessEngineConfiguration().getClock().getCurrentTime().getTime()).properties(properties).build();
}
return null;
}
use of org.activiti.crystalball.simulator.SimulationEvent in project Activiti by Activiti.
the class UserTaskExecutionListener method findUserTaskCompleteEvent.
private SimulationEvent findUserTaskCompleteEvent(DelegateTask delegateTask) {
if (delegateTask.hasVariable(StartReplayProcessEventHandler.PROCESS_INSTANCE_ID)) {
String toSimulateProcessInstanceId = (String) delegateTask.getVariable(StartReplayProcessEventHandler.PROCESS_INSTANCE_ID);
String toSimulateTaskDefinitionKey = delegateTask.getTaskDefinitionKey();
for (SimulationEvent e : events) {
if (typeToFind.equals(e.getType()) && toSimulateProcessInstanceId.equals(e.getProperty(UserTaskCompleteTransformer.PROCESS_INSTANCE_ID)) && toSimulateTaskDefinitionKey.equals(e.getProperty(UserTaskCompleteTransformer.TASK_DEFINITION_KEY)))
return e;
}
}
return null;
}
use of org.activiti.crystalball.simulator.SimulationEvent in project Activiti by Activiti.
the class UserTaskExecutionListener method notify.
@Override
public void notify(DelegateTask delegateTask) {
SimulationEvent eventToSimulate = findUserTaskCompleteEvent(delegateTask);
if (eventToSimulate != null) {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("taskId", delegateTask.getId());
properties.put("variables", eventToSimulate.getProperty(UserTaskCompleteTransformer.TASK_VARIABLES));
// we were able to resolve event to simulate automatically
SimulationEvent e = new SimulationEvent.Builder(typeToCreate).properties(properties).build();
SimulationRunContext.getEventCalendar().addEvent(e);
}
}
use of org.activiti.crystalball.simulator.SimulationEvent in project Activiti by Activiti.
the class DeploymentCreateTransformer method apply.
@Override
public SimulationEvent apply(ActivitiEvent event) {
if (ActivitiEventType.ENTITY_CREATED.equals(event.getType()) && (event instanceof ActivitiEntityEvent) && ((ActivitiEntityEvent) event).getEntity() instanceof DeploymentEntity) {
DeploymentEntity deploymentEntity = (DeploymentEntity) ((ActivitiEntityEvent) event).getEntity();
Map<String, Object> simEventProperties = new HashMap<String, Object>();
simEventProperties.put(resourcesKey, deploymentEntity.getResources());
return new SimulationEvent.Builder(simulationEventType).simulationTime(Context.getProcessEngineConfiguration().getClock().getCurrentTime().getTime()).properties(simEventProperties).build();
}
return null;
}
use of org.activiti.crystalball.simulator.SimulationEvent in project Activiti by Activiti.
the class EventLogProcessInstanceCreateTransformer method apply.
@SuppressWarnings({ "unchecked" })
@Override
public SimulationEvent apply(EventLogEntry event) {
if ("PROCESSINSTANCE_START".equals(event.getType())) {
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> data;
try {
data = objectMapper.readValue(event.getData(), new TypeReference<HashMap<String, Object>>() {
});
} catch (IOException e) {
throw new CrystalballException("unable to parse JSON string.", e);
}
String processDefinitionId = (String) data.get(Fields.PROCESS_DEFINITION_ID);
Map<String, Object> variableMap = (Map<String, Object>) data.get(Fields.VARIABLES);
String businessKeyValue = (String) data.get(Fields.BUSINESS_KEY);
String processInstanceId = (String) data.get(Fields.PROCESS_INSTANCE_ID);
Map<String, Object> simEventProperties = new HashMap<String, Object>();
simEventProperties.put(processDefinitionIdKey, processDefinitionId);
simEventProperties.put(this.businessKey, businessKeyValue);
simEventProperties.put(variablesKey, variableMap);
simEventProperties.put(PROCESS_INSTANCE_ID, processInstanceId);
return new SimulationEvent.Builder(simulationEventType).priority((int) event.getLogNumber()).properties(simEventProperties).build();
}
return null;
}
Aggregations