Search in sources :

Example 1 with GroupNameNotes

use of com.google.gerrit.server.group.db.GroupNameNotes 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")));
    }
}
Also used : AccountGroup(com.google.gerrit.entities.AccountGroup) AllUsersName(com.google.gerrit.server.config.AllUsersName) AuditLogFormatter(com.google.gerrit.server.group.db.AuditLogFormatter) GroupNameNotes(com.google.gerrit.server.group.db.GroupNameNotes) InternalGroup(com.google.gerrit.entities.InternalGroup) GroupConfig(com.google.gerrit.server.group.db.GroupConfig) GroupIndexCollection(com.google.gerrit.server.index.group.GroupIndexCollection) IOException(java.io.IOException) GroupReference(com.google.gerrit.entities.GroupReference) PersonIdent(org.eclipse.jgit.lib.PersonIdent) Nullable(com.google.gerrit.common.Nullable) BatchRefUpdate(org.eclipse.jgit.lib.BatchRefUpdate) Optional(java.util.Optional) GroupIndex(com.google.gerrit.server.index.group.GroupIndex) GroupDelta(com.google.gerrit.server.group.db.GroupDelta) RefUpdateUtil(com.google.gerrit.git.RefUpdateUtil) ServiceUserClassifier(com.google.gerrit.server.account.ServiceUserClassifier) GitReferenceUpdated(com.google.gerrit.server.extensions.events.GitReferenceUpdated) Repository(org.eclipse.jgit.lib.Repository) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) Repository(org.eclipse.jgit.lib.Repository) GroupNameNotes(com.google.gerrit.server.group.db.GroupNameNotes) AccountGroup(com.google.gerrit.entities.AccountGroup) GroupConfig(com.google.gerrit.server.group.db.GroupConfig) GroupReference(com.google.gerrit.entities.GroupReference)

Example 2 with GroupNameNotes

use of com.google.gerrit.server.group.db.GroupNameNotes 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"));
}
Also used : GroupNameNotes(com.google.gerrit.server.group.db.GroupNameNotes) GroupConfig(com.google.gerrit.server.group.db.GroupConfig) AccountGroup(com.google.gerrit.entities.AccountGroup) AuditLogFormatter(com.google.gerrit.server.group.db.AuditLogFormatter)

Aggregations

AccountGroup (com.google.gerrit.entities.AccountGroup)2 AuditLogFormatter (com.google.gerrit.server.group.db.AuditLogFormatter)2 GroupConfig (com.google.gerrit.server.group.db.GroupConfig)2 GroupNameNotes (com.google.gerrit.server.group.db.GroupNameNotes)2 Nullable (com.google.gerrit.common.Nullable)1 GroupReference (com.google.gerrit.entities.GroupReference)1 InternalGroup (com.google.gerrit.entities.InternalGroup)1 RefUpdateUtil (com.google.gerrit.git.RefUpdateUtil)1 ServiceUserClassifier (com.google.gerrit.server.account.ServiceUserClassifier)1 AllUsersName (com.google.gerrit.server.config.AllUsersName)1 GitReferenceUpdated (com.google.gerrit.server.extensions.events.GitReferenceUpdated)1 MetaDataUpdate (com.google.gerrit.server.git.meta.MetaDataUpdate)1 GroupDelta (com.google.gerrit.server.group.db.GroupDelta)1 GroupIndex (com.google.gerrit.server.index.group.GroupIndex)1 GroupIndexCollection (com.google.gerrit.server.index.group.GroupIndexCollection)1 IOException (java.io.IOException)1 Optional (java.util.Optional)1 BatchRefUpdate (org.eclipse.jgit.lib.BatchRefUpdate)1 PersonIdent (org.eclipse.jgit.lib.PersonIdent)1 Repository (org.eclipse.jgit.lib.Repository)1