Search in sources :

Example 1 with EventLogEntryEntity

use of org.activiti.engine.impl.persistence.entity.EventLogEntryEntity in project Activiti by Activiti.

the class AbstractDatabaseEventLoggerEventHandler method createEventLogEntry.

protected EventLogEntryEntity createEventLogEntry(String type, String processDefinitionId, String processInstanceId, String executionId, String taskId, Map<String, Object> data) {
    EventLogEntryEntity eventLogEntry = new EventLogEntryEntity();
    eventLogEntry.setProcessDefinitionId(processDefinitionId);
    eventLogEntry.setProcessInstanceId(processInstanceId);
    eventLogEntry.setExecutionId(executionId);
    eventLogEntry.setTaskId(taskId);
    eventLogEntry.setType(type);
    eventLogEntry.setTimeStamp(timeStamp);
    putInMapIfNotNull(data, Fields.TIMESTAMP, timeStamp);
    // Current user
    String userId = Authentication.getAuthenticatedUserId();
    if (userId != null) {
        eventLogEntry.setUserId(userId);
        putInMapIfNotNull(data, "userId", userId);
    }
    // Current tenant
    if (!data.containsKey(Fields.TENANT_ID) && processDefinitionId != null) {
        DeploymentCache<ProcessDefinitionEntity> processDefinitionCache = Context.getProcessEngineConfiguration().getProcessDefinitionCache();
        if (processDefinitionCache != null) {
            ProcessDefinitionEntity processDefinitionEntity = processDefinitionCache.get(processDefinitionId);
            if (processDefinitionEntity != null && !ProcessEngineConfigurationImpl.NO_TENANT_ID.equals(processDefinitionEntity.getTenantId())) {
                putInMapIfNotNull(data, Fields.TENANT_ID, processDefinitionEntity.getTenantId());
            }
        }
    }
    try {
        eventLogEntry.setData(objectMapper.writeValueAsBytes(data));
    } catch (Exception e) {
        logger.warn("Could not serialize event data. Data will not be written to the database", e);
    }
    return eventLogEntry;
}
Also used : EventLogEntryEntity(org.activiti.engine.impl.persistence.entity.EventLogEntryEntity) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)

Example 2 with EventLogEntryEntity

use of org.activiti.engine.impl.persistence.entity.EventLogEntryEntity in project Activiti by Activiti.

the class TestVariableEventListenerStore method onEvent.

@Override
public void onEvent(ActivitiEvent event) {
    if (event instanceof ActivitiVariableEvent) {
        eventsReceived.add(event);
        EventLogEntryEntity eventLogEntry = new EventLogEntryEntity();
        eventLogEntry.setProcessDefinitionId(event.getProcessDefinitionId());
        eventLogEntry.setProcessInstanceId(event.getProcessInstanceId());
        eventLogEntry.setExecutionId(event.getExecutionId());
        eventLogEntry.setTaskId(((ActivitiVariableEvent) event).getTaskId());
        eventLogEntry.setType(event.getType().name());
        eventLogEntry.setTimeStamp(new Date());
        CommandContext commandContext = Context.getCommandContext();
        commandContext.getEventLogEntryEntityManager().insert(eventLogEntry);
    }
}
Also used : EventLogEntryEntity(org.activiti.engine.impl.persistence.entity.EventLogEntryEntity) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) ActivitiVariableEvent(org.activiti.engine.delegate.event.ActivitiVariableEvent) Date(java.util.Date)

Aggregations

EventLogEntryEntity (org.activiti.engine.impl.persistence.entity.EventLogEntryEntity)2 Date (java.util.Date)1 ActivitiVariableEvent (org.activiti.engine.delegate.event.ActivitiVariableEvent)1 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)1 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)1