use of com.google.gerrit.server.group.db.GroupConfig in project gerrit by GerritCodeReview.
the class Schema_184 method upgrade.
@Override
public void upgrade(Arguments args, UpdateUI ui) throws Exception {
try (Repository allUsersRepo = args.repoManager.openRepository(args.allUsers)) {
AccountGroup.NameKey newName = AccountGroup.nameKey(ServiceUserClassifier.SERVICE_USERS);
Optional<GroupReference> nonInteractiveUsers = GroupNameNotes.loadAllGroups(allUsersRepo).stream().filter(g -> g.getName().equals("Non-Interactive Users")).findAny();
if (!nonInteractiveUsers.isPresent()) {
return;
}
GroupNameNotes newNameNotes = GroupNameNotes.forRename(args.allUsers, allUsersRepo, nonInteractiveUsers.get().getUUID(), AccountGroup.nameKey(nonInteractiveUsers.get().getName()), newName);
GroupConfig groupConfig = GroupConfig.loadForGroup(args.allUsers, allUsersRepo, nonInteractiveUsers.get().getUUID());
groupConfig.setGroupDelta(GroupDelta.builder().setName(newName).build(), AuditLogFormatter.createPartiallyWorkingFallBack());
commit(args.allUsers, args.serverUser, allUsersRepo, groupConfig, newNameNotes);
index(args.groupIndexCollection, groupConfig.getLoadedGroup().orElseThrow(() -> new IllegalStateException("Created group wasn't automatically loaded")));
}
}
use of com.google.gerrit.server.group.db.GroupConfig in project gerrit by GerritCodeReview.
the class SchemaCreatorImpl method createGroupInNoteDb.
private InternalGroup createGroupInNoteDb(Repository allUsersRepo, InternalGroupCreation groupCreation, GroupDelta groupDelta) throws ConfigInvalidException, IOException, DuplicateKeyException {
// This method is only executed on a new server which doesn't have any accounts or groups.
AuditLogFormatter auditLogFormatter = AuditLogFormatter.createBackedBy(ImmutableSet.of(), ImmutableSet.of(), serverId);
GroupConfig groupConfig = GroupConfig.createForNewGroup(allUsersName, allUsersRepo, groupCreation);
groupConfig.setGroupDelta(groupDelta, auditLogFormatter);
AccountGroup.NameKey groupName = groupDelta.getName().orElseGet(groupCreation::getNameKey);
GroupNameNotes groupNameNotes = GroupNameNotes.forNewGroup(allUsersName, allUsersRepo, groupCreation.getGroupUUID(), groupName);
commit(allUsersRepo, groupConfig, groupNameNotes);
return groupConfig.getLoadedGroup().orElseThrow(() -> new IllegalStateException("Created group wasn't automatically loaded"));
}
use of com.google.gerrit.server.group.db.GroupConfig in project gerrit by GerritCodeReview.
the class GroupsOnInit method addGroupMemberInNoteDb.
private void addGroupMemberInNoteDb(Repository repository, AccountGroup.UUID groupUuid, Account account) throws IOException, ConfigInvalidException, NoSuchGroupException {
GroupConfig groupConfig = GroupConfig.loadForGroup(allUsers, repository, groupUuid);
InternalGroup group = groupConfig.getLoadedGroup().orElseThrow(() -> new NoSuchGroupException(groupUuid));
GroupDelta groupDelta = getMemberAdditionDelta(account);
AuditLogFormatter auditLogFormatter = getAuditLogFormatter(account);
groupConfig.setGroupDelta(groupDelta, auditLogFormatter);
commit(repository, groupConfig, group.getCreatedOn());
}
use of com.google.gerrit.server.group.db.GroupConfig in project gerrit by GerritCodeReview.
the class GroupsOnInit method getExistingGroup.
/**
* Returns the {@code AccountGroup} for the specified {@code GroupReference}.
*
* @param groupReference the {@code GroupReference} of the group
* @return the {@code InternalGroup} represented by the {@code GroupReference}
* @throws IOException if an error occurs while reading from NoteDb
* @throws ConfigInvalidException if the data in NoteDb is in an incorrect format
* @throws NoSuchGroupException if a group with such a name doesn't exist
*/
public InternalGroup getExistingGroup(GroupReference groupReference) throws NoSuchGroupException, IOException, ConfigInvalidException {
File allUsersRepoPath = getPathToAllUsersRepository();
if (allUsersRepoPath != null) {
try (Repository allUsersRepo = new FileRepository(allUsersRepoPath)) {
AccountGroup.UUID groupUuid = groupReference.getUUID();
GroupConfig groupConfig = GroupConfig.loadForGroup(allUsers, allUsersRepo, groupUuid);
return groupConfig.getLoadedGroup().orElseThrow(() -> new NoSuchGroupException(groupReference.getUUID()));
}
}
throw new NoSuchGroupException(groupReference.getUUID());
}
Aggregations