Java Code Examples for org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution#setVariable()

The following examples show how to use org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution#setVariable() . 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: While.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void execute(ActivityExecution execution) throws Exception {
  PvmTransition more = execution.getActivity().findOutgoingTransition("more");
  PvmTransition done = execution.getActivity().findOutgoingTransition("done");

  Integer value = (Integer) execution.getVariable(variableName);

  if (value==null) {
    execution.setVariable(variableName, from);
    execution.leaveActivityViaTransition(more);

  } else {
    value = value+1;

    if (value<to) {
      execution.setVariable(variableName, value);
      execution.leaveActivityViaTransition(more);

    } else {
      execution.leaveActivityViaTransition(done);
    }
  }
}
 
Example 2
Source File: EscalationHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected static void executeEscalationHandler(EscalationEventDefinition escalationEventDefinition, ActivityExecutionMappingCollector activityExecutionMappingCollector, String escalationCode) {

    PvmActivity escalationHandler = escalationEventDefinition.getEscalationHandler();
    PvmScope escalationScope = getScopeForEscalation(escalationEventDefinition);
    ActivityExecution escalationExecution = activityExecutionMappingCollector.getExecutionForScope(escalationScope);

    if (escalationEventDefinition.getEscalationCodeVariable() != null) {
      escalationExecution.setVariable(escalationEventDefinition.getEscalationCodeVariable(), escalationCode);
    }

    escalationExecution.executeActivity(escalationHandler);
  }
 
Example 3
Source File: ThrowErrorDelegate.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void handle(ActivityExecution execution, String action) throws Exception {
  execution.setVariable(action, true);
  String type = (String) execution.getVariable("type");
  if ("error".equalsIgnoreCase(type)) {
    throw new BpmnError("MyError");
  }
  else if ("exception".equalsIgnoreCase(type)) {
    throw new MyBusinessException("MyException");
  }
  else if ("leave".equalsIgnoreCase(type)) {
    execution.setVariable("type", null);
    leave(execution);
  }
}
 
Example 4
Source File: WaitStateUndoService.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void execute(ActivityExecution execution) throws Exception {
  String variableName = (String) counterName.getValue(execution);
  Object variable = execution.getVariable(variableName);
  if(variable == null) {
    execution.setVariable(variableName, (Integer) 1);
  }
  else  {
    execution.setVariable(variableName, ((Integer)variable)+1);
  }
}
 
Example 5
Source File: ThrowErrorDelegate.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void handle(ActivityExecution execution, String action) throws Exception {
  execution.setVariable(action, true);
  String type = (String) execution.getVariable("type");
  if ("error".equalsIgnoreCase(type)) {
    throw new BpmnError("MyError");
  }
  else if ("exception".equalsIgnoreCase(type)) {
    throw new MyBusinessException("MyException");
  }
  else if ("leave".equalsIgnoreCase(type)) {
    execution.setVariable("type", null);
    leave(execution);
  }
}
 
Example 6
Source File: ShellActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void execute(ActivityExecution execution) {

    readFields(execution);

    List<String> argList = new ArrayList<String>();
    argList.add(commandStr);

    if (arg1Str != null)
      argList.add(arg1Str);
    if (arg2Str != null)
      argList.add(arg2Str);
    if (arg3Str != null)
      argList.add(arg3Str);
    if (arg4Str != null)
      argList.add(arg4Str);
    if (arg5Str != null)
      argList.add(arg5Str);

    ProcessBuilder processBuilder = new ProcessBuilder(argList);

    try {
      processBuilder.redirectErrorStream(redirectErrorFlag);
      if (cleanEnvBoolan) {
        Map<String, String> env = processBuilder.environment();
        env.clear();
      }
      if (directoryStr != null && directoryStr.length() > 0)
        processBuilder.directory(new File(directoryStr));

      Process process = processBuilder.start();

      if (waitFlag) {
        int errorCode = process.waitFor();

        if (resultVariableStr != null) {
          String result = convertStreamToStr(process.getInputStream());
          execution.setVariable(resultVariableStr, result);
        }

        if (errorCodeVariableStr != null) {
          execution.setVariable(errorCodeVariableStr, Integer.toString(errorCode));

        }

      }
    } catch (Exception e) {
      throw LOG.shellExecutionException(e);
    }

    leave(execution);
  }
 
Example 7
Source File: Printer.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void printMessage(ActivityExecution execution) {
  execution.setVariable("myVar", "Hello from Printer!");
}
 
Example 8
Source File: SentenceToUpperCaseBean.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void setSentence(ActivityExecution execution) {
  execution.setVariable("myVar", sentenceGenerator.getSentence().toUpperCase());
}