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);
    }
  }
  @Override
  protected ConsumerGroupSPI internalCreateConsumerGroup(String name) throws RegistrationException {
    ConsumerGroupSPI group = super.internalCreateConsumerGroup(name);

    ChromatticSession session = persister.getSession();
    mappings =
        session.findByPath(ConsumersAndGroupsMapping.class, ConsumersAndGroupsMapping.NODE_NAME);
    try {
      ConsumerGroupMapping cgm = mappings.createConsumerGroup(name);
      mappings.getConsumerGroups().add(cgm);
      group.setPersistentKey(cgm.getPersistentKey());
      cgm.initFrom(group);
      persister.closeSession(true);
    } catch (Exception e) {
      persister.closeSession(false);
      throw new RegistrationException(e);
    }

    return group;
  }