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;
}
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;
}
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());
}
}
}
}
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());
}
}
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());
}
}
}
}
Aggregations