org.activiti.engine.delegate.ExecutionListener Java Examples

The following examples show how to use org.activiti.engine.delegate.ExecutionListener. 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: ContinueProcessOperation.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void executeMultiInstanceSynchronous(FlowNode flowNode) {

    // Execution listener: event 'start'
    if (CollectionUtil.isNotEmpty(flowNode.getExecutionListeners())) {
      executeExecutionListeners(flowNode, ExecutionListener.EVENTNAME_START);
    }

    // Execute any boundary events, sub process boundary events will be executed from the activity behavior
    if (!inCompensation && flowNode instanceof Activity) { // Only activities can have boundary events
      List<BoundaryEvent> boundaryEvents = ((Activity) flowNode).getBoundaryEvents();
      if (CollectionUtil.isNotEmpty(boundaryEvents)) {
        executeBoundaryEvents(boundaryEvents, execution);
      }
    }

    // Execute the multi instance behavior
    ActivityBehavior activityBehavior = (ActivityBehavior) flowNode.getBehavior();

    if (activityBehavior != null) {
      executeActivityBehavior(activityBehavior, flowNode);

    } else {
      throw new ActivitiException("Expected an activity behavior in flow node " + flowNode.getId());
    }
  }
 
Example #2
Source File: TakeOutgoingSequenceFlowsOperation.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void handleActivityEnd(FlowNode flowNode) {
  // a process instance execution can never leave a flow node, but it can pass here whilst cleaning up
  // hence the check for NOT being a process instance
  if (!execution.isProcessInstanceType()) {

    if (CollectionUtil.isNotEmpty(flowNode.getExecutionListeners())) {
      executeExecutionListeners(flowNode, ExecutionListener.EVENTNAME_END);
    }

    commandContext.getHistoryManager().recordActivityEnd(execution, null);

    if (!(execution.getCurrentFlowElement() instanceof SubProcess)) {
      Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
          ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_COMPLETED, flowNode.getId(), flowNode.getName(),
              execution.getId(), execution.getProcessInstanceId(), execution.getProcessDefinitionId(), flowNode));
    }

  }
}
 
Example #3
Source File: MultiInstanceActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Since the first loop of the multi instance is not executed as a regular activity,
 * it is needed to call the start listeners yourself.
 */
protected void callCustomActivityStartListeners(ActivityExecution execution) {
  List<ExecutionListener> listeners = activity.getExecutionListeners(org.activiti5.engine.impl.pvm.PvmEvent.EVENTNAME_START);
  
  List<ExecutionListener> filteredExecutionListeners = new ArrayList<ExecutionListener>(listeners.size());
  if (listeners != null) {
   // Sad that we have to do this, but it's the only way I could find (which is also safe for backwards compatibility)
   
   for (ExecutionListener executionListener : listeners) {
   	if (!(executionListener instanceof ActivityInstanceStartHandler)) {
   		filteredExecutionListeners.add(executionListener);
   	}
   }
   
   CallActivityListenersOperation atomicOperation = new CallActivityListenersOperation(filteredExecutionListeners);
   Context.getCommandContext().performOperation(atomicOperation, (InterpretableExecution)execution);
  }
  
}
 
Example #4
Source File: DelegateExpressionExecutionListener.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void notify(DelegateExecution execution) {
  // Note: we can't cache the result of the expression, because the
  // execution can change: eg. delegateExpression='${mySpringBeanFactory.randomSpringBean()}'
  Object delegate = expression.getValue(execution);
  ClassDelegate.applyFieldDeclaration(fieldDeclarations, delegate);
  
  if (delegate instanceof ExecutionListener) {
    Context.getProcessEngineConfiguration()
      .getDelegateInterceptor()
      .handleInvocation(new ExecutionListenerInvocation((ExecutionListener) delegate, execution));
  } else if (delegate instanceof JavaDelegate) {
    Context.getProcessEngineConfiguration()
      .getDelegateInterceptor()
      .handleInvocation(new JavaDelegateInvocation((JavaDelegate) delegate, execution));
  } else {
    throw new ActivitiIllegalArgumentException("Delegate expression " + expression 
            + " did not resolve to an implementation of " + ExecutionListener.class 
            + " nor " + JavaDelegate.class);
  }
}
 
Example #5
Source File: ScopeImpl.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public List<ExecutionListener> getExecutionListeners(String eventName) {
  List<ExecutionListener> executionListenerList = getExecutionListeners().get(eventName);
  if (executionListenerList!=null) {
    return executionListenerList;
  }
  return Collections.EMPTY_LIST;
}
 
Example #6
Source File: ContinueProcessOperation.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void executeSynchronous(FlowNode flowNode) {
  commandContext.getHistoryManager().recordActivityStart(execution);

  // Execution listener: event 'start'
  if (CollectionUtil.isNotEmpty(flowNode.getExecutionListeners())) {
    executeExecutionListeners(flowNode, ExecutionListener.EVENTNAME_START);
  }

  // Execute any boundary events, sub process boundary events will be executed from the activity behavior
  if (!inCompensation && flowNode instanceof Activity) { // Only activities can have boundary events
    List<BoundaryEvent> boundaryEvents = ((Activity) flowNode).getBoundaryEvents();
    if (CollectionUtil.isNotEmpty(boundaryEvents)) {
      executeBoundaryEvents(boundaryEvents, execution);
    }
  }

  // Execute actual behavior
  ActivityBehavior activityBehavior = (ActivityBehavior) flowNode.getBehavior();

  if (activityBehavior != null) {
    executeActivityBehavior(activityBehavior, flowNode);

  } else {
    logger.debug("No activityBehavior on activity '{}' with execution {}", flowNode.getId(), execution.getId());
    Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(execution, true);
  }
}
 
Example #7
Source File: MultiInstanceActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(InterpretableExecution execution) {
	for (ExecutionListener executionListener : listeners) {
     try {
       Context.getProcessEngineConfiguration()
         .getDelegateInterceptor()
         .handleInvocation(new ExecutionListenerInvocation(executionListener, execution));
     } catch (Exception e) {
       throw new ActivitiException("Couldn't execute listener", e);
     }
   }
}
 
Example #8
Source File: ContinueMultiInstanceOperation.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void executeSynchronous(FlowNode flowNode) {
  
  // Execution listener
  if (CollectionUtil.isNotEmpty(flowNode.getExecutionListeners())) {
    executeExecutionListeners(flowNode, ExecutionListener.EVENTNAME_START);
  }
  
  commandContext.getHistoryManager().recordActivityStart(execution);
  
  // Execute actual behavior
  ActivityBehavior activityBehavior = (ActivityBehavior) flowNode.getBehavior();
  if (activityBehavior != null) {
    logger.debug("Executing activityBehavior {} on activity '{}' with execution {}", activityBehavior.getClass(), flowNode.getId(), execution.getId());
    
    if (Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
      Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
          ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_STARTED, flowNode.getId(), flowNode.getName(), execution.getId(),
              execution.getProcessInstanceId(), execution.getProcessDefinitionId(), flowNode));
    }
    
    try {
      activityBehavior.execute(execution);
    } catch (BpmnError error) {
      // re-throw business fault so that it can be caught by an Error Intermediate Event or Error Event Sub-Process in the process
      ErrorPropagation.propagateError(error, execution);
    } catch (RuntimeException e) {
      if (LogMDC.isMDCEnabled()) {
        LogMDC.putMDCExecution(execution);
      }
      throw e;
    }
  } else {
    logger.debug("No activityBehavior on activity '{}' with execution {}", flowNode.getId(), execution.getId());
  }
}
 
Example #9
Source File: ClassDelegate.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected ExecutionListener getExecutionListenerInstance() {
  Object delegateInstance = instantiateDelegate(className, fieldDeclarations);
  if (delegateInstance instanceof ExecutionListener) {
    return (ExecutionListener) delegateInstance; 
  } else if (delegateInstance instanceof JavaDelegate) {
    return new ServiceTaskJavaDelegateActivityBehavior((JavaDelegate) delegateInstance);
  } else {
    throw new ActivitiIllegalArgumentException(delegateInstance.getClass().getName()+" doesn't implement "+ExecutionListener.class+" nor "+JavaDelegate.class);
  }
}
 
Example #10
Source File: AbstractBpmnParseHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected ExecutionListener createExecutionListener(BpmnParse bpmnParse, ActivitiListener activitiListener) {
  ExecutionListener executionListener = null;

  if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.equalsIgnoreCase(activitiListener.getImplementationType())) {
    executionListener = bpmnParse.getListenerFactory().createClassDelegateExecutionListener(activitiListener);  
  } else if (ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.equalsIgnoreCase(activitiListener.getImplementationType())) {
    executionListener = bpmnParse.getListenerFactory().createExpressionExecutionListener(activitiListener);
  } else if (ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.equalsIgnoreCase(activitiListener.getImplementationType())) {
    executionListener = bpmnParse.getListenerFactory().createDelegateExpressionExecutionListener(activitiListener);
  }
  return executionListener;
}
 
Example #11
Source File: AbstractBpmnParseHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected ExecutionListener createExecutionListener(BpmnParse bpmnParse, ActivitiListener activitiListener) {
  ExecutionListener executionListener = null;

  if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.equalsIgnoreCase(activitiListener.getImplementationType())) {
    executionListener = bpmnParse.getListenerFactory().createClassDelegateExecutionListener(activitiListener);
  } else if (ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.equalsIgnoreCase(activitiListener.getImplementationType())) {
    executionListener = bpmnParse.getListenerFactory().createExpressionExecutionListener(activitiListener);
  } else if (ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.equalsIgnoreCase(activitiListener.getImplementationType())) {
    executionListener = bpmnParse.getListenerFactory().createDelegateExpressionExecutionListener(activitiListener);
  }
  return executionListener;
}
 
Example #12
Source File: ClassDelegate.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected ExecutionListener getExecutionListenerInstance() {
  Object delegateInstance = instantiateDelegate(className, fieldDeclarations);
  if (delegateInstance instanceof ExecutionListener) {
    return (ExecutionListener) delegateInstance;
  } else if (delegateInstance instanceof JavaDelegate) {
    return new ServiceTaskJavaDelegateActivityBehavior((JavaDelegate) delegateInstance);
  } else {
    throw new ActivitiIllegalArgumentException(delegateInstance.getClass().getName() + " doesn't implement " + ExecutionListener.class + " nor " + JavaDelegate.class);
  }
}
 
Example #13
Source File: DelegateExpressionExecutionListener.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void notify(DelegateExecution execution) {
  Object delegate = DelegateExpressionUtil.resolveDelegateExpression(expression, execution, fieldDeclarations); 
  if (delegate instanceof ExecutionListener) {
    Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new ExecutionListenerInvocation((ExecutionListener) delegate, execution));
  } else if (delegate instanceof JavaDelegate) {
    Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new JavaDelegateInvocation((JavaDelegate) delegate, execution));
  } else {
    throw new ActivitiIllegalArgumentException("Delegate expression " + expression + " did not resolve to an implementation of " + ExecutionListener.class + " nor " + JavaDelegate.class);
  }
}
 
Example #14
Source File: TransitionImpl.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public List<ExecutionListener> getExecutionListeners() {
  if (executionListeners==null) {
    return Collections.EMPTY_LIST;
  }
  return executionListeners;
}
 
Example #15
Source File: AlfrescoProcessBpmnParseHandler.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void executeParse(BpmnParse bpmnParse, Process process)
{
    ProcessDefinitionEntity processDefinition = bpmnParse.getCurrentProcessDefinition();
    processDefinition.addExecutionListener(ExecutionListener.EVENTNAME_START, processCreateListener);
    if (multiTenancyEnabled && tenantService.isEnabled())
    {
        String key = tenantService.getName(processDefinition.getKey());
        processDefinition.setKey(key);
    }
}
 
Example #16
Source File: ScopeImpl.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void addExecutionListener(String eventName, ExecutionListener executionListener, int index) {
  List<ExecutionListener> listeners = executionListeners.get(eventName);
  if (listeners==null) {
    listeners = new ArrayList<ExecutionListener>();
    executionListeners.put(eventName, listeners);
  }
  if (index<0) {
    listeners.add(executionListener);
  } else {
    listeners.add(index, executionListener);
  }
}
 
Example #17
Source File: DefaultListenerFactory.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public ExecutionListener createDelegateExpressionExecutionListener(ActivitiListener activitiListener) {
  return new DelegateExpressionExecutionListener(expressionManager.createExpression(activitiListener.getImplementation()), createFieldDeclarations(activitiListener.getFieldExtensions()));
}
 
Example #18
Source File: DefaultListenerFactory.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public ExecutionListener createExpressionExecutionListener(ActivitiListener activitiListener) {
  return new ExpressionExecutionListener(expressionManager.createExpression(activitiListener.getImplementation()));
}
 
Example #19
Source File: DefaultListenerFactory.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public ExecutionListener createClassDelegateExecutionListener(ActivitiListener activitiListener) {
  return classDelegateFactory.create(activitiListener.getImplementation(), createFieldDeclarations(activitiListener.getFieldExtensions()));
}
 
Example #20
Source File: MultiInstanceActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
/**
 * Since no transitions are followed when leaving the inner activity, it is needed to call the end listeners yourself.
 */
protected void callActivityEndListeners(DelegateExecution execution) {
  Context.getCommandContext().getProcessEngineConfiguration().getListenerNotificationHelper()
    .executeExecutionListeners(activity, execution, ExecutionListener.EVENTNAME_END);
}
 
Example #21
Source File: CdiEventSupportBpmnParseHandler.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
protected void addStartEventListener(FlowElement flowElement) {
  CdiExecutionListener listener = new CdiExecutionListener(flowElement.getId(), BusinessProcessEventType.START_ACTIVITY);
  addActivitiListenerToElement(flowElement, ExecutionListener.EVENTNAME_START, listener);
}
 
Example #22
Source File: ExecutionListenerInvocation.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public ExecutionListenerInvocation(ExecutionListener executionListenerInstance, DelegateExecution execution) {
  this.executionListenerInstance = executionListenerInstance;
  this.execution = execution;
}
 
Example #23
Source File: CdiEventSupportBpmnParseHandler.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
protected void addEndEventListener(FlowElement flowElement) {
  CdiExecutionListener listener = new CdiExecutionListener(flowElement.getId(), BusinessProcessEventType.END_ACTIVITY);
  addActivitiListenerToElement(flowElement, ExecutionListener.EVENTNAME_END, listener);
}
 
Example #24
Source File: AlfrescoProcessBpmnParseHandler.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setProcessCreateListener(ExecutionListener processCreateListener)
{
    this.processCreateListener = processCreateListener;
}
 
Example #25
Source File: DefaultListenerFactory.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public ExecutionListener createDelegateExpressionExecutionListener(ActivitiListener activitiListener) {
  return new DelegateExpressionExecutionListener(expressionManager.createExpression(activitiListener.getImplementation()), 
          createFieldDeclarations(activitiListener.getFieldExtensions()));
}
 
Example #26
Source File: ScopeImpl.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void addExecutionListener(String eventName, ExecutionListener executionListener) {
  addExecutionListener(eventName, executionListener, -1);
}
 
Example #27
Source File: ScopeImpl.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public Map<String, List<ExecutionListener>> getExecutionListeners() {
  return executionListeners;
}
 
Example #28
Source File: TransitionImpl.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void addExecutionListener(ExecutionListener executionListener) {
  if (executionListeners==null) {
    executionListeners = new ArrayList<ExecutionListener>();
  }
  executionListeners.add(executionListener);
}
 
Example #29
Source File: TransitionImpl.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void setExecutionListeners(List<ExecutionListener> executionListeners) {
  this.executionListeners = executionListeners;
}
 
Example #30
Source File: ExecutionListenerInvocation.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public ExecutionListenerInvocation(ExecutionListener executionListenerInstance, DelegateExecution execution) {
  this.executionListenerInstance = executionListenerInstance;
  this.execution = execution;
}