private void generateIdForObject(
      PrismObject object, IdGeneratorResult result, Operation operation) {
    if (object == null) {
      return;
    }

    List<PrismContainer> containers = getChildrenContainers(object);
    Set<Long> usedIds = new HashSet<>();
    for (PrismContainer c : containers) {
      if (c == null || c.getValues() == null) {
        continue;
      }

      for (PrismContainerValue val : (List<PrismContainerValue>) c.getValues()) {
        if (val.getId() != null) {
          usedIds.add(val.getId());
        }
      }
    }

    Long nextId = 1L;
    for (PrismContainer c : containers) {
      if (c == null || c.getValues() == null) {
        continue;
      }

      for (PrismContainerValue val : (List<PrismContainerValue>) c.getValues()) {
        if (val.getId() != null) {
          if (Operation.ADD.equals(operation)) {
            result.getValues().add(val);
          }
          continue;
        }

        while (usedIds.contains(nextId)) {
          nextId++;
        }

        val.setId(nextId);
        usedIds.add(nextId);

        if (!Operation.ADD_WITH_OVERWRITE.equals(operation)
            && !Operation.MODIFY.equals(operation)) {
          result.getValues().add(val);
        }
      }
    }
  }
  /**
   * Method inserts id for prism container values, which didn't have ids, also returns all container
   * values which has generated id
   *
   * @param object
   * @return
   */
  public IdGeneratorResult generate(PrismObject object, Operation operation) {
    IdGeneratorResult result = new IdGeneratorResult();
    boolean adding = Operation.ADD.equals(operation);
    result.setGeneratedOid(adding);

    if (StringUtils.isEmpty(object.getOid())) {
      String oid = UUID.randomUUID().toString();
      object.setOid(oid);

      result.setGeneratedOid(true);
    }

    generateIdForObject(object, result, operation);

    return result;
  }