Java Code Examples for org.camunda.bpm.engine.delegate.DelegateExecution#getCurrentActivityId()

The following examples show how to use org.camunda.bpm.engine.delegate.DelegateExecution#getCurrentActivityId() . 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: AbstractServiceNodeStartListener.java    From wecube-platform with Apache License 2.0 6 votes vote down vote up
protected void logServiceNodeStart(DelegateExecution execution) {
    String nodeId = execution.getCurrentActivityId();
    String procInstanceBizKey = execution.getProcessBusinessKey();

    ServiceNodeStatusRepository serviceNodeStatusRepository = SpringApplicationContextUtil
            .getBean(ServiceNodeStatusRepository.class);

    ServiceNodeStatusEntity entity = serviceNodeStatusRepository
            .findOneByProcInstanceBizKeyAndNodeId(procInstanceBizKey, nodeId);

    if (entity == null) {
        getLogger().warn("{} is null for procInstanceBizKey={},nodeId={}", ServiceNodeStatusEntity.class.getSimpleName(),
                procInstanceBizKey, nodeId);
        throw new IllegalStateException("service node status entity doesnt exist");
    }
    
    Date currTime = new Date();
    entity.setUpdatedBy(WorkflowConstants.DEFAULT_USER);
    entity.setUpdatedTime(currTime);
    entity.setStatus(TraceStatus.InProgress);
    entity.setStartTime(currTime);
    
    serviceNodeStatusRepository.saveAndFlush(entity);
    
}
 
Example 2
Source File: AbstractServiceNodeEndListener.java    From wecube-platform with Apache License 2.0 6 votes vote down vote up
protected void logServiceNodeEnd(DelegateExecution execution) {
    String nodeId = execution.getCurrentActivityId();
    String procInstanceBizKey = execution.getProcessBusinessKey();

    ServiceNodeStatusRepository serviceNodeStatusRepository = SpringApplicationContextUtil
            .getBean(ServiceNodeStatusRepository.class);

    ServiceNodeStatusEntity entity = serviceNodeStatusRepository
            .findOneByProcInstanceBizKeyAndNodeId(procInstanceBizKey, nodeId);

    if (entity == null) {
        getLogger().warn("{} is null for procInstanceBizKey={},nodeId={}", ServiceNodeStatusEntity.class.getSimpleName(),
                procInstanceBizKey, nodeId);
        throw new IllegalStateException("service node status entity doesnt exist");
    }
    
    Date currTime = new Date();
    entity.setUpdatedBy(WorkflowConstants.DEFAULT_USER);
    entity.setUpdatedTime(currTime);
    entity.setStatus(TraceStatus.Completed);
    entity.setEndTime(currTime);
    
    serviceNodeStatusRepository.saveAndFlush(entity);
    
}
 
Example 3
Source File: EmitEventAdapter.java    From flowing-retail with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(DelegateExecution context) throws Exception {
  String traceId = context.getProcessBusinessKey();

  String eventNameString = null;
  if (eventName!=null && eventName.getValue(context)!=null) {
    eventNameString = (String) eventName.getValue(context);
  } else {
    // if not configured we use the element id from the flow definition as default
    eventNameString = context.getCurrentActivityId();
  }
  
  messageSender.send(new Message<String>( //
      eventNameString, //
      traceId, //
      null)); // no payload at the moment
}
 
Example 4
Source File: CdiEventListener.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected BusinessProcessEvent createEvent(DelegateExecution execution) {
  ProcessDefinition processDefinition = Context.getExecutionContext().getProcessDefinition();

  // map type
  String eventName = execution.getEventName();
  BusinessProcessEventType type = null;
  if(ExecutionListener.EVENTNAME_START.equals(eventName)) {
    type = BusinessProcessEventType.START_ACTIVITY;
  } else if(ExecutionListener.EVENTNAME_END.equals(eventName)) {
    type = BusinessProcessEventType.END_ACTIVITY;
  } else if(ExecutionListener.EVENTNAME_TAKE.equals(eventName)) {
    type = BusinessProcessEventType.TAKE;
  }

  return new CdiBusinessProcessEvent(execution.getCurrentActivityId(), execution.getCurrentTransitionId(), processDefinition, execution, type, ClockUtil.getCurrentTime());
}
 
Example 5
Source File: DelegateEvent.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public static DelegateEvent fromExecution(DelegateExecution delegateExecution) {
  DelegateEvent event = new DelegateEvent();

  event.activityInstanceId = delegateExecution.getActivityInstanceId();
  event.businessKey = delegateExecution.getBusinessKey();
  event.currentActivityId = delegateExecution.getCurrentActivityId();
  event.currentActivityName = delegateExecution.getCurrentActivityName();
  event.currentTransitionId = delegateExecution.getCurrentTransitionId();
  event.eventName = delegateExecution.getEventName();
  event.id = delegateExecution.getId();
  event.parentActivityInstanceId = delegateExecution.getParentActivityInstanceId();
  event.parentId = delegateExecution.getParentId();
  event.processBusinessKey = delegateExecution.getProcessBusinessKey();
  event.processDefinitionId = delegateExecution.getProcessDefinitionId();
  event.processInstanceId = delegateExecution.getProcessInstanceId();
  event.tenantId = delegateExecution.getTenantId();
  event.variableScopeKey = delegateExecution.getVariableScopeKey();

  return event;
}
 
Example 6
Source File: AbstractServiceNodeListener.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
protected boolean isCustomServiceTask(DelegateExecution execution) {

        String activityId = execution.getCurrentActivityId();
        if (activityId != null) {
            if (activityId.startsWith("srvBeanST-") || activityId.startsWith("srvTimeOutBeanST-")
                    || activityId.startsWith("srvFailBeanST-")) {
                return true;
            }
        }
        return false;
    }
 
Example 7
Source File: AbstractServiceTaskHandleDelegate.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
protected void logServiceNodeExecution(DelegateExecution execution) {
    String activityId = execution.getCurrentActivityId();
    if (activityId == null) {
        return;
    }

    String nodeId = activityId;
    if (activityId.startsWith(WorkflowConstants.PREFIX_SRV_BEAN_SERVICETASK)) {
        nodeId = activityId.substring(WorkflowConstants.PREFIX_SRV_BEAN_SERVICETASK.length());
    }

    String procInstanceBizKey = execution.getProcessBusinessKey();

    ServiceNodeStatusRepository repository = SpringApplicationContextUtil
            .getBean(ServiceNodeStatusRepository.class);

    ServiceNodeStatusEntity entity = repository.findOneByProcInstanceBizKeyAndNodeId(procInstanceBizKey, nodeId);

    if (entity != null) {
        entity.setTryTimes(entity.getTryTimes() + 1);
        entity.setStatus(TraceStatus.InProgress);
        entity.setUpdatedTime(new Date());
        entity.setUpdatedBy(WorkflowConstants.DEFAULT_USER);
        repository.save(entity);
    }

}
 
Example 8
Source File: AbstractServiceExceptionHandleDelegate.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
protected void logServiceNodeException(DelegateExecution execution, TraceStatus traceStatus, String idPrefix) {
    String activityId = execution.getCurrentActivityId();
    if (activityId == null) {
        return;
    }

    if (!activityId.startsWith(idPrefix)) {
        return;
    }

    String nodeId = activityId.substring(idPrefix.length());
    String procInstanceBizKey = execution.getProcessBusinessKey();

    ServiceNodeStatusRepository repository = SpringApplicationContextUtil
            .getBean(ServiceNodeStatusRepository.class);

    ServiceNodeStatusEntity entity = repository.findOneByProcInstanceBizKeyAndNodeId(procInstanceBizKey, nodeId);

    if (entity == null) {
        getLogger().warn("{} doesnt exist for procInstanceBizKey={},nodeId={}",
                ServiceNodeStatusEntity.class.getSimpleName(), procInstanceBizKey, nodeId);
        throw new IllegalStateException("Entity doesnt exist");
    }

    entity.setUpdatedBy(WorkflowConstants.DEFAULT_USER);
    entity.setUpdatedTime(new Date());
    entity.setStatus(traceStatus);

    repository.save(entity);
}
 
Example 9
Source File: SelectorBuilder.java    From camunda-bpm-reactor with Apache License 2.0 5 votes vote down vote up
public static SelectorBuilder selector(final DelegateExecution delegateExecution) {
  String typeName = extractTypeName(delegateExecution);
  String element = ("sequenceFlow".equals(typeName))
    ? delegateExecution.getCurrentTransitionId()
    : delegateExecution.getCurrentActivityId();

  return selector()
    .context(Context.bpmn)
    .type(typeName)
    .process(GetProcessDefinitionKey.from(delegateExecution))
    .element(element)
    .event(delegateExecution.getEventName());
}
 
Example 10
Source File: ExecutionEvent.java    From camunda-bpm-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
public ExecutionEvent(DelegateExecution delegateExecution) {
  this.activityInstanceId = delegateExecution.getActivityInstanceId();
  this.businessKey = delegateExecution.getBusinessKey();
  this.currentActivityId = delegateExecution.getCurrentActivityId();
  this.currentActivityName = delegateExecution.getCurrentActivityName();
  this.currentTransitionId = delegateExecution.getCurrentTransitionId();
  this.eventName = delegateExecution.getEventName();
  this.id = delegateExecution.getId();
  this.parentActivityInstanceId = delegateExecution.getParentActivityInstanceId();
  this.parentId = delegateExecution.getParentId();
  this.processBusinessKey = delegateExecution.getProcessBusinessKey();
  this.processDefinitionId = delegateExecution.getProcessDefinitionId();
  this.processInstanceId = delegateExecution.getProcessInstanceId();
  this.tenantId = delegateExecution.getTenantId();
}
 
Example 11
Source File: ExecutionEvent.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public ExecutionEvent(DelegateExecution delegateExecution) {
  this.activityInstanceId = delegateExecution.getActivityInstanceId();
  this.businessKey = delegateExecution.getBusinessKey();
  this.currentActivityId = delegateExecution.getCurrentActivityId();
  this.currentActivityName = delegateExecution.getCurrentActivityName();
  this.currentTransitionId = delegateExecution.getCurrentTransitionId();
  this.eventName = delegateExecution.getEventName();
  this.id = delegateExecution.getId();
  this.parentActivityInstanceId = delegateExecution.getParentActivityInstanceId();
  this.parentId = delegateExecution.getParentId();
  this.processBusinessKey = delegateExecution.getProcessBusinessKey();
  this.processDefinitionId = delegateExecution.getProcessDefinitionId();
  this.processInstanceId = delegateExecution.getProcessInstanceId();
  this.tenantId = delegateExecution.getTenantId();
}
 
Example 12
Source File: ProcessApplicationEventListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testIntermediateTimerEvent() {

  // given
  final List<String> timerEvents = new ArrayList<String>();

  EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication() {
    public ExecutionListener getExecutionListener() {
      return new ExecutionListener() {
        public void notify(DelegateExecution delegateExecution) {
          String currentActivityId = delegateExecution.getCurrentActivityId();
          String eventName = delegateExecution.getEventName();
          if ("timer".equals(currentActivityId) &&
              (ExecutionListener.EVENTNAME_START.equals(eventName) || ExecutionListener.EVENTNAME_END.equals(eventName))) {
            timerEvents.add(delegateExecution.getEventName());
          }
        }
      };
    }
  };

  // register app so that it is notified about events
  managementService.registerProcessApplication(deploymentId, processApplication.getReference());

  // when
  runtimeService.startProcessInstanceByKey("process");
  String jobId = managementService.createJobQuery().singleResult().getId();
  managementService.executeJob(jobId);

  // then
  assertEquals(2, timerEvents.size());

  // "start" event listener
  assertEquals(ExecutionListener.EVENTNAME_START, timerEvents.get(0));

  // "end" event listener
  assertEquals(ExecutionListener.EVENTNAME_END, timerEvents.get(1));
}
 
Example 13
Source File: ProcessApplicationEventListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testIntermediateSignalEvent() {

  // given
  final List<String> timerEvents = new ArrayList<String>();

  EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication() {
    public ExecutionListener getExecutionListener() {
      return new ExecutionListener() {
        public void notify(DelegateExecution delegateExecution) {
          String currentActivityId = delegateExecution.getCurrentActivityId();
          String eventName = delegateExecution.getEventName();
          if ("signal".equals(currentActivityId) &&
              (ExecutionListener.EVENTNAME_START.equals(eventName) || ExecutionListener.EVENTNAME_END.equals(eventName))) {
            timerEvents.add(delegateExecution.getEventName());
          }
        }
      };
    }
  };

  // register app so that it is notified about events
  managementService.registerProcessApplication(deploymentId, processApplication.getReference());

  // when
  runtimeService.startProcessInstanceByKey("process");
  runtimeService.signalEventReceived("abort");

  // then
  assertEquals(2, timerEvents.size());

  // "start" event listener
  assertEquals(ExecutionListener.EVENTNAME_START, timerEvents.get(0));

  // "end" event listener
  assertEquals(ExecutionListener.EVENTNAME_END, timerEvents.get(1));
}
 
Example 14
Source File: TestExecutionListener.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void notify(DelegateExecution execution) throws Exception {
  String counterKey = execution.getCurrentActivityId() + "-" +execution.getEventName();
  collectedEvents.add(counterKey);
}
 
Example 15
Source File: IntermediateEventExecutionListener.java    From camunda-bpm-process-test-coverage with Apache License 2.0 3 votes vote down vote up
private CoveredFlowNode createCoveredFlowNode(DelegateExecution execution) {

        // Get the process definition in order to obtain the key
        final RepositoryService repositoryService = execution.getProcessEngineServices().getRepositoryService();
        final ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(
                execution.getProcessDefinitionId()).singleResult();

        final String currentActivityId = execution.getCurrentActivityId();

        final CoveredFlowNode coveredFlowNode = new CoveredFlowNode(processDefinition.getKey(), currentActivityId);

        return coveredFlowNode;
    }