in src/main/java/com/googlesource/gerrit/plugins/importer/ImportGroup.java [206:255]
private AccountGroup createGroup(Input input, GroupInfo info)
throws OrmException, NoSuchAccountException, IOException, RestApiException,
ConfigInvalidException {
String uniqueName = getUniqueGroupName(info.name);
if (!info.name.equals(uniqueName)) {
log.warn(
String.format(
"Group %s with UUID %s is imported with name %s", info.name, info.id, uniqueName));
info.name = uniqueName;
}
AccountGroup group = createAccountGroup(info);
AccountGroupName gn = new AccountGroupName(group);
// first insert the group name to validate that the group name hasn't
// already been used to create another group
try {
db.accountGroupNames().insert(Collections.singleton(gn));
} catch (OrmDuplicateKeyException e) {
throw new ResourceConflictException(info.name);
}
db.accountGroups().insert(Collections.singleton(group));
groupCache.evict(group.getGroupUUID(), group.getId(), group.getNameKey());
if (!info.id.equals(info.ownerId)) {
if (getGroupByUUID(info.ownerId) == null) {
if (isInternalGroup(new AccountGroup.UUID(info.ownerId))) {
String ownerGroupName = getGroupName(info.ownerId);
if (input.importOwnerGroup) {
importGroupFactory
.create(new AccountGroup.NameKey(ownerGroupName))
.apply(new ConfigResource(), input);
} else {
throw new IllegalStateException(
String.format(
"Cannot set non-existing group %s as owner of group %s.",
ownerGroupName, info.name));
}
}
}
group.setOwnerGroupUUID(new AccountGroup.UUID(info.ownerId));
db.accountGroups().upsert(Collections.singleton(group));
}
addMembers(group.getId(), info.members);
addGroups(input, group.getId(), info.name, info.includes);
groupCache.evict(group.getGroupUUID(), group.getId(), group.getNameKey());
return group;
}