org.flowable.engine.impl.persistence.entity.ExecutionEntity Java Examples

The following examples show how to use org.flowable.engine.impl.persistence.entity.ExecutionEntity. 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: ReceiveEventTaskActivityBehavior.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected String getEventDefinitionKey(CommandContext commandContext, ExecutionEntity executionEntity) {
    Object key = null;

    if (StringUtils.isNotEmpty(eventDefinitionKey)) {
        Expression expression = CommandContextUtil.getProcessEngineConfiguration(commandContext)
            .getExpressionManager()
            .createExpression(eventDefinitionKey);
        key = expression.getValue(executionEntity);
    }

    if (key == null) {
        throw new FlowableException("Could not resolve key for: " + eventDefinitionKey);
    }

    return key.toString();
}
 
Example #2
Source File: SetProcessInstanceBusinessKeyCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public Void execute(CommandContext commandContext) {
    ExecutionEntityManager executionManager = CommandContextUtil.getExecutionEntityManager(commandContext);
    ExecutionEntity processInstance = executionManager.findById(processInstanceId);
    if (processInstance == null) {
        throw new FlowableObjectNotFoundException("No process instance found for id = '" + processInstanceId + "'.", ProcessInstance.class);
    } else if (!processInstance.isProcessInstanceType()) {
        throw new FlowableIllegalArgumentException("A process instance id is required, but the provided id " + "'" + processInstanceId + "' " + "points to a child execution of process instance " + "'"
                + processInstance.getProcessInstanceId() + "'. " + "Please invoke the " + getClass().getSimpleName() + " with a root execution id.");
    }

    if (Flowable5Util.isFlowable5ProcessDefinitionId(commandContext, processInstance.getProcessDefinitionId())) {
        CommandContextUtil.getProcessEngineConfiguration(commandContext).getFlowable5CompatibilityHandler().updateBusinessKey(processInstanceId, businessKey);
        return null;
    }

    executionManager.updateProcessInstanceBusinessKey(processInstance, businessKey);

    return null;
}
 
Example #3
Source File: DestroyScopeOperation.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {

    // Find the actual scope that needs to be destroyed.
    // This could be the incoming execution, or the first parent execution where isScope = true

    // Find parent scope execution
    ExecutionEntity scopeExecution = execution.isScope() ? execution : findFirstParentScopeExecution(execution);

    if (scopeExecution == null) {
        throw new FlowableException("Programmatic error: no parent scope execution found for boundary event");
    }

    ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager(commandContext);

    // Delete all child executions
    executionEntityManager.deleteChildExecutions(scopeExecution, execution.getDeleteReason(), true);
    executionEntityManager.deleteExecutionAndRelatedData(scopeExecution, execution.getDeleteReason(), false, true, null);

    if (scopeExecution.isActive()) {
        CommandContextUtil.getActivityInstanceEntityManager(commandContext).recordActivityEnd(scopeExecution, scopeExecution.getDeleteReason());
    }
    executionEntityManager.delete(scopeExecution);
}
 
Example #4
Source File: NeedsActiveExecutionCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public T execute(CommandContext commandContext) {
    if (executionId == null) {
        throw new FlowableIllegalArgumentException("executionId is null");
    }

    ExecutionEntity execution = CommandContextUtil.getExecutionEntityManager(commandContext).findById(executionId);

    if (execution == null) {
        throw new FlowableObjectNotFoundException("execution " + executionId + " doesn't exist", Execution.class);
    }

    if (execution.isSuspended()) {
        throw new FlowableException(getSuspendedExceptionMessage());
    }

    return execute(commandContext, execution);
}
 
Example #5
Source File: MultiInstanceActivityBehavior.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void executeCompensationBoundaryEvents(FlowElement flowElement, DelegateExecution execution) {

        // Execute compensation boundary events
        Collection<BoundaryEvent> boundaryEvents = findBoundaryEventsForFlowNode(execution.getProcessDefinitionId(), flowElement);
        if (CollectionUtil.isNotEmpty(boundaryEvents)) {

            // The parent execution becomes a scope, and a child execution is created for each of the boundary events
            for (BoundaryEvent boundaryEvent : boundaryEvents) {

                if (CollectionUtil.isEmpty(boundaryEvent.getEventDefinitions())) {
                    continue;
                }

                if (boundaryEvent.getEventDefinitions().get(0) instanceof CompensateEventDefinition) {
                    ExecutionEntity childExecutionEntity = CommandContextUtil.getExecutionEntityManager()
                            .createChildExecution((ExecutionEntity) execution);
                    childExecutionEntity.setParentId(execution.getId());
                    childExecutionEntity.setCurrentFlowElement(boundaryEvent);
                    childExecutionEntity.setScope(false);

                    ActivityBehavior boundaryEventBehavior = ((ActivityBehavior) boundaryEvent.getBehavior());
                    boundaryEventBehavior.execute(childExecutionEntity);
                }
            }
        }
    }
 
Example #6
Source File: FlowableUserRequestHandler.java    From syncope with Apache License 2.0 6 votes vote down vote up
protected StringBuilder createProcessInstanceQuery(final String userKey) {
    StringBuilder query = new StringBuilder().
            append("SELECT DISTINCT ID_,BUSINESS_KEY_,PROC_DEF_ID_,PROC_INST_ID_,START_TIME_ FROM ").
            append(engine.getManagementService().getTableName(ExecutionEntity.class)).
            append(" WHERE BUSINESS_KEY_ NOT LIKE '").
            append(FlowableRuntimeUtils.getProcBusinessKey(FlowableRuntimeUtils.WF_PROCESS_ID, "%")).
            append('\'');
    if (userKey != null) {
        query.append(" AND BUSINESS_KEY_ LIKE '").
                append(FlowableRuntimeUtils.getProcBusinessKey("%", userKey)).
                append('\'');
    }
    query.append(" AND PARENT_ID_ IS NULL");

    return query;
}
 
Example #7
Source File: CallActivityTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void onEvent(FlowableEvent event) {
    FlowableEngineEventType engineEventType = (FlowableEngineEventType) event.getType();
    switch (engineEventType) {
        case ENTITY_CREATED:
            FlowableEntityEvent entityEvent = (FlowableEntityEvent) event;
            if (entityEvent.getEntity() instanceof ExecutionEntity) {
                eventsReceived.add(event);
            }
            break;
        case ACTIVITY_STARTED:
        case ACTIVITY_COMPLETED:
        case ACTIVITY_CANCELLED:
        case TASK_CREATED:
        case TASK_COMPLETED:
        case PROCESS_STARTED:
        case PROCESS_COMPLETED:
        case PROCESS_CANCELLED:
        case PROCESS_COMPLETED_WITH_TERMINATE_END_EVENT:
            eventsReceived.add(event);
            break;
        default:
            break;

    }
}
 
Example #8
Source File: TerminateEndEventActivityBehavior.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {

    CommandContext commandContext = Context.getCommandContext();
    ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager(commandContext);
    
    // The current execution always stops here
    ExecutionEntity executionEntity = (ExecutionEntity) execution;
    executionEntityManager.deleteExecutionAndRelatedData(executionEntity, createDeleteReason(executionEntity.getCurrentActivityId()), false);
    
    if (terminateAll) {
        terminateAllBehaviour(executionEntity, commandContext, executionEntityManager);
    } else if (terminateMultiInstance) {
        terminateMultiInstanceRoot(executionEntity, commandContext, executionEntityManager);
    } else {
        defaultTerminateEndEventBehaviour(executionEntity, commandContext, executionEntityManager);
    }
}
 
Example #9
Source File: ExternalWorkerTaskCompleteJobHandler.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
    ExecutionEntity executionEntity = (ExecutionEntity) variableScope;

    VariableService variableService = CommandContextUtil.getVariableService(commandContext);
    List<VariableInstanceEntity> jobVariables = variableService.findVariableInstanceBySubScopeIdAndScopeType(executionEntity.getId(), ScopeTypes.BPMN_EXTERNAL_WORKER);
    for (VariableInstanceEntity jobVariable : jobVariables) {
        executionEntity.setVariable(jobVariable.getName(), jobVariable.getValue());
        CountingEntityUtil.handleDeleteVariableInstanceEntityCount(jobVariable, false);
        variableService.deleteVariableInstance(jobVariable);
    }

    if (configuration != null && configuration.startsWith("error:")) {
        String errorCode;
        if (configuration.length() > 6) {
            errorCode = configuration.substring(6);
        } else {
            errorCode = null;
        }
        ErrorPropagation.propagateError(errorCode, executionEntity);
    } else {
        CommandContextUtil.getAgenda(commandContext).planTriggerExecutionOperation(executionEntity);
    }
}
 
Example #10
Source File: DefaultHistoryManager.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void updateProcessBusinessKeyInHistory(ExecutionEntity processInstance) {
    if (processInstance != null) {
        if (isHistoryEnabled(processInstance.getProcessDefinitionId())) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("updateProcessBusinessKeyInHistory : {}", processInstance.getId());
            }
            
            HistoricProcessInstanceEntity historicProcessInstance = getHistoricProcessInstanceEntityManager().findById(processInstance.getId());
            if (historicProcessInstance != null) {
                historicProcessInstance.setBusinessKey(processInstance.getProcessInstanceBusinessKey());
                getHistoricProcessInstanceEntityManager().update(historicProcessInstance, false);
            }
        }
    }
}
 
Example #11
Source File: InjectParallelUserTaskCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
protected void updateExecutions(CommandContext commandContext, ProcessDefinitionEntity processDefinitionEntity, 
        ExecutionEntity processInstance, List<ExecutionEntity> childExecutions) {
    
    TaskEntity taskEntity = CommandContextUtil.getTaskService().getTask(taskId);
    
    ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager(commandContext);
    ExecutionEntity executionAtTask = executionEntityManager.findById(taskEntity.getExecutionId());

    BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(processDefinitionEntity.getId());
    FlowElement taskElement = bpmnModel.getFlowElement(executionAtTask.getCurrentActivityId());
    FlowElement subProcessElement = bpmnModel.getFlowElement(((SubProcess) taskElement.getParentContainer()).getId());
    ExecutionEntity subProcessExecution = executionEntityManager.createChildExecution(executionAtTask.getParent());
    subProcessExecution.setScope(true);
    subProcessExecution.setCurrentFlowElement(subProcessElement);
    CommandContextUtil.getActivityInstanceEntityManager(commandContext).recordActivityStart(subProcessExecution);
    
    executionAtTask.setParent(subProcessExecution);
    
    ExecutionEntity taskExecution = executionEntityManager.createChildExecution(subProcessExecution);

    FlowElement userTaskElement = bpmnModel.getFlowElement(dynamicUserTaskBuilder.getDynamicTaskId());
    taskExecution.setCurrentFlowElement(userTaskElement);
    
    Context.getAgenda().planContinueProcessOperation(taskExecution);
}
 
Example #12
Source File: HasExecutionVariableCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public Boolean execute(CommandContext commandContext) {
    if (executionId == null) {
        throw new FlowableIllegalArgumentException("executionId is null");
    }
    if (variableName == null) {
        throw new FlowableIllegalArgumentException("variableName is null");
    }

    ExecutionEntity execution = CommandContextUtil.getExecutionEntityManager(commandContext).findById(executionId);

    if (execution == null) {
        throw new FlowableObjectNotFoundException("execution " + executionId + " doesn't exist", Execution.class);
    }

    boolean hasVariable = false;

    if (isLocal) {
        hasVariable = execution.hasVariableLocal(variableName);
    } else {
        hasVariable = execution.hasVariable(variableName);
    }

    return hasVariable;
}
 
Example #13
Source File: TaskHelper.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public static void deleteTasksByProcessInstanceId(String processInstanceId, String deleteReason, boolean cascade) {
    List<TaskEntity> tasks = CommandContextUtil.getTaskService().findTasksByProcessInstanceId(processInstanceId);

    for (TaskEntity task : tasks) {
        FlowableEventDispatcher eventDispatcher = CommandContextUtil.getEventDispatcher();
        if (eventDispatcher != null && eventDispatcher.isEnabled() && !task.isCanceled()) {
            task.setCanceled(true);

            ExecutionEntity execution = CommandContextUtil.getExecutionEntityManager().findById(task.getExecutionId());
            eventDispatcher
                    .dispatchEvent(org.flowable.engine.delegate.event.impl.FlowableEventBuilder
                            .createActivityCancelledEvent(execution.getActivityId(), task.getName(),
                                    task.getExecutionId(), task.getProcessInstanceId(),
                                    task.getProcessDefinitionId(), "userTask", deleteReason));
        }

        deleteTask(task, deleteReason, cascade, true, true);
    }
}
 
Example #14
Source File: CompositeHistoryManagerTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
void recordFormPropertiesSubmitted() {
    ExecutionEntity processInstance = new ExecutionEntityImpl();
    Map<String, String> properties = new HashMap<>();
    properties.put("key", "value");
    Date createTime = Date.from(Instant.now().plusSeconds(3));
    compositeHistoryManager.recordFormPropertiesSubmitted(processInstance, properties, "task-1", createTime);

    verify(historyManager1).recordFormPropertiesSubmitted(same(processInstance), eq(properties), eq("task-1"), eq(createTime));
    verify(historyManager2).recordFormPropertiesSubmitted(same(processInstance), eq(properties), eq("task-1"), eq(createTime));
}
 
Example #15
Source File: MybatisExecutionDataManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public List<ExecutionEntity> findExecutionsByProcessInstanceId(final String processInstanceId) {
    if (isExecutionTreeFetched(processInstanceId)) {
        return getListFromCache(executionByProcessInstanceMatcher, processInstanceId);
    } else {
        return getList("selectExecutionsByProcessInstanceId", processInstanceId, executionByProcessInstanceMatcher, true);
    }
}
 
Example #16
Source File: DefaultIdentityLinkInterceptor.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void handleCreateProcessInstance(ExecutionEntity processInstanceExecution) {
    String authenticatedUserId = Authentication.getAuthenticatedUserId();
    if (authenticatedUserId != null) {
        IdentityLinkUtil.createProcessInstanceIdentityLink(processInstanceExecution, authenticatedUserId, null, IdentityLinkType.STARTER);
    }
}
 
Example #17
Source File: DeleteMultiInstanceExecutionCmd.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected ExecutionEntity getMultiInstanceRootExecution(ExecutionEntity executionEntity) {
    ExecutionEntity multiInstanceRootExecution = null;
    ExecutionEntity currentExecution = executionEntity;
    while (currentExecution != null && multiInstanceRootExecution == null && currentExecution.getParent() != null) {
        if (currentExecution.isMultiInstanceRoot()) {
            multiInstanceRootExecution = currentExecution;
        } else {
            currentExecution = currentExecution.getParent();
        }
    }
    return multiInstanceRootExecution;
}
 
Example #18
Source File: ProcessInstanceMigrationTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = { TEST_PROCESS_WITH_PARALLEL_GATEWAY })
public void testSetProcessDefinitionVersionSubExecutions() {
    // start process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("forkJoin");

    // check that the user tasks have been reached
    assertThat(taskService.createTaskQuery().count()).isEqualTo(2);

    // deploy new version of the process definition
    org.flowable.engine.repository.Deployment deployment = repositoryService.createDeployment().addClasspathResource(TEST_PROCESS_WITH_PARALLEL_GATEWAY).deploy();
    assertThat(repositoryService.createProcessDefinitionQuery().count()).isEqualTo(2);

    // migrate process instance to new process definition version
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
    commandExecutor.execute(new SetProcessDefinitionVersionCmd(pi.getId(), 2));

    // check that all executions of the instance now use the new process
    // definition version
    ProcessDefinition newProcessDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionVersion(2).singleResult();
    List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(pi.getId()).list();
    for (Execution execution : executions) {
        assertThat(((ExecutionEntity) execution).getProcessDefinitionId()).isEqualTo(newProcessDefinition.getId());
    }

    // undeploy "manually" deployed process definition
    repositoryService.deleteDeployment(deployment.getId(), true);
}
 
Example #19
Source File: CreateAttachmentCmd.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected ExecutionEntity verifyExecutionParameters(CommandContext commandContext) {
    ExecutionEntity execution = CommandContextUtil.getExecutionEntityManager(commandContext).findById(processInstanceId);

    if (execution == null) {
        throw new FlowableObjectNotFoundException("Process instance " + processInstanceId + " doesn't exist", ProcessInstance.class);
    }

    if (execution.isSuspended()) {
        throw new FlowableException("It is not allowed to add an attachment to a suspended process instance");
    }

    return execution;
}
 
Example #20
Source File: TakeOutgoingSequenceFlowsOperation.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void cleanupExecutions(FlowElement currentFlowElement) {
    if (execution.getParentId() != null && execution.isScope()) {

        // If the execution is a scope (and not a process instance), the scope must first be
        // destroyed before we can continue and follow the sequence flow

        agenda.planDestroyScopeOperation(execution);

    } else if (currentFlowElement instanceof Activity) {

        // If the current activity is an activity, we need to remove any currently active boundary events

        Activity activity = (Activity) currentFlowElement;
        if (CollectionUtil.isNotEmpty(activity.getBoundaryEvents())) {

            // Cancel events are not removed
            List<String> notToDeleteEvents = new ArrayList<>();
            for (BoundaryEvent event : activity.getBoundaryEvents()) {
                if (CollectionUtil.isNotEmpty(event.getEventDefinitions()) &&
                        event.getEventDefinitions().get(0) instanceof CancelEventDefinition) {
                    
                    notToDeleteEvents.add(event.getId());
                }
            }

            // Delete all child executions
            Collection<ExecutionEntity> childExecutions = CommandContextUtil.getExecutionEntityManager(commandContext).findChildExecutionsByParentExecutionId(execution.getId());
            for (ExecutionEntity childExecution : childExecutions) {
                if (childExecution.getCurrentFlowElement() == null || !notToDeleteEvents.contains(childExecution.getCurrentFlowElement().getId())) {
                    CommandContextUtil.getExecutionEntityManager(commandContext).deleteExecutionAndRelatedData(childExecution, null, false);
                }
            }
        }
    }
}
 
Example #21
Source File: InclusiveGatewayTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected List<Execution> getInactiveExecutionsInActivityId(String activityId) {
    List<Execution> result = new ArrayList<>();
    List<Execution> executions = runtimeService.createExecutionQuery().list();
    Iterator<Execution> iterator = executions.iterator();
    while (iterator.hasNext()) {
        Execution execution = iterator.next();
        if (execution.getActivityId() != null
                && execution.getActivityId().equals(activityId)
                && !((ExecutionEntity) execution).isActive()) {
            result.add(execution);
        }
    }
    return result;
}
 
Example #22
Source File: BoundaryConditionalEventActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
    CommandContext commandContext = Context.getCommandContext();
    ExecutionEntity executionEntity = (ExecutionEntity) execution;

    FlowableEventDispatcher eventDispatcher = CommandContextUtil.getProcessEngineConfiguration(commandContext).getEventDispatcher();
    if (eventDispatcher != null && eventDispatcher.isEnabled()) {
        eventDispatcher.dispatchEvent(FlowableEventBuilder.createConditionalEvent(FlowableEngineEventType.ACTIVITY_CONDITIONAL_WAITING, executionEntity.getActivityId(), 
                        conditionExpression, executionEntity.getId(), executionEntity.getProcessInstanceId(), executionEntity.getProcessDefinitionId()));
    }
}
 
Example #23
Source File: FindActiveActivityIdsCmd.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void collectActiveActivityIds(ExecutionEntity executionEntity, List<String> activeActivityIds) {
    if (executionEntity.isActive() && executionEntity.getActivityId() != null) {
        activeActivityIds.add(executionEntity.getActivityId());
    }

    for (ExecutionEntity childExecution : executionEntity.getExecutions()) {
        collectActiveActivityIds(childExecution, activeActivityIds);
    }
}
 
Example #24
Source File: CorrelationUtil.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public static String getCorrelationKey(String elementName, CommandContext commandContext, FlowElement flowElement, ExecutionEntity executionEntity) {
    String correlationKey = null;
    if (flowElement != null) {
        List<ExtensionElement> eventCorrelations = flowElement.getExtensionElements().get(elementName);
        if (eventCorrelations != null && !eventCorrelations.isEmpty()) {
            ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
            ExpressionManager expressionManager = processEngineConfiguration.getExpressionManager();

            Map<String, Object> correlationParameters = new HashMap<>();
            for (ExtensionElement eventCorrelation : eventCorrelations) {
                String name = eventCorrelation.getAttributeValue(null, "name");
                String valueExpression = eventCorrelation.getAttributeValue(null, "value");
                if (StringUtils.isNotEmpty(valueExpression)) {
                    if (executionEntity != null) {
                        Object value = expressionManager.createExpression(valueExpression).getValue(executionEntity);
                        correlationParameters.put(name, value);
                    } else {
                        correlationParameters.put(name, valueExpression);
                    }
                    
                } else {
                    correlationParameters.put(name, null);
                }
            }

            correlationKey = CommandContextUtil.getEventRegistry().generateKey(correlationParameters);
        }
    }
    
    return correlationKey;
}
 
Example #25
Source File: AddMultiInstanceExecutionCmd.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public Execution execute(CommandContext commandContext) {
    ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager();
    
    ExecutionEntity miExecution = searchForMultiInstanceActivity(activityId, parentExecutionId, executionEntityManager);
    
    if (miExecution == null) {
        throw new FlowableException("No multi instance execution found for activity id " + activityId);
    }
    
    if (Flowable5Util.isFlowable5ProcessDefinitionId(commandContext, miExecution.getProcessDefinitionId())) {
        throw new FlowableException("Flowable 5 process definitions are not supported");
    }
    
    ExecutionEntity childExecution = executionEntityManager.createChildExecution(miExecution);
    childExecution.setCurrentFlowElement(miExecution.getCurrentFlowElement());
    
    BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(miExecution.getProcessDefinitionId());
    Activity miActivityElement = (Activity) bpmnModel.getFlowElement(miExecution.getActivityId());
    MultiInstanceLoopCharacteristics multiInstanceLoopCharacteristics = miActivityElement.getLoopCharacteristics();
    
    Integer currentNumberOfInstances = (Integer) miExecution.getVariable(NUMBER_OF_INSTANCES);
    miExecution.setVariableLocal(NUMBER_OF_INSTANCES, currentNumberOfInstances + 1);
    
    if (executionVariables != null) {
        childExecution.setVariablesLocal(executionVariables);
    }
    
    if (!multiInstanceLoopCharacteristics.isSequential()) {
        miExecution.setActive(true);
        miExecution.setScope(false);
        
        childExecution.setCurrentFlowElement(miActivityElement);
        CommandContextUtil.getAgenda().planContinueMultiInstanceOperation(childExecution, miExecution, currentNumberOfInstances);
    }
    
    return childExecution;
}
 
Example #26
Source File: SequentialMultiInstanceBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Called when the wrapped {@link ActivityBehavior} calls the {@link AbstractBpmnActivityBehavior#leave(DelegateExecution)} method. Handles the completion of one instance, and executes the logic
 * for the sequential behavior.
 */
@Override
public void leave(DelegateExecution execution) {
    DelegateExecution multiInstanceRootExecution = getMultiInstanceRootExecution(execution);
    int loopCounter = getLoopVariable(execution, getCollectionElementIndexVariable()) + 1;
    int nrOfInstances = getLoopVariable(multiInstanceRootExecution, NUMBER_OF_INSTANCES);
    int nrOfCompletedInstances = getLoopVariable(multiInstanceRootExecution, NUMBER_OF_COMPLETED_INSTANCES) + 1;
    int nrOfActiveInstances = getLoopVariable(multiInstanceRootExecution, NUMBER_OF_ACTIVE_INSTANCES);

    setLoopVariable(multiInstanceRootExecution, NUMBER_OF_COMPLETED_INSTANCES, nrOfCompletedInstances);
    logLoopDetails(execution, "instance completed", loopCounter, nrOfCompletedInstances, nrOfActiveInstances, nrOfInstances);

    callActivityEndListeners(execution);

    boolean completeConditionSatisfied = completionConditionSatisfied(multiInstanceRootExecution);
    if (loopCounter >= nrOfInstances || completeConditionSatisfied) {
        if(completeConditionSatisfied) {
            sendCompletedWithConditionEvent(multiInstanceRootExecution);
        }
        else {
            sendCompletedEvent(multiInstanceRootExecution);
        }

        super.leave(execution);
    } else {
        continueSequentialMultiInstance(execution, loopCounter, (ExecutionEntity) multiInstanceRootExecution);
    }
}
 
Example #27
Source File: ContinueProcessOperation.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public ContinueProcessOperation(CommandContext commandContext, ExecutionEntity execution,
        boolean forceSynchronousOperation, boolean inCompensation, MigrationContext migrationContext) {

    super(commandContext, execution);
    this.forceSynchronousOperation = forceSynchronousOperation;
    this.inCompensation = inCompensation;
    this.migrationContext = migrationContext;
}
 
Example #28
Source File: ContinueProcessOperation.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected List<ExecutionEntity> createBoundaryEvents(List<BoundaryEvent> boundaryEvents, ExecutionEntity execution) {

        List<ExecutionEntity> boundaryEventExecutions = new ArrayList<>(boundaryEvents.size());

        // The parent execution becomes a scope, and a child execution is created for each of the boundary events
        for (BoundaryEvent boundaryEvent : boundaryEvents) {

            if (!(boundaryEvent.getBehavior() instanceof BoundaryEventRegistryEventActivityBehavior)) {
                if (CollectionUtil.isEmpty(boundaryEvent.getEventDefinitions())
                        || (boundaryEvent.getEventDefinitions().get(0) instanceof CompensateEventDefinition)) {
                    continue;
                }
            }

            // A Child execution of the current execution is created to represent the boundary event being active
            ExecutionEntity childExecutionEntity = CommandContextUtil.getExecutionEntityManager(commandContext).createChildExecution(execution);
            childExecutionEntity.setParentId(execution.getId());
            childExecutionEntity.setCurrentFlowElement(boundaryEvent);
            childExecutionEntity.setScope(false);
            boundaryEventExecutions.add(childExecutionEntity);
            
            CommandContextUtil.getActivityInstanceEntityManager(commandContext).recordActivityStart(childExecutionEntity);
            
            ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
            if (processEngineConfiguration.isLoggingSessionEnabled()) {
                BpmnLoggingSessionUtil.addLoggingData(BpmnLoggingSessionUtil.getBoundaryCreateEventType(boundaryEvent), 
                                "Creating boundary event (" + BpmnLoggingSessionUtil.getBoundaryEventType(boundaryEvent) + 
                                ") for execution id " + childExecutionEntity.getId(), childExecutionEntity);
            }
        }

        return boundaryEventExecutions;
    }
 
Example #29
Source File: IntermediateCatchTimerEventActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
    // end date should be ignored for intermediate timer events.
    FlowElement currentFlowElement = execution.getCurrentFlowElement();
    TimerJobEntity timerJob = TimerUtil.createTimerEntityForTimerEventDefinition(timerEventDefinition, currentFlowElement,
            false, (ExecutionEntity) execution, TriggerTimerEventJobHandler.TYPE,
            TimerEventHandler.createConfiguration(execution.getCurrentActivityId(), null, timerEventDefinition.getCalendarName()));

    if (timerJob != null) {
        CommandContextUtil.getTimerJobService().scheduleTimerJob(timerJob);
    }
}
 
Example #30
Source File: MybatisExecutionDataManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public List<ExecutionEntity> findExecutionsByQueryCriteria(ExecutionQueryImpl executionQuery) {
    // False -> executions should not be cached if using executionTreeFetching
    boolean useCache = !performanceSettings.isEnableEagerExecutionTreeFetching();
    if (useCache) {
        return getDbSqlSession().selectList("selectExecutionsByQueryCriteria", executionQuery, getManagedEntityClass());
    } else {
        return getDbSqlSession().selectListNoCacheLoadAndStore("selectExecutionsByQueryCriteria", executionQuery);
    }
}