Search in sources :

Example 11 with ActivitiEntityEvent

use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.

the class ProcessInstanceCreateTransformer method apply.

@Override
public SimulationEvent apply(ActivitiEvent event) {
    if (ActivitiEventType.ENTITY_INITIALIZED.equals(event.getType()) && (event instanceof ActivitiEntityEvent) && ((ActivitiEntityEvent) event).getEntity() instanceof ProcessInstance && ((ExecutionEntity) ((ActivitiEntityEvent) event).getEntity()).isProcessInstanceType()) {
        ProcessInstance processInstance = (ProcessInstance) ((ActivitiEntityEvent) event).getEntity();
        ExecutionEntity executionEntity = (ExecutionEntity) ((ActivitiEntityEvent) event).getEntity();
        Map<String, Object> simEventProperties = new HashMap<String, Object>();
        simEventProperties.put(processDefinitionIdKey, processInstance.getProcessDefinitionId());
        simEventProperties.put(businessKey, processInstance.getBusinessKey());
        simEventProperties.put(variablesKey, executionEntity.getVariables());
        simEventProperties.put(PROCESS_INSTANCE_ID, executionEntity.getProcessInstanceId());
        return new SimulationEvent.Builder(simulationEventType).simulationTime(Context.getProcessEngineConfiguration().getClock().getCurrentTime().getTime()).properties(simEventProperties).build();
    }
    return null;
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) HashMap(java.util.HashMap) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) SimulationEvent(org.activiti.crystalball.simulator.SimulationEvent)

Example 12 with ActivitiEntityEvent

use of org.activiti.engine.delegate.event.ActivitiEntityEvent 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 13 with ActivitiEntityEvent

use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.

the class ActivitiEventBuilder method populateEventWithCurrentContext.

protected static void populateEventWithCurrentContext(ActivitiEventImpl event) {
    boolean extractedFromContext = false;
    if (Context.isExecutionContextActive()) {
        ExecutionContext executionContext = Context.getExecutionContext();
        if (executionContext != null) {
            extractedFromContext = true;
            event.setExecutionId(executionContext.getExecution().getId());
            event.setProcessInstanceId(executionContext.getExecution().getProcessInstanceId());
            event.setProcessDefinitionId(executionContext.getExecution().getProcessDefinitionId());
        }
    }
    // Fallback to fetching context from the object itself
    if (!extractedFromContext) {
        if (event instanceof ActivitiEntityEvent) {
            Object persistendObject = ((ActivitiEntityEvent) event).getEntity();
            if (persistendObject instanceof Job) {
                event.setExecutionId(((Job) persistendObject).getExecutionId());
                event.setProcessInstanceId(((Job) persistendObject).getProcessInstanceId());
                event.setProcessDefinitionId(((Job) persistendObject).getProcessDefinitionId());
            } else if (persistendObject instanceof DelegateExecution) {
                event.setExecutionId(((DelegateExecution) persistendObject).getId());
                event.setProcessInstanceId(((DelegateExecution) persistendObject).getProcessInstanceId());
                event.setProcessDefinitionId(((DelegateExecution) persistendObject).getProcessDefinitionId());
            } else if (persistendObject instanceof IdentityLinkEntity) {
                IdentityLinkEntity idLink = (IdentityLinkEntity) persistendObject;
                if (idLink.getProcessDefinitionId() != null) {
                    event.setProcessDefinitionId(idLink.getProcessDefId());
                } else if (idLink.getProcessInstance() != null) {
                    event.setProcessDefinitionId(idLink.getProcessInstance().getProcessDefinitionId());
                    event.setProcessInstanceId(idLink.getProcessInstanceId());
                    event.setExecutionId(idLink.getProcessInstanceId());
                } else if (idLink.getTask() != null) {
                    event.setProcessDefinitionId(idLink.getTask().getProcessDefinitionId());
                    event.setProcessInstanceId(idLink.getTask().getProcessInstanceId());
                    event.setExecutionId(idLink.getTask().getExecutionId());
                }
            } else if (persistendObject instanceof Task) {
                event.setProcessInstanceId(((Task) persistendObject).getProcessInstanceId());
                event.setExecutionId(((Task) persistendObject).getExecutionId());
                event.setProcessDefinitionId(((Task) persistendObject).getProcessDefinitionId());
            } else if (persistendObject instanceof ProcessDefinition) {
                event.setProcessDefinitionId(((ProcessDefinition) persistendObject).getId());
            }
        }
    }
}
Also used : IdentityLinkEntity(org.activiti.engine.impl.persistence.entity.IdentityLinkEntity) Task(org.activiti.engine.task.Task) ExecutionContext(org.activiti.engine.impl.context.ExecutionContext) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) DelegateExecution(org.activiti.engine.delegate.DelegateExecution) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Job(org.activiti.engine.runtime.Job)

Example 14 with ActivitiEntityEvent

use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.

the class AttachmentEventsTest method testAttachmentEntityEventsOnHistoricProcessInstanceDelete.

@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testAttachmentEntityEventsOnHistoricProcessInstanceDelete() throws Exception {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
        // Create link-attachment
        Attachment attachment = taskService.createAttachment("test", null, processInstance.getId(), "attachment name", "description", "http://activiti.org");
        listener.clearEventsReceived();
        runtimeService.deleteProcessInstance(processInstance.getId(), null);
        historyService.deleteHistoricProcessInstance(processInstance.getId());
        assertEquals(1, listener.getEventsReceived().size());
        ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
        assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
        assertEquals(processInstance.getId(), event.getProcessInstanceId());
        assertEquals(processInstance.getId(), event.getExecutionId());
        assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
        Attachment attachmentFromEvent = (Attachment) event.getEntity();
        assertEquals(attachment.getId(), attachmentFromEvent.getId());
    }
}
Also used : ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Attachment(org.activiti.engine.task.Attachment) Deployment(org.activiti.engine.test.Deployment)

Example 15 with ActivitiEntityEvent

use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.

the class AttachmentEventsTest method testAttachmentEntityEventsOnHistoricTaskDelete.

public void testAttachmentEntityEventsOnHistoricTaskDelete() throws Exception {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        Task task = null;
        try {
            task = taskService.newTask();
            taskService.saveTask(task);
            assertNotNull(task);
            // Create link-attachment
            Attachment attachment = taskService.createAttachment("test", task.getId(), null, "attachment name", "description", "http://activiti.org");
            listener.clearEventsReceived();
            // Delete task and historic task
            taskService.deleteTask(task.getId());
            historyService.deleteHistoricTaskInstance(task.getId());
            assertEquals(1, listener.getEventsReceived().size());
            ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
            assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
            assertNull(event.getProcessInstanceId());
            assertNull(event.getExecutionId());
            assertNull(event.getProcessDefinitionId());
            Attachment attachmentFromEvent = (Attachment) event.getEntity();
            assertEquals(attachment.getId(), attachmentFromEvent.getId());
        } finally {
            if (task != null && task.getId() != null) {
                taskService.deleteTask(task.getId());
                historyService.deleteHistoricTaskInstance(task.getId());
            }
        }
    }
}
Also used : Task(org.activiti.engine.task.Task) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) Attachment(org.activiti.engine.task.Attachment)

Aggregations

ActivitiEntityEvent (org.activiti.engine.delegate.event.ActivitiEntityEvent)31 Deployment (org.activiti.engine.test.Deployment)19 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)17 Task (org.activiti.engine.task.Task)15 Attachment (org.activiti.engine.task.Attachment)5 ActivitiEvent (org.activiti.engine.delegate.event.ActivitiEvent)4 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)4 HashMap (java.util.HashMap)3 Job (org.activiti.engine.runtime.Job)3 IdentityLink (org.activiti.engine.task.IdentityLink)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 SimulationEvent (org.activiti.crystalball.simulator.SimulationEvent)2 ActivitiProcessStartedEvent (org.activiti.engine.delegate.event.ActivitiProcessStartedEvent)2 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)2 Comment (org.activiti.engine.task.Comment)2 Calendar (java.util.Calendar)1 Date (java.util.Date)1 DelegateExecution (org.activiti.engine.delegate.DelegateExecution)1 ActivitiCancelledEvent (org.activiti.engine.delegate.event.ActivitiCancelledEvent)1 Group (org.activiti.engine.identity.Group)1