org.camunda.bpm.engine.delegate.DelegateCaseExecution Java Examples

The following examples show how to use org.camunda.bpm.engine.delegate.DelegateCaseExecution. 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: MyCaseExecutionListener.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void notify(DelegateCaseExecution caseExecution, String event) {
  String eventCounterName = event + "EventCounter";

  Integer eventCounter = (Integer) caseExecution.getVariable(eventCounterName);

  if (eventCounter == null) {
    eventCounter = 0;
  }

  Integer counter = (Integer) caseExecution.getVariable("eventCounter");

  if (counter == null) {
    counter = 0;
  }

  caseExecution.setVariable(event, true);
  caseExecution.setVariable(eventCounterName, eventCounter + 1);
  caseExecution.setVariable("eventCounter", counter + 1);
  caseExecution.setVariable(event+"OnCaseExecutionId", caseExecution.getId());

}
 
Example #2
Source File: TenantIdProviderTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void providerCalledWithSuperCaseInstance() {

  ContextLoggingTenantIdProvider tenantIdProvider = new ContextLoggingTenantIdProvider();
  TestTenantIdProvider.delegate = tenantIdProvider;

  testRule.deploy(CMMN_SUBPROCESS_FILE, CMMN_FILE_WITH_MANUAL_ACTIVATION);
  CaseDefinition superCaseDefinition = engineRule.getRepositoryService().createCaseDefinitionQuery().caseDefinitionKey(CASE_DEFINITION_KEY).singleResult();


  // if a case instance is created
  engineRule.getCaseService().withCaseDefinitionByKey(CASE_DEFINITION_KEY).create();
  startCaseTask();

  // then the tenant id provider is passed in the case definition
  DelegateCaseExecution superCaseExecution = tenantIdProvider.caseParameters.get(1).getSuperCaseExecution();
  assertThat(superCaseExecution, is(notNullValue()));
  assertThat(superCaseExecution.getCaseDefinitionId(), is(superCaseDefinition.getId()));
}
 
Example #3
Source File: DelegateExpressionCaseExecutionListener.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void notify(DelegateCaseExecution caseExecution) throws Exception {
  // Note: we can't cache the result of the expression, because the
  // caseExecution can change: eg. delegateExpression='${mySpringBeanFactory.randomSpringBean()}'
  Object delegate = expression.getValue(caseExecution);
  applyFieldDeclaration(fieldDeclarations, delegate);

  if (delegate instanceof CaseExecutionListener) {
    CaseExecutionListener listenerInstance = (CaseExecutionListener) delegate;
    Context
      .getProcessEngineConfiguration()
      .getDelegateInterceptor()
      .handleInvocation(new CaseExecutionListenerInvocation(listenerInstance, caseExecution));
  } else {
    throw new ProcessEngineException("Delegate expression " + expression
            + " did not resolve to an implementation of " + CaseExecutionListener.class);
  }
}
 
Example #4
Source File: DefaultCmmnHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public HistoryEvent createCaseInstanceCloseEvt(DelegateCaseExecution caseExecution) {
  final CaseExecutionEntity caseExecutionEntity = (CaseExecutionEntity) caseExecution;

  // create event instance
  HistoricCaseInstanceEventEntity evt = loadCaseInstanceEventEntity(caseExecutionEntity);

  // initialize event
  initCaseInstanceEvent(evt, caseExecutionEntity, HistoryEventTypes.CASE_INSTANCE_CLOSE);

  // set end time
  evt.setEndTime(ClockUtil.getCurrentTime());

  if (evt.getStartTime() != null) {
    evt.setDurationInMillis(evt.getEndTime().getTime() - evt.getStartTime().getTime());
  }

  return evt;
}
 
Example #5
Source File: DefaultCmmnHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public HistoryEvent createCaseActivityInstanceUpdateEvt(DelegateCaseExecution caseExecution) {
  final CaseExecutionEntity caseExecutionEntity = (CaseExecutionEntity) caseExecution;

  // create event instance
  HistoricCaseActivityInstanceEventEntity evt = loadCaseActivityInstanceEventEntity(caseExecutionEntity);

  // initialize event
  initCaseActivityInstanceEvent(evt, caseExecutionEntity, HistoryEventTypes.CASE_ACTIVITY_INSTANCE_UPDATE);

  if (caseExecutionEntity.getTask() != null) {
    evt.setTaskId(caseExecutionEntity.getTask().getId());
  }

  if (caseExecutionEntity.getSubProcessInstance() != null) {
    evt.setCalledProcessInstanceId(caseExecutionEntity.getSubProcessInstance().getId());
  }

  if (caseExecutionEntity.getSubCaseInstance() != null) {
    evt.setCalledCaseInstanceId(caseExecutionEntity.getSubCaseInstance().getId());
  }

  return evt;
}
 
Example #6
Source File: DefaultCmmnHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public HistoryEvent createCaseActivityInstanceEndEvt(DelegateCaseExecution caseExecution) {
  final CaseExecutionEntity caseExecutionEntity = (CaseExecutionEntity) caseExecution;

  // create event instance
  HistoricCaseActivityInstanceEventEntity evt = loadCaseActivityInstanceEventEntity(caseExecutionEntity);

  // initialize event
  initCaseActivityInstanceEvent(evt, caseExecutionEntity, HistoryEventTypes.CASE_ACTIVITY_INSTANCE_END);

  // set end time
  evt.setEndTime(ClockUtil.getCurrentTime());

  // calculate duration
  if (evt.getStartTime() != null) {
    evt.setDurationInMillis(evt.getEndTime().getTime() - evt.getStartTime().getTime());
  }

  return evt;
}
 
Example #7
Source File: DelegateTaskFakeTest.java    From camunda-bpm-mockito with Apache License 2.0 6 votes vote down vote up
@Test
public void delegateCaseExecution_use_attributes_from_execution() {
  delegate.withCaseExecutionId("1");
  assertThat(delegate.getCaseExecutionId()).isEqualTo("1");

  DelegateCaseExecution execution = new DelegateCaseExecutionFake("2")
    .withCaseDefinitionId("cd1")
    .withProcessEngineServices(processEngineServices)
    .withTenantId("tenant")
    .withCaseInstanceId("caId")
    ;
  delegate.withCaseExecution(execution);

  assertThat(delegate.getCaseExecutionId()).isEqualTo("2");
  assertThat(delegate.getCaseDefinitionId()).isEqualTo("cd1");
  assertThat(delegate.getProcessEngineServices()).isEqualTo(processEngineServices);
  assertThat(delegate.getTenantId()).isEqualTo("tenant");
  assertThat(delegate.getCaseInstanceId()).isEqualTo("caId");
}
 
Example #8
Source File: DelegateTaskFake.java    From camunda-bpm-mockito with Apache License 2.0 5 votes vote down vote up
private <T> T valueFromCaseOrProcessExecution(
  Function<DelegateExecution, T> fromProcess,
  Function<DelegateCaseExecution, T> fromCase,
  T fromTask) {

  return Optional.ofNullable(delegateExecution)
    .map(fromProcess)
    .orElse(Optional.ofNullable(delegateCaseExecution)
      .map(fromCase)
      .orElse(fromTask)
    );
}
 
Example #9
Source File: ClassDelegateCaseExecutionListener.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void notify(DelegateCaseExecution caseExecution) throws Exception {
  CaseExecutionListener listenerInstance = getListenerInstance();

  Context
    .getProcessEngineConfiguration()
    .getDelegateInterceptor()
    .handleInvocation(new CaseExecutionListenerInvocation(listenerInstance, caseExecution));
}
 
Example #10
Source File: ScriptCaseExecutionListener.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void notify(DelegateCaseExecution caseExecution) throws Exception {
  ScriptInvocation invocation = new ScriptInvocation(script, caseExecution);
  Context
    .getProcessEngineConfiguration()
    .getDelegateInterceptor()
    .handleInvocation(invocation);
}
 
Example #11
Source File: ExecutableScript.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected String getActivityIdExceptionMessage(VariableScope variableScope) {
  String activityId = null;
  String definitionIdMessage = "";

  if (variableScope instanceof DelegateExecution) {
    activityId = ((DelegateExecution) variableScope).getCurrentActivityId();
    definitionIdMessage = " in the process definition with id '" + ((DelegateExecution) variableScope).getProcessDefinitionId() + "'";
  } else if (variableScope instanceof TaskEntity) {
    TaskEntity task = (TaskEntity) variableScope;
    if (task.getExecution() != null) {
      activityId = task.getExecution().getActivityId();
      definitionIdMessage = " in the process definition with id '" + task.getProcessDefinitionId() + "'";
    }
    if (task.getCaseExecution() != null) {
      activityId = task.getCaseExecution().getActivityId();
      definitionIdMessage = " in the case definition with id '" + task.getCaseDefinitionId() + "'";
    }
  } else if (variableScope instanceof DelegateCaseExecution) {
    activityId = ((DelegateCaseExecution) variableScope).getActivityId();
    definitionIdMessage = " in the case definition with id '" + ((DelegateCaseExecution) variableScope).getCaseDefinitionId() + "'";
  }

  if (activityId == null) {
    return "";
  } else {
    return " while executing activity '" + activityId + "'" + definitionIdMessage;
  }
}
 
Example #12
Source File: CamundaEventBusTest.java    From camunda-bpm-reactor with Apache License 2.0 5 votes vote down vote up
@Test
public void notify_caseExecution() throws Exception {
  eventBus.register(SelectorBuilder.selector().context(cmmn), caseExecutionListener);

  DelegateCaseExecution execution= CamundaReactorTestHelper.delegateCaseExecution();
  when(execution.getProcessEngineServices().getRepositoryService()).thenReturn(repositoryService);

  eventBus.notify(execution);

  verify(caseExecutionListener).notify(execution);
}
 
Example #13
Source File: SelectorBuilder.java    From camunda-bpm-reactor with Apache License 2.0 5 votes vote down vote up
public static SelectorBuilder selector(final DelegateCaseExecution delegateCaseExecution) {
  String typeName = extractTypeName(delegateCaseExecution);
  String element = delegateCaseExecution.getActivityId();

  return selector()
    .context(Context.cmmn)
    .type(typeName)
    .caseDefinitionKey(GetProcessDefinitionKey.from(delegateCaseExecution))
    .element(element)
    .event(delegateCaseExecution.getEventName());
}
 
Example #14
Source File: ReactorCaseExecutionListenerTestHelper.java    From camunda-bpm-reactor with Apache License 2.0 5 votes vote down vote up
@Test
public void register() throws Exception {
  DelegateCaseExecution execution = delegateCaseExecution();

  camundaEventBus.notify(execution);

  assertThat(listener.received).isEqualTo(execution);
}
 
Example #15
Source File: AbstractListenerTestHelper.java    From camunda-bpm-reactor with Apache License 2.0 5 votes vote down vote up
public static DelegateCaseExecution delegateCaseExecution() {
  final DelegateCaseExecution execution = mock(DelegateCaseExecution.class, RETURNS_DEEP_STUBS);

  when(execution.getCmmnModelElementInstance().getElementType().getTypeName()).thenReturn("serviceTask");
  when(execution.getCaseDefinitionId()).thenReturn("process:1:1");
  when(execution.getEventName()).thenReturn("start");
  when(execution.getActivityId()).thenReturn("service1");

  return execution;
}
 
Example #16
Source File: DelegateTaskFake.java    From camunda-bpm-mockito with Apache License 2.0 5 votes vote down vote up
@Override
public ProcessEngineServices getProcessEngineServices() {
  return valueFromCaseOrProcessExecution(
    DelegateExecution::getProcessEngineServices,
    DelegateCaseExecution::getProcessEngineServices,
    processEngineServicesAwareFake.getProcessEngineServices()
  );
}
 
Example #17
Source File: CamundaReactorTestHelper.java    From camunda-bpm-reactor with Apache License 2.0 5 votes vote down vote up
public static DelegateCaseExecution delegateCaseExecution() {
  final DelegateCaseExecution execution = mock(DelegateCaseExecution.class, RETURNS_DEEP_STUBS);

  when(execution.getCmmnModelElementInstance().getElementType().getTypeName()).thenReturn("serviceTask");
  when(execution.getCaseDefinitionId()).thenReturn(CASE_DEFINITION_ID);
  when(execution.getEventName()).thenReturn("start");
  when(execution.getActivityId()).thenReturn("service1");

  return execution;
}
 
Example #18
Source File: FlightDepartedListener.java    From Showcase with Apache License 2.0 5 votes vote down vote up
public void notify(DelegateCaseExecution caseExecution) throws Exception {
    LOGGER.info("Plan Item '" + caseExecution.getActivityId()
            + "' labeled '" + caseExecution.getActivityName()
            + "' has performed transition: '" + caseExecution.getEventName()
            + "' with trackingId: '" + caseExecution.getCaseBusinessKey() + "'");

    shipmentBoundaryService.setStatus(caseExecution.getCaseBusinessKey(), Status.FLIGHT_DEPARTED);

}
 
Example #19
Source File: DefaultCmmnHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public HistoryEvent createCaseInstanceCreateEvt(DelegateCaseExecution caseExecution) {
  final CaseExecutionEntity caseExecutionEntity = (CaseExecutionEntity) caseExecution;

  // create event instance
  HistoricCaseInstanceEventEntity evt = newCaseInstanceEventEntity(caseExecutionEntity);

  // initialize event
  initCaseInstanceEvent(evt, caseExecutionEntity, HistoryEventTypes.CASE_INSTANCE_CREATE);

  // set create time
  evt.setCreateTime(ClockUtil.getCurrentTime());

  // set create user id
  evt.setCreateUserId(Context.getCommandContext().getAuthenticatedUserId());

  // set super case instance id
  CmmnExecution superCaseExecution = caseExecutionEntity.getSuperCaseExecution();
  if (superCaseExecution != null) {
    evt.setSuperCaseInstanceId(superCaseExecution.getCaseInstanceId());
  }

  // set super process instance id
  ExecutionEntity superExecution = caseExecutionEntity.getSuperExecution();
  if (superExecution != null) {
    evt.setSuperProcessInstanceId(superExecution.getProcessInstanceId());
  }

  return evt;
}
 
Example #20
Source File: DefaultCmmnHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public HistoryEvent createCaseInstanceUpdateEvt(DelegateCaseExecution caseExecution) {
  final CaseExecutionEntity caseExecutionEntity = (CaseExecutionEntity) caseExecution;

  // create event instance
  HistoricCaseInstanceEventEntity evt = loadCaseInstanceEventEntity(caseExecutionEntity);

  // initialize event
  initCaseInstanceEvent(evt, caseExecutionEntity, HistoryEventTypes.CASE_INSTANCE_UPDATE);

  return evt;
}
 
Example #21
Source File: DefaultCmmnHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public HistoryEvent createCaseActivityInstanceCreateEvt(DelegateCaseExecution caseExecution) {
  final CaseExecutionEntity caseExecutionEntity = (CaseExecutionEntity) caseExecution;

  // create event instance
  HistoricCaseActivityInstanceEventEntity evt = newCaseActivityInstanceEventEntity(caseExecutionEntity);

  // initialize event
  initCaseActivityInstanceEvent(evt, caseExecutionEntity, HistoryEventTypes.CASE_ACTIVITY_INSTANCE_CREATE);

  // set start time
  evt.setCreateTime(ClockUtil.getCurrentTime());

  return evt;
}
 
Example #22
Source File: CaseActivityInstanceUpdateListener.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected HistoryEvent createHistoryEvent(DelegateCaseExecution caseExecution) {
  ensureHistoryLevelInitialized();
  if (historyLevel.isHistoryEventProduced(HistoryEventTypes.CASE_ACTIVITY_INSTANCE_UPDATE, caseExecution)) {
    return eventProducer.createCaseActivityInstanceUpdateEvt(caseExecution);
  }
  else {
    return null;
  }
}
 
Example #23
Source File: CaseInstanceCloseListener.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected HistoryEvent createHistoryEvent(DelegateCaseExecution caseExecution) {
  ensureHistoryLevelInitialized();
  if (historyLevel.isHistoryEventProduced(HistoryEventTypes.CASE_INSTANCE_CLOSE, caseExecution)) {
    return eventProducer.createCaseInstanceCloseEvt(caseExecution);
  }
  else {
    return null;
  }
}
 
Example #24
Source File: CaseActivityInstanceEndListener.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected HistoryEvent createHistoryEvent(DelegateCaseExecution caseExecution) {
  ensureHistoryLevelInitialized();
  if (historyLevel.isHistoryEventProduced(HistoryEventTypes.CASE_ACTIVITY_INSTANCE_END, caseExecution)) {
    return eventProducer.createCaseActivityInstanceEndEvt(caseExecution);
  }
  else {
    return null;
  }
}
 
Example #25
Source File: CaseInstanceUpdateListener.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected HistoryEvent createHistoryEvent(DelegateCaseExecution caseExecution) {
  ensureHistoryLevelInitialized();
  if (historyLevel.isHistoryEventProduced(HistoryEventTypes.CASE_INSTANCE_UPDATE, caseExecution)) {
    return eventProducer.createCaseInstanceUpdateEvt(caseExecution);
  }
  else {
    return null;
  }
}
 
Example #26
Source File: CaseInstanceCreateListener.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected HistoryEvent createHistoryEvent(DelegateCaseExecution caseExecution) {
  ensureHistoryLevelInitialized();
  if (historyLevel.isHistoryEventProduced(HistoryEventTypes.CASE_INSTANCE_CREATE, caseExecution)) {
    return eventProducer.createCaseInstanceCreateEvt(caseExecution);
  }
  else {
    return null;
  }
}
 
Example #27
Source File: CaseActivityInstanceCreateListener.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected HistoryEvent createHistoryEvent(DelegateCaseExecution caseExecution) {
  ensureHistoryLevelInitialized();
  if (historyLevel.isHistoryEventProduced(HistoryEventTypes.CASE_ACTIVITY_INSTANCE_CREATE, caseExecution)) {
    return eventProducer.createCaseActivityInstanceCreateEvt(caseExecution);
  }
  else {
    return null;
  }
}
 
Example #28
Source File: HistoryCaseExecutionListener.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void notify(DelegateCaseExecution caseExecution) throws Exception {
  HistoryEvent historyEvent = createHistoryEvent(caseExecution);

  if (historyEvent != null) {
    Context.getProcessEngineConfiguration()
      .getHistoryEventHandler()
      .handleEvent(historyEvent);
  }

}
 
Example #29
Source File: MultiTenancyDelegateCaseExecutionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected static DelegateCaseExecutionAsserter hasTenantId(final String expectedTenantId) {
  return new DelegateCaseExecutionAsserter() {

    @Override
    public void doAssert(DelegateCaseExecution execution) {
      assertThat(execution.getTenantId(), is(expectedTenantId));
    }
  };
}
 
Example #30
Source File: FieldInjectionCaseExecutionListener.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void notify(DelegateCaseExecution caseExecution) {
  caseExecution.setVariable("greeting", "Hello from " + greeter.getValue(caseExecution));
  caseExecution.setVariable("helloWorld", helloWorld.getValue(caseExecution));
  caseExecution.setVariable("prefix", prefix.getValue(caseExecution));
  caseExecution.setVariable("suffix", suffix.getValue(caseExecution));

  // kind of workaround to pass through the test
  greeter = null;
  helloWorld = null;
  prefix = null;
  suffix = null;
}