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

The following examples show how to use org.activiti.engine.delegate.event.ActivitiEventType. 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: TerminateEndEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void endAllHistoricActivities(String processInstanceId, String deleteReason) {

    if (!Context.getProcessEngineConfiguration().getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
      return;
    }

    List<HistoricActivityInstanceEntity> historicActivityInstances = Context.getCommandContext().getHistoricActivityInstanceEntityManager()
      .findUnfinishedHistoricActivityInstancesByProcessInstanceId(processInstanceId);

    for (HistoricActivityInstanceEntity historicActivityInstance : historicActivityInstances) {
      historicActivityInstance.markEnded(deleteReason);

      // Fire event
      ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
      if (config != null && config.getEventDispatcher().isEnabled()) {
        config.getEventDispatcher().dispatchEvent(
            ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_ENDED, historicActivityInstance));
      }
    }

  }
 
Example #2
Source File: EventLogger.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void initializeDefaultHandlers() {
	
	// Initialization of all event handlers
	
	addEventHandler(ActivitiEventType.TASK_CREATED, TaskCreatedEventHandler.class);
	addEventHandler(ActivitiEventType.TASK_COMPLETED, TaskCompletedEventHandler.class);
	addEventHandler(ActivitiEventType.TASK_ASSIGNED, TaskAssignedEventHandler.class);
	
	addEventHandler(ActivitiEventType.SEQUENCEFLOW_TAKEN, SequenceFlowTakenEventHandler.class);
	
	addEventHandler(ActivitiEventType.ACTIVITY_COMPLETED, ActivityCompletedEventHandler.class);
	addEventHandler(ActivitiEventType.ACTIVITY_STARTED, ActivityStartedEventHandler.class);
	addEventHandler(ActivitiEventType.ACTIVITY_SIGNALED, ActivitySignaledEventHandler.class);
	addEventHandler(ActivitiEventType.ACTIVITY_MESSAGE_RECEIVED, ActivityMessageEventHandler.class);
	addEventHandler(ActivitiEventType.ACTIVITY_COMPENSATE, ActivityCompensatedEventHandler.class);
	addEventHandler(ActivitiEventType.ACTIVITY_ERROR_RECEIVED, ActivityErrorReceivedEventHandler.class);
	
	addEventHandler(ActivitiEventType.VARIABLE_CREATED, VariableCreatedEventHandler.class);
	addEventHandler(ActivitiEventType.VARIABLE_DELETED, VariableDeletedEventHandler.class);
	addEventHandler(ActivitiEventType.VARIABLE_UPDATED, VariableUpdatedEventHandler.class);
}
 
Example #3
Source File: ErrorPropagation.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public static void propagateError(String errorCode, ActivityExecution execution) {

    while (execution != null) {
      String eventHandlerId = findLocalErrorEventHandler(execution, errorCode);
      if (eventHandlerId != null) {
        executeCatch(eventHandlerId, execution, errorCode);
        break;
      }
      
      if (execution.isProcessInstanceType()) {
        // dispatch process completed event
        if (Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
          Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                  ActivitiEventBuilder.createEntityEvent(ActivitiEventType.PROCESS_COMPLETED_WITH_ERROR_END_EVENT, execution));
        }
      }
      execution = getSuperExecution(execution);
    }
    if (execution == null) {
      throw new BpmnError(errorCode, "No catching boundary event found for error with errorCode '"
              + errorCode + "', neither in same process nor in parent process");
    }
  }
 
Example #4
Source File: TriggerCmd.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected Object execute(CommandContext commandContext, ExecutionEntity execution) {
  if (Activiti5Util.isActiviti5ProcessDefinitionId(commandContext, execution.getProcessDefinitionId())) {
    Activiti5CompatibilityHandler activiti5CompatibilityHandler = Activiti5Util.getActiviti5CompatibilityHandler();
    activiti5CompatibilityHandler.trigger(executionId, processVariables);
    return null;
  }

  if (processVariables != null) {
    execution.setVariables(processVariables);
  }

  if (transientVariables != null) {
    execution.setTransientVariables(transientVariables);
  }

  Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
      ActivitiEventBuilder.createSignalEvent(ActivitiEventType.ACTIVITY_SIGNALED, execution.getCurrentActivityId(), null,
          null, execution.getId(), execution.getProcessInstanceId(), execution.getProcessDefinitionId()));

  Context.getAgenda().planTriggerExecutionOperation(execution);
  return null;
}
 
Example #5
Source File: BoundaryMessageEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
  CommandContext commandContext = Context.getCommandContext();
  ExecutionEntity executionEntity = (ExecutionEntity) execution;
  
  String messageName = null;
  if (StringUtils.isNotEmpty(messageEventDefinition.getMessageRef())) {
    messageName = messageEventDefinition.getMessageRef();
  } else {
    Expression messageExpression = commandContext.getProcessEngineConfiguration().getExpressionManager()
        .createExpression(messageEventDefinition.getMessageExpression());
    messageName = messageExpression.getValue(execution).toString();
  }
  
  commandContext.getEventSubscriptionEntityManager().insertMessageEvent(messageName, executionEntity);
  
  if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
      commandContext.getProcessEngineConfiguration().getEventDispatcher()
              .dispatchEvent(ActivitiEventBuilder.createMessageEvent(ActivitiEventType.ACTIVITY_MESSAGE_WAITING, executionEntity.getActivityId(), messageName,
                      null, executionEntity.getId(), executionEntity.getProcessInstanceId(), executionEntity.getProcessDefinitionId()));
    }
}
 
Example #6
Source File: TaskEntity.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void insert(ExecutionEntity execution) {
  CommandContext commandContext = Context.getCommandContext();
  DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
  dbSqlSession.insert(this);
  
  // Inherit tenant id (if applicable)
  if (execution != null && execution.getTenantId() != null) {
  	setTenantId(execution.getTenantId());
  }
  
  if(execution != null) {
    execution.addTask(this);
  }
  
  commandContext.getHistoryManager().recordTaskCreated(this, execution);
  
  if(commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
  	commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
  			ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, this));
  	commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
  			ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, this));
  }
}
 
Example #7
Source File: CommentEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void insert(CommentEntity commentEntity) {
  checkHistoryEnabled();
  
  insert(commentEntity, false);

  Comment comment = (Comment) commentEntity;
  if (getEventDispatcher().isEnabled()) {
    // Forced to fetch the process-instance to associate the right
    // process definition
    String processDefinitionId = null;
    String processInstanceId = comment.getProcessInstanceId();
    if (comment.getProcessInstanceId() != null) {
      ExecutionEntity process = getExecutionEntityManager().findById(comment.getProcessInstanceId());
      if (process != null) {
        processDefinitionId = process.getProcessDefinitionId();
      }
    }
    getEventDispatcher().dispatchEvent(
        ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, commentEntity, processInstanceId, processInstanceId, processDefinitionId));
    getEventDispatcher().dispatchEvent(
        ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, commentEntity, processInstanceId, processInstanceId, processDefinitionId));
  }
}
 
Example #8
Source File: VariableInstanceEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void delete(VariableInstanceEntity entity, boolean fireDeleteEvent) {
  super.delete(entity, false);
  ByteArrayRef byteArrayRef = entity.getByteArrayRef();
  if (byteArrayRef != null) {
    byteArrayRef.delete();
  }
  entity.setDeleted(true);
  
  if (entity.getExecutionId() != null && isExecutionRelatedEntityCountEnabledGlobally()) {
    CountingExecutionEntity executionEntity = (CountingExecutionEntity) getExecutionEntityManager().findById(entity.getExecutionId());
    if (isExecutionRelatedEntityCountEnabled(executionEntity)) {
      executionEntity.setVariableCount(executionEntity.getVariableCount() - 1);
    }
  }

  ActivitiEventDispatcher eventDispatcher =  getEventDispatcher();
  if (fireDeleteEvent && eventDispatcher.isEnabled()) {
    eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, entity));
    
    eventDispatcher.dispatchEvent(createVariableDeleteEvent(entity));
  }
  
}
 
Example #9
Source File: BpmnDeployer.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the version on each process definition entity, and the identifier.  If the map contains
 * an older version for a process definition, then the version is set to that older entity's
 * version plus one; otherwise it is set to 1.  Also dispatches an ENTITY_CREATED event.
 */
protected void setProcessDefinitionVersionsAndIds(ParsedDeployment parsedDeployment,
    Map<ProcessDefinitionEntity, ProcessDefinitionEntity> mapNewToOldProcessDefinitions) {
  CommandContext commandContext = Context.getCommandContext();

  for (ProcessDefinitionEntity processDefinition : parsedDeployment.getAllProcessDefinitions()) {
    int version = 1;
    
    ProcessDefinitionEntity latest = mapNewToOldProcessDefinitions.get(processDefinition);
    if (latest != null) {
      version = latest.getVersion() + 1;
    }
    
    processDefinition.setVersion(version);
    processDefinition.setId(getIdForNewProcessDefinition(processDefinition));
    
    if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
      commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, processDefinition));
    }
  }
}
 
Example #10
Source File: CommentEntityManager.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void insert(PersistentObject persistentObject) {
  checkHistoryEnabled();
  super.insert(persistentObject);
  
  Comment comment = (Comment) persistentObject;
  if(getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
  	// Forced to fetch the process-instance to associate the right process definition
  	String processDefinitionId = null;
  	String processInstanceId = comment.getProcessInstanceId();
  	if(comment.getProcessInstanceId() != null) {
  		ExecutionEntity process = getProcessInstanceManager().findExecutionById(comment.getProcessInstanceId());
  		if(process != null) {
  			processDefinitionId = process.getProcessDefinitionId();
  		}
  	}
  	getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
  			ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, persistentObject, processInstanceId, processInstanceId, processDefinitionId));
  	getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
  			ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, persistentObject, processInstanceId, processInstanceId, processDefinitionId));
  }
}
 
Example #11
Source File: TimerJobEntity.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void insert() {
  Context.getCommandContext()
    .getDbSqlSession()
    .insert(this);
  
  // add link to execution
  if (executionId != null) {
    ExecutionEntity execution = Context.getCommandContext()
      .getExecutionEntityManager()
      .findExecutionById(executionId);
    execution.addTimerJob(this);
    
    // Inherit tenant if (if applicable)
    if (execution.getTenantId() != null) {
      setTenantId(execution.getTenantId());
    }
  }
  
  if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
    Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
        ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, this));
    Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
        ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, this));
  }
}
 
Example #12
Source File: ActivityEventsTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testActivitySignalBoundaryEventsOnSubProcess() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("signalOnSubProcess");
  assertNotNull(processInstance);

  Execution executionWithSignal = runtimeService.createExecutionQuery().activityId("userTaskInsideProcess").singleResult();
  assertNotNull(executionWithSignal);

  runtimeService.signalEventReceived("signalName");
  assertEquals(1, listener.getEventsReceived().size());

  // Next, an signal-event is expected, as a result of the message
  assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiActivityCancelledEvent);
  ActivitiActivityCancelledEvent signalEvent = (ActivitiActivityCancelledEvent) listener.getEventsReceived().get(0);
  assertEquals(ActivitiEventType.ACTIVITY_CANCELLED, signalEvent.getType());
  assertEquals("userTaskInsideProcess", signalEvent.getActivityId());
  assertEquals(executionWithSignal.getId(), signalEvent.getExecutionId());
  assertEquals(executionWithSignal.getProcessInstanceId(), signalEvent.getProcessInstanceId());
  assertEquals(processInstance.getProcessDefinitionId(), signalEvent.getProcessDefinitionId());
  assertNotNull(signalEvent.getCause());
  assertTrue(signalEvent.getCause() instanceof SignalEventSubscriptionEntity);
  SignalEventSubscriptionEntity cause = (SignalEventSubscriptionEntity) signalEvent.getCause();
  assertEquals("signalName", cause.getEventName());
}
 
Example #13
Source File: JobEventsTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testJobCanceledAndTimerStartEventOnProcessRedeploy() throws Exception {
  // GIVEN deploy process definition
  String deployment1 = repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/api/event/JobEventsTest.testTimerFiredForTimerStart.bpmn20.xml").deploy().getId();
  checkEventCount(1, ActivitiEventType.TIMER_SCHEDULED);
  listener.clearEventsReceived();

  // WHEN
  String deployment2 = repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/api/event/JobEventsTest.testTimerFiredForTimerStart.bpmn20.xml").deploy().getId();

  // THEN
  checkEventCount(1, ActivitiEventType.JOB_CANCELED);
  checkEventCount(1, ActivitiEventType.TIMER_SCHEDULED);

  listener.clearEventsReceived();

  repositoryService.deleteDeployment(deployment2);
  checkEventCount(1, ActivitiEventType.JOB_CANCELED);
  checkEventCount(1, ActivitiEventType.TIMER_SCHEDULED);

  listener.clearEventsReceived();

  repositoryService.deleteDeployment(deployment1);
  checkEventCount(1, ActivitiEventType.JOB_CANCELED);
}
 
Example #14
Source File: EngineEventsTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testEngineEventsTest() {
  // Fetch the listener to check received events
  TestActivitiEventListener listener = (TestActivitiEventListener) processEngineConfiguration.getBeans().get("eventListener");
  assertNotNull(listener);

  // Check create-event
  assertEquals(1, listener.getEventsReceived().size());
  assertEquals(ActivitiEventType.ENGINE_CREATED, listener.getEventsReceived().get(0).getType());
  listener.clearEventsReceived();

  // Check close-event
  processEngine.close();
  assertEquals(1, listener.getEventsReceived().size());
  assertEquals(ActivitiEventType.ENGINE_CLOSED, listener.getEventsReceived().get(0).getType());

}
 
Example #15
Source File: SuspendedJobEntity.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void delete() {
  Context.getCommandContext()
    .getDbSqlSession()
    .delete(this);

  // Also delete the job's exception byte array
  exceptionByteArrayRef.delete();

  if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
    Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
        ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, this));
  }
}
 
Example #16
Source File: ActivityEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Test events related to message events, called from the API.
 */
@Deployment
public void testActivityMessageEvents() throws Exception {
	ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("messageProcess");
	assertNotNull(processInstance);

	Execution executionWithMessage = runtimeService.createExecutionQuery().activityId("shipOrder").singleResult();
	assertNotNull(executionWithMessage);

	runtimeService.messageEventReceived("messageName", executionWithMessage.getId());
	assertEquals(2, listener.getEventsReceived().size());

	// First, a message-event is expected
	assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiMessageEvent);
	ActivitiMessageEvent messageEvent = (ActivitiMessageEvent) listener.getEventsReceived().get(0);
	assertEquals(ActivitiEventType.ACTIVITY_MESSAGE_RECEIVED, messageEvent.getType());
	assertEquals("shipOrder", messageEvent.getActivityId());
	assertEquals(executionWithMessage.getId(), messageEvent.getExecutionId());
	assertEquals(executionWithMessage.getProcessInstanceId(), messageEvent.getProcessInstanceId());
	assertEquals(processInstance.getProcessDefinitionId(), messageEvent.getProcessDefinitionId());
	assertEquals("messageName", messageEvent.getMessageName());
	assertNull(messageEvent.getMessageData());

	// Next, an signal-event is expected, as a result of the message
	assertTrue(listener.getEventsReceived().get(1) instanceof ActivitiSignalEvent);
	ActivitiSignalEvent signalEvent = (ActivitiSignalEvent) listener.getEventsReceived().get(1);
	assertEquals(ActivitiEventType.ACTIVITY_SIGNALED, signalEvent.getType());
	assertEquals("shipOrder", signalEvent.getActivityId());
	assertEquals(executionWithMessage.getId(), signalEvent.getExecutionId());
	assertEquals(executionWithMessage.getProcessInstanceId(), signalEvent.getProcessInstanceId());
	assertEquals(processInstance.getProcessDefinitionId(), signalEvent.getProcessDefinitionId());
	assertEquals("messageName", signalEvent.getSignalName());
	assertNull(signalEvent.getSignalData());
	
	assertDatabaseEventPresent(ActivitiEventType.ACTIVITY_MESSAGE_RECEIVED);
}
 
Example #17
Source File: VariableEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Test variable events when done within a process (eg. execution-listener)
 */
@Deployment
public void ActivitiEventType() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("variableProcess");
  assertNotNull(processInstance);

  assertEquals(3, listener.getEventsReceived().size());

  // Check create event
  ActivitiVariableEvent event = (ActivitiVariableEvent) listener.getEventsReceived().get(0);
  assertEquals(ActivitiEventType.VARIABLE_CREATED, event.getType());
  assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
  assertEquals(processInstance.getId(), event.getExecutionId());
  assertEquals(processInstance.getId(), event.getProcessInstanceId());
  assertNull(event.getTaskId());
  assertEquals("variable", event.getVariableName());
  assertEquals(123, event.getVariableValue());

  // Check update event
  event = (ActivitiVariableEvent) listener.getEventsReceived().get(1);
  assertEquals(ActivitiEventType.VARIABLE_UPDATED, event.getType());
  assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
  assertEquals(processInstance.getId(), event.getExecutionId());
  assertEquals(processInstance.getId(), event.getProcessInstanceId());
  assertNull(event.getTaskId());
  assertEquals("variable", event.getVariableName());
  assertEquals(456, event.getVariableValue());

  // Check delete event
  event = (ActivitiVariableEvent) listener.getEventsReceived().get(2);
  assertEquals(ActivitiEventType.VARIABLE_DELETED, event.getType());
  assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
  assertEquals(processInstance.getId(), event.getExecutionId());
  assertEquals(processInstance.getId(), event.getProcessInstanceId());
  assertNull(event.getTaskId());
  assertEquals("variable", event.getVariableName());
  assertEquals(456, event.getVariableValue());
}
 
Example #18
Source File: AbstractCompleteTaskCmd.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void executeTaskComplete(CommandContext commandContext, TaskEntity taskEntity, Map<String, Object> variables, boolean localScope) {
  // Task complete logic

  if (taskEntity.getDelegationState() != null && taskEntity.getDelegationState().equals(DelegationState.PENDING)) {
    throw new ActivitiException("A delegated task cannot be completed, but should be resolved instead.");
  }

  commandContext.getProcessEngineConfiguration().getListenerNotificationHelper().executeTaskListeners(taskEntity, TaskListener.EVENTNAME_COMPLETE);
  if (Authentication.getAuthenticatedUserId() != null && taskEntity.getProcessInstanceId() != null) {
    ExecutionEntity processInstanceEntity = commandContext.getExecutionEntityManager().findById(taskEntity.getProcessInstanceId());
    commandContext.getIdentityLinkEntityManager().involveUser(processInstanceEntity, Authentication.getAuthenticatedUserId(),IdentityLinkType.PARTICIPANT);
  }

  ActivitiEventDispatcher eventDispatcher = Context.getProcessEngineConfiguration().getEventDispatcher();
  if (eventDispatcher.isEnabled()) {
    if (variables != null) {
      eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityWithVariablesEvent(ActivitiEventType.TASK_COMPLETED, taskEntity, variables, localScope));
    } else {
      eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.TASK_COMPLETED, taskEntity));
    }
  }

  commandContext.getTaskEntityManager().deleteTask(taskEntity, null, false, false);

  // Continue process (if not a standalone task)
  if (taskEntity.getExecutionId() != null) {
    ExecutionEntity executionEntity = commandContext.getExecutionEntityManager().findById(taskEntity.getExecutionId());
    Context.getAgenda().planTriggerExecutionOperation(executionEntity);
  }
}
 
Example #19
Source File: ProcessDefinitionInfoEntityManager.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void updateProcessDefinitionInfo(ProcessDefinitionInfoEntity updatedProcessDefinitionInfo) {
  CommandContext commandContext = Context.getCommandContext();
  DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
  dbSqlSession.update(updatedProcessDefinitionInfo);
  
  if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
    Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
        ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, updatedProcessDefinitionInfo));
  }
}
 
Example #20
Source File: TaskEntityManager.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void deleteTask(TaskEntity task, String deleteReason, boolean cascade) {
  if (!task.isDeleted()) {
  	 task.fireEvent(TaskListener.EVENTNAME_DELETE);
    task.setDeleted(true);
    
    CommandContext commandContext = Context.getCommandContext();
    String taskId = task.getId();
    
    List<Task> subTasks = findTasksByParentTaskId(taskId);
    for (Task subTask: subTasks) {
      deleteTask((TaskEntity) subTask, deleteReason, cascade);
    }
    
    commandContext
      .getIdentityLinkEntityManager()
      .deleteIdentityLinksByTaskId(taskId);

    commandContext
      .getVariableInstanceEntityManager()
      .deleteVariableInstanceByTask(task);

    if (cascade) {
      commandContext
        .getHistoricTaskInstanceEntityManager()
        .deleteHistoricTaskInstanceById(taskId);
    } else {
      commandContext
        .getHistoryManager()
        .recordTaskEnd(taskId, deleteReason);
    }
      
    getDbSqlSession().delete(task);
    
    if(commandContext.getEventDispatcher().isEnabled()) {
    	commandContext.getEventDispatcher().dispatchEvent(
    			ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, task));
    }
  }
}
 
Example #21
Source File: GroupEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void delete(String groupId) {
  GroupEntity group = groupDataManager.findById(groupId); 

  if (group != null) {
    
    getMembershipEntityManager().deleteMembershipByGroupId(groupId);
    if (getEventDispatcher().isEnabled()) {
      getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createMembershipEvent(ActivitiEventType.MEMBERSHIPS_DELETED, groupId, null));
    }
    
    delete(group);
  }
}
 
Example #22
Source File: ProcessInstanceEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testProcessInstanceTerminatedEvents_complete() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
  assertNotNull(processInstance);

  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  taskService.complete(task.getId());

  List<ActivitiEvent> processTerminatedEvents = listener.filterEvents(ActivitiEventType.PROCESS_CANCELLED);
  assertEquals("There should be no ActivitiEventType.PROCESS_TERMINATED event after process complete.", 0, processTerminatedEvents.size());
}
 
Example #23
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 #24
Source File: TaskEntity.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void updateVariableInstance(VariableInstanceEntity variableInstance, Object value,
    ExecutionEntity sourceActivityExecution) {
  super.updateVariableInstance(variableInstance, value, sourceActivityExecution);
  
  // Dispatch event, if needed
  if(Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
  	Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
  			ActivitiEventBuilder.createVariableEvent(ActivitiEventType.VARIABLE_UPDATED, variableInstance.getName(), value, variableInstance.getType(), 
  					variableInstance.getTaskId(), variableInstance.getExecutionId(), getProcessInstanceId(), getProcessDefinitionId()));
  }
}
 
Example #25
Source File: TaskEntity.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
public void complete(Map variablesMap, boolean localScope) {
	
	if (getDelegationState() != null && getDelegationState().equals(DelegationState.PENDING)) {
		throw new ActivitiException("A delegated task cannot be completed, but should be resolved instead.");
	}
	
  fireEvent(TaskListener.EVENTNAME_COMPLETE);

  if (Authentication.getAuthenticatedUserId() != null && processInstanceId != null) {
    getProcessInstance().involveUser(Authentication.getAuthenticatedUserId(), IdentityLinkType.PARTICIPANT);
  }
  
  if(Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
  	Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
  	    ActivitiEventBuilder.createEntityWithVariablesEvent(ActivitiEventType.TASK_COMPLETED, this, variablesMap, localScope));
  }
 
  Context
    .getCommandContext()
    .getTaskEntityManager()
    .deleteTask(this, TaskEntity.DELETE_REASON_COMPLETED, false);
  
  if (executionId!=null) {
    ExecutionEntity execution = getExecution();
    execution.removeTask(this);
    execution.signal(null, null);
  }
}
 
Example #26
Source File: ActivityEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Test events related to message events, called from the API.
 */
@Deployment
public void testActivityMessageBoundaryEventsOnSubProcess() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("messageOnSubProcess");
  assertNotNull(processInstance);

  Execution executionWithMessage = runtimeService.createExecutionQuery().activityId("cloudformtask1").singleResult();
  assertNotNull(executionWithMessage);

  runtimeService.messageEventReceived("message_1", executionWithMessage.getId());
  assertEquals(2, listener.getEventsReceived().size());

  // First, a message-event is expected
  assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiMessageEvent);
  ActivitiMessageEvent messageEvent = (ActivitiMessageEvent) listener.getEventsReceived().get(0);
  assertEquals(ActivitiEventType.ACTIVITY_MESSAGE_RECEIVED, messageEvent.getType());
  assertEquals("boundaryMessageEventCatching", messageEvent.getActivityId());
  assertEquals(executionWithMessage.getId(), messageEvent.getExecutionId());
  assertEquals(executionWithMessage.getProcessInstanceId(), messageEvent.getProcessInstanceId());
  assertEquals(processInstance.getProcessDefinitionId(), messageEvent.getProcessDefinitionId());
  assertEquals("message_1", messageEvent.getMessageName());
  assertNull(messageEvent.getMessageData());

  // Next, an signal-event is expected, as a result of the message
  assertTrue(listener.getEventsReceived().get(1) instanceof ActivitiActivityCancelledEvent);
  ActivitiActivityCancelledEvent signalEvent = (ActivitiActivityCancelledEvent) listener.getEventsReceived().get(1);
  assertEquals(ActivitiEventType.ACTIVITY_CANCELLED, signalEvent.getType());
  assertEquals("cloudformtask1", signalEvent.getActivityId());
  assertEquals(executionWithMessage.getId(), signalEvent.getExecutionId());
  assertEquals(executionWithMessage.getProcessInstanceId(), signalEvent.getProcessInstanceId());
  assertEquals(processInstance.getProcessDefinitionId(), signalEvent.getProcessDefinitionId());
  assertNotNull(signalEvent.getCause());
  assertTrue(signalEvent.getCause() instanceof MessageEventSubscriptionEntity);
  MessageEventSubscriptionEntity cause = (MessageEventSubscriptionEntity) signalEvent.getCause();
  assertEquals("message_1", cause.getEventName());

  assertDatabaseEventPresent(ActivitiEventType.ACTIVITY_MESSAGE_RECEIVED);
}
 
Example #27
Source File: ProcessInstanceEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Test +-->End1 Start-<> +-->End2
 * <p/>
 * process on PROCESS_COMPLETED event
 */
@Deployment(resources = { "org/activiti/engine/test/api/event/ProcessInstanceEventsTest.parallelGatewayTwoEndsProcess.bpmn20.xml" })
public void testProcessCompleted_ParallelGatewayTwoEnds() throws Exception {
  this.runtimeService.startProcessInstanceByKey("noEndProcess");

  List<ActivitiEvent> events = listener.filterEvents(ActivitiEventType.PROCESS_COMPLETED);
  assertEquals("ActivitiEventType.PROCESS_COMPLETED was expected 1 time.", 1, events.size());
}
 
Example #28
Source File: GroupEntityManager.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void updateGroup(Group updatedGroup) {
  CommandContext commandContext = Context.getCommandContext();
  DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
  dbSqlSession.update((GroupEntity) updatedGroup);
  
  if(getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
  	getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
  			ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, updatedGroup));
  }
}
 
Example #29
Source File: CancelJobsCmd.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Void execute(CommandContext commandContext) {
  JobEntity jobToDelete = null;
  for (String jobId: jobIds) {
    jobToDelete = commandContext
      .getJobEntityManager()
      .findJobById(jobId);
    
    if (jobToDelete != null) {
      if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
          ActivitiEventBuilder.createEntityEvent(ActivitiEventType.JOB_CANCELED, jobToDelete));
      }

      jobToDelete.delete();
    
    } else {
      TimerJobEntity timerJobToDelete = commandContext.getTimerJobEntityManager().findJobById(jobId);

      if (timerJobToDelete != null) {
        if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
          commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
              ActivitiEventBuilder.createEntityEvent(ActivitiEventType.JOB_CANCELED, timerJobToDelete));
        }

        timerJobToDelete.delete();
      }
    }
  }
  return null;
}
 
Example #30
Source File: ProcessInstanceEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = {"org/activiti5/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"})
public void testProcessInstanceCancelledEvents_complete() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
  assertNotNull(processInstance);

  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  taskService.complete(task.getId());

  List<ActivitiEvent> processCancelledEvents = listener.filterEvents(ActivitiEventType.PROCESS_CANCELLED);
  assertEquals("There should be no ActivitiEventType.PROCESS_CANCELLED event after process complete.", 0, processCancelledEvents.size());
  List<ActivitiEvent> taskCancelledEvents = listener.filterEvents(ActivitiEventType.ACTIVITY_CANCELLED);
  assertEquals("There should be no ActivitiEventType.ACTIVITY_CANCELLED event.", 0, taskCancelledEvents.size());

}