public ConsumerGroupSPI toModel(
      ConsumerGroupSPI initial, JCRRegistrationPersistenceManager persistenceManager) {
    ConsumerGroupSPI group =
        (initial != null ? initial : persistenceManager.newConsumerGroupSPI(getName()));
    group.setPersistentKey(getPersistentKey());
    RegistrationStatus status = getStatus();
    if (status == null) {
      status = RegistrationStatus.PENDING;
    }
    group.setStatus(status);

    try {
      for (ConsumerMapping cm : getConsumers()) {
        Consumer consumer = persistenceManager.getConsumerById(cm.getPersistentKey());
        if (consumer == null) {
          consumer = cm.toModel((ConsumerSPI) consumer, persistenceManager);
        }

        group.addConsumer(consumer);
      }

      return group;
    } catch (RegistrationException e) {
      throw new RuntimeException(e);
    }
  }
  public void initFrom(ConsumerGroupSPI group) {
    setName(group.getName());
    setStatus(group.getStatus());

    try {
      for (Consumer consumer : group.getConsumers()) {
        String id = consumer.getPersistentKey();
        ConsumerMapping cm = findConsumerById(id);
        ParameterValidation.throwIllegalArgExceptionIfNull(
            cm, "ConsumerMapping (no such mapping with id: " + id + ")");
        getConsumers().add(cm);
        cm.initFrom((ConsumerSPI) consumer);
      }
    } catch (RegistrationException e) {
      throw new RuntimeException(e);
    }
  }