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

The following examples show how to use org.camunda.bpm.engine.delegate.DelegateExecution#getVariable() . 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: ChargeCreditCardAdapter.java    From flowing-retail with Apache License 2.0 6 votes vote down vote up
public void execute(DelegateExecution ctx) throws Exception {
  CreateChargeRequest request = new CreateChargeRequest();
  request.amount = (int) ctx.getVariable("remainingAmount");

  CreateChargeResponse response = rest.postForObject( //
      stripeChargeUrl, //
      request, //
      CreateChargeResponse.class);   
  
  // TODO Add error scenarios to StripeFake and then raise "Error_CreditCardError" here
  if (response.errorCode!=null) {
    ctx.setVariable("errorCode", response.errorCode);
    throw new BpmnError("Error_PaymentError");
  }

  ctx.setVariable("paymentTransactionId", response.transactionId);
}
 
Example 2
Source File: ThrowBpmnErrorDelegate.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void execute(DelegateExecution execution) throws Exception {
  Integer executionsBeforeError = (Integer) execution.getVariable("executionsBeforeError");
  Integer executions = (Integer) execution.getVariable("executions");
  Boolean exceptionType = (Boolean) execution.getVariable("exceptionType");
  if (executions == null) {
    executions = 0;
  }
  executions++;
  if (executionsBeforeError == null || executionsBeforeError < executions) {
    if (exceptionType != null && exceptionType) {
      throw new MyBusinessException("This is a business exception, which can be caught by a BPMN Error Event.");  
    } else {
      throw new BpmnError("23", "This is a business fault, which can be caught by a BPMN Error Event.");
    }
  } else {
    execution.setVariable("executions", executions);
  }
}
 
Example 3
Source File: FirstFailingDelegate.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) throws Exception {
  Boolean fail = (Boolean) execution.getVariable("firstFail");

  if (fail == null || fail == true) {
    throw new ProcessEngineException(FIRST_EXCEPTION_MESSAGE);
  }
}
 
Example 4
Source File: ThrowBpmnErrorDelegate.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void throwErrorIfRequested(DelegateExecution execution) {
  Boolean shouldThrowError = (Boolean) execution.getVariable(ERROR_INDICATOR_VARIABLE);

  if (Boolean.TRUE.equals(shouldThrowError)) {
    String errorName = (String) execution.getVariable(ERROR_NAME_VARIABLE);
    if (errorName == null) {
      errorName = DEFAULT_ERROR_NAME;
    }

    throw new BpmnError(errorName);
  }
}
 
Example 5
Source File: PaymentCompletedAdapter.java    From flowing-retail-old with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) throws Exception {
  PaymentEventProducer eventProducer = new PaymentEventProducer();
  
  String transactionId = (String)execution.getVariable("transactionId");
  String refId = (String)execution.getVariable("refId");
  String reason = (String)execution.getVariable("reason");

  eventProducer.publishEventPaymentReceivedEvent(transactionId, refId, reason);
}
 
Example 6
Source File: PaymentRestHacksControllerV4.java    From flowing-retail with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution ctx) throws Exception {
  CreateChargeRequest request = new CreateChargeRequest();
  request.amount = (long) ctx.getVariable("amount");

  CreateChargeResponse response = new HystrixCommand<CreateChargeResponse>(HystrixCommandGroupKey.Factory.asKey("stripe")) {
    protected CreateChargeResponse run() throws Exception {
      return rest.postForObject( //
          stripeChargeUrl, //
          request, //
          CreateChargeResponse.class);
    }
  }.execute();
  
  ctx.setVariable("paymentTransactionId", response.transactionId);
}
 
Example 7
Source File: TransientVariableTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) throws Exception {
  for (char i = 'a'; i < 'm'; i++) {
    Object value = execution.getVariable("" + i);
    // variable 'j' is a transient null
    if (i != 'j' ) {
      assertNotNull(value);
    } else assertNull(value);
  }
}
 
Example 8
Source File: DummyServiceTask.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) throws Exception {
  boolean expressionWasExecuted = (Boolean )execution.getVariable("expressionWasExecuted");
  boolean delegateExpressionWasExecuted = (Boolean )execution.getVariable("delegateExpressionWasExecuted");
  boolean wasExecuted = (Boolean )execution.getVariable("wasExecuted");
  
  this.expressionWasExecuted = expressionWasExecuted;
  this.delegateExpressionWasExecuted = delegateExpressionWasExecuted;
  this.wasExecuted = wasExecuted;
}
 
Example 9
Source File: BookFlightService.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) throws Exception {
  String flight = (String) execution.getVariable("flight");

  if (flight != null) {
    bookedFlights.add(flight);
  }
}
 
Example 10
Source File: ReservePaymentActivity.java    From Hands-On-RESTful-API-Design-Patterns-and-Best-Practices with MIT License 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) throws Exception {
	LOG.info("execute {} - {}", ProcessConstants.SERVICE_NAME_PAYMENT, SERVICE_ACTION);
	BusinessEntity sc = (BusinessEntity) execution.getVariable(ProcessConstants.VAR_SC);
	ServiceResponse response = rpcClient.invokeService(
			ProcessUtil.buildServiceRequest(sc, ProcessConstants.SERVICE_NAME_PAYMENT, SERVICE_ACTION));
	ProcessUtil.processResponse(execution, response);
	execution.setVariable(ProcessConstants.VAR_PAYMENT_RESERVED, true);
}
 
Example 11
Source File: FailingDelegate.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) throws Exception {
  
  Boolean fail = (Boolean) execution.getVariable("fail");
  
  if (fail != null && fail == true) {
    throw new ProcessEngineException("Expected exception");
  }
}
 
Example 12
Source File: RemoveAndUpdateValueDelegate.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) throws Exception {
  List<String> list = (List<String>) execution.getVariable("listVar");

  execution.removeVariable("listVar");

  // implicitly update the previous list, should update the variable value
  list.add(NEW_ELEMENT);
}
 
Example 13
Source File: SendSignalDelegate.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) throws Exception {
  businessProcess.setVariable("processName", "throwSignal-visited (was " + businessProcess.getVariable("processName")  + ")");

  String signalProcessInstanceId = (String) execution.getVariable("signalProcessInstanceId");
  String executionId = runtimeService.createExecutionQuery().processInstanceId(signalProcessInstanceId).signalEventSubscriptionName("alert").singleResult().getId();

  CommandContext commandContext = Context.getCommandContext();
  List<EventSubscriptionEntity> findSignalEventSubscriptionsByEventName = commandContext
          .getEventSubscriptionManager()
          .findSignalEventSubscriptionsByNameAndExecution("alert", executionId);

  for (EventSubscriptionEntity signalEventSubscriptionEntity : findSignalEventSubscriptionsByEventName) {
      signalEventSubscriptionEntity.eventReceived(null, true);
  }
}
 
Example 14
Source File: ReplaceAndUpdateValueDelegate.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) throws Exception {
  List<String> list = (List<String>) execution.getVariable("listVar");

  // replace the list by another object
  execution.setVariable("listVar", new ArrayList<String>());

  // implicitly update the previous list, should update the variable value
  list.add(NEW_ELEMENT);
}
 
Example 15
Source File: UpdateRouterConfiguration.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) throws Exception {
  
  String version = (String) execution.getVariable("version");
  if ("1.0".equals(version) || "2.0".equals(version)) {
    System.out.println(" ### Updating router configuration..." );
  } else {
    throw new Exception("Unsupported Version: " + version);
  }
}
 
Example 16
Source File: AssertVariableInstancesDelegate.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) throws Exception {

    // validate integer variable
    Integer expectedIntValue = 1234;
    assertEquals(expectedIntValue, execution.getVariable("anIntegerVariable"));
    assertEquals(expectedIntValue, execution.getVariableTyped("anIntegerVariable").getValue());
    assertEquals(ValueType.INTEGER, execution.getVariableTyped("anIntegerVariable").getType());
    assertNull(execution.getVariableLocal("anIntegerVariable"));
    assertNull(execution.getVariableLocalTyped("anIntegerVariable"));

    // set an additional local variable
    execution.setVariableLocal("aStringVariable", "aStringValue");

    String expectedStringValue = "aStringValue";
    assertEquals(expectedStringValue, execution.getVariable("aStringVariable"));
    assertEquals(expectedStringValue, execution.getVariableTyped("aStringVariable").getValue());
    assertEquals(ValueType.STRING, execution.getVariableTyped("aStringVariable").getType());
    assertEquals(expectedStringValue, execution.getVariableLocal("aStringVariable"));
    assertEquals(expectedStringValue, execution.getVariableLocalTyped("aStringVariable").getValue());
    assertEquals(ValueType.STRING, execution.getVariableLocalTyped("aStringVariable").getType());

    SimpleSerializableBean objectValue = (SimpleSerializableBean) execution.getVariable("anObjectValue");
    assertNotNull(objectValue);
    assertEquals(10, objectValue.getIntProperty());
    ObjectValue variableTyped = execution.getVariableTyped("anObjectValue");
    assertEquals(10, variableTyped.getValue(SimpleSerializableBean.class).getIntProperty());
    assertEquals(Variables.SerializationDataFormats.JAVA.getName(), variableTyped.getSerializationDataFormat());

    objectValue = (SimpleSerializableBean) execution.getVariable("anUntypedObjectValue");
    assertNotNull(objectValue);
    assertEquals(30, objectValue.getIntProperty());
    variableTyped = execution.getVariableTyped("anUntypedObjectValue");
    assertEquals(30, variableTyped.getValue(SimpleSerializableBean.class).getIntProperty());
    assertEquals(Context.getProcessEngineConfiguration().getDefaultSerializationFormat(), variableTyped.getSerializationDataFormat());

  }
 
Example 17
Source File: SetBusinessKeyTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(DelegateExecution execution) throws Exception {
  String newKeyValue = (String) execution.getVariable(BUSINESS_KEY_VARIABLE);
  execution.setProcessBusinessKey(newKeyValue);
}
 
Example 18
Source File: SetBusinessKeyListener.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
  DelegateExecution execution = delegateTask.getExecution();
  String newKeyValue = (String) execution.getVariable(BUSINESS_KEY_VARIABLE);
  execution.setProcessBusinessKey(newKeyValue);
}
 
Example 19
Source File: IncidentTimestampScenario.java    From camunda-bpm-platform with Apache License 2.0 3 votes vote down vote up
@Override
public void execute(DelegateExecution execution) throws Exception {

  Boolean fail = (Boolean) execution.getVariable("fail");

  if (fail == null || fail == true) {
    throw new ProcessEngineException(EXCEPTION_MESSAGE);
  }

}
 
Example 20
Source File: ImplicitObjectValueUpdateHandler.java    From camunda-bpm-platform with Apache License 2.0 2 votes vote down vote up
public void execute(DelegateExecution execution) throws Exception {
  JsonSerializable variable = (JsonSerializable) execution.getVariable(VARIABLE_NAME);

  addADay(variable);  // implicit update, i.e. no setVariable call

}