org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution Java Examples

The following examples show how to use org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution. 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: EventScopeCreatingSubprocess.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void complete(ActivityExecution execution) {

    ActivityExecution outgoingExecution = execution.getParent().createExecution();
    outgoingExecution.setConcurrent(false);
    outgoingExecution.setActivity(execution.getActivity());

    // eventscope execution
    execution.setConcurrent(false);
    execution.setActive(false);
    ((PvmExecutionImpl)execution).setEventScope(true);

    List<PvmTransition> outgoingTransitions = execution.getActivity().getOutgoingTransitions();
    if(outgoingTransitions.isEmpty()) {
      outgoingExecution.end(true);
    }else {
      outgoingExecution.leaveActivityViaTransitions(outgoingTransitions, Collections.EMPTY_LIST);
    }
  }
 
Example #2
Source File: EventBasedGatewayActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(ActivityExecution execution) throws Exception {
  // If conditional events exist after the event based gateway they should be evaluated.
  // If a condition is satisfied the event based gateway should be left,
  // otherwise the event based gateway is a wait state
  ActivityImpl eventBasedGateway = (ActivityImpl) execution.getActivity();
  for (ActivityImpl act : eventBasedGateway.getEventActivities()) {
    ActivityBehavior activityBehavior = act.getActivityBehavior();
    if (activityBehavior instanceof ConditionalEventBehavior) {
      ConditionalEventBehavior conditionalEventBehavior = (ConditionalEventBehavior) activityBehavior;
      ConditionalEventDefinition conditionalEventDefinition = conditionalEventBehavior.getConditionalEventDefinition();
      if (conditionalEventDefinition.tryEvaluate(execution)) {
        ((ExecutionEntity) execution).executeEventHandlerActivity(conditionalEventDefinition.getConditionalActivity());
        return;
      }
    }
  }
}
 
Example #3
Source File: While.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void execute(ActivityExecution execution) throws Exception {
  PvmTransition more = execution.getActivity().findOutgoingTransition("more");
  PvmTransition done = execution.getActivity().findOutgoingTransition("done");

  Integer value = (Integer) execution.getVariable(variableName);

  if (value==null) {
    execution.setVariable(variableName, from);
    execution.leaveActivityViaTransition(more);

  } else {
    value = value+1;

    if (value<to) {
      execution.setVariable(variableName, value);
      execution.leaveActivityViaTransition(more);

    } else {
      execution.leaveActivityViaTransition(done);
    }
  }
}
 
Example #4
Source File: InclusiveGatewayActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected boolean activatesGateway(ActivityExecution execution, PvmActivity gatewayActivity) {
  int numExecutionsGuaranteedToActivate = gatewayActivity.getIncomingTransitions().size();
  ActivityExecution scopeExecution = execution.isScope() ? execution : execution.getParent();

  List<ActivityExecution> executionsAtGateway = execution.findInactiveConcurrentExecutions(gatewayActivity);

  if (executionsAtGateway.size() >= numExecutionsGuaranteedToActivate) {
    return true;
  }
  else {
    Collection<ActivityExecution> executionsNotAtGateway = getLeafExecutions(scopeExecution);
    executionsNotAtGateway.removeAll(executionsAtGateway);

    for (ActivityExecution executionNotAtGateway : executionsNotAtGateway) {
      if (canReachActivity(executionNotAtGateway, gatewayActivity)) {
        return false;
      }
    }

    // if no more token may arrive, then activate
    return true;
  }

}
 
Example #5
Source File: AbstractBpmnActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void signalCompensationDone(ActivityExecution execution) {
  // default behavior is to join compensating executions and propagate the signal if all executions have compensated

  // only wait for non-event-scope executions cause a compensation event subprocess consume the compensation event and
  // do not have to compensate embedded subprocesses (which are still non-event-scope executions)

  if(((PvmExecutionImpl) execution).getNonEventScopeExecutions().isEmpty()) {
    if(execution.getParent() != null) {
      ActivityExecution parent = execution.getParent();
      execution.remove();
      parent.signal(SIGNAL_COMPENSATION_DONE, null);
    }
  } else {
    ((ExecutionEntity)execution).forceUpdate();
  }

}
 
Example #6
Source File: ServiceTaskExpressionActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void performExecution(final ActivityExecution execution) throws Exception {
  executeWithErrorPropagation(execution, new Callable<Void>() {
    @Override
    public Void call() throws Exception {
      //getValue() can have side-effects, that's why we have to call it independently from the result variable
      Object value = expression.getValue(execution);
      if (resultVariable != null) {
        execution.setVariable(resultVariable, value);
      }
      leave(execution);
      return null;
    }
  });

}
 
Example #7
Source File: ShellActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
private void readFields(ActivityExecution execution) {
  commandStr = getStringFromField(command, execution);
  arg1Str = getStringFromField(arg1, execution);
  arg2Str = getStringFromField(arg2, execution);
  arg3Str = getStringFromField(arg3, execution);
  arg4Str = getStringFromField(arg4, execution);
  arg5Str = getStringFromField(arg5, execution);
  waitStr = getStringFromField(wait, execution);
  resultVariableStr = getStringFromField(outputVariable, execution);
  errorCodeVariableStr = getStringFromField(errorCodeVariable, execution);

  String redirectErrorStr = getStringFromField(redirectError, execution);
  String cleanEnvStr = getStringFromField(cleanEnv, execution);

  waitFlag = waitStr == null || waitStr.equals("true");
  redirectErrorFlag = redirectErrorStr != null && redirectErrorStr.equals("true");
  cleanEnvBoolan = cleanEnvStr != null && cleanEnvStr.equals("true");
  directoryStr = getStringFromField(directory, execution);

}
 
Example #8
Source File: FetchGoodsPubSubAdapter.java    From flowing-retail with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(ActivityExecution context) throws Exception {
  Order order = orderRepository.findById( //
      (String)context.getVariable("orderId")).get(); 
  String traceId = context.getProcessBusinessKey();

  // publish
  messageSender.send(new Message<FetchGoodsCommandPayload>( //
          "FetchGoodsCommand", //
          traceId, //
          new FetchGoodsCommandPayload() //
            .setRefId(order.getId()) //
            .setItems(order.getItems())));
  
  addMessageSubscription(context, "GoodsFetchedEvent");
}
 
Example #9
Source File: SequentialMultiInstanceActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public ActivityExecution createInnerInstance(ActivityExecution scopeExecution) {

  if (hasLoopVariable(scopeExecution, NUMBER_OF_ACTIVE_INSTANCES) && getLoopVariable(scopeExecution, NUMBER_OF_ACTIVE_INSTANCES) > 0) {
    throw LOG.unsupportedConcurrencyException(scopeExecution.toString(), this.getClass().getSimpleName());
  }
  else {
    int nrOfInstances = getLoopVariable(scopeExecution, NUMBER_OF_INSTANCES);

    setLoopVariable(scopeExecution, LOOP_COUNTER, nrOfInstances);
    setLoopVariable(scopeExecution, NUMBER_OF_INSTANCES, nrOfInstances + 1);
    setLoopVariable(scopeExecution, NUMBER_OF_ACTIVE_INSTANCES, 1);
  }

  return scopeExecution;
}
 
Example #10
Source File: IntermediateCatchEventActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void execute(ActivityExecution execution) throws Exception {
  if (isAfterEventBasedGateway) {
    leave(execution);

  } else {
    // Do nothing: waitstate behavior
  }
}
 
Example #11
Source File: InclusiveGatewayActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected Collection<ActivityExecution> getLeafExecutions(ActivityExecution parent) {
  List<ActivityExecution> executionlist = new ArrayList<ActivityExecution>();
  List<? extends ActivityExecution> subExecutions = parent.getNonEventScopeExecutions();
  if (subExecutions.size() == 0) {
    executionlist.add(parent);
  } else {
    for (ActivityExecution concurrentExecution : subExecutions) {
      executionlist.addAll(getLeafExecutions(concurrentExecution));
    }
  }

  return executionlist;
}
 
Example #12
Source File: EventSubProcessActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void complete(ActivityExecution scopeExecution) {
  // check whether legacy behavior needs to be performed.
  if(!LegacyBehavior.eventSubprocessComplete(scopeExecution)) {
    // in case legacy behavior is not performed, the event subprocess behaves in the same way as a regular subprocess.
    super.complete(scopeExecution);
  }
}
 
Example #13
Source File: EventSubProcessActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void concurrentChildExecutionEnded(ActivityExecution scopeExecution, ActivityExecution endedExecution) {
  // Check whether legacy behavior needs to be performed.
  // Legacy behavior means that the event subprocess is not a scope and as a result does not
  // join concurrent executions on it's own. Instead it delegates to the the subprocess activity behavior in which it is embedded.
  if(!LegacyBehavior.eventSubprocessConcurrentChildExecutionEnded(scopeExecution, endedExecution)) {
    // in case legacy behavior is not performed, the event subprocess behaves in the same way as a regular subprocess.
    super.concurrentChildExecutionEnded(scopeExecution, endedExecution);
  }
}
 
Example #14
Source File: PvmExecutionImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings({"rawtypes", "unchecked"})
public List<ActivityExecution> findInactiveConcurrentExecutions(PvmActivity activity) {
  List<PvmExecutionImpl> inactiveConcurrentExecutionsInActivity = new ArrayList<>();
  if (isConcurrent()) {
    return getParent().findInactiveChildExecutions(activity);
  } else if (!isActive()) {
    inactiveConcurrentExecutionsInActivity.add(this);
  }

  return (List) inactiveConcurrentExecutionsInActivity;
}
 
Example #15
Source File: CommandPubEventSubAdapter.java    From flowing-retail-old with Apache License 2.0 5 votes vote down vote up
protected void addMessageSubscription(final ActivityExecution execution, String eventName) {
  ExecutionEntity executionEntity = (ExecutionEntity)execution;
  EventSubscriptionEntity eventSubscriptionEntity = new EventSubscriptionEntity(executionEntity, EventType.MESSAGE);
  eventSubscriptionEntity.setEventName(eventName);
  eventSubscriptionEntity.setActivity(executionEntity.getActivity());
  eventSubscriptionEntity.insert();
}
 
Example #16
Source File: ActivityExecutionMappingCollector.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(ActivityExecution execution) {
  if (!initialized) {
    // lazy initialization to avoid exceptions on creation
    appendActivityExecutionMapping(initialExecution);
    initialized = true;
  }

  appendActivityExecutionMapping(execution);
}
 
Example #17
Source File: SubProcessActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(ActivityExecution execution) throws Exception {
  PvmActivity activity = execution.getActivity();
  PvmActivity initialActivity = activity.getProperties().get(BpmnProperties.INITIAL_ACTIVITY);

  ensureNotNull("No initial activity found for subprocess " + execution.getActivity().getId(), "initialActivity", initialActivity);

  execution.executeActivity(initialActivity);
}
 
Example #18
Source File: CancelBoundaryEventActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void signal(ActivityExecution execution, String signalName, Object signalData) throws Exception {

    if (LegacyBehavior.signalCancelBoundaryEvent(signalName)) {
      // join compensating executions
      if (!execution.hasChildren()) {
        leave(execution);
      }
      else {
        ((ExecutionEntity)execution).forceUpdate();
      }
    }
    else {
      super.signal(execution, signalName, signalData);
    }
  }
 
Example #19
Source File: ThrowErrorDelegate.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void handle(ActivityExecution execution, String action) throws Exception {
  execution.setVariable(action, true);
  String type = (String) execution.getVariable("type");
  if ("error".equalsIgnoreCase(type)) {
    throw new BpmnError("MyError");
  }
  else if ("exception".equalsIgnoreCase(type)) {
    throw new MyBusinessException("MyException");
  }
  else if ("leave".equalsIgnoreCase(type)) {
    execution.setVariable("type", null);
    leave(execution);
  }
}
 
Example #20
Source File: UserTaskActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void performExecution(ActivityExecution execution) throws Exception {
  TaskEntity task = new TaskEntity((ExecutionEntity) execution);
  task.insert();

  // initialize task properties
  taskDecorator.decorate(task, execution);

  // fire lifecycle events after task is initialized
  task.transitionTo(TaskState.STATE_CREATED);
}
 
Example #21
Source File: CallableElementActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public Object resolveDelegateClass(final ActivityExecution execution) {
  ProcessApplicationReference targetProcessApplication
          = ProcessApplicationContextUtil.getTargetProcessApplication((ExecutionEntity) execution);
  if (ProcessApplicationContextUtil.requiresContextSwitch(targetProcessApplication)) {
    return Context.executeWithinProcessApplication(new Callable<Object>() {

      @Override
      public Object call() throws Exception {
        return resolveDelegateClass(execution);
      }
    }, targetProcessApplication, new InvocationContext(execution));
  } else {
    return instantiateDelegateClass(execution);
  }
}
 
Example #22
Source File: TaskEntity.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * @return true if the next listener can be invoked; false if not
 */
protected boolean invokeListener(CoreExecution currentExecution, String eventName, TaskListener taskListener) throws Exception {
  boolean isBpmnTask = currentExecution instanceof ActivityExecution && currentExecution != null;
  final TaskListenerInvocation listenerInvocation = new TaskListenerInvocation(taskListener, this, currentExecution);

  try {
    Context.getProcessEngineConfiguration()
      .getDelegateInterceptor()
      .handleInvocation(listenerInvocation);
  } catch (Exception ex) {
    // exceptions on delete events are never handled as BPMN errors
    if (isBpmnTask && !eventName.equals(EVENTNAME_DELETE)) {
      try {
        BpmnExceptionHandler.propagateException((ActivityExecution) currentExecution, ex);
        return false;
      }
      catch (ErrorPropagationException e) {
        // exception has been logged by thrower
        // re-throw the original exception so that it is logged
        // and set as cause of the failure
        throw ex;
      }
    }
    else {
      throw ex;
    }
  }
  return true;
}
 
Example #23
Source File: CompensationUtil.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Collect all compensate event subscriptions for activity on the scope of
 * given execution.
 */
public static List<EventSubscriptionEntity> collectCompensateEventSubscriptionsForActivity(ActivityExecution execution, String activityRef) {

  final List<EventSubscriptionEntity> eventSubscriptions = collectCompensateEventSubscriptionsForScope(execution);
  final String subscriptionActivityId = getSubscriptionActivityId(execution, activityRef);

  List<EventSubscriptionEntity> eventSubscriptionsForActivity = new ArrayList<EventSubscriptionEntity>();
  for (EventSubscriptionEntity subscription : eventSubscriptions) {
    if (subscriptionActivityId.equals(subscription.getActivityId())) {
      eventSubscriptionsForActivity.add(subscription);
    }
  }
  return eventSubscriptionsForActivity;
}
 
Example #24
Source File: ExternalTaskActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(ActivityExecution execution) throws Exception {
  ExecutionEntity executionEntity = (ExecutionEntity) execution;
  PriorityProvider<ExternalTaskActivityBehavior> provider = Context.getProcessEngineConfiguration().getExternalTaskPriorityProvider();

  long priority = provider.determinePriority(executionEntity, this, null);
  String topic = (String) topicNameValueProvider.getValue(executionEntity);

  ExternalTaskEntity.createAndInsert(executionEntity, topic, priority);

}
 
Example #25
Source File: BpmnExceptionHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected static void propagateExceptionAsError(Exception exception, ActivityExecution execution) throws Exception {
  if (isProcessEngineExceptionWithoutCause(exception) || isTransactionNotActive()) {
    throw exception;
  }
  else {
    propagateError(null, exception.getMessage(),exception, execution);
  }
}
 
Example #26
Source File: ServiceTaskDelegateExpressionActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected ActivityBehavior getActivityBehaviorInstance(ActivityExecution execution, Object delegateInstance) {

    if (delegateInstance instanceof ActivityBehavior) {
      return new CustomActivityBehavior((ActivityBehavior) delegateInstance);
    } else if (delegateInstance instanceof JavaDelegate) {
      return new ServiceTaskJavaDelegateActivityBehavior((JavaDelegate) delegateInstance);
    } else {
      throw LOG.missingDelegateParentClassException(delegateInstance.getClass().getName(),
        JavaDelegate.class.getName(), ActivityBehavior.class.getName());
    }
  }
 
Example #27
Source File: Decision.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void execute(ActivityExecution execution) throws Exception {
  PvmTransition transition = null;
  String creditRating = (String) execution.getVariable("creditRating");
  if (creditRating.equals("AAA+")) {
    transition = execution.getActivity().findOutgoingTransition("wow");
  } else if (creditRating.equals("Aaa-")) {
    transition = execution.getActivity().findOutgoingTransition("nice");
  } else {
    transition = execution.getActivity().findOutgoingTransition("default");
  }

  execution.leaveActivityViaTransition(transition);
}
 
Example #28
Source File: EscalationHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected static void executeEscalationHandler(EscalationEventDefinition escalationEventDefinition, ActivityExecutionMappingCollector activityExecutionMappingCollector, String escalationCode) {

    PvmActivity escalationHandler = escalationEventDefinition.getEscalationHandler();
    PvmScope escalationScope = getScopeForEscalation(escalationEventDefinition);
    ActivityExecution escalationExecution = activityExecutionMappingCollector.getExecutionForScope(escalationScope);

    if (escalationEventDefinition.getEscalationCodeVariable() != null) {
      escalationExecution.setVariable(escalationEventDefinition.getEscalationCodeVariable(), escalationCode);
    }

    escalationExecution.executeActivity(escalationHandler);
  }
 
Example #29
Source File: SubProcessActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void concurrentChildExecutionEnded(ActivityExecution scopeExecution, ActivityExecution endedExecution) {
  // join
  endedExecution.remove();
  scopeExecution.tryPruneLastConcurrentChild();
  scopeExecution.forceUpdate();
}
 
Example #30
Source File: ClassDelegateActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(final ActivityExecution execution) throws Exception {
  this.executeWithErrorPropagation(execution, new Callable<Void>() {
    @Override
    public Void call() throws Exception {
      getActivityBehaviorInstance(execution).execute(execution);
      return null;
    }
  });
}