コード例 #1
0
  protected void setVariable(
      Execution execution,
      String name,
      Object value,
      RestVariable.RestVariableScope scope,
      boolean isNew) {
    // Create can only be done on new variables. Existing variables should be updated using PUT
    boolean hasVariable = hasVariableOnScope(execution, name, scope);
    if (isNew && hasVariable) {
      throw new ActivitiException(
          "Variable '" + name + "' is already present on execution '" + execution.getId() + "'.");
    }

    if (!isNew && !hasVariable) {
      throw new ActivitiObjectNotFoundException(
          "Execution '"
              + execution.getId()
              + "' doesn't have a variable with name: '"
              + name
              + "'.",
          null);
    }

    RuntimeService runtimeService = BPMNOSGIService.getRumtimeService();
    if (scope == RestVariable.RestVariableScope.LOCAL) {
      runtimeService.setVariableLocal(execution.getId(), name, value);
    } else {
      if (execution.getParentId() != null) {
        runtimeService.setVariable(execution.getParentId(), name, value);
      } else {
        runtimeService.setVariable(execution.getId(), name, value);
      }
    }
  }