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

The following examples show how to use org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior. 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: DebugSessionImpl.java    From camunda-bpm-workbench with GNU Affero General Public License v3.0 6 votes vote down vote up
public void updateScript(String processDefinitionId, String activityId, Script script) {
  ProcessDefinitionEntity processDefinition =
    (ProcessDefinitionEntity) getProcessEngine().getRepositoryService().getProcessDefinition(processDefinitionId);

  ActivityImpl activity = processDefinition.findActivity(activityId);

  ActivityBehavior activityBehavior = activity.getActivityBehavior();

  if (activityBehavior instanceof ScriptTaskActivityBehavior) {
    SourceExecutableScript taskScript = (SourceExecutableScript) ((ScriptTaskActivityBehavior) activityBehavior).getScript();
    taskScript.setScriptSource(script.getScript());
    // TODO set script language here
  } else {
    throw new DebuggerException("Activity " + activityId + " is no script task");
  }
}
 
Example #2
Source File: ServiceTaskDelegateExpressionActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void doSignal(final ActivityExecution execution, final String signalName, final Object signalData) throws Exception {
  Object delegate = expression.getValue(execution);
  applyFieldDeclaration(fieldDeclarations, delegate);
  final ActivityBehavior activityBehaviorInstance = getActivityBehaviorInstance(execution, delegate);

  if (activityBehaviorInstance instanceof CustomActivityBehavior) {
    CustomActivityBehavior behavior = (CustomActivityBehavior) activityBehaviorInstance;
    ActivityBehavior delegateActivityBehavior = behavior.getDelegateActivityBehavior();

    if (!(delegateActivityBehavior instanceof SignallableActivityBehavior)) {
      // legacy behavior: do nothing when it is not a signallable activity behavior
      return;
    }
  }
  executeWithErrorPropagation(execution, new Callable<Void>() {
    @Override
    public Void call() throws Exception {
      ((SignallableActivityBehavior) activityBehaviorInstance).signal(execution, signalName, signalData);
      return null;
    }
  });
}
 
Example #3
Source File: ClassDelegateActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void doSignal(final ActivityExecution execution, final String signalName, final Object signalData) throws Exception {
  final ActivityBehavior activityBehaviorInstance = getActivityBehaviorInstance(execution);

  if (activityBehaviorInstance instanceof CustomActivityBehavior) {
    CustomActivityBehavior behavior = (CustomActivityBehavior) activityBehaviorInstance;
    ActivityBehavior delegate = behavior.getDelegateActivityBehavior();

    if (!(delegate instanceof SignallableActivityBehavior)) {
      throw LOG.incorrectlyUsedSignalException(SignallableActivityBehavior.class.getName() );
    }
  }
  executeWithErrorPropagation(execution, new Callable<Void>() {
    @Override
    public Void call() throws Exception {
      ((SignallableActivityBehavior) activityBehaviorInstance).signal(execution, signalName, signalData);
      return null;
    }
  });
}
 
Example #4
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 #5
Source File: ConditionalEventHandler.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void handleEvent(EventSubscriptionEntity eventSubscription, Object payload, Object localPayload, 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);
  }
}
 
Example #6
Source File: LegacyBehavior.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * <p>Required for migrating active sequential MI receive tasks. These activities were formerly not scope,
 * but are now. This has the following implications:
 *
 * <p>Before migration:
 * <ul><li> the event subscription is attached to the miBody scope execution</ul>
 *
 * <p>After migration:
 * <ul><li> a new subscription is created for every instance
 * <li> the new subscription is attached to a dedicated scope execution as a child of the miBody scope
 *   execution</ul>
 *
 * <p>Thus, this method removes the subscription on the miBody scope
 */
public static void removeLegacySubscriptionOnParent(ExecutionEntity execution, EventSubscriptionEntity eventSubscription) {
  ActivityImpl activity = execution.getActivity();
  if (activity == null) {
    return;
  }

  ActivityBehavior behavior = activity.getActivityBehavior();
  ActivityBehavior parentBehavior = (ActivityBehavior) (activity.getFlowScope() != null ? activity.getFlowScope().getActivityBehavior() : null);

  if (behavior instanceof ReceiveTaskActivityBehavior &&
      parentBehavior instanceof MultiInstanceActivityBehavior) {
    List<EventSubscriptionEntity> parentSubscriptions = execution.getParent().getEventSubscriptions();

    for (EventSubscriptionEntity subscription : parentSubscriptions) {
      // distinguish a boundary event on the mi body with the same message name from the receive task subscription
      if (areEqualEventSubscriptions(subscription, eventSubscription)) {
        subscription.delete();
      }
    }
  }

}
 
Example #7
Source File: DebugSessionImpl.java    From camunda-bpm-workbench with GNU Affero General Public License v3.0 6 votes vote down vote up
public Script getScript(String processDefinitionId, String activityId) {
  ProcessDefinitionEntity processDefinition =
    (ProcessDefinitionEntity) getProcessEngine().getRepositoryService().getProcessDefinition(processDefinitionId);

  ActivityImpl activity = processDefinition.findActivity(activityId);

  ActivityBehavior activityBehavior = activity.getActivityBehavior();

  if (activityBehavior instanceof ScriptTaskActivityBehavior) {
    Script script = new Script();
    ExecutableScript taskScript = ((ScriptTaskActivityBehavior) activityBehavior).getScript();

    if (!(taskScript instanceof SourceExecutableScript)) {
      throw new DebuggerException("Encountered non-source script");
    }

    SourceExecutableScript sourceScript = (SourceExecutableScript) taskScript;

    script.setScript(sourceScript.getScriptSource());
    script.setScriptingLanguage(sourceScript.getLanguage());

    return script;
  } else {
    throw new DebuggerException("Activity " + activityId + " is no script task");
  }
}
 
Example #8
Source File: LegacyBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected static boolean wasNoScope72(ActivityImpl activity) {
  ActivityBehavior activityBehavior = activity.getActivityBehavior();
  ActivityBehavior parentActivityBehavior = (ActivityBehavior) (activity.getFlowScope() != null ? activity.getFlowScope().getActivityBehavior() : null);
  return (activityBehavior instanceof EventSubProcessActivityBehavior)
      || (activityBehavior instanceof SubProcessActivityBehavior
            && parentActivityBehavior instanceof SequentialMultiInstanceActivityBehavior)
      || (activityBehavior instanceof ReceiveTaskActivityBehavior
            && parentActivityBehavior instanceof MultiInstanceActivityBehavior);
}
 
Example #9
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 #10
Source File: ServiceTaskDelegateExpressionActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void performExecution(final ActivityExecution execution) throws Exception {
 Callable<Void> callable = new Callable<Void>() {
    @Override
    public Void call() throws Exception {
      // Note: we can't cache the result of the expression, because the
      // execution can change: eg. delegateExpression='${mySpringBeanFactory.randomSpringBean()}'
      Object delegate = expression.getValue(execution);
      applyFieldDeclaration(fieldDeclarations, delegate);

      if (delegate instanceof ActivityBehavior) {
        Context.getProcessEngineConfiguration()
          .getDelegateInterceptor()
          .handleInvocation(new ActivityBehaviorInvocation((ActivityBehavior) delegate, execution));

      } else if (delegate instanceof JavaDelegate) {
        Context.getProcessEngineConfiguration()
          .getDelegateInterceptor()
          .handleInvocation(new JavaDelegateInvocation((JavaDelegate) delegate, execution));
        leave(execution);

      } else {
        throw LOG.resolveDelegateExpressionException(expression, ActivityBehavior.class, JavaDelegate.class);
      }
      return null;
    }
  };
  executeWithErrorPropagation(execution, callable);
}
 
Example #11
Source File: ClassDelegateActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected ActivityBehavior getActivityBehaviorInstance(ActivityExecution execution) {
  Object delegateInstance = instantiateDelegate(className, fieldDeclarations);

  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 #12
Source File: ActivityBehaviorUtil.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static ActivityBehavior getActivityBehavior(PvmExecutionImpl execution) {
  String id = execution.getId();

  PvmActivity activity = execution.getActivity();
  ensureNotNull(PvmException.class, "Execution '"+id+"' has no current activity.", "activity", activity);

  ActivityBehavior behavior = activity.getActivityBehavior();
  ensureNotNull(PvmException.class, "There is no behavior specified in "+activity+" for execution '"+id+"'.", "behavior", behavior);

  return behavior;
}
 
Example #13
Source File: LegacyBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static boolean eventSubprocessConcurrentChildExecutionEnded(ActivityExecution scopeExecution, ActivityExecution endedExecution) {
  boolean performLegacyBehavior = isLegacyBehaviorRequired(endedExecution);

  if(performLegacyBehavior) {
    LOG.endConcurrentExecutionInEventSubprocess();
    // notify the grandparent flow scope in a similar way PvmAtomicOperationAcitivtyEnd does
    ScopeImpl flowScope = endedExecution.getActivity().getFlowScope();
    if (flowScope != null) {
      flowScope = flowScope.getFlowScope();

      if (flowScope != null) {
        if (flowScope == endedExecution.getActivity().getProcessDefinition()) {
          endedExecution.remove();
          scopeExecution.tryPruneLastConcurrentChild();
          scopeExecution.forceUpdate();
        }
        else {
          PvmActivity flowScopeActivity = (PvmActivity) flowScope;

          ActivityBehavior activityBehavior = flowScopeActivity.getActivityBehavior();
          if (activityBehavior instanceof CompositeActivityBehavior) {
            ((CompositeActivityBehavior) activityBehavior).concurrentChildExecutionEnded(scopeExecution, endedExecution);
          }
        }
      }
    }
  }

  return performLegacyBehavior;
}
 
Example #14
Source File: OSGiELResolverBehaviorIntegrationTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 5 votes vote down vote up
@Test
public void runProcess() throws Exception {
  TestActivityBehaviour behaviour = new TestActivityBehaviour();
  ctx.registerService(ActivityBehavior.class, behaviour, null);
  processEngine.getRuntimeService().startProcessInstanceByKey("delegate");
  assertThat(behaviour.getCalled(), is(true));
}
 
Example #15
Source File: OSGiELResolverTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 5 votes vote down vote up
@Test
public void getValueForSingleActivityBehavior() throws InvalidSyntaxException {
  String lookupName = "testActivityBehaviour";
  ActivityBehavior serviceObject = new TestActivityBehaviour();
  ServiceReference<ActivityBehavior> reference = mockService(serviceObject);
  registerServiceRefsAtContext(ActivityBehavior.class, null, reference);
  ActivityBehavior value = (ActivityBehavior) resolver.getValue(elContext, null, lookupName);
  assertThat(value, is(sameInstance(serviceObject)));
  wasPropertyResolved();
}
 
Example #16
Source File: OSGiELResolverTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void getValueForTwoActivityBehaviors() throws InvalidSyntaxException {
  String lookupName = "testActivityBehaviour";
  ActivityBehavior serviceObject = new TestActivityBehaviour();
  ActivityBehavior anotherServiceObject = mock(ActivityBehavior.class);
  ServiceReference<ActivityBehavior> reference1 = mockService(serviceObject);
  ServiceReference<ActivityBehavior> reference2 = mockService(anotherServiceObject);
  registerServiceRefsAtContext(ActivityBehavior.class, null, reference1, reference2);
  ActivityBehavior value = (ActivityBehavior) resolver.getValue(elContext, null, lookupName);
  assertThat(value, is(sameInstance(serviceObject)));
  wasPropertyResolved();
}
 
Example #17
Source File: OSGiELResolverTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test(expected = RuntimeException.class)
public void getValueForTwoActivityBehaviorsWithSameName() throws InvalidSyntaxException {
  String lookupName = "testActivityBehaviour";
  ActivityBehavior behaviour1 = new TestActivityBehaviour();
  ActivityBehavior behaviour2 = new TestActivityBehaviour();
  ServiceReference<ActivityBehavior> reference1 = mockService(behaviour1);
  ServiceReference<ActivityBehavior> reference2 = mockService(behaviour2);
  registerServiceRefsAtContext(ActivityBehavior.class, null, reference1, reference2);
  resolver.getValue(elContext, null, lookupName);
}
 
Example #18
Source File: BlueprintELResolver.java    From camunda-bpm-platform-osgi with Apache License 2.0 5 votes vote down vote up
public void unbindActivityBehaviourService(ActivityBehavior delegate, Map props) {
  String name = (String) props.get("osgi.service.blueprint.compname");
  if (activityBehaviourMap.containsKey(name)) {
    activityBehaviourMap.remove(name);
  }
  LOGGER.info("removed Camunda service from activityBehaviour cache " + name);
}
 
Example #19
Source File: ActivityBehaviorInvocation.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public ActivityBehaviorInvocation(ActivityBehavior behaviorInstance, ActivityExecution execution) {
  super(execution, null);
  this.behaviorInstance = behaviorInstance;
  this.execution = execution;
}
 
Example #20
Source File: PvmAtomicOperationActivityEnd.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void execute(PvmExecutionImpl execution) {
  // restore activity instance id
  if (execution.getActivityInstanceId() == null) {
    execution.setActivityInstanceId(execution.getParentActivityInstanceId());
  }

  PvmActivity activity = execution.getActivity();
  Map<ScopeImpl, PvmExecutionImpl> activityExecutionMapping = execution.createActivityExecutionMapping();

  PvmExecutionImpl propagatingExecution = execution;

  if(execution.isScope() && activity.isScope()) {
    if (!LegacyBehavior.destroySecondNonScope(execution)) {
      execution.destroy();
      if(!execution.isConcurrent()) {
        execution.remove();
        propagatingExecution = execution.getParent();
        propagatingExecution.setActivity(execution.getActivity());
      }
    }
  }

  propagatingExecution = LegacyBehavior.determinePropagatingExecutionOnEnd(propagatingExecution, activityExecutionMapping);
  PvmScope flowScope = activity.getFlowScope();

  // 1. flow scope = Process Definition
  if(flowScope == activity.getProcessDefinition()) {

    // 1.1 concurrent execution => end + tryPrune()
    if(propagatingExecution.isConcurrent()) {
      propagatingExecution.remove();
      propagatingExecution.getParent().tryPruneLastConcurrentChild();
      propagatingExecution.getParent().forceUpdate();
    }
    else {
      // 1.2 Process End
      propagatingExecution.setEnded(true);
      if (!propagatingExecution.isPreserveScope()) {
        propagatingExecution.performOperation(PROCESS_END);
      }
    }
  }
  else {
    // 2. flowScope != process definition
    PvmActivity flowScopeActivity = (PvmActivity) flowScope;

    ActivityBehavior activityBehavior = flowScopeActivity.getActivityBehavior();
    if (activityBehavior instanceof CompositeActivityBehavior) {
      CompositeActivityBehavior compositeActivityBehavior = (CompositeActivityBehavior) activityBehavior;
      // 2.1 Concurrent execution => composite behavior.concurrentExecutionEnded()
      if(propagatingExecution.isConcurrent() && !LegacyBehavior.isConcurrentScope(propagatingExecution)) {
        compositeActivityBehavior.concurrentChildExecutionEnded(propagatingExecution.getParent(), propagatingExecution);
      }
      else {
        // 2.2 Scope Execution => composite behavior.complete()
        propagatingExecution.setActivity(flowScopeActivity);
        compositeActivityBehavior.complete(propagatingExecution);
      }

    }
    else {
      // activity behavior is not composite => this is unexpected
      throw new ProcessEngineException("Expected behavior of composite scope "+activity
          +" to be a CompositeActivityBehavior but got "+activityBehavior);
    }
  }
}
 
Example #21
Source File: CustomActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public ActivityBehavior getDelegateActivityBehavior() {
  return delegateActivityBehavior;
}
 
Example #22
Source File: CustomActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public CustomActivityBehavior(ActivityBehavior activityBehavior) {
  this.delegateActivityBehavior = activityBehavior;
}
 
Example #23
Source File: BlueprintELResolver.java    From camunda-bpm-platform-osgi with Apache License 2.0 4 votes vote down vote up
public void bindActivityBehaviourService(ActivityBehavior delegate, Map props) {
  String name = (String) props.get("osgi.service.blueprint.compname");
  activityBehaviourMap.put(name, delegate);
  LOGGER.info("added service to activityBehaviour cache " + name);
}
 
Example #24
Source File: GatewayMappingValidator.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected boolean isWaitStateGateway(ActivityImpl activity) {
  ActivityBehavior behavior = activity.getActivityBehavior();
  return behavior instanceof ParallelGatewayActivityBehavior
      || behavior instanceof InclusiveGatewayActivityBehavior;
}
 
Example #25
Source File: SameEventTypeValidator.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected boolean isEvent(ActivityImpl activity) {
  ActivityBehavior behavior = activity.getActivityBehavior();
  return behavior instanceof BoundaryEventActivityBehavior
      || behavior instanceof EventSubProcessStartEventActivityBehavior;
}
 
Example #26
Source File: ProcessDefinitionBuilder.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public ProcessDefinitionBuilder behavior(ActivityBehavior activityBehaviour) {
  getActivity().setActivityBehavior(activityBehaviour);
  return this;
}
 
Example #27
Source File: LegacyBehavior.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected static boolean wasNoScope73(ActivityImpl activity, PvmExecutionImpl scopeExecutionCandidate) {
  ActivityBehavior activityBehavior = activity.getActivityBehavior();
  return (activityBehavior instanceof CompensationEventActivityBehavior)
      || (activityBehavior instanceof CancelEndEventActivityBehavior)
      || isMultiInstanceInCompensation(activity, scopeExecutionCandidate);
}
 
Example #28
Source File: ActivityImpl.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Override
public ActivityBehavior getActivityBehavior() {
  return activityBehavior;
}
 
Example #29
Source File: ActivityImpl.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void setActivityBehavior(ActivityBehavior activityBehavior) {
  this.activityBehavior = activityBehavior;
}
 
Example #30
Source File: PvmActivity.java    From camunda-bpm-platform with Apache License 2.0 2 votes vote down vote up
/**
 * The inner behavior of an activity. The inner behavior is the logic which is executed after
 * the {@link ExecutionListener#EVENTNAME_START start} listeners have been executed.
 *
 * In case the activity {@link #isScope() is scope}, a new execution will be created
 *
 * @return the inner behavior of the activity
 */
ActivityBehavior getActivityBehavior();