org.activiti.engine.delegate.event.ActivitiEntityEvent Java Examples

The following examples show how to use org.activiti.engine.delegate.event.ActivitiEntityEvent. 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: FunctionEventListener.java    From lemon with Apache License 2.0 6 votes vote down vote up
public void onProcessCompleted(ActivitiEntityEvent event) {
    logger.debug("process completed {}", event);

    String processInstanceId = event.getProcessInstanceId();
    ExecutionEntity executionEntity = Context.getCommandContext()
            .getExecutionEntityManager()
            .findExecutionById(processInstanceId);
    String businessKey = executionEntity.getBusinessKey();
    String processDefinitionId = event.getProcessDefinitionId();
    String activityId = "";
    String activityName = this.findActivityName(activityId,
            processDefinitionId);
    int eventCode = 24;
    String eventName = "process-end";
    String userId = Authentication.getAuthenticatedUserId();
    this.invokeExpression(eventCode, eventName, businessKey, userId,
            activityId, activityName);
}
 
Example #2
Source File: CancelCallActivityByMessageTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@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: ActivitiEventDispatcherImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: TaskEventsTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #5
Source File: TaskAutoRedirectGlobalEventListener.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
@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 #6
Source File: ProcessInstanceCreateTransformer.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@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).
            priority(2).
            build();
  }
  return null;
}
 
Example #7
Source File: FunctionEventListener.java    From lemon with Apache License 2.0 6 votes vote down vote up
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 #8
Source File: ProcessInstanceEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void onEvent(ActivitiEvent event) {
  if (event instanceof ActivitiEntityEvent && ProcessInstance.class.isAssignableFrom(((ActivitiEntityEvent) event).getEntity().getClass())) {
    // check whether entity in the event is initialized before
    // adding to the list.
    assertNotNull(((ExecutionEntity) ((ActivitiEntityEvent) event).getEntity()).getId());
    eventsReceived.add(event);
  } else if (ActivitiEventType.PROCESS_CANCELLED.equals(event.getType()) || ActivitiEventType.ACTIVITY_CANCELLED.equals(event.getType())) {
    eventsReceived.add(event);
  }
}
 
Example #9
Source File: ActivitiEventBuilder.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected static void populateEventWithCurrentContext(ActivitiEventImpl event) {
  if (event instanceof ActivitiEntityEvent) {
    Object persistedObject = ((ActivitiEntityEvent) event).getEntity();
    if (persistedObject instanceof Job) {
      event.setExecutionId(((Job) persistedObject).getExecutionId());
      event.setProcessInstanceId(((Job) persistedObject).getProcessInstanceId());
      event.setProcessDefinitionId(((Job) persistedObject).getProcessDefinitionId());
    } else if (persistedObject instanceof DelegateExecution) {
      event.setExecutionId(((DelegateExecution) persistedObject).getId());
      event.setProcessInstanceId(((DelegateExecution) persistedObject).getProcessInstanceId());
      event.setProcessDefinitionId(((DelegateExecution) persistedObject).getProcessDefinitionId());
    } else if (persistedObject instanceof IdentityLinkEntity) {
      IdentityLinkEntity idLink = (IdentityLinkEntity) persistedObject;
      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 (persistedObject instanceof Task) {
      event.setProcessInstanceId(((Task) persistedObject).getProcessInstanceId());
      event.setExecutionId(((Task) persistedObject).getExecutionId());
      event.setProcessDefinitionId(((Task) persistedObject).getProcessDefinitionId());
    } else if (persistedObject instanceof ProcessDefinition) {
      event.setProcessDefinitionId(((ProcessDefinition) persistedObject).getId());
    }
  }
}
 
Example #10
Source File: BaseDelegateEventListener.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected boolean isValidEvent(ActivitiEvent event) {
boolean valid = false;
 if(entityClass != null) {
 	if(event instanceof ActivitiEntityEvent) {
 		Object entity = ((ActivitiEntityEvent) event).getEntity();
 		if(entity != null) {
 			valid = entityClass.isAssignableFrom(entity.getClass());
 		}
 	}
 } else {
 	// If no class is specified, all events are valid
 	valid = true;
 }
 return valid;
}
 
Example #11
Source File: ActivitiEventBuilder.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * @param type
 *          type of event
 * @param entity
 *          the entity this event targets
 * @return an {@link ActivitiEntityEvent}. In case an {@link ExecutionContext} is active, the execution related event fields will be populated. If not, execution details will be retrieved from the
 *         {@link Object} if possible.
 */
public static ActivitiEntityEvent createEntityEvent(ActivitiEventType type, Object entity) {
  ActivitiEntityEventImpl newEvent = new ActivitiEntityEventImpl(entity, type);

  // In case an execution-context is active, populate the event fields
  // related to the execution
  populateEventWithCurrentContext(newEvent);
  return newEvent;
}
 
Example #12
Source File: ActivitiEventBuilder.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * @param type type of event
 * @param entity the entity this event targets
 * @param cause the cause of the event
 * @return an {@link ActivitiEntityEvent} that is also instance of {@link ActivitiExceptionEvent}. 
 */
public static ActivitiEntityEvent createEntityExceptionEvent(ActivitiEventType type, Object entity, Throwable cause, String executionId,
		String processInstanceId, String processDefinitionId) {
	ActivitiEntityExceptionEventImpl newEvent = new ActivitiEntityExceptionEventImpl(entity, type, cause);

	newEvent.setExecutionId(executionId);
	newEvent.setProcessInstanceId(processInstanceId);
	newEvent.setProcessDefinitionId(processDefinitionId);
	return newEvent;
}
 
Example #13
Source File: ActivitiEventBuilder.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * @param type type of event
 * @param entity the entity this event targets
 * @param cause the cause of the event
 * @return an {@link ActivitiEntityEvent} that is also instance of {@link ActivitiExceptionEvent}. 
 * In case an {@link ExecutionContext} is active, the execution related event fields will be populated.
 */
public static ActivitiEntityEvent createEntityExceptionEvent(ActivitiEventType type, Object entity, Throwable cause) {
	ActivitiEntityExceptionEventImpl newEvent = new ActivitiEntityExceptionEventImpl(entity, type, cause);

	// In case an execution-context is active, populate the event fields related to the execution
	populateEventWithCurrentContext(newEvent);
	return newEvent;
}
 
Example #14
Source File: ActivitiEventBuilder.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * @param type type of event
 * @param entity the entity this event targets
 * @return an {@link ActivitiEntityEvent}
 */
public static ActivitiEntityEvent createEntityEvent(ActivitiEventType type, Object entity, String executionId,
		String processInstanceId, String processDefinitionId) {
	ActivitiEntityEventImpl newEvent = new ActivitiEntityEventImpl(entity, type);

	newEvent.setExecutionId(executionId);
	newEvent.setProcessInstanceId(processInstanceId);
	newEvent.setProcessDefinitionId(processDefinitionId);
	return newEvent;
}
 
Example #15
Source File: FunctionEventListener.java    From lemon with Apache License 2.0 5 votes vote down vote up
@Override
public void onEvent(ActivitiEvent event) {
    switch (event.getType()) {
    case ACTIVITY_STARTED:
        this.onActivityStart((ActivitiActivityEvent) event);

        break;

    case ACTIVITY_COMPLETED:
        this.onActivityEnd((ActivitiActivityEvent) event);

        break;

    case TASK_COMPLETED:
        this.onTaskCompleted((ActivitiEntityEvent) event);

        break;

    case PROCESS_COMPLETED:
        this.onProcessCompleted((ActivitiEntityEvent) event);

        break;

    case PROCESS_CANCELLED:
        this.onProcessCancelled((ActivitiCancelledEvent) event);

        break;

    default:
        logger.debug("Event received: {}", event.getType());
    }
}
 
Example #16
Source File: ProcessDefinitionEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void assertSequence(ActivitiEntityEvent before, ActivitiEntityEvent after) {
  int beforeIndex = 0;
  int afterIndex = 0;
  for (int index = 0; index < listener.getEventsReceived().size(); index++) {
    ActivitiEvent activitiEvent = listener.getEventsReceived().get(index);

    if (isEqual(before, activitiEvent))
      beforeIndex = index;
    if (isEqual(after, activitiEvent))
      afterIndex = index;
  }
  assertTrue(beforeIndex < afterIndex);
}
 
Example #17
Source File: ProcessDefinitionEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * equals is not implemented.
 */
private boolean isEqual(ActivitiEntityEvent event1, ActivitiEvent activitiEvent) {
  if (activitiEvent instanceof ActivitiEntityEvent && event1.getType().equals(activitiEvent.getType())) {
    ActivitiEntityEvent activitiEntityEvent = (ActivitiEntityEvent) activitiEvent;
    if (activitiEntityEvent.getEntity().getClass().equals(event1.getEntity().getClass())) {
      return true;
    }
  }
  return false;
}
 
Example #18
Source File: ProcessDefinitionEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void initializeServices() {
  super.initializeServices();

  listener = new TestMultipleActivitiEventListener();
  listener.setEventClasses(ActivitiEntityEvent.class);
  listener.setEntityClasses(ProcessDefinition.class, TimerJobEntity.class);

  processEngineConfiguration.getEventDispatcher().addEventListener(listener);
}
 
Example #19
Source File: ProcessInstanceEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = {
        "org/activiti/engine/test/bpmn/event/error/BoundaryErrorEventTest.testCatchErrorOnCallActivity-parent.bpmn20.xml",
        "org/activiti/engine/test/bpmn/event/error/BoundaryErrorEventTest.subprocess.bpmn20.xml"
})
public void testProcessCompletedEvents_callActivityErrorEndEvent() throws Exception {
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("catchErrorOnCallActivity");

  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("Task in subprocess", task.getName());
  List<ProcessInstance> subProcesses = runtimeService.createProcessInstanceQuery().superProcessInstanceId(pi.getId()).list();
  assertEquals(1, subProcesses.size());

  // Completing the task will reach the end error event,
  // which is caught on the call activity boundary
  taskService.complete(task.getId());

  List<ActivitiEvent> processCompletedEvents = listener.filterEvents(ActivitiEventType.PROCESS_COMPLETED_WITH_ERROR_END_EVENT);
  assertEquals("There should be exactly an ActivitiEventType.PROCESS_COMPLETED_WITH_ERROR_END_EVENT event after the task complete.", 1, processCompletedEvents.size());
  ActivitiEntityEvent processCompletedEvent = (ActivitiEntityEvent) processCompletedEvents.get(0);
  assertEquals(subProcesses.get(0).getId(), processCompletedEvent.getExecutionId());

  task = taskService.createTaskQuery().singleResult();
  assertEquals("Escalated Task", task.getName());

  // Completing the task will end the process instance
  taskService.complete(task.getId());
  assertProcessEnded(pi.getId());
}
 
Example #20
Source File: ProcessInstanceEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void onEvent(ActivitiEvent event) {
  if (event instanceof ActivitiEntityEvent && org.activiti5.engine.runtime.ProcessInstance.class.isAssignableFrom(((ActivitiEntityEvent) event).getEntity().getClass())) {
    // check whether entity in the event is initialized before adding to the list.
    assertNotNull(((ExecutionEntity) ((ActivitiEntityEvent) event).getEntity()).getId());
    eventsReceived.add(event);
  } else if (ActivitiEventType.PROCESS_CANCELLED.equals(event.getType()) || ActivitiEventType.ACTIVITY_CANCELLED.equals(event.getType())) {
    eventsReceived.add(event);
  }
}
 
Example #21
Source File: ProcessInstanceEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = {
        "org/activiti5/engine/test/bpmn/event/error/BoundaryErrorEventTest.testCatchErrorOnCallActivity-parent.bpmn20.xml",
        "org/activiti5/engine/test/bpmn/event/error/BoundaryErrorEventTest.subprocess.bpmn20.xml"
})
public void testProcessCompletedEvents_callActivityErrorEndEvent() throws Exception {
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("catchErrorOnCallActivity");

  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("Task in subprocess", task.getName());
  List<ProcessInstance> subProcesses = runtimeService.createProcessInstanceQuery().superProcessInstanceId(pi.getId()).list();
  assertEquals(1, subProcesses.size());

  // Completing the task will reach the end error event,
  // which is caught on the call activity boundary
  taskService.complete(task.getId());

  List<ActivitiEvent> processCompletedEvents = listener.filterEvents(ActivitiEventType.PROCESS_COMPLETED_WITH_ERROR_END_EVENT);
  assertEquals("There should be exactly one ActivitiEventType.PROCESS_COMPLETED_WITH_ERROR_END_EVENT event after the task complete.", 1, processCompletedEvents.size());
  ActivitiEntityEvent processCompletedEvent = (ActivitiEntityEvent) processCompletedEvents.get(0);
  assertEquals(subProcesses.get(0).getId(), processCompletedEvent.getExecutionId());

  task = taskService.createTaskQuery().singleResult();
  assertEquals("Escalated Task", task.getName());

  // Completing the task will end the process instance
  taskService.complete(task.getId());
  assertProcessEnded(pi.getId());
}
 
Example #22
Source File: ProcessDefinitionEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void initializeServices() {
  super.initializeServices();

  listener = new TestMultipleActivitiEventListener();
   listener.setEventClasses(ActivitiEntityEvent.class);
   listener.setEntityClasses(ProcessDefinition.class, org.activiti5.engine.impl.persistence.entity.TimerJobEntity.class);

   processEngineConfiguration.getEventDispatcher().addEventListener(listener);
}
 
Example #23
Source File: JobEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void checkEventContext(ActivitiEvent event, Job entity) {
  assertEquals(entity.getProcessInstanceId(), event.getProcessInstanceId());
  assertEquals(entity.getProcessDefinitionId(), event.getProcessDefinitionId());
  assertNotNull(event.getExecutionId());

  assertTrue(event instanceof ActivitiEntityEvent);
  ActivitiEntityEvent entityEvent = (ActivitiEntityEvent) event;
  assertTrue(entityEvent.getEntity() instanceof Job);
  assertEquals(entity.getId(), ((Job) entityEvent.getEntity()).getId());
}
 
Example #24
Source File: TestActivitiEntityEventTaskListener.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void onEvent(ActivitiEvent event) {
	super.onEvent(event);
	if (event instanceof ActivitiEntityEvent && Task.class.isAssignableFrom(((ActivitiEntityEvent) event).getEntity().getClass())) {
		tasks.add(copy((Task) ((ActivitiEntityEvent) event).getEntity()));
	}
}
 
Example #25
Source File: AttachmentEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
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 #26
Source File: UserTaskCompleteTransformer.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public SimulationEvent apply(ActivitiEvent event) {
  if (ActivitiEventType.TASK_COMPLETED.equals(event.getType())) {
    Task task = (Task) ((ActivitiEntityEvent) event).getEntity();

    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("taskId", task.getId());
    properties.put(TASK_DEFINITION_KEY, task.getTaskDefinitionKey());
    properties.put(PROCESS_INSTANCE_ID, task.getProcessInstanceId());
    properties.put(TASK_VARIABLES, task.getProcessVariables());
    return new SimulationEvent.Builder(this.simulationEventType).simulationTime(Context.getProcessEngineConfiguration().getClock().getCurrentTime().getTime()).properties(properties).build();
  }
  return null;
}
 
Example #27
Source File: DeploymentCreateTransformer.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@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).priority(1).build();
  }
  return null;
}
 
Example #28
Source File: ProcessDefinitionEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * equals is not implemented.
 */
private boolean isEqual(ActivitiEntityEvent event1, ActivitiEvent activitiEvent) {
  if (activitiEvent instanceof ActivitiEntityEvent && event1.getType().equals(activitiEvent.getType())) {
    ActivitiEntityEvent activitiEntityEvent = (ActivitiEntityEvent) activitiEvent;
    if (activitiEntityEvent.getEntity().getClass().equals(event1.getEntity().getClass())) {
      return true;
    }
  }
  return false;
}
 
Example #29
Source File: ProcessDefinitionEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private void assertSequence(ActivitiEntityEvent before, ActivitiEntityEvent after) {
  int beforeIndex = 0;
  int afterIndex = 0;
  for (int index = 0; index < listener.getEventsReceived().size(); index++) {
    ActivitiEvent activitiEvent = listener.getEventsReceived().get(index);

    if (isEqual(before, activitiEvent)) {
      beforeIndex = index;
    }
    if (isEqual(after, activitiEvent)) {
      afterIndex = index;
    }
  }
  assertTrue(beforeIndex < afterIndex);
}
 
Example #30
Source File: ProcessDefinitionEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * test sequence of events for process definition with timer start event
 */
@Deployment(resources= {"org/activiti5/engine/test/bpmn/event/timer/StartTimerEventTest.testDurationStartTimerEvent.bpmn20.xml"})
public void testTimerStartEventDeployment() {
  org.activiti5.engine.impl.cfg.ProcessEngineConfigurationImpl activiti5ProcessConfig = (org.activiti5.engine.impl.cfg.ProcessEngineConfigurationImpl) 
      processEngineConfiguration.getActiviti5CompatibilityHandler().getRawProcessConfiguration();
  
  ProcessDefinition processDefinition = activiti5ProcessConfig.getRepositoryService().
      createProcessDefinitionQuery().processDefinitionKey("startTimerEventExample").singleResult();
  ActivitiEntityEvent processDefinitionCreated = ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, processDefinition);

  Job timer = activiti5ProcessConfig.getManagementService().createTimerJobQuery().singleResult();
  ActivitiEntityEvent timerCreated = ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, timer);
  assertSequence(processDefinitionCreated, timerCreated);
  listener.clearEventsReceived();
}