org.activiti.engine.delegate.event.impl.ActivitiEventBuilder Java Examples

The following examples show how to use org.activiti.engine.delegate.event.impl.ActivitiEventBuilder. 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: DefaultHistoryManager.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void recordProcessInstanceStart(ExecutionEntity processInstance, FlowElement startElement) {
  if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
    HistoricProcessInstanceEntity historicProcessInstance = getHistoricProcessInstanceEntityManager().create(processInstance); 
    historicProcessInstance.setStartActivityId(startElement.getId());

    // Insert historic process-instance
    getHistoricProcessInstanceEntityManager().insert(historicProcessInstance, false);
    
    // Fire event
    ActivitiEventDispatcher activitiEventDispatcher = getEventDispatcher();
    if (activitiEventDispatcher != null && activitiEventDispatcher.isEnabled()) {
      activitiEventDispatcher.dispatchEvent(
          ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_PROCESS_INSTANCE_CREATED, historicProcessInstance));
    }

  }
}
 
Example #2
Source File: JobEntity.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void delete() {
    Context.getCommandContext()
            .getDbSqlSession()
            .delete(this);

    // Also delete the job's exception and the custom values byte array
    exceptionByteArrayRef.delete();
    customValuesByteArrayRef.delete();

    // remove link to execution
    if (executionId != null) {
        ExecutionEntity execution = Context.getCommandContext()
                .getExecutionEntityManager()
                .findExecutionById(executionId);
        execution.removeJob(this);
    }

    if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_DELETED, this));
    }
}
 
Example #3
Source File: DefaultHistoryManager.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void recordSubProcessInstanceStart(ExecutionEntity parentExecution, ExecutionEntity subProcessInstance, FlowElement initialElement) {
  if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {

    HistoricProcessInstanceEntity historicProcessInstance = getHistoricProcessInstanceEntityManager().create(subProcessInstance); 

    // Fix for ACT-1728: startActivityId not initialized with subprocess instance
    if (historicProcessInstance.getStartActivityId() == null) {
      historicProcessInstance.setStartActivityId(initialElement.getId());
    }
    getHistoricProcessInstanceEntityManager().insert(historicProcessInstance, false);
    
    // Fire event
    ActivitiEventDispatcher activitiEventDispatcher = getEventDispatcher();
    if (activitiEventDispatcher != null && activitiEventDispatcher.isEnabled()) {
      activitiEventDispatcher.dispatchEvent(
          ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_PROCESS_INSTANCE_CREATED, historicProcessInstance));
    }

    HistoricActivityInstanceEntity activitiyInstance = findActivityInstance(parentExecution, false, true);
    if (activitiyInstance != null) {
      activitiyInstance.setCalledProcessInstanceId(subProcessInstance.getProcessInstanceId());
    }

  }
}
 
Example #4
Source File: ContinueProcessOperation.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void executeActivityBehavior(ActivityBehavior activityBehavior, FlowNode flowNode) {
  logger.debug("Executing activityBehavior {} on activity '{}' with execution {}", activityBehavior.getClass(), flowNode.getId(), execution.getId());

  if (Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
    Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
        ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_STARTED, flowNode.getId(), flowNode.getName(), execution.getId(),
            execution.getProcessInstanceId(), execution.getProcessDefinitionId(), flowNode));
  }

  try {
    activityBehavior.execute(execution);
  } catch (RuntimeException e) {
    if (LogMDC.isMDCEnabled()) {
      LogMDC.putMDCExecution(execution);
    }
    throw e;
  }
}
 
Example #5
Source File: TakeOutgoingSequenceFlowsOperation.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void handleActivityEnd(FlowNode flowNode) {
  // a process instance execution can never leave a flow node, but it can pass here whilst cleaning up
  // hence the check for NOT being a process instance
  if (!execution.isProcessInstanceType()) {

    if (CollectionUtil.isNotEmpty(flowNode.getExecutionListeners())) {
      executeExecutionListeners(flowNode, ExecutionListener.EVENTNAME_END);
    }

    commandContext.getHistoryManager().recordActivityEnd(execution, null);

    if (!(execution.getCurrentFlowElement() instanceof SubProcess)) {
      Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
          ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_COMPLETED, flowNode.getId(), flowNode.getName(),
              execution.getId(), execution.getProcessInstanceId(), execution.getProcessDefinitionId(), flowNode));
    }

  }
}
 
Example #6
Source File: TaskEntity.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void setDueDate(Date dueDate, boolean dispatchUpdateEvent) {
    this.dueDate = dueDate;

    CommandContext commandContext = Context.getCommandContext();
    if (commandContext != null) {
        commandContext
                .getHistoryManager()
                .recordTaskDueDateChange(id, dueDate);

        if (dispatchUpdateEvent && commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
            if (dispatchUpdateEvent) {
                commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                        ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_UPDATED, this));
            }
        }
    }
}
 
Example #7
Source File: DeadLetterJobEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void delete(DeadLetterJobEntity jobEntity) {
  super.delete(jobEntity);

  deleteExceptionByteArrayRef(jobEntity);
  
  if (jobEntity.getExecutionId() != null && isExecutionRelatedEntityCountEnabledGlobally()) {
    CountingExecutionEntity executionEntity = (CountingExecutionEntity) getExecutionEntityManager().findById(jobEntity.getExecutionId());
    if (isExecutionRelatedEntityCountEnabled(executionEntity)) {
      executionEntity.setDeadLetterJobCount(executionEntity.getDeadLetterJobCount() - 1);
    }
  }
  
  // Send event
  if (getEventDispatcher().isEnabled()) {
    getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, this));
  }
}
 
Example #8
Source File: SuspendedJobEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void delete(SuspendedJobEntity jobEntity) {
  super.delete(jobEntity);

  deleteExceptionByteArrayRef(jobEntity);
  
  if (jobEntity.getExecutionId() != null && isExecutionRelatedEntityCountEnabledGlobally()) {
    CountingExecutionEntity executionEntity = (CountingExecutionEntity) getExecutionEntityManager().findById(jobEntity.getExecutionId());
    if (isExecutionRelatedEntityCountEnabled(executionEntity)) {
      executionEntity.setSuspendedJobCount(executionEntity.getSuspendedJobCount() - 1);
    }
  }
  
  // Send event
  if (getEventDispatcher().isEnabled()) {
    getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, this));
  }
}
 
Example #9
Source File: TaskEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteTasksByProcessInstanceId(String processInstanceId, String deleteReason, boolean cascade) {
  List<TaskEntity> tasks = findTasksByProcessInstanceId(processInstanceId);

  for (TaskEntity task : tasks) {
  	if (getEventDispatcher().isEnabled() && task.isCanceled() == false) {
  		task.setCanceled(true);
      getEventDispatcher().dispatchEvent(
            ActivitiEventBuilder.createActivityCancelledEvent(task.getExecution().getActivityId(), task.getName(), 
                task.getExecutionId(), task.getProcessInstanceId(),
                task.getProcessDefinitionId(), "userTask", deleteReason));
    }

    deleteTask(task, deleteReason, cascade, false);
  }
}
 
Example #10
Source File: TimerJobEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void delete(TimerJobEntity jobEntity) {
  super.delete(jobEntity);

  deleteExceptionByteArrayRef(jobEntity);
  removeExecutionLink(jobEntity);
  
  if (jobEntity.getExecutionId() != null && isExecutionRelatedEntityCountEnabledGlobally()) {
    CountingExecutionEntity executionEntity = (CountingExecutionEntity) getExecutionEntityManager().findById(jobEntity.getExecutionId());
    if (isExecutionRelatedEntityCountEnabled(executionEntity)) {
      executionEntity.setTimerJobCount(executionEntity.getTimerJobCount() - 1);
    }
  }
  
  // Send event
  if (getEventDispatcher().isEnabled()) {
    getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, this));
  }
}
 
Example #11
Source File: IdentityLinkEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteIdentityLink(IdentityLinkEntity identityLink, boolean cascadeHistory) {
  delete(identityLink, false);
  if (cascadeHistory) {
    getHistoryManager().deleteHistoricIdentityLink(identityLink.getId());
  }
  
  if (identityLink.getProcessInstanceId() != null && isExecutionRelatedEntityCountEnabledGlobally()) {
    CountingExecutionEntity executionEntity = (CountingExecutionEntity) getExecutionEntityManager().findById(identityLink.getProcessInstanceId());
    if (isExecutionRelatedEntityCountEnabled(executionEntity)) {
      executionEntity.setIdentityLinkCount(executionEntity.getIdentityLinkCount() -1);
    }
  }

  if (getEventDispatcher().isEnabled()) {
    getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, identityLink));
  }
}
 
Example #12
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 #13
Source File: TaskEntity.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void setPriority(int priority, boolean dispatchUpdateEvent) {
    this.priority = priority;

    CommandContext commandContext = Context.getCommandContext();
    if (commandContext != null) {
        commandContext
                .getHistoryManager()
                .recordTaskPriorityChange(id, priority);

        if (dispatchUpdateEvent && commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
            if (dispatchUpdateEvent) {
                commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                        ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_UPDATED, this));
            }
        }
    }
}
 
Example #14
Source File: SaveAttachmentCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public Object execute(CommandContext commandContext) {
    AttachmentEntity updateAttachment = commandContext
            .getDbSqlSession()
            .selectById(AttachmentEntity.class, attachment.getId());

    updateAttachment.setName(attachment.getName());
    updateAttachment.setDescription(attachment.getDescription());

    if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        // Forced to fetch the process-instance to associate the right process definition
        String processDefinitionId = null;
        String processInstanceId = updateAttachment.getProcessInstanceId();
        if (updateAttachment.getProcessInstanceId() != null) {
            ExecutionEntity process = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);
            if (process != null) {
                processDefinitionId = process.getProcessDefinitionId();
            }
        }

        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_UPDATED, attachment, processInstanceId, processInstanceId, processDefinitionId));
    }

    return null;
}
 
Example #15
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 #16
Source File: DefaultHistoryManager.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void recordProcessInstanceEnd(String processInstanceId, String deleteReason, String activityId) {

    if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricProcessInstanceEntity historicProcessInstance = getHistoricProcessInstanceManager()
                .findHistoricProcessInstance(processInstanceId);

        if (historicProcessInstance != null) {
            historicProcessInstance.markEnded(deleteReason);
            historicProcessInstance.setEndActivityId(activityId);

            // Fire event
            ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
            if (config != null && config.getEventDispatcher().isEnabled()) {
                config.getEventDispatcher().dispatchEvent(
                        ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.HISTORIC_PROCESS_INSTANCE_ENDED, historicProcessInstance));
            }
        }
    }
}
 
Example #17
Source File: SetJobRetriesCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public Void execute(CommandContext commandContext) {
    JobEntity job = commandContext
            .getJobEntityManager()
            .findJobById(jobId);
    if (job != null) {
        job.setRetries(retries);

        if (commandContext.getEventDispatcher().isEnabled()) {
            commandContext.getEventDispatcher().dispatchEvent(
                    ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_UPDATED, job));
        }
    } else {
        throw new ActivitiObjectNotFoundException("No job found with id '" + jobId + "'.", Job.class);
    }
    return null;
}
 
Example #18
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 #19
Source File: IntermediateCatchMessageEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
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 #20
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 #21
Source File: DeadLetterJobEntity.java    From flowable-engine 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);

        // Inherit tenant if (if applicable)
        if (execution.getTenantId() != null) {
            setTenantId(execution.getTenantId());
        }
    }

    if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_CREATED, this));
        Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_INITIALIZED, this));
    }
}
 
Example #22
Source File: TaskEntity.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void insert(ExecutionEntity execution, boolean fireEvents) {
    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() && fireEvents) {
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_CREATED, this));
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_INITIALIZED, this));
    }
}
 
Example #23
Source File: CommentEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void delete(CommentEntity commentEntity) {
  checkHistoryEnabled();
  
  delete(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_DELETED, commentEntity, processInstanceId, processInstanceId, processDefinitionId));
  }
}
 
Example #24
Source File: SetProcessDefinitionCategoryCmd.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Void execute(CommandContext commandContext) {

    if (processDefinitionId == null) {
      throw new ActivitiIllegalArgumentException("Process definition id is null");
    }

    ProcessDefinitionEntity processDefinition = commandContext.getProcessDefinitionEntityManager().findById(processDefinitionId);

    if (processDefinition == null) {
      throw new ActivitiObjectNotFoundException("No process definition found for id = '" + processDefinitionId + "'", ProcessDefinition.class);
    }
    
    if (Activiti5Util.isActiviti5ProcessDefinition(commandContext, processDefinition)) {
      Activiti5CompatibilityHandler activiti5CompatibilityHandler = Activiti5Util.getActiviti5CompatibilityHandler(); 
      activiti5CompatibilityHandler.setProcessDefinitionCategory(processDefinitionId, category);
      return null;
    }

    // Update category
    processDefinition.setCategory(category);

    // Remove process definition from cache, it will be refetched later
    DeploymentCache<ProcessDefinitionCacheEntry> processDefinitionCache = commandContext.getProcessEngineConfiguration().getProcessDefinitionCache();
    if (processDefinitionCache != null) {
      processDefinitionCache.remove(processDefinitionId);
    }

    if (commandContext.getEventDispatcher().isEnabled()) {
      commandContext.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, processDefinition));
    }

    return null;
  }
 
Example #25
Source File: TaskEntityImpl.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 #26
Source File: ProcessDefinitionInfoEntityManager.java    From flowable-engine 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(FlowableEngineEventType.ENTITY_UPDATED, updatedProcessDefinitionInfo));
    }
}
 
Example #27
Source File: SetDeploymentCategoryCmd.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Void execute(CommandContext commandContext) {

    if (deploymentId == null) {
      throw new ActivitiIllegalArgumentException("Deployment id is null");
    }

    DeploymentEntity deployment = commandContext.getDeploymentEntityManager().findById(deploymentId);

    if (deployment == null) {
      throw new ActivitiObjectNotFoundException("No deployment found for id = '" + deploymentId + "'", Deployment.class);
    }
    
    if (commandContext.getProcessEngineConfiguration().isActiviti5CompatibilityEnabled() && 
        Activiti5CompatibilityHandler.ACTIVITI_5_ENGINE_TAG.equals(deployment.getEngineVersion())) {
      
      commandContext.getProcessEngineConfiguration().getActiviti5CompatibilityHandler().setDeploymentCategory(deploymentId, category);
    }

    // Update category
    deployment.setCategory(category);

    if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
      commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, deployment));
    }

    return null;
  }
 
Example #28
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().findById(jobId);

    if (jobToDelete != null) {
      // When given job doesn't exist, ignore
      if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.JOB_CANCELED, jobToDelete));
      }

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

      if (timerJobToDelete != null) {
        // When given job doesn't exist, ignore
        if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
          commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.JOB_CANCELED, timerJobToDelete));
        }

        commandContext.getTimerJobEntityManager().delete(timerJobToDelete);
      }
    }
  }
  return null;
}
 
Example #29
Source File: DefaultHistoryManager.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void recordActivityStart(ExecutionEntity executionEntity) {
  if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
    if (executionEntity.getActivityId() != null && executionEntity.getCurrentFlowElement() != null) {
      
      HistoricActivityInstanceEntity historicActivityInstanceEntity = null;
      
      // Historic activity instance could have been created (but only in cache, never persisted)
      // for example when submitting form properties
      HistoricActivityInstanceEntity historicActivityInstanceEntityFromCache = 
          getHistoricActivityInstanceFromCache(executionEntity.getId(), executionEntity.getActivityId(), true);
      if (historicActivityInstanceEntityFromCache != null) {
        historicActivityInstanceEntity = historicActivityInstanceEntityFromCache;
      } else {
        historicActivityInstanceEntity = createHistoricActivityInstanceEntity(executionEntity);
      }
      
      // Fire event
      ActivitiEventDispatcher activitiEventDispatcher = getEventDispatcher();
      if (activitiEventDispatcher != null && activitiEventDispatcher.isEnabled()) {
        activitiEventDispatcher.dispatchEvent(
            ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_CREATED, historicActivityInstanceEntity));
      }
      
    }
  }
}
 
Example #30
Source File: ExecutionEntity.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * creates a new execution. properties processDefinition, processInstance and activity will be initialized.
 */
@Override
public ExecutionEntity createExecution() {
    // create the new child execution
    ExecutionEntity createdExecution = newExecution();

    // manage the bidirectional parent-child relation
    ensureExecutionsInitialized();
    executions.add(createdExecution);
    createdExecution.setParent(this);

    // initialize the new execution
    createdExecution.setProcessDefinition(getProcessDefinition());
    createdExecution.setProcessInstance(getProcessInstance());
    createdExecution.setActivity(getActivity());

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Child execution {} created with parent {}", createdExecution, this);
    }

    if (Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_CREATED, createdExecution));
        Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_INITIALIZED, createdExecution));
    }

    return createdExecution;
}