Search in sources :

Example 11 with ActivityImpl

use of org.camunda.bpm.engine.impl.pvm.process.ActivityImpl in project camunda-bpm-platform by camunda.

the class AbstractBpmnActivityBehavior method doLeave.

/**
 * Subclasses that call leave() will first pass through this method, before
 * the regular {@link FlowNodeActivityBehavior#leave(ActivityExecution)} is
 * called.
 */
@Override
public void doLeave(ActivityExecution execution) {
    PvmActivity currentActivity = execution.getActivity();
    ActivityImpl compensationHandler = ((ActivityImpl) currentActivity).findCompensationHandler();
    // subscription for compensation event subprocess is already created
    if (compensationHandler != null && !isCompensationEventSubprocess(compensationHandler)) {
        createCompensateEventSubscription(execution, compensationHandler);
    }
    super.doLeave(execution);
}
Also used : ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity)

Example 12 with ActivityImpl

use of org.camunda.bpm.engine.impl.pvm.process.ActivityImpl in project camunda-bpm-platform by camunda.

the class SignalEventReceivedCmd method startProcessInstances.

private void startProcessInstances(List<EventSubscriptionEntity> startSignalEventSubscriptions, Map<String, ProcessDefinitionEntity> processDefinitions) {
    for (EventSubscriptionEntity signalStartEventSubscription : startSignalEventSubscriptions) {
        ProcessDefinitionEntity processDefinition = processDefinitions.get(signalStartEventSubscription.getId());
        if (processDefinition != null) {
            ActivityImpl signalStartEvent = processDefinition.findActivity(signalStartEventSubscription.getActivityId());
            PvmProcessInstance processInstance = processDefinition.createProcessInstanceForInitial(signalStartEvent);
            processInstance.start(builder.getVariables());
        }
    }
}
Also used : PvmProcessInstance(org.camunda.bpm.engine.impl.pvm.PvmProcessInstance) ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 13 with ActivityImpl

use of org.camunda.bpm.engine.impl.pvm.process.ActivityImpl in project camunda-bpm-platform by camunda.

the class StartProcessInstanceAtActivitiesCmd method determineFirstActivity.

/**
 * get the activity that is started by the first instruction, if exists;
 * return null if the first instruction is a start-transition instruction
 */
protected ActivityImpl determineFirstActivity(ProcessDefinitionImpl processDefinition, ProcessInstanceModificationBuilderImpl modificationBuilder) {
    AbstractProcessInstanceModificationCommand firstInstruction = modificationBuilder.getModificationOperations().get(0);
    if (firstInstruction instanceof AbstractInstantiationCmd) {
        AbstractInstantiationCmd instantiationInstruction = (AbstractInstantiationCmd) firstInstruction;
        CoreModelElement targetElement = instantiationInstruction.getTargetElement(processDefinition);
        ensureNotNull(NotValidException.class, "Element '" + instantiationInstruction.getTargetElementId() + "' does not exist in process " + processDefinition.getId(), "targetElement", targetElement);
        if (targetElement instanceof ActivityImpl) {
            return (ActivityImpl) targetElement;
        } else if (targetElement instanceof TransitionImpl) {
            return (ActivityImpl) ((TransitionImpl) targetElement).getDestination();
        }
    }
    return null;
}
Also used : TransitionImpl(org.camunda.bpm.engine.impl.pvm.process.TransitionImpl) ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) CoreModelElement(org.camunda.bpm.engine.impl.core.model.CoreModelElement)

Example 14 with ActivityImpl

use of org.camunda.bpm.engine.impl.pvm.process.ActivityImpl in project camunda-bpm-platform by camunda.

the class ConditionalEventHandler method handleEvent.

@Override
public void handleEvent(EventSubscriptionEntity eventSubscription, Object payload, String businessKey, CommandContext commandContext) {
    VariableEvent variableEvent;
    if (payload == null || payload instanceof VariableEvent) {
        variableEvent = (VariableEvent) payload;
    } else {
        throw new ProcessEngineException("Payload have to be " + VariableEvent.class.getName() + ", to evaluate condition.");
    }
    ActivityImpl activity = eventSubscription.getActivity();
    ActivityBehavior activityBehavior = activity.getActivityBehavior();
    if (activityBehavior instanceof ConditionalEventBehavior) {
        ConditionalEventBehavior conditionalBehavior = (ConditionalEventBehavior) activityBehavior;
        conditionalBehavior.leaveOnSatisfiedCondition(eventSubscription, variableEvent);
    } else {
        throw new ProcessEngineException("Conditional Event has not correct behavior: " + activityBehavior);
    }
}
Also used : VariableEvent(org.camunda.bpm.engine.impl.core.variable.event.VariableEvent) ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) ActivityBehavior(org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior) ConditionalEventBehavior(org.camunda.bpm.engine.impl.bpmn.behavior.ConditionalEventBehavior) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 15 with ActivityImpl

use of org.camunda.bpm.engine.impl.pvm.process.ActivityImpl in project camunda-bpm-platform by camunda.

the class CompensationEventHandler method handleEvent.

@Override
public void handleEvent(EventSubscriptionEntity eventSubscription, Object payload, String businessKey, CommandContext commandContext) {
    eventSubscription.delete();
    String configuration = eventSubscription.getConfiguration();
    ensureNotNull("Compensating execution not set for compensate event subscription with id " + eventSubscription.getId(), "configuration", configuration);
    ExecutionEntity compensatingExecution = commandContext.getExecutionManager().findExecutionById(configuration);
    ActivityImpl compensationHandler = eventSubscription.getActivity();
    // activate execution
    compensatingExecution.setActive(true);
    if (compensatingExecution.getActivity().getActivityBehavior() instanceof CompositeActivityBehavior) {
        compensatingExecution.getParent().setActivityInstanceId(compensatingExecution.getActivityInstanceId());
    }
    if (compensationHandler.isScope() && !compensationHandler.isCompensationHandler()) {
        // descend into scope:
        List<EventSubscriptionEntity> eventsForThisScope = compensatingExecution.getCompensateEventSubscriptions();
        CompensationUtil.throwCompensationEvent(eventsForThisScope, compensatingExecution, false);
    } else {
        try {
            if (compensationHandler.isSubProcessScope() && compensationHandler.isTriggeredByEvent()) {
                compensatingExecution.executeActivity(compensationHandler);
            } else {
                // since we already have a scope execution, we don't need to create another one
                // for a simple scoped compensation handler
                compensatingExecution.setActivity(compensationHandler);
                compensatingExecution.performOperation(PvmAtomicOperation.ACTIVITY_START);
            }
        } catch (Exception e) {
            throw new ProcessEngineException("Error while handling compensation event " + eventSubscription, e);
        }
    }
}
Also used : ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) CompositeActivityBehavior(org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Aggregations

ActivityImpl (org.camunda.bpm.engine.impl.pvm.process.ActivityImpl)94 Deployment (org.camunda.bpm.engine.test.Deployment)29 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)12 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)12 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)10 ScopeImpl (org.camunda.bpm.engine.impl.pvm.process.ScopeImpl)10 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)8 TransitionImpl (org.camunda.bpm.engine.impl.pvm.process.TransitionImpl)8 EventSubscriptionEntity (org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)7 PvmExecutionImpl (org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl)7 MigrationInstruction (org.camunda.bpm.engine.migration.MigrationInstruction)5 ActivityBehavior (org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior)4 ArrayList (java.util.ArrayList)3 DeploymentCache (org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache)3 PvmTransition (org.camunda.bpm.engine.impl.pvm.PvmTransition)3 ConditionalEventBehavior (org.camunda.bpm.engine.impl.bpmn.behavior.ConditionalEventBehavior)2 MultiInstanceActivityBehavior (org.camunda.bpm.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior)2 SequentialMultiInstanceActivityBehavior (org.camunda.bpm.engine.impl.bpmn.behavior.SequentialMultiInstanceActivityBehavior)2 CoreModelElement (org.camunda.bpm.engine.impl.core.model.CoreModelElement)2 AsyncContinuationConfiguration (org.camunda.bpm.engine.impl.jobexecutor.AsyncContinuationJobHandler.AsyncContinuationConfiguration)2