@PostConstruct
 public void loadOrganizationalUnits() {
   Collection<ConfigGroup> groups =
       configurationService.getConfiguration(ConfigType.ORGANIZATIONAL_UNIT);
   if (groups != null) {
     for (ConfigGroup groupConfig : groups) {
       OrganizationalUnit ou = organizationalUnitFactory.newOrganizationalUnit(groupConfig);
       registeredOrganizationalUnits.put(ou.getName(), ou);
     }
   }
 }
  @Override
  public void updateOrganizationalUnitOwner(final String name, final String owner) {
    final ConfigGroup thisGroupConfig = findGroupConfig(name);

    if (thisGroupConfig != null) {
      thisGroupConfig.setConfigItem(configurationFactory.newConfigItem("owner", owner));
      configurationService.updateConfiguration(thisGroupConfig);

      final OrganizationalUnit updatedOrganizationalUnit =
          organizationalUnitFactory.newOrganizationalUnit(thisGroupConfig);
      registeredOrganizationalUnits.put(
          updatedOrganizationalUnit.getName(), updatedOrganizationalUnit);
    } else {
      throw new IllegalArgumentException("OrganizationalUnit " + name + " not found");
    }
  }
  @Override
  public OrganizationalUnit createOrganizationalUnit(final String name, final String owner) {
    final ConfigGroup groupConfig =
        configurationFactory.newConfigGroup(ConfigType.ORGANIZATIONAL_UNIT, name, "");
    groupConfig.addConfigItem(configurationFactory.newConfigItem("owner", owner));
    groupConfig.addConfigItem(
        configurationFactory.newConfigItem("repositories", new ArrayList<String>()));
    groupConfig.addConfigItem(
        configurationFactory.newConfigItem("security:roles", new ArrayList<String>()));
    configurationService.addConfiguration(groupConfig);

    final OrganizationalUnit newOrganizationalUnit =
        organizationalUnitFactory.newOrganizationalUnit(groupConfig);
    registeredOrganizationalUnits.put(newOrganizationalUnit.getName(), newOrganizationalUnit);

    newOrganizationalUnitEvent.fire(new NewOrganizationalUnitEvent(newOrganizationalUnit));

    return newOrganizationalUnit;
  }
  @SuppressWarnings({"unchecked", "rawtypes"})
  @Override
  public void removeRole(final OrganizationalUnit organizationalUnit, final String role) {
    final ConfigGroup thisGroupConfig = findGroupConfig(organizationalUnit.getName());

    if (thisGroupConfig != null) {
      final ConfigItem<List> roles = thisGroupConfig.getConfigItem("security:roles");
      roles.getValue().remove(role);

      configurationService.updateConfiguration(thisGroupConfig);

      final OrganizationalUnit updatedOrganizationalUnit =
          organizationalUnitFactory.newOrganizationalUnit(thisGroupConfig);
      registeredOrganizationalUnits.put(
          updatedOrganizationalUnit.getName(), updatedOrganizationalUnit);
    } else {
      throw new IllegalArgumentException(
          "OrganizationalUnit " + organizationalUnit.getName() + " not found");
    }
  }
  @SuppressWarnings({"unchecked", "rawtypes"})
  @Override
  public void addRepository(
      final OrganizationalUnit organizationalUnit, final Repository repository) {
    final ConfigGroup thisGroupConfig = findGroupConfig(organizationalUnit.getName());

    if (thisGroupConfig != null) {
      ConfigItem<List> repositories = thisGroupConfig.getConfigItem("repositories");
      repositories.getValue().add(repository.getAlias());

      configurationService.updateConfiguration(thisGroupConfig);

      final OrganizationalUnit updatedOrganizationalUnit =
          organizationalUnitFactory.newOrganizationalUnit(thisGroupConfig);
      registeredOrganizationalUnits.put(
          updatedOrganizationalUnit.getName(), updatedOrganizationalUnit);
    } else {
      throw new IllegalArgumentException(
          "OrganizationalUnit " + organizationalUnit.getName() + " not found");
    }
  }