Java Code Examples for org.activiti.engine.impl.persistence.entity.ExecutionEntity#setName()

The following examples show how to use org.activiti.engine.impl.persistence.entity.ExecutionEntity#setName() . 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: SetProcessInstanceNameCmd.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public Void execute(CommandContext commandContext) {
  if (processInstanceId == null) {
    throw new ActivitiIllegalArgumentException("processInstanceId is null");
  }

  ExecutionEntity execution = commandContext.getExecutionEntityManager().findById(processInstanceId);

  if (execution == null) {
    throw new ActivitiObjectNotFoundException("process instance " + processInstanceId + " doesn't exist", ProcessInstance.class);
  }

  if (!execution.isProcessInstanceType()) {
    throw new ActivitiObjectNotFoundException("process instance " + processInstanceId + " doesn't exist, the given ID references an execution, though", ProcessInstance.class);
  }

  if (execution.isSuspended()) {
    throw new ActivitiException("process instance " + processInstanceId + " is suspended, cannot set name");
  }

  // Actually set the name
  execution.setName(name);

  // Record the change in history
  commandContext.getHistoryManager().recordProcessInstanceNameChange(processInstanceId, name);

  return null;
}
 
Example 2
Source File: SetProcessInstanceNameCmd.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public Void execute(CommandContext commandContext) {
    if (processInstanceId == null) {
        throw new ActivitiIllegalArgumentException("processInstanceId is null");
    }

    ExecutionEntity execution = commandContext
            .getExecutionEntityManager()
            .findExecutionById(processInstanceId);

    if (execution == null) {
        throw new ActivitiObjectNotFoundException("process instance " + processInstanceId + " doesn't exist", ProcessInstance.class);
    }

    if (!execution.isProcessInstanceType()) {
        throw new ActivitiObjectNotFoundException("process instance " + processInstanceId +
                " doesn't exist, the given ID references an execution, though", ProcessInstance.class);
    }

    if (execution.isSuspended()) {
        throw new ActivitiException("process instance " + processInstanceId + " is suspended, cannot set name");
    }

    // Actually set the name
    execution.setName(name);

    // Record the change in history
    commandContext.getHistoryManager().recordProcessInstanceNameChange(processInstanceId, name);

    return null;
}
 
Example 3
Source File: StartProcessInstanceCmd.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public ProcessInstance execute(CommandContext commandContext) {
    DeploymentManager deploymentManager = commandContext
            .getProcessEngineConfiguration()
            .getDeploymentManager();

    // Find the process definition
    ProcessDefinition processDefinition = null;
    if (processDefinitionId != null) {
        processDefinition = deploymentManager.findDeployedProcessDefinitionById(processDefinitionId);
        if (processDefinition == null) {
            throw new ActivitiObjectNotFoundException("No process definition found for id = '" + processDefinitionId + "'", ProcessDefinition.class);
        }
    } else if (processDefinitionKey != null && (tenantId == null || ProcessEngineConfiguration.NO_TENANT_ID.equals(tenantId))) {
        processDefinition = deploymentManager.findDeployedLatestProcessDefinitionByKey(processDefinitionKey);
        if (processDefinition == null) {
            throw new ActivitiObjectNotFoundException("No process definition found for key '" + processDefinitionKey + "'", ProcessDefinition.class);
        }
    } else if (processDefinitionKey != null && tenantId != null && !ProcessEngineConfiguration.NO_TENANT_ID.equals(tenantId)) {
        processDefinition = deploymentManager.findDeployedLatestProcessDefinitionByKeyAndTenantId(processDefinitionKey, tenantId);
        if (processDefinition == null) {
            throw new ActivitiObjectNotFoundException("No process definition found for key '" + processDefinitionKey + "' for tenant identifier " + tenantId, ProcessDefinition.class);
        }
    } else {
        throw new ActivitiIllegalArgumentException("processDefinitionKey and processDefinitionId are null");
    }

    // Do not start process a process instance if the process definition is suspended
    if (deploymentManager.isProcessDefinitionSuspended(processDefinition.getId())) {
        throw new ActivitiException("Cannot start process instance. Process definition "
                + processDefinition.getName() + " (id = " + processDefinition.getId() + ") is suspended");
    }

    // Start the process instance
    ExecutionEntity processInstance = ((ProcessDefinitionEntity) processDefinition).createProcessInstance(businessKey);

    // now set the variables passed into the start command
    initializeVariables(processInstance);

    // now set processInstance name
    if (processInstanceName != null) {
        processInstance.setName(processInstanceName);
        commandContext.getHistoryManager().recordProcessInstanceNameChange(processInstance.getId(), processInstanceName);
    }

    processInstance.start();

    return processInstance;
}
 
Example 4
Source File: UpdateProcessInstanceNameEventListener.java    From lemon with Apache License 2.0 4 votes vote down vote up
protected void onInitialized(ActivitiEvent event) {
    if (!(event instanceof ActivitiEntityEventImpl)) {
        return;
    }

    ActivitiEntityEventImpl activitiEntityEventImpl = (ActivitiEntityEventImpl) event;
    Object entity = activitiEntityEventImpl.getEntity();

    if (!(entity instanceof ExecutionEntity)) {
        return;
    }

    ActivitiEventType activitiEventType = activitiEntityEventImpl.getType();

    if (activitiEventType != ActivitiEventType.ENTITY_INITIALIZED) {
        return;
    }

    ExecutionEntity executionEntity = (ExecutionEntity) entity;

    if (!executionEntity.isProcessInstanceType()) {
        return;
    }

    String processInstanceId = executionEntity.getId();
    String processDefinitionId = executionEntity.getProcessDefinitionId();
    CommandContext commandContext = Context.getCommandContext();
    ProcessDefinitionEntity processDefinition = new GetDeploymentProcessDefinitionCmd(
            processDefinitionId).execute(commandContext);

    // {流程标题:title}-{发起人:startUser}-{发起时间:startTime}
    String processDefinitionName = processDefinition.getName();

    if (processDefinitionName == null) {
        processDefinitionName = processDefinition.getKey();
    }

    String userId = Authentication.getAuthenticatedUserId();
    String displayName = userConnector.findById(userId).getDisplayName();
    String processInstanceName = processDefinitionName + "-" + displayName
            + "-"
            + new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date());
    // runtime
    executionEntity.setName(processInstanceName);

    // history
    HistoricProcessInstanceEntity historicProcessInstanceEntity = commandContext
            .getHistoricProcessInstanceEntityManager()
            .findHistoricProcessInstance(processInstanceId);
    historicProcessInstanceEntity.setName(processInstanceName);
}