/**
   * Updates an existing {@link UdaDefinition} - if it was not found, nothing will be done. Checks
   * if the caller is the owner, performs business key uniqueness check if the id has changed and
   * validates the passed {@link VOUdaDefinition}.
   *
   * @param voDef the updated {@link VOUdaDefinition}
   * @param owner the owning {@link Organization}
   * @throws OperationNotPermittedException in case the calling {@link Organization} is not the
   *     owner
   * @throws ValidationException in case the passed {@link VOUdaDefinition} is invalid
   * @throws ConcurrentModificationException in case the {@link UdaDefinition} to update has been
   *     changed concurrently
   * @throws NonUniqueBusinessKeyException in case the change leads to a non-unique business key
   * @throws ObjectNotFoundException in case the {@link UdaDefinition} to update was not found
   */
  void updateDefinition(VOUdaDefinition voDef, Organization owner)
      throws OperationNotPermittedException, ValidationException, ConcurrentModificationException,
          NonUniqueBusinessKeyException, ObjectNotFoundException {

    UdaDefinition existing = ds.getReference(UdaDefinition.class, voDef.getKey());
    PermissionCheck.owns(existing, owner, logger, ctx);
    // target type and encryption flag must not be changed as it will cause
    // inconsistencies for all depending UDAs

    voDef.setTargetType(existing.getTargetType().name());
    voDef.setEncrypted(existing.isEncrypted());

    // verify business key uniqueness
    UdaDefinition tempForUniquenessCheck = null;
    tempForUniquenessCheck = UdaAssembler.toUdaDefinition(voDef);

    tempForUniquenessCheck.setOrganization(owner);
    tempForUniquenessCheck.setKey(existing.getKey());
    try {
      ds.validateBusinessKeyUniqueness(tempForUniquenessCheck);
      UdaAssembler.updateUdaDefinition(existing, voDef);
    } catch (NonUniqueBusinessKeyException e) {
      logger.logWarn(
          Log4jLogger.SYSTEM_LOG,
          e,
          LogMessageIdentifier.WARN_NON_UNIQUE_BUSINESS_KEY_UDA_DEFINITION);
      ctx.setRollbackOnly();
      throw e;
    }
  }
  /**
   * Deletes the passed list of {@link VOUdaDefinition}s - ignores the ones that are not found. For
   * the found ones, access permission and concurrent modification checks will be performed.
   *
   * @param defs the {@link VOUdaDefinition} to delete
   * @param caller the calling {@link Organization}
   * @throws OperationNotPermittedException
   * @throws ConcurrentModificationException
   */
  public void deleteUdaDefinitions(List<VOUdaDefinition> defs, Organization caller)
      throws OperationNotPermittedException, ConcurrentModificationException {

    for (VOUdaDefinition voDef : defs) {
      UdaDefinition existing = ds.find(UdaDefinition.class, voDef.getKey());
      if (existing == null) {
        // already deleted
        continue;
      }
      PermissionCheck.owns(existing, caller, logger, ctx);
      UdaAssembler.verifyVersionAndKey(existing, voDef);
      // cascade rule will cause deletion of udas as well
      ds.remove(existing);
    }
  }