List configs = getAdminConfig(companyId, type);
AdminConfig config = null;
UserConfig userConfig = null;
if (configs.size() == 0) {
String configId = Long.toString(CounterManagerUtil.increment(
AdminConfig.class.getName()));
Company company = CompanyManagerUtil.getCompany(companyId);
userConfig = new UserConfig(
UserConfig.DEFAULT_GROUPS, UserConfig.DEFAULT_ROLES,
UserConfig.DEFAULT_RESERVED_USER_IDS,
UserConfig.DEFAULT_RESERVED_USER_EMAIL_ADDRESSES,
UserConfig.DEFAULT_MAIL_HOST_NAMES,
_getUserConfigRegistrationEmail());
config = AdminConfigUtil.create(configId);
config.setCompanyId(companyId);
config.setType(type);
config.setName(name);
config.setConfigObj(userConfig);
AdminConfigUtil.update(config);
configs.add(config);
}
else {
config = (AdminConfig)configs.iterator().next();
userConfig = (UserConfig)config.getConfigObj();
}
// Make sure new fields are not null
if (userConfig.getRegistrationEmail() == null) {
userConfig.setRegistrationEmail(_getUserConfigRegistrationEmail());
config.setConfigObj(userConfig);
AdminConfigUtil.update(config);
}