use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class StarredChangesUtil method byAccountId.
public ImmutableSet<Change.Id> byAccountId(Account.Id accountId, String label) {
try (Repository repo = repoManager.openRepository(allUsers)) {
ImmutableSet.Builder<Change.Id> builder = ImmutableSet.builder();
for (Ref ref : repo.getRefDatabase().getRefsByPrefix(RefNames.REFS_STARRED_CHANGES)) {
Account.Id currentAccountId = Account.Id.fromRef(ref.getName());
// Skip all refs that don't correspond with accountId.
if (currentAccountId == null || !currentAccountId.equals(accountId)) {
continue;
}
// Skip all refs that don't contain the required label.
StarRef starRef = readLabels(repo, ref.getName());
if (!starRef.labels().contains(label)) {
continue;
}
// Skip invalid change ids.
Change.Id changeId = Change.Id.fromAllUsersRef(ref.getName());
if (changeId == null) {
continue;
}
builder.add(changeId);
}
return builder.build();
} catch (IOException e) {
throw new StorageException(String.format("Get starred changes for account %d failed", accountId.get()), e);
}
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class AccountState method fromAccountConfig.
/**
* Creates an AccountState from the given account config.
*
* <p>If external ID notes are provided the revision of the external IDs branch from which the
* external IDs for the account should be loaded is taken from the external ID notes. If external
* ID notes are not given the revision of the external IDs branch is taken from the account
* config. Updating external IDs is done via {@link ExternalIdNotes} and if external IDs were
* updated the revision of the external IDs branch in account config is outdated. Hence after
* updating external IDs the external ID notes must be provided.
*
* @param externalIds class to access external IDs
* @param accountConfig the account config, must already be loaded
* @param extIdNotes external ID notes, must already be loaded, may be {@code null}
* @param defaultPreferences the default preferences for this Gerrit installation
* @return the account state, {@link Optional#empty()} if the account doesn't exist
* @throws IOException if accessing the external IDs fails
*/
public static Optional<AccountState> fromAccountConfig(ExternalIds externalIds, AccountConfig accountConfig, @Nullable ExternalIdNotes extIdNotes, CachedPreferences defaultPreferences) throws IOException {
if (!accountConfig.getLoadedAccount().isPresent()) {
return Optional.empty();
}
Account account = accountConfig.getLoadedAccount().get();
Optional<ObjectId> extIdsRev = extIdNotes != null ? Optional.ofNullable(extIdNotes.getRevision()) : accountConfig.getExternalIdsRev();
ImmutableSet<ExternalId> extIds = extIdsRev.isPresent() ? externalIds.byAccount(account.id(), extIdsRev.get()) : ImmutableSet.of();
// Don't leak references to AccountConfig into the AccountState, since it holds a reference to
// an open Repository instance.
ImmutableMap<ProjectWatchKey, ImmutableSet<NotifyType>> projectWatches = accountConfig.getProjectWatches();
return Optional.of(new AutoValue_AccountState(account, extIds, ExternalId.getUserName(extIds), projectWatches, Optional.of(defaultPreferences), Optional.of(accountConfig.asCachedPreferences())));
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class GroupMembers method getProjectOwners.
private Set<Account> getProjectOwners(final Project.NameKey project, Set<AccountGroup.UUID> seen) throws NoSuchProjectException, IOException {
seen.add(SystemGroupBackend.PROJECT_OWNERS);
if (project == null) {
return Collections.emptySet();
}
ProjectState projectState = projectCache.get(project).orElseThrow(noSuchProject(project));
final HashSet<Account> projectOwners = new HashSet<>();
for (AccountGroup.UUID ownerGroup : projectState.getAllOwners()) {
if (!seen.contains(ownerGroup)) {
projectOwners.addAll(listAccounts(ownerGroup, project, seen));
}
}
return projectOwners;
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class AccountIdHandler method parseArguments.
@Override
public int parseArguments(Parameters params) throws CmdLineException {
String token = params.getParameter(0);
Account.Id accountId;
try {
try {
accountId = accountResolver.resolve(token).asUnique().account().id();
} catch (UnprocessableEntityException e) {
switch(authType) {
case HTTP_LDAP:
case CLIENT_SSL_CERT_LDAP:
case LDAP:
accountId = createAccountByLdap(token);
break;
case CUSTOM_EXTENSION:
case DEVELOPMENT_BECOME_ANY_ACCOUNT:
case HTTP:
case LDAP_BIND:
case OAUTH:
case OPENID:
case OPENID_SSO:
default:
String msg = "user \"%s\" not found";
logger.atSevere().withCause(e).log(msg, token);
throw new CmdLineException(owner, localizable(msg), token);
}
}
} catch (StorageException e) {
CmdLineException newException = new CmdLineException(owner, localizable("database is down"));
newException.initCause(e);
throw newException;
} catch (IOException e) {
throw new CmdLineException(owner, "Failed to load account", e);
} catch (ConfigInvalidException e) {
throw new CmdLineException(owner, "Invalid account config", e);
}
setter.addValue(accountId);
return 1;
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class ChangeData method draftRefs.
private Map<Account.Id, ObjectId> draftRefs() {
if (draftsByUser == null) {
if (!lazyload()) {
return Collections.emptyMap();
}
Change c = change();
if (c == null) {
return Collections.emptyMap();
}
draftsByUser = new HashMap<>();
for (Ref ref : commentsUtil.getDraftRefs(notes().getChangeId())) {
Account.Id account = Account.Id.fromRefSuffix(ref.getName());
if (account != null && // this point.
!notes().getDraftComments(account, ref).isEmpty()) {
draftsByUser.put(account, ref.getObjectId());
}
}
}
return draftsByUser;
}
Aggregations