Search in sources :

Example 1 with CrystalballException

use of org.activiti.crystalball.simulator.CrystalballException 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)

Example 2 with CrystalballException

use of org.activiti.crystalball.simulator.CrystalballException 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)

Aggregations

TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 CrystalballException (org.activiti.crystalball.simulator.CrystalballException)2 SimulationEvent (org.activiti.crystalball.simulator.SimulationEvent)2 Map (java.util.Map)1