/**
   * This method will create a {@link FunctionDefintion} as described by the function passed in.
   *
   * @see
   *     org.kuali.rice.krms.impl.repository.FunctionBoService#createFunction(org.kuali.rice.krms.api.repository.function.FunctionDefinition)
   */
  @Override
  public FunctionDefinition createFunction(FunctionDefinition function) {
    if (function == null) {
      throw new IllegalArgumentException("function is null");
    }

    final String nameKey = function.getName();
    final String namespaceKey = function.getNamespace();
    final FunctionDefinition existing = getFunctionByNameAndNamespace(nameKey, namespaceKey);
    if (existing != null
        && existing.getName().equals(nameKey)
        && existing.getNamespace().equals(namespaceKey)) {
      throw new IllegalStateException("the function to create already exists: " + function);
    }

    FunctionBo functionBo = FunctionBo.from(function);
    businessObjectService.save(functionBo);
    return FunctionBo.to(functionBo);
  }
  /**
   * This overridden method updates an existing Function in the repository
   *
   * @see
   *     org.kuali.rice.krms.impl.repository.FunctionBoService#updateFunction(org.kuali.rice.krms.api.repository.function.FunctionDefinition)
   */
  @Override
  public void updateFunction(FunctionDefinition function) {
    if (function == null) {
      throw new IllegalArgumentException("function is null");
    }

    final String functionIdKey = function.getId();
    final FunctionDefinition existing = getFunctionById(functionIdKey);
    if (existing == null) {
      throw new IllegalStateException("the function does not exist: " + function);
    }
    final FunctionDefinition toUpdate;
    if (!existing.getId().equals(function.getId())) {
      final FunctionDefinition.Builder builder = FunctionDefinition.Builder.create(function);
      builder.setId(existing.getId());
      toUpdate = builder.build();
    } else {
      toUpdate = function;
    }

    businessObjectService.save(FunctionBo.from(toUpdate));
  }