Java Code Examples for org.activiti.engine.repository.ProcessDefinition#getEngineVersion()

The following examples show how to use org.activiti.engine.repository.ProcessDefinition#getEngineVersion() . 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: Activiti5Util.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public static boolean isActiviti5ProcessDefinition(CommandContext commandContext, ProcessDefinition processDefinition) {
  
  if (!commandContext.getProcessEngineConfiguration().isActiviti5CompatibilityEnabled()) {
    return false;
  }
  
  if (processDefinition.getEngineVersion() != null) {
    if (Activiti5CompatibilityHandler.ACTIVITI_5_ENGINE_TAG.equals(processDefinition.getEngineVersion())) {
      if (commandContext.getProcessEngineConfiguration().isActiviti5CompatibilityEnabled()) {
        return true;
      }
    } else {
      throw new ActivitiException("Invalid 'engine' for process definition " + processDefinition.getId() + " : " + processDefinition.getEngineVersion());
    }
  }
  return false;
}
 
Example 2
Source File: IsActiviti5ProcessDefinitionCmd.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public Boolean execute(CommandContext commandContext) {
  if (!commandContext.getProcessEngineConfiguration().isActiviti5CompatibilityEnabled()) {
    return false;
  }
  
  ProcessDefinition processDefinition = commandContext.getProcessEngineConfiguration()
      .getDeploymentManager()
      .findDeployedProcessDefinitionById(processDefinitionId);
  
  if (processDefinition.getEngineVersion() != null) {
    if (Activiti5CompatibilityHandler.ACTIVITI_5_ENGINE_TAG.equals(processDefinition.getEngineVersion())) {
      if (commandContext.getProcessEngineConfiguration().isActiviti5CompatibilityEnabled()) {
        return true;
      }
    } else {
      throw new ActivitiException("Invalid 'engine' for process definition " + processDefinition.getId() + " : " + processDefinition.getEngineVersion());
    }
  }
  return false;
}
 
Example 3
Source File: ProcessInstanceHelper.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public ProcessInstance createAndStartProcessInstanceByMessage(ProcessDefinition processDefinition, String messageName,
    Map<String, Object> variables, Map<String, Object> transientVariables) {

  CommandContext commandContext = Context.getCommandContext();
  if (processDefinition.getEngineVersion() != null) {
    if (Activiti5CompatibilityHandler.ACTIVITI_5_ENGINE_TAG.equals(processDefinition.getEngineVersion())) {
      Activiti5CompatibilityHandler activiti5CompatibilityHandler = commandContext.getProcessEngineConfiguration().getActiviti5CompatibilityHandler();

      if (activiti5CompatibilityHandler == null) {
        throw new ActivitiException("Found Activiti 5 process definition, but no compatibility handler on the classpath");
      }

      return activiti5CompatibilityHandler.startProcessInstanceByMessage(messageName, variables, null, processDefinition.getTenantId());

    } else {
      throw new ActivitiException("Invalid 'engine' for process definition " + processDefinition.getId() + " : " + processDefinition.getEngineVersion());
    }
  }

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

  // Get model from cache
  Process process = ProcessDefinitionUtil.getProcess(processDefinition.getId());
  if (process == null) {
    throw new ActivitiException("Cannot start process instance. Process model " + processDefinition.getName() + " (id = " + processDefinition.getId() + ") could not be found");
  }

  FlowElement initialFlowElement = null;
  for (FlowElement flowElement : process.getFlowElements()) {
    if (flowElement instanceof StartEvent) {
      StartEvent startEvent = (StartEvent) flowElement;
      if (CollectionUtil.isNotEmpty(startEvent.getEventDefinitions()) && startEvent.getEventDefinitions().get(0) instanceof MessageEventDefinition) {

        MessageEventDefinition messageEventDefinition = (MessageEventDefinition) startEvent.getEventDefinitions().get(0);
        if (messageEventDefinition.getMessageRef().equals(messageName)) {
          initialFlowElement = flowElement;
          break;
        }
      }
    }
  }
  if (initialFlowElement == null) {
    throw new ActivitiException("No message start event found for process definition " + processDefinition.getId() + " and message name " + messageName);
  }

  return createAndStartProcessInstanceWithInitialFlowElement(processDefinition, null, null, initialFlowElement, process, variables, transientVariables, true);
}