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

The following examples show how to use org.activiti.engine.repository.ProcessDefinition#getTenantId() . 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: DeploymentEntityManager.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected ProcessDefinition findNewLatestProcessDefinitionAfterRemovalOf(ProcessDefinition processDefinitionToBeRemoved) {
  
  // The latest process definition is not necessarily the one with 'version -1' (some versions could have been deleted)
  // Hence, the following logic
  
  ProcessDefinitionQueryImpl query = new ProcessDefinitionQueryImpl();
  query.processDefinitionKey(processDefinitionToBeRemoved.getKey());
  
  if (processDefinitionToBeRemoved.getTenantId() != null 
      && !ProcessEngineConfiguration.NO_TENANT_ID.equals(processDefinitionToBeRemoved.getTenantId())) {
    query.processDefinitionTenantId(processDefinitionToBeRemoved.getTenantId());
  } else {
    query.processDefinitionWithoutTenantId();
  }
  
  query.processDefinitionVersionLowerThan(processDefinitionToBeRemoved.getVersion());
  query.orderByProcessDefinitionVersion().desc();
  
  List<ProcessDefinition> processDefinitions = getProcessDefinitionManager().findProcessDefinitionsByQueryCriteria(query, new Page(0, 1));
  if (processDefinitions != null && processDefinitions.size() > 0) {
    return processDefinitions.get(0);
  } 
  return null;
}
 
Example 2
Source File: DeploymentEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void restoreTimerStartEvent(ProcessDefinition previousProcessDefinition, StartEvent startEvent, EventDefinition eventDefinition) {
  TimerEventDefinition timerEventDefinition = (TimerEventDefinition) eventDefinition;
  TimerJobEntity timer = TimerUtil.createTimerEntityForTimerEventDefinition((TimerEventDefinition) eventDefinition, false, null, TimerStartEventJobHandler.TYPE,
      TimerEventHandler.createConfiguration(startEvent.getId(), timerEventDefinition.getEndDate(), timerEventDefinition.getCalendarName()));
  
  if (timer != null) {
    TimerJobEntity timerJob = getJobManager().createTimerJob((TimerEventDefinition) eventDefinition, false, null, TimerStartEventJobHandler.TYPE,
        TimerEventHandler.createConfiguration(startEvent.getId(), timerEventDefinition.getEndDate(), timerEventDefinition.getCalendarName()));
    
    timerJob.setProcessDefinitionId(previousProcessDefinition.getId());
    
    if (previousProcessDefinition.getTenantId() != null) {
      timerJob.setTenantId(previousProcessDefinition.getTenantId());
    }
    
    getJobManager().scheduleTimerJob(timerJob);
  }
}
 
Example 3
Source File: DeploymentEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void restoreSignalStartEvent(ProcessDefinition previousProcessDefinition, BpmnModel bpmnModel, StartEvent startEvent, EventDefinition eventDefinition) {
  SignalEventDefinition signalEventDefinition = (SignalEventDefinition) eventDefinition;
  SignalEventSubscriptionEntity subscriptionEntity = getEventSubscriptionEntityManager().createSignalEventSubscription();
  Signal signal = bpmnModel.getSignal(signalEventDefinition.getSignalRef());
  if (signal != null) {
    subscriptionEntity.setEventName(signal.getName());
  } else {
    subscriptionEntity.setEventName(signalEventDefinition.getSignalRef());
  }
  subscriptionEntity.setActivityId(startEvent.getId());
  subscriptionEntity.setProcessDefinitionId(previousProcessDefinition.getId());
  if (previousProcessDefinition.getTenantId() != null) {
    subscriptionEntity.setTenantId(previousProcessDefinition.getTenantId());
  }

  getEventSubscriptionEntityManager().insert(subscriptionEntity);
}
 
Example 4
Source File: DeploymentEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void restoreMessageStartEvent(ProcessDefinition previousProcessDefinition, BpmnModel bpmnModel, StartEvent startEvent, EventDefinition eventDefinition) {
  MessageEventDefinition messageEventDefinition = (MessageEventDefinition) eventDefinition;
  if (bpmnModel.containsMessageId(messageEventDefinition.getMessageRef())) {
    Message message = bpmnModel.getMessage(messageEventDefinition.getMessageRef());
    messageEventDefinition.setMessageRef(message.getName());
  }

  MessageEventSubscriptionEntity newSubscription = getEventSubscriptionEntityManager().createMessageEventSubscription();
  newSubscription.setEventName(messageEventDefinition.getMessageRef());
  newSubscription.setActivityId(startEvent.getId());
  newSubscription.setConfiguration(previousProcessDefinition.getId());
  newSubscription.setProcessDefinitionId(previousProcessDefinition.getId());

  if (previousProcessDefinition.getTenantId() != null) {
    newSubscription.setTenantId(previousProcessDefinition.getTenantId());
  }

  getEventSubscriptionEntityManager().insert(newSubscription);
}
 
Example 5
Source File: DeploymentEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected ProcessDefinition findNewLatestProcessDefinitionAfterRemovalOf(ProcessDefinition processDefinitionToBeRemoved) {
  
  // The latest process definition is not necessarily the one with 'version -1' (some versions could have been deleted)
  // Hence, the following logic
  
  ProcessDefinitionQueryImpl query = new ProcessDefinitionQueryImpl();
  query.processDefinitionKey(processDefinitionToBeRemoved.getKey());
  
  if (processDefinitionToBeRemoved.getTenantId() != null 
      && !ProcessEngineConfiguration.NO_TENANT_ID.equals(processDefinitionToBeRemoved.getTenantId())) {
    query.processDefinitionTenantId(processDefinitionToBeRemoved.getTenantId());
  } else {
    query.processDefinitionWithoutTenantId();
  }
  
  query.processDefinitionVersionLowerThan(processDefinitionToBeRemoved.getVersion());
  query.orderByProcessDefinitionVersion().desc();
  
  List<ProcessDefinition> processDefinitions = getProcessDefinitionEntityManager().findProcessDefinitionsByQueryCriteria(query, new Page(0, 1));
  if (processDefinitions != null && processDefinitions.size() > 0) {
    return processDefinitions.get(0);
  } 
  return null;
}
 
Example 6
Source File: DeploymentEntityManager.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected ProcessDefinitionEntity findLatestProcessDefinition(ProcessDefinition processDefinition) {
  ProcessDefinitionEntity latestProcessDefinition = null;
  if (processDefinition.getTenantId() != null && !ProcessEngineConfiguration.NO_TENANT_ID.equals(processDefinition.getTenantId())) {
    latestProcessDefinition = Context.getCommandContext().getProcessDefinitionEntityManager()
        .findLatestProcessDefinitionByKeyAndTenantId(processDefinition.getKey(), processDefinition.getTenantId());
  } else {
    latestProcessDefinition = Context.getCommandContext().getProcessDefinitionEntityManager()
        .findLatestProcessDefinitionByKey(processDefinition.getKey());
  }
  return latestProcessDefinition;
}
 
Example 7
Source File: SignalThrowingEventListener.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void onEvent(ActivitiEvent event) {
	if (isValidEvent(event)) {

		if (event.getProcessInstanceId() == null && processInstanceScope) {
			throw new ActivitiIllegalArgumentException(
			    "Cannot throw process-instance scoped signal, since the dispatched event is not part of an ongoing process instance");
		}

		CommandContext commandContext = Context.getCommandContext();
		List<SignalEventSubscriptionEntity> subscriptionEntities = null;
		if (processInstanceScope) {
			subscriptionEntities = commandContext.getEventSubscriptionEntityManager()
			    .findSignalEventSubscriptionsByProcessInstanceAndEventName(event.getProcessInstanceId(), signalName);
		} else {
			String tenantId = null;
			if (event.getProcessDefinitionId() != null) {
				ProcessDefinition processDefinition = commandContext.getProcessEngineConfiguration()
						.getDeploymentManager().findDeployedProcessDefinitionById(event.getProcessDefinitionId());
				tenantId = processDefinition.getTenantId();
			}
			subscriptionEntities = commandContext.getEventSubscriptionEntityManager()
			    .findSignalEventSubscriptionsByEventName(signalName, tenantId);
		}

		for (SignalEventSubscriptionEntity signalEventSubscriptionEntity : subscriptionEntities) {
			signalEventSubscriptionEntity.eventReceived(null, false);
		}
	}
}
 
Example 8
Source File: ProcessDefinitionRepresentation.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ProcessDefinitionRepresentation(ProcessDefinition processDefinition) {
    this.id = processDefinition.getId();
    this.name = processDefinition.getName();
    this.description = processDefinition.getDescription();
    this.key = processDefinition.getKey();
    this.category = processDefinition.getCategory();
    this.version = processDefinition.getVersion();
    this.deploymentId = processDefinition.getDeploymentId();
    this.tenantId = processDefinition.getTenantId();
    this.hasStartForm = processDefinition.hasStartFormKey();
}
 
Example 9
Source File: DeploymentEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected ProcessDefinitionEntity findLatestProcessDefinition(ProcessDefinition processDefinition) {
  ProcessDefinitionEntity latestProcessDefinition = null;
  if (processDefinition.getTenantId() != null && !ProcessEngineConfiguration.NO_TENANT_ID.equals(processDefinition.getTenantId())) {
    latestProcessDefinition = getProcessDefinitionEntityManager()
        .findLatestProcessDefinitionByKeyAndTenantId(processDefinition.getKey(), processDefinition.getTenantId());
  } else {
    latestProcessDefinition = getProcessDefinitionEntityManager()
        .findLatestProcessDefinitionByKey(processDefinition.getKey());
  }
  return latestProcessDefinition;
}
 
Example 10
Source File: SignalThrowingEventListener.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void onEvent(ActivitiEvent event) {
  if (isValidEvent(event)) {

    if (event.getProcessInstanceId() == null && processInstanceScope) {
      throw new ActivitiIllegalArgumentException("Cannot throw process-instance scoped signal, since the dispatched event is not part of an ongoing process instance");
    }

    CommandContext commandContext = Context.getCommandContext();
    EventSubscriptionEntityManager eventSubscriptionEntityManager = commandContext.getEventSubscriptionEntityManager();
    List<SignalEventSubscriptionEntity> subscriptionEntities = null;
    if (processInstanceScope) {
      subscriptionEntities = eventSubscriptionEntityManager.findSignalEventSubscriptionsByProcessInstanceAndEventName(event.getProcessInstanceId(), signalName);
    } else {
      String tenantId = null;
      if (event.getProcessDefinitionId() != null) {
        ProcessDefinition processDefinition = commandContext.getProcessEngineConfiguration().getDeploymentManager().findDeployedProcessDefinitionById(event.getProcessDefinitionId());
        tenantId = processDefinition.getTenantId();
      }
      subscriptionEntities = eventSubscriptionEntityManager.findSignalEventSubscriptionsByEventName(signalName, tenantId);
    }

    for (SignalEventSubscriptionEntity signalEventSubscriptionEntity : subscriptionEntities) {
      eventSubscriptionEntityManager.eventReceived(signalEventSubscriptionEntity, null, false);
    }
  }
}
 
Example 11
Source File: TenancyTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testGetLatestProcessDefinitionVersionForSameProcessDefinitionKey() {
  String tenant1 = "tenant1";
  String tenant2 = "tenant2";
  
  // Tenant 1 ==> version 4
  for (int i=0; i<4; i++) {
    deployTestProcessWithTestTenant(tenant1);
  }
  
  // Tenant 2 ==> version 2
  for (int i=0; i<2; i++) {
    deployTestProcessWithTestTenant(tenant2);
  }
  
  // No tenant ==> version 3
  for (int i=0; i<3; i++) {
    deployTestProcessWithTwoTasksNoTenant();
  }
  
  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
    .processDefinitionTenantId(tenant1)
    .latestVersion()
    .singleResult();
  assertEquals(4, processDefinition.getVersion());
  
  processDefinition = repositoryService.createProcessDefinitionQuery()
      .processDefinitionTenantId(tenant2)
      .latestVersion()
      .singleResult();
    assertEquals(2, processDefinition.getVersion());
    
    processDefinition = repositoryService.createProcessDefinitionQuery()
        .processDefinitionWithoutTenantId()
        .latestVersion()
        .singleResult();
    assertEquals(3, processDefinition.getVersion());
    
    List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().latestVersion().list();
    assertEquals(3, processDefinitions.size());
    
    // Verify they have different tenant ids
    int tenant1Count = 0, tenant2Count = 0, noTenantCount = 0 ;
    for (ProcessDefinition p : processDefinitions) {
      if (p.getTenantId() == null || p.getTenantId().equals(ProcessEngineConfiguration.NO_TENANT_ID)) {
        noTenantCount++;
      } else if (p.getTenantId().equals(tenant1)) {
        tenant1Count++;
      } else if (p.getTenantId().equals(tenant2)) {
        tenant2Count++;
      }
    }
    assertEquals(1, tenant1Count);
    assertEquals(1, tenant2Count);
    assertEquals(1, noTenantCount);
}
 
Example 12
Source File: TenancyTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testGetLatestProcessDefinitionVersionForSameProcessDefinitionKey() {
	String tenant1 = "tenant1";
	String tenant2 = "tenant2";
	
	// Tenant 1 ==> version 4
	for (int i=0; i<4; i++) {
		deployTestProcessWithTestTenant(tenant1);
	}
	
	// Tenant 2 ==> version 2
	for (int i=0; i<2; i++) {
		deployTestProcessWithTestTenant(tenant2);
	}
	
	// No tenant ==> version 3
	for (int i=0; i<3; i++) {
		deployTestProcessWithTwoTasksNoTenant();
	}
	
	ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
		.processDefinitionTenantId(tenant1)
		.latestVersion()
		.singleResult();
	assertEquals(4, processDefinition.getVersion());
	
	processDefinition = repositoryService.createProcessDefinitionQuery()
			.processDefinitionTenantId(tenant2)
			.latestVersion()
			.singleResult();
		assertEquals(2, processDefinition.getVersion());
		
		processDefinition = repositoryService.createProcessDefinitionQuery()
				.processDefinitionWithoutTenantId()
				.latestVersion()
				.singleResult();
		assertEquals(3, processDefinition.getVersion());
		
		List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().latestVersion().list();
		assertEquals(3, processDefinitions.size());
		
		// Verify they have different tenant ids
		int tenant1Count = 0, tenant2Count = 0, noTenantCount = 0 ;
		for (ProcessDefinition p : processDefinitions) {
			if (p.getTenantId() == null || p.getTenantId().equals(ProcessEngineConfiguration.NO_TENANT_ID)) {
				noTenantCount++;
			} else if (p.getTenantId().equals(tenant1)) {
				tenant1Count++;
			} else if (p.getTenantId().equals(tenant2)) {
				tenant2Count++;
			}
		}
		assertEquals(1, tenant1Count);
		assertEquals(1, tenant2Count);
		assertEquals(1, noTenantCount);
}