Java Code Examples for org.activiti.engine.runtime.ProcessInstance#isEnded()

The following examples show how to use org.activiti.engine.runtime.ProcessInstance#isEnded() . 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: BusinessProcess.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deprecated
public ProcessInstance startProcessByName(String string, Map<String, Object> variables) {

  if (Context.getCommandContext() != null) {
    throw new ActivitiCdiException("Cannot use startProcessByName in an activiti command.");
  }

  ProcessDefinition definition = processEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionName(string).singleResult();
  if (definition == null) {
    throw new ActivitiObjectNotFoundException("No process definition found for name: " + string, ProcessDefinition.class);
  }
  Map<String, Object> cachedVariables = getAndClearCachedVariables();
  cachedVariables.putAll(variables);
  ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceById(definition.getId(), cachedVariables);
  if (!instance.isEnded()) {
    setExecution(instance);
  }
  return instance;
}
 
Example 2
Source File: BusinessProcess.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deprecated
public ProcessInstance startProcessByName(String string) {

  if (Context.getCommandContext() != null) {
    throw new ActivitiCdiException("Cannot use startProcessByName in an activiti command.");
  }

  ProcessDefinition definition = processEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionName(string).singleResult();
  if (definition == null) {
    throw new ActivitiObjectNotFoundException("No process definition found for name: " + string, ProcessDefinition.class);
  }
  ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceById(definition.getId(), getAndClearCachedVariables());
  if (!instance.isEnded()) {
    setExecution(instance);
  }
  return instance;
}
 
Example 3
Source File: BusinessProcess.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ProcessInstance startProcessById(String processDefinitionId) {
  validateValidUsage();

  ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitionId, getAndClearCachedVariables());
  if (!instance.isEnded()) {
    setExecution(instance);
  }
  return instance;
}
 
Example 4
Source File: RestResponseFactory.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ProcessInstanceResponse createProcessInstanceResponse(ProcessInstance processInstance, RestUrlBuilder urlBuilder) {
  ProcessInstanceResponse result = new ProcessInstanceResponse();
  result.setActivityId(processInstance.getActivityId());
  result.setBusinessKey(processInstance.getBusinessKey());
  result.setId(processInstance.getId());
  result.setName(processInstance.getName());
  result.setProcessDefinitionId(processInstance.getProcessDefinitionId());
  result.setProcessDefinitionUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_DEFINITION, processInstance.getProcessDefinitionId()));
  result.setProcessDefinitionKey(processInstance.getProcessDefinitionKey());
  result.setEnded(processInstance.isEnded());
  result.setSuspended(processInstance.isSuspended());
  result.setUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId()));
  result.setTenantId(processInstance.getTenantId());

  // Added by Ryan Johnston
  if (processInstance.isEnded()) {
    // Process complete. Note the same in the result.
    result.setCompleted(true);
  } else {
    // Process not complete. Note the same in the result.
    result.setCompleted(false);
  }
  // End Added by Ryan Johnston

  if (processInstance.getProcessVariables() != null) {
    Map<String, Object> variableMap = processInstance.getProcessVariables();
    for (String name : variableMap.keySet()) {
      result.addVariable(createRestVariable(name, variableMap.get(name), RestVariableScope.LOCAL, processInstance.getId(), VARIABLE_PROCESS, false, urlBuilder));
    }
  }

  return result;
}
 
Example 5
Source File: BusinessProcess.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ProcessInstance startProcessByMessage(String messageName, String businessKey, Map<String, Object> processVariables) {
  validateValidUsage();

  Map<String, Object> cachedVariables = getAndClearCachedVariables();
  cachedVariables.putAll(processVariables);
  ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceByMessage(messageName, businessKey, cachedVariables);
  if (!processInstance.isEnded()) {
    setExecution(processInstance);
  }
  return processInstance;
}
 
Example 6
Source File: BusinessProcess.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ProcessInstance startProcessByMessage(String messageName, Map<String, Object> processVariables) {
  validateValidUsage();

  Map<String, Object> cachedVariables = getAndClearCachedVariables();
  cachedVariables.putAll(processVariables);
  ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceByMessage(messageName, cachedVariables);
  if (!processInstance.isEnded()) {
    setExecution(processInstance);
  }
  return processInstance;
}
 
Example 7
Source File: BusinessProcess.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ProcessInstance startProcessByMessage(String messageName) {
  validateValidUsage();

  Map<String, Object> cachedVariables = getAndClearCachedVariables();
  ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceByMessage(messageName, cachedVariables);
  if (!processInstance.isEnded()) {
    setExecution(processInstance);
  }
  return processInstance;
}
 
Example 8
Source File: BusinessProcess.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ProcessInstance startProcessByKey(String key, String businessKey, Map<String, Object> variables) {
  validateValidUsage();

  Map<String, Object> cachedVariables = getAndClearCachedVariables();
  cachedVariables.putAll(variables);
  ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceByKey(key, businessKey, cachedVariables);
  if (!instance.isEnded()) {
    setExecution(instance);
  }
  return instance;
}
 
Example 9
Source File: BusinessProcess.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ProcessInstance startProcessByKey(String key, Map<String, Object> variables) {
  validateValidUsage();

  Map<String, Object> cachedVariables = getAndClearCachedVariables();
  cachedVariables.putAll(variables);
  ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceByKey(key, cachedVariables);
  if (!instance.isEnded()) {
    setExecution(instance);
  }
  return instance;
}
 
Example 10
Source File: BusinessProcess.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ProcessInstance startProcessByKey(String key, String businessKey) {
  validateValidUsage();

  ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceByKey(key, businessKey, getAndClearCachedVariables());
  if (!instance.isEnded()) {
    setExecution(instance);
  }
  return instance;
}
 
Example 11
Source File: BusinessProcess.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ProcessInstance startProcessByKey(String key) {
  validateValidUsage();

  ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceByKey(key, getAndClearCachedVariables());
  if (!instance.isEnded()) {
    setExecution(instance);
  }
  return instance;
}
 
Example 12
Source File: BusinessProcess.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ProcessInstance startProcessById(String processDefinitionId, String businessKey, Map<String, Object> variables) {
  validateValidUsage();

  Map<String, Object> cachedVariables = getAndClearCachedVariables();
  cachedVariables.putAll(variables);
  ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitionId, businessKey, cachedVariables);
  if (!instance.isEnded()) {
    setExecution(instance);
  }
  return instance;
}
 
Example 13
Source File: BusinessProcess.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ProcessInstance startProcessById(String processDefinitionId, Map<String, Object> variables) {
  validateValidUsage();

  Map<String, Object> cachedVariables = getAndClearCachedVariables();
  cachedVariables.putAll(variables);
  ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitionId, cachedVariables);
  if (!instance.isEnded()) {
    setExecution(instance);
  }
  return instance;
}
 
Example 14
Source File: BusinessProcess.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ProcessInstance startProcessById(String processDefinitionId, String businessKey) {
  validateValidUsage();

  ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitionId, businessKey, getAndClearCachedVariables());
  if (!instance.isEnded()) {
    setExecution(instance);
  }
  return instance;
}
 
Example 15
Source File: ActivitiService.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ProcessInstance startProcessInstance(String processDefinitionId, Map<String, Object> variables, String processInstanceName) {
	
	 // Actually start the process
       // No need to pass the tenant id here, the process definition is already tenant based and the process instance will inherit it
       ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinitionId, variables);
       
       // Can only set name in case process didn't end instantly
       if (!processInstance.isEnded() && processInstanceName != null) {
           runtimeService.setProcessInstanceName(processInstance.getId(), processInstanceName);
       }
       
       return processInstance;
       
}
 
Example 16
Source File: RestResponseFactory.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public ProcessInstanceResponse createProcessInstanceResponse(ProcessInstance processInstance, boolean returnVariables, Map<String, Object> runtimeVariableMap,
    List<HistoricVariableInstance> historicVariableList) {

  RestUrlBuilder urlBuilder = createUrlBuilder();
  ProcessInstanceResponse result = new ProcessInstanceResponse();
  result.setActivityId(processInstance.getActivityId());
  result.setBusinessKey(processInstance.getBusinessKey());
  result.setId(processInstance.getId());
  result.setName(processInstance.getName());
  result.setProcessDefinitionId(processInstance.getProcessDefinitionId());
  result.setProcessDefinitionUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_DEFINITION, processInstance.getProcessDefinitionId()));
  result.setProcessDefinitionKey(processInstance.getProcessDefinitionKey());
  result.setEnded(processInstance.isEnded());
  result.setSuspended(processInstance.isSuspended());
  result.setUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId()));
  result.setTenantId(processInstance.getTenantId());

  // Added by Ryan Johnston
  if (processInstance.isEnded()) {
    // Process complete. Note the same in the result.
    result.setCompleted(true);
  } else {
    // Process not complete. Note the same in the result.
    result.setCompleted(false);
  }

  if (returnVariables) {

    if (processInstance.isEnded()) {
      if (historicVariableList != null) {
        for (HistoricVariableInstance historicVariable : historicVariableList) {
          result.addVariable(createRestVariable(historicVariable.getVariableName(), historicVariable.getValue(), RestVariableScope.LOCAL, processInstance.getId(), VARIABLE_PROCESS, false,
              urlBuilder));
        }
      }

    } else {
      if (runtimeVariableMap != null) {
        for (String name : runtimeVariableMap.keySet()) {
          result.addVariable(createRestVariable(name, runtimeVariableMap.get(name), RestVariableScope.LOCAL, processInstance.getId(), VARIABLE_PROCESS, false, urlBuilder));
        }
      }
    }
  }
  // End Added by Ryan Johnston

  return result;
}
 
Example 17
Source File: ActivitiWorkflowEngine.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
* {@inheritDoc}
*/
public WorkflowPath startWorkflow(String workflowDefinitionId, Map<QName, Serializable> parameters)
{
    try
    {
        String currentUserName = AuthenticationUtil.getFullyAuthenticatedUser();
        Authentication.setAuthenticatedUserId(currentUserName);
        
        String processDefId = createLocalId(workflowDefinitionId);
        
        // Set start task properties. This should be done before instance is started, since it's id will be used
        Map<String, Object> variables = propertyConverter.getStartVariables(processDefId, parameters);
        variables.put(WorkflowConstants.PROP_CANCELLED, Boolean.FALSE);
        
        // Add company home
        Object companyHome = nodeConverter.convertNode(getCompanyHome());
        variables.put(WorkflowConstants.PROP_COMPANY_HOME, companyHome);
         
        // Add the initiator
        NodeRef initiator = getPersonNodeRef(currentUserName);
        if (initiator != null)
        {
            variables.put(WorkflowConstants.PROP_INITIATOR, nodeConverter.convertNode(initiator));
            // Also add the initiator home reference, if one exists
            NodeRef initiatorHome = (NodeRef) nodeService.getProperty(initiator, ContentModel.PROP_HOMEFOLDER);
            if (initiatorHome != null)
            {
                variables.put(WorkflowConstants.PROP_INITIATOR_HOME, nodeConverter.convertNode(initiatorHome));
            }
        }
        
        // Start the process-instance
        CommandContext context = Context.getCommandContext();
        boolean isContextSuspended = false;
        if (context != null && context.getException() == null)
        {
            // MNT-11926: push null context to stack to avoid context reusage when new instance is not flushed
            Context.setCommandContext(null);
            isContextSuspended = true;
        }
        try
        {
            ProcessInstance instance = runtimeService.startProcessInstanceById(processDefId, variables);
            if (instance.isEnded())
            {
                return typeConverter.buildCompletedPath(instance.getId(), instance.getId());
            }
            else
            {
                WorkflowPath path = typeConverter.convert((Execution) instance);
                endStartTaskAutomatically(path, instance);
                return path;
            }
        }
        finally
        {
            if (isContextSuspended)
            {
                // pop null context out of stack
                Context.removeCommandContext();
            }
        }
    }
    catch (ActivitiException ae)
    {
        String msg = messageService.getMessage(ERR_START_WORKFLOW, workflowDefinitionId);
        if(logger.isDebugEnabled())
        {
        	logger.debug(msg, ae);
        }
        throw new WorkflowException(msg, ae);
    }
}