public static ExecutionEntity getCompensatingExecution(EventSubscriptionEntity eventSubscription) { String configuration = eventSubscription.getConfiguration(); if (configuration != null) { return Context.getCommandContext().getExecutionManager().findExecutionById(configuration); } else { return null; } }
public static ExecutionEntity getCompensatingExecution(EventSubscriptionEntity eventSubscription) { String configuration = eventSubscription.getConfiguration(); if (configuration != null) { return Context.getCommandContext().getExecutionManager().findExecutionById(configuration); } else { return null; } }
protected Map<String, ProcessDefinitionEntity> getProcessDefinitionsOfSubscriptions(List<EventSubscriptionEntity> startSignalEventSubscriptions) { DeploymentCache deploymentCache = Context.getProcessEngineConfiguration().getDeploymentCache(); Map<String, ProcessDefinitionEntity> processDefinitions = new HashMap<String, ProcessDefinitionEntity>(); for (EventSubscriptionEntity eventSubscription : startSignalEventSubscriptions) { String processDefinitionId = eventSubscription.getConfiguration(); ensureNotNull("Configuration of signal start event subscription '" + eventSubscription.getId() + "' contains no process definition id.", processDefinitionId); ProcessDefinitionEntity processDefinition = deploymentCache.findDeployedProcessDefinitionById(processDefinitionId); if (processDefinition != null && !processDefinition.isSuspended()) { processDefinitions.put(eventSubscription.getId(), processDefinition); } } return processDefinitions; }
protected Map<String, ProcessDefinitionEntity> getProcessDefinitionsOfSubscriptions(List<EventSubscriptionEntity> startSignalEventSubscriptions) { DeploymentCache deploymentCache = Context.getProcessEngineConfiguration().getDeploymentCache(); Map<String, ProcessDefinitionEntity> processDefinitions = new HashMap<String, ProcessDefinitionEntity>(); for (EventSubscriptionEntity eventSubscription : startSignalEventSubscriptions) { String processDefinitionId = eventSubscription.getConfiguration(); ensureNotNull("Configuration of signal start event subscription '" + eventSubscription.getId() + "' contains no process definition id.", processDefinitionId); ProcessDefinitionEntity processDefinition = deploymentCache.findDeployedProcessDefinitionById(processDefinitionId); if (processDefinition != null && !processDefinition.isSuspended()) { processDefinitions.put(eventSubscription.getId(), processDefinition); } } return processDefinitions; }
public ProcessDefinitionEntity getProcessDefinition() { if (executionId != null) { ExecutionEntity execution = getExecution(); return (ProcessDefinitionEntity) execution.getProcessDefinition(); } else { // this assumes that start event subscriptions have the process definition id // as their configuration (which holds for message and signal start events) String processDefinitionId = getConfiguration(); return Context.getProcessEngineConfiguration() .getDeploymentCache() .findDeployedProcessDefinitionById(processDefinitionId); } }
public ProcessDefinitionEntity getProcessDefinition() { if (executionId != null) { ExecutionEntity execution = getExecution(); return (ProcessDefinitionEntity) execution.getProcessDefinition(); } else { // this assumes that start event subscriptions have the process definition id // as their configuration (which holds for message and signal start events) String processDefinitionId = getConfiguration(); return Context.getProcessEngineConfiguration() .getDeploymentCache() .findDeployedProcessDefinitionById(processDefinitionId); } }
@Override public void handle(MigratingInstanceParseContext parseContext, EventSubscriptionEntity element) { MigratingProcessElementInstance migratingInstance; if (element.getConfiguration() != null) { migratingInstance = createMigratingEventScopeInstance(parseContext, element); } else { migratingInstance = createMigratingEventSubscriptionInstance(parseContext, element); } ExecutionEntity owningExecution = element.getExecution(); MigratingScopeInstance parentInstance = null; if (owningExecution.isEventScope()) { parentInstance = parseContext.getMigratingCompensationInstanceByExecutionId(owningExecution.getId()); } else { parentInstance = parseContext.getMigratingActivityInstanceById(owningExecution.getParentActivityInstanceId()); } migratingInstance.setParent(parentInstance); }
protected void handleStartEvent(EventSubscriptionEntity eventSubscription, Map<String, Object> payload, String businessKey, CommandContext commandContext) { String processDefinitionId = eventSubscription.getConfiguration(); ensureNotNull("Configuration of signal start event subscription '" + eventSubscription.getId() + "' contains no process definition id.", processDefinitionId); DeploymentCache deploymentCache = Context.getProcessEngineConfiguration().getDeploymentCache(); ProcessDefinitionEntity processDefinition = deploymentCache.findDeployedProcessDefinitionById(processDefinitionId); if (processDefinition == null || processDefinition.isSuspended()) { // ignore event subscription LOG.debugIgnoringEventSubscription(eventSubscription, processDefinitionId); } else { ActivityImpl signalStartEvent = processDefinition.findActivity(eventSubscription.getActivityId()); PvmProcessInstance processInstance = processDefinition.createProcessInstance(businessKey, signalStartEvent); processInstance.start(payload); } }
protected void handleStartEvent(EventSubscriptionEntity eventSubscription, Map<String, Object> payload, String businessKey, CommandContext commandContext) { String processDefinitionId = eventSubscription.getConfiguration(); ensureNotNull("Configuration of signal start event subscription '" + eventSubscription.getId() + "' contains no process definition id.", processDefinitionId); DeploymentCache deploymentCache = Context.getProcessEngineConfiguration().getDeploymentCache(); ProcessDefinitionEntity processDefinition = deploymentCache.findDeployedProcessDefinitionById(processDefinitionId); if (processDefinition == null || processDefinition.isSuspended()) { // ignore event subscription LOG.debugIgnoringEventSubscription(eventSubscription, processDefinitionId); } else { ActivityImpl signalStartEvent = processDefinition.findActivity(eventSubscription.getActivityId()); PvmProcessInstance processInstance = processDefinition.createProcessInstance(businessKey, signalStartEvent); processInstance.start(payload); } }
@Test @Deployment(resources = SINGLE_CONDITIONAL_START_EVENT_XML) public void testDeploymentCreatesSubscriptions() { // given a deployed process String processDefinitionId = repositoryService.createProcessDefinitionQuery().processDefinitionKey(CONDITIONAL_EVENT_PROCESS).singleResult().getId(); // when List<EventSubscription> eventSubscriptions = runtimeService.createEventSubscriptionQuery().list(); // then assertEquals(1, eventSubscriptions.size()); EventSubscriptionEntity conditionalEventSubscription = (EventSubscriptionEntity) eventSubscriptions.get(0); assertEquals(EventType.CONDITONAL.name(), conditionalEventSubscription.getEventType()); assertEquals(processDefinitionId, conditionalEventSubscription.getConfiguration()); assertNull(conditionalEventSubscription.getEventName()); assertNull(conditionalEventSubscription.getExecutionId()); assertNull(conditionalEventSubscription.getProcessInstanceId()); }
@Test public void testMixedSubscriptionsWhenDeletingTwoProcessDefinitionsInOneTransaction2() { // given second version without condition String definitionId1 = deployProcess(SINGLE_MESSAGE_START_EVENT_XML); String definitionId2 = deployModel(MODEL_WITHOUT_MESSAGE); String definitionId3 = deployProcess(SINGLE_MESSAGE_START_EVENT_XML); // when repositoryService.deleteProcessDefinitions() .byIds(definitionId2, definitionId3) .delete(); // then assertEquals(1, runtimeService.createEventSubscriptionQuery().count()); assertEquals(definitionId1, ((EventSubscriptionEntity) runtimeService.createEventSubscriptionQuery().singleResult()).getConfiguration()); }
@Test public void testMixedSubscriptionsWhenDeletingTwoProcessDefinitionsInOneTransaction3() { // given third version without condition String definitionId1 = deployProcess(SINGLE_CONDITIONAL_XML); String definitionId2 = deployProcess(SINGLE_CONDITIONAL_XML); String definitionId3 = deployModel(MODEL_WITHOUT_CONDITION); // when repositoryService.deleteProcessDefinitions() .byIds(definitionId2, definitionId3) .delete(); // then assertEquals(1, runtimeService.createEventSubscriptionQuery().count()); assertEquals(definitionId1, ((EventSubscriptionEntity) runtimeService.createEventSubscriptionQuery().singleResult()).getConfiguration()); }
@Test public void testMixedSubscriptionsWhenDeletingTwoProcessDefinitionsInOneTransaction3() { // given third version without condition String definitionId1 = deployProcess(SINGLE_MESSAGE_START_EVENT_XML); String definitionId2 = deployProcess(SINGLE_MESSAGE_START_EVENT_XML); String definitionId3 = deployModel(MODEL_WITHOUT_MESSAGE); // when repositoryService.deleteProcessDefinitions() .byIds(definitionId2, definitionId3) .delete(); // then assertEquals(1, runtimeService.createEventSubscriptionQuery().count()); assertEquals(definitionId1, ((EventSubscriptionEntity) runtimeService.createEventSubscriptionQuery().singleResult()).getConfiguration()); }
@Test public void testMixedSubscriptionsWhenDeletingTwoProcessDefinitionsInOneTransaction2() { // given second version without condition String definitionId1 = deployProcess(SINGLE_CONDITIONAL_XML); String definitionId2 = deployModel(MODEL_WITHOUT_CONDITION); String definitionId3 = deployProcess(SINGLE_CONDITIONAL_XML); // when repositoryService.deleteProcessDefinitions() .byIds(definitionId2, definitionId3) .delete(); // then assertEquals(1, runtimeService.createEventSubscriptionQuery().count()); assertEquals(definitionId1, ((EventSubscriptionEntity) runtimeService.createEventSubscriptionQuery().singleResult()).getConfiguration()); }
/** * Tests the case when the previous of the previous version will be needed. */ @Test public void testSubscribePreviousPreviousVersion() { String definitionId1 = deployProcess(SINGLE_CONDITIONAL_XML); String definitionId2 = deployProcess(SINGLE_CONDITIONAL_XML); String definitionId3 = deployProcess(SINGLE_CONDITIONAL_XML); //we're deleting version 3, but as version 2 is already deleted, we must subscribe version 1 // when repositoryService.deleteProcessDefinitions() .byIds(definitionId2, definitionId3) .delete(); // then assertEquals(1, runtimeService.createEventSubscriptionQuery().count()); assertEquals(definitionId1, ((EventSubscriptionEntity) runtimeService.createEventSubscriptionQuery().singleResult()).getConfiguration()); }
/** * Tests the case, when no new subscription is needed, as it is not the latest version, that is being deleted. */ @Test public void testDeleteNotLatestVersion() { @SuppressWarnings("unused") String definitionId1 = deployProcess(SINGLE_MESSAGE_START_EVENT_XML); String definitionId2 = deployProcess(SINGLE_MESSAGE_START_EVENT_XML); String definitionId3 = deployProcess(SINGLE_MESSAGE_START_EVENT_XML); // when repositoryService.deleteProcessDefinitions() .byIds(definitionId2) .delete(); // then assertEquals(1, runtimeService.createEventSubscriptionQuery().count()); assertEquals(definitionId3, ((EventSubscriptionEntity) runtimeService.createEventSubscriptionQuery().singleResult()).getConfiguration()); }
/** * Tests the case when the previous of the previous version will be needed. */ @Test public void testSubscribePreviousPreviousVersion() { String definitionId1 = deployProcess(SINGLE_MESSAGE_START_EVENT_XML); String definitionId2 = deployProcess(SINGLE_MESSAGE_START_EVENT_XML); String definitionId3 = deployProcess(SINGLE_MESSAGE_START_EVENT_XML); //we're deleting version 3, but as version 2 is already deleted, we must subscribe version 1 // when repositoryService.deleteProcessDefinitions() .byIds(definitionId2, definitionId3) .delete(); // then assertEquals(1, runtimeService.createEventSubscriptionQuery().count()); assertEquals(definitionId1, ((EventSubscriptionEntity) runtimeService.createEventSubscriptionQuery().singleResult()).getConfiguration()); }
/** * Tests the case, when no new subscription is needed, as it is not the latest version, that is being deleted. */ @Test public void testDeleteNotLatestVersion() { @SuppressWarnings("unused") String definitionId1 = deployProcess(SINGLE_CONDITIONAL_XML); String definitionId2 = deployProcess(SINGLE_CONDITIONAL_XML); String definitionId3 = deployProcess(SINGLE_CONDITIONAL_XML); // when repositoryService.deleteProcessDefinitions() .byIds(definitionId2) .delete(); // then assertEquals(1, runtimeService.createEventSubscriptionQuery().count()); assertEquals(definitionId3, ((EventSubscriptionEntity) runtimeService.createEventSubscriptionQuery().singleResult()).getConfiguration()); }
@Test @Deployment(resources = SINGLE_CONDITIONAL_START_EVENT_XML) public void testEventSubscriptionAfterDeleteLatestProcessVersion() { // given a deployed process ProcessDefinition processDefinitionV1 = repositoryService.createProcessDefinitionQuery().singleResult(); assertNotNull(processDefinitionV1); // deploy second version of the process String deploymentId = testRule.deploy(SINGLE_CONDITIONAL_XML).getId(); // when repositoryService.deleteDeployment(deploymentId, true); // then ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey(CONDITIONAL_EVENT_PROCESS).singleResult(); assertEquals(processDefinitionV1.getId(), processDefinition.getId()); EventSubscriptionEntity eventSubscription = (EventSubscriptionEntity) runtimeService.createEventSubscriptionQuery().singleResult(); assertNotNull(eventSubscription); assertEquals(processDefinitionV1.getId(), eventSubscription.getConfiguration()); }
@Test public void testEventSubscriptionAfterDeleteLatestProcessVersion() { // given a deployed process testRule.deploy(SINGLE_MESSAGE_START_EVENT_XML); ProcessDefinition processDefinitionV1 = repositoryService.createProcessDefinitionQuery().singleResult(); assertNotNull(processDefinitionV1); // deploy second version of the process String deploymentId = testRule.deploy(SINGLE_MESSAGE_START_EVENT_XML).getId(); // when repositoryService.deleteDeployment(deploymentId, true); // then ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey(MESSAGE_EVENT_PROCESS).singleResult(); assertEquals(processDefinitionV1.getId(), processDefinition.getId()); EventSubscriptionEntity eventSubscription = (EventSubscriptionEntity) runtimeService.createEventSubscriptionQuery().singleResult(); assertNotNull(eventSubscription); assertEquals(processDefinitionV1.getId(), eventSubscription.getConfiguration()); }