Search in sources :

Example 6 with SimulationEvent

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;
}
Also used : Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) SimulationEvent(org.activiti.crystalball.simulator.SimulationEvent)

Example 7 with SimulationEvent

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;
}
Also used : SimulationEvent(org.activiti.crystalball.simulator.SimulationEvent)

Example 8 with SimulationEvent

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);
    }
}
Also used : HashMap(java.util.HashMap) SimulationEvent(org.activiti.crystalball.simulator.SimulationEvent)

Example 9 with SimulationEvent

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;
}
Also used : DeploymentEntity(org.activiti.engine.impl.persistence.entity.DeploymentEntity) HashMap(java.util.HashMap) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) SimulationEvent(org.activiti.crystalball.simulator.SimulationEvent)

Example 10 with SimulationEvent

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;
}
Also used : CrystalballException(org.activiti.crystalball.simulator.CrystalballException) HashMap(java.util.HashMap) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap) SimulationEvent(org.activiti.crystalball.simulator.SimulationEvent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

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