code: public ProcessDefinitionEntity getMostRecentVersionOfProcessDefinition(ProcessDefinitionEntity processDefinition) {
      String key = processDefinition.getKey();
      String tenantId = processDefinition.getTenantId();
      ProcessDefinitionEntityManager processDefinitionManager 
        = Context.getCommandContext().getProcessEngineConfiguration().getProcessDefinitionEntityManager();
  
      ProcessDefinitionEntity existingDefinition = null;
  
      if (tenantId != null && !tenantId.equals(ProcessEngineConfiguration.NO_TENANT_ID)) {
        existingDefinition = processDefinitionManager.findLatestProcessDefinitionByKeyAndTenantId(key, tenantId);
      } else {
        existingDefinition = processDefinitionManager.findLatestProcessDefinitionByKey(key);
      }
  
      return existingDefinition;
    }
docs: Gets the most recent persisted process definition that matches this one for tenant and key.
  If none is found, returns null.  This method assumes that the tenant and key are properly
  set on the process definition entity.