Search in sources :

Example 11 with SimulationEvent

use of org.activiti.crystalball.simulator.SimulationEvent in project Activiti by Activiti.

the class EventLogUserTaskCompleteTransformer method apply.

@SuppressWarnings("unchecked")
@Override
public SimulationEvent apply(EventLogEntry event) {
    if (ActivitiEventType.TASK_COMPLETED.toString().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 taskIdValue = (String) data.get(Fields.ACTIVITY_ID);
        boolean localScope = false;
        Map<String, Object> variableMap = null;
        if (data.get(Fields.VARIABLES) != null) {
            variableMap = (Map<String, Object>) data.get(Fields.VARIABLES);
        } else {
            variableMap = (Map<String, Object>) data.get(Fields.LOCAL_VARIABLES);
            localScope = true;
        }
        String taskDefinitionKeyValue = (String) data.get(Fields.TASK_DEFINITION_KEY);
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("taskId", taskIdValue);
        properties.put(TASK_DEFINITION_KEY, taskDefinitionKeyValue);
        properties.put(PROCESS_INSTANCE_ID, event.getProcessInstanceId());
        if (variableMap != null) {
            properties.put(TASK_VARIABLES, variableMap);
            properties.put(VARIABLES_LOCAL_SCOPE, localScope);
        }
        return new SimulationEvent.Builder(this.simulationEventType).priority((int) event.getLogNumber()).properties(properties).build();
    }
    return null;
}
Also used : CrystalballException(org.activiti.crystalball.simulator.CrystalballException) HashMap(java.util.HashMap) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) SimulationEvent(org.activiti.crystalball.simulator.SimulationEvent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 12 with SimulationEvent

use of org.activiti.crystalball.simulator.SimulationEvent in project Activiti by Activiti.

the class AcquireJobNotificationEventHandler method init.

@Override
public void init() {
    log.info(jobExecutor.getName() + " starting to acquire jobs");
    jobExecutor.start();
    SimulationEvent event = new SimulationEvent.Builder(SimulationEvent.TYPE_ACQUIRE_JOB_NOTIFICATION_EVENT).simulationTime(SimulationRunContext.getClock().getCurrentTime().getTime()).property(((SimulationDefaultJobExecutor) jobExecutor).getAcquireJobsRunnable()).build();
    SimulationRunContext.getEventCalendar().addEvent(event);
}
Also used : SimulationEvent(org.activiti.crystalball.simulator.SimulationEvent) SimulationDefaultJobExecutor(org.activiti.crystalball.simulator.processengine.jobexecutor.SimulationDefaultJobExecutor)

Example 13 with SimulationEvent

use of org.activiti.crystalball.simulator.SimulationEvent in project Activiti by Activiti.

the class StartReplayProcessEventHandler method init.

@Override
public void init() {
    SimulationEvent toReplayStartEvent = findProcessInstanceStartEvent();
    SimulationEvent startEvent = new SimulationEvent.Builder(eventTypeToSchedule).properties(toReplayStartEvent.getProperties()).build();
    // add start process event
    SimulationRunContext.getEventCalendar().addEvent(startEvent);
}
Also used : SimulationEvent(org.activiti.crystalball.simulator.SimulationEvent)

Example 14 with SimulationEvent

use of org.activiti.crystalball.simulator.SimulationEvent in project Activiti by Activiti.

the class ReplayEventLogTest method getTransformers.

private static 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, 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 15 with SimulationEvent

use of org.activiti.crystalball.simulator.SimulationEvent in project Activiti by Activiti.

the class ReplayRunTest method getTransformers.

private static List<Function<ActivitiEvent, SimulationEvent>> getTransformers() {
    List<Function<ActivitiEvent, SimulationEvent>> transformers = new ArrayList<Function<ActivitiEvent, SimulationEvent>>();
    transformers.add(new ProcessInstanceCreateTransformer(PROCESS_INSTANCE_START_EVENT_TYPE, PROCESS_DEFINITION_ID_KEY, BUSINESS_KEY, VARIABLES_KEY));
    transformers.add(new UserTaskCompleteTransformer(USER_TASK_COMPLETED_EVENT_TYPE));
    return transformers;
}
Also used : Function(org.activiti.crystalball.simulator.delegate.event.Function) ProcessInstanceCreateTransformer(org.activiti.crystalball.simulator.delegate.event.impl.ProcessInstanceCreateTransformer) UserTaskCompleteTransformer(org.activiti.crystalball.simulator.delegate.event.impl.UserTaskCompleteTransformer) ActivitiEvent(org.activiti.engine.delegate.event.ActivitiEvent) SimulationEvent(org.activiti.crystalball.simulator.SimulationEvent)

Aggregations

SimulationEvent (org.activiti.crystalball.simulator.SimulationEvent)16 HashMap (java.util.HashMap)7 Function (org.activiti.crystalball.simulator.delegate.event.Function)3 EventLogEntry (org.activiti.engine.event.EventLogEntry)3 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 CrystalballException (org.activiti.crystalball.simulator.CrystalballException)2 EventLogProcessInstanceCreateTransformer (org.activiti.crystalball.simulator.delegate.event.impl.EventLogProcessInstanceCreateTransformer)2 EventLogUserTaskCompleteTransformer (org.activiti.crystalball.simulator.delegate.event.impl.EventLogUserTaskCompleteTransformer)2 ActivitiEntityEvent (org.activiti.engine.delegate.event.ActivitiEntityEvent)2 Task (org.activiti.engine.task.Task)2 Date (java.util.Date)1 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