Java Code Examples for org.activiti.engine.delegate.event.ActivitiEntityEvent#getEntity()
The following examples show how to use
org.activiti.engine.delegate.event.ActivitiEntityEvent#getEntity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActivitiEventDispatcherImpl.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
@Override public void dispatchEvent(ActivitiEvent event) { if (enabled) { eventSupport.dispatchEvent(event); } if (event.getType() == ActivitiEventType.ENTITY_DELETED && event instanceof ActivitiEntityEvent) { ActivitiEntityEvent entityEvent = (ActivitiEntityEvent) event; if (entityEvent.getEntity() instanceof ProcessDefinition) { // process definition deleted event doesn't need to be dispatched to event listeners return; } } // Try getting hold of the Process definition, based on the process definition key, if a context is active CommandContext commandContext = Context.getCommandContext(); if (commandContext != null) { BpmnModel bpmnModel = extractBpmnModelFromEvent(event); if (bpmnModel != null) { ((ActivitiEventSupport) bpmnModel.getEventSupport()).dispatchEvent(event); } } }
Example 2
Source File: CancelCallActivityByMessageTest.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
@Override public void onEvent(ActivitiEvent event) { switch (event.getType()) { case ENTITY_CREATED: ActivitiEntityEvent entityEvent = (ActivitiEntityEvent) event; if (entityEvent.getEntity() instanceof ExecutionEntity) { eventsReceived.add(event); } break; case ACTIVITY_STARTED: case ACTIVITY_COMPLETED: case ACTIVITY_CANCELLED: case TASK_CREATED: case TASK_COMPLETED: case PROCESS_STARTED: case PROCESS_COMPLETED: case PROCESS_CANCELLED: eventsReceived.add(event); break; default: break; } }
Example 3
Source File: TaskEventsTest.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
/** * Check events related to process instance delete and standalone task delete. */ @Deployment(resources= {"org/activiti5/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"}) public void testDeleteEventDoesNotDispathComplete() throws Exception { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); assertNotNull(processInstance); listener.clearEventsReceived(); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); assertNotNull(task); // Delete process, should delete task as well, but not complete runtimeService.deleteProcessInstance(processInstance.getId(), "testing task delete events"); assertEquals(1, listener.getEventsReceived().size()); ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0); assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType()); assertTrue(event.getEntity() instanceof org.activiti5.engine.task.Task); org.activiti5.engine.task.Task taskFromEvent = (org.activiti5.engine.task.Task) event.getEntity(); assertEquals(task.getId(), taskFromEvent.getId()); assertExecutionDetails(event, processInstance); }
Example 4
Source File: TaskAutoRedirectGlobalEventListener.java From activiti-in-action-codes with Apache License 2.0 | 6 votes |
@Override public void onEvent(ActivitiEvent event) { ActivitiEntityEvent entityEvent = (ActivitiEntityEvent) event; Object entity = entityEvent.getEntity(); if (entity instanceof TaskEntity) { TaskEntity task = (TaskEntity) entity; String originUserId = task.getAssignee(); String newUserId = userMap.get(originUserId); if (StringUtils.isNotBlank(newUserId)) { task.setAssignee(newUserId); TaskService taskService = event.getEngineServices().getTaskService(); String message = getClass().getName() + "-> 任务[" + task.getName() + "]的办理人[" + originUserId + "]自动转办给了用户[" + newUserId + "]"; taskService.addComment(task.getId(), task.getProcessInstanceId(), "redirect", message); } } }
Example 5
Source File: FunctionEventListener.java From lemon with Apache License 2.0 | 6 votes |
public void onTaskCompleted(ActivitiEntityEvent event) { logger.debug("task completed {}", event); String processInstanceId = event.getProcessInstanceId(); ExecutionEntity executionEntity = Context.getCommandContext() .getExecutionEntityManager() .findExecutionById(processInstanceId); String businessKey = executionEntity.getBusinessKey(); String processDefinitionId = event.getProcessDefinitionId(); Task task = (Task) event.getEntity(); String activityId = task.getTaskDefinitionKey(); String activityName = this.findActivityName(activityId, processDefinitionId); int eventCode = 5; String eventName = "complete"; String userId = Authentication.getAuthenticatedUserId(); this.invokeExpression(eventCode, eventName, businessKey, userId, activityId, activityName); }
Example 6
Source File: TaskCompletedEventHandler.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Override public EventLogEntryEntity generateEventLogEntry(CommandContext commandContext) { ActivitiEntityEvent activitiEntityEvent = (ActivitiEntityEvent) event; TaskEntity task = (TaskEntity) activitiEntityEvent.getEntity(); Map<String, Object> data = handleCommonTaskFields(task); long duration = timeStamp.getTime() - task.getCreateTime().getTime(); putInMapIfNotNull(data, Fields.DURATION, duration); if (event instanceof ActivitiEntityWithVariablesEvent) { ActivitiEntityWithVariablesEvent activitiEntityWithVariablesEvent = (ActivitiEntityWithVariablesEvent) event; if (activitiEntityWithVariablesEvent.getVariables() != null && !activitiEntityWithVariablesEvent.getVariables().isEmpty()) { Map<String, Object> variableMap = new HashMap<String, Object>(); for (Object variableName : activitiEntityWithVariablesEvent.getVariables().keySet()) { putInMapIfNotNull(variableMap, (String) variableName, activitiEntityWithVariablesEvent.getVariables().get(variableName)); } if (activitiEntityWithVariablesEvent.isLocalScope()) { putInMapIfNotNull(data, Fields.LOCAL_VARIABLES, variableMap); } else { putInMapIfNotNull(data, Fields.VARIABLES, variableMap); } } } return createEventLogEntry(task.getProcessDefinitionId(), task.getProcessInstanceId(), task.getExecutionId(), task.getId(), data); }
Example 7
Source File: DebugInfoEntityEventListener.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected ExecutionEntity getExecutionEntity(ActivitiEvent event) { ActivitiEntityEvent entityEvent = (ActivitiEntityEvent) event; Object entity = entityEvent.getEntity(); if (entity instanceof ExecutionEntity) { ExecutionEntity executionEntity = (ExecutionEntity) entity; return executionEntity; } return null; }
Example 8
Source File: AttachmentEventsTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
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()); } } } }
Example 9
Source File: StandaloneAttachmentEventsTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
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()); } } } }