Search in sources :

Example 1 with AccountLoader

use of com.google.gerrit.server.account.AccountLoader in project gerrit by GerritCodeReview.

the class GetPastAssignees method apply.

@Override
public Response<List<AccountInfo>> apply(ChangeResource rsrc) throws OrmException {
    Set<Account.Id> pastAssignees = rsrc.getControl().getNotes().load().getPastAssignees();
    if (pastAssignees == null) {
        return Response.ok(Collections.emptyList());
    }
    AccountLoader accountLoader = accountLoaderFactory.create(true);
    List<AccountInfo> infos = pastAssignees.stream().map(accountLoader::get).collect(toList());
    accountLoader.fill();
    return Response.ok(infos);
}
Also used : AccountLoader(com.google.gerrit.server.account.AccountLoader) AccountInfo(com.google.gerrit.extensions.common.AccountInfo)

Example 2 with AccountLoader

use of com.google.gerrit.server.account.AccountLoader in project gerrit by GerritCodeReview.

the class AddMembers method toAccountInfoList.

private List<AccountInfo> toAccountInfoList(Set<Account.Id> accountIds) throws OrmException {
    List<AccountInfo> result = new ArrayList<>();
    AccountLoader loader = infoFactory.create(true);
    for (Account.Id accId : accountIds) {
        result.add(loader.get(accId));
    }
    loader.fill();
    return result;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) AccountLoader(com.google.gerrit.server.account.AccountLoader) ArrayList(java.util.ArrayList) AccountInfo(com.google.gerrit.extensions.common.AccountInfo)

Example 3 with AccountLoader

use of com.google.gerrit.server.account.AccountLoader in project gerrit by GerritCodeReview.

the class GetMember method apply.

@Override
public AccountInfo apply(MemberResource rsrc) throws OrmException {
    AccountLoader loader = infoFactory.create(true);
    AccountInfo info = loader.get(rsrc.getMember().getAccountId());
    loader.fill();
    return info;
}
Also used : AccountLoader(com.google.gerrit.server.account.AccountLoader) AccountInfo(com.google.gerrit.extensions.common.AccountInfo)

Example 4 with AccountLoader

use of com.google.gerrit.server.account.AccountLoader in project gerrit by GerritCodeReview.

the class RevisionApiImpl method votes.

@Override
public ListMultimap<String, ApprovalInfo> votes() throws RestApiException {
    ListMultimap<String, ApprovalInfo> result = ListMultimapBuilder.treeKeys().arrayListValues().build();
    try {
        Iterable<PatchSetApproval> approvals = approvalsUtil.byPatchSet(revision.getNotes(), revision.getPatchSet().id());
        AccountLoader accountLoader = accountLoaderFactory.create(EnumSet.of(FillOptions.ID, FillOptions.NAME, FillOptions.EMAIL, FillOptions.USERNAME));
        for (PatchSetApproval approval : approvals) {
            String label = approval.label();
            ApprovalInfo info = new ApprovalInfo(approval.accountId().get(), Integer.valueOf(approval.value()), null, approval.tag().orElse(null), approval.granted());
            accountLoader.put(info);
            result.get(label).add(info);
        }
        accountLoader.fill();
    } catch (Exception e) {
        throw asRestApiException("Cannot get votes", e);
    }
    return result;
}
Also used : ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) AccountLoader(com.google.gerrit.server.account.AccountLoader) IdString(com.google.gerrit.extensions.restapi.IdString) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 5 with AccountLoader

use of com.google.gerrit.server.account.AccountLoader in project gerrit by GerritCodeReview.

the class ReviewersUtil method loadAccounts.

private List<SuggestedReviewerInfo> loadAccounts(List<Account.Id> accountIds) throws PermissionBackendException {
    Set<FillOptions> fillOptions = Sets.union(AccountLoader.DETAILED_OPTIONS, EnumSet.of(FillOptions.SECONDARY_EMAILS));
    AccountLoader accountLoader = accountLoaderFactory.create(fillOptions);
    try (Timer0.Context ctx = metrics.loadAccountsLatency.start()) {
        List<SuggestedReviewerInfo> reviewer = accountIds.stream().map(accountLoader::get).filter(Objects::nonNull).map(a -> {
            SuggestedReviewerInfo info = new SuggestedReviewerInfo();
            info.account = a;
            info.count = 1;
            return info;
        }).collect(toList());
        accountLoader.fill();
        return reviewer;
    }
}
Also used : GroupBackend(com.google.gerrit.server.account.GroupBackend) Inject(com.google.inject.Inject) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) ReviewerModifier(com.google.gerrit.server.change.ReviewerModifier) EnumSet(java.util.EnumSet) FieldDef(com.google.gerrit.index.FieldDef) ImmutableSet(com.google.common.collect.ImmutableSet) GroupBaseInfo(com.google.gerrit.extensions.common.GroupBaseInfo) Timer0(com.google.gerrit.metrics.Timer0) Account(com.google.gerrit.entities.Account) FillOptions(com.google.gerrit.server.account.AccountDirectory.FillOptions) AccountQueryBuilder(com.google.gerrit.server.query.account.AccountQueryBuilder) Set(java.util.Set) AccountIndexCollection(com.google.gerrit.server.index.account.AccountIndexCollection) Sets(com.google.common.collect.Sets) GroupReference(com.google.gerrit.entities.GroupReference) Objects(java.util.Objects) TooManyTermsInQueryException(com.google.gerrit.index.query.TooManyTermsInQueryException) List(java.util.List) Nullable(com.google.gerrit.common.Nullable) Url(com.google.gerrit.extensions.restapi.Url) MetricMaker(com.google.gerrit.metrics.MetricMaker) LazyArgs.lazy(com.google.common.flogger.LazyArgs.lazy) FluentLogger(com.google.common.flogger.FluentLogger) Singleton(com.google.inject.Singleton) AccountLoader(com.google.gerrit.server.account.AccountLoader) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) IndexConfig(com.google.gerrit.index.IndexConfig) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) ResultSet(com.google.gerrit.index.query.ResultSet) AccountPredicates(com.google.gerrit.server.query.account.AccountPredicates) GroupMembers(com.google.gerrit.server.account.GroupMembers) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) ImmutableList(com.google.common.collect.ImmutableList) QueryParseException(com.google.gerrit.index.query.QueryParseException) Description(com.google.gerrit.metrics.Description) FieldBundle(com.google.gerrit.index.query.FieldBundle) AccountIndexRewriter(com.google.gerrit.server.index.account.AccountIndexRewriter) Predicate(com.google.gerrit.index.query.Predicate) SuggestedReviewerInfo(com.google.gerrit.extensions.common.SuggestedReviewerInfo) AccountControl(com.google.gerrit.server.account.AccountControl) CurrentUser(com.google.gerrit.server.CurrentUser) AccountField(com.google.gerrit.server.index.account.AccountField) StorageException(com.google.gerrit.exceptions.StorageException) Units(com.google.gerrit.metrics.Description.Units) ProjectState(com.google.gerrit.server.project.ProjectState) QueryOptions(com.google.gerrit.index.QueryOptions) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) IOException(java.io.IOException) Collectors.toList(java.util.stream.Collectors.toList) Provider(com.google.inject.Provider) Project(com.google.gerrit.entities.Project) AccountState(com.google.gerrit.server.account.AccountState) ServiceUserClassifier(com.google.gerrit.server.account.ServiceUserClassifier) Collections(java.util.Collections) AccountLoader(com.google.gerrit.server.account.AccountLoader) SuggestedReviewerInfo(com.google.gerrit.extensions.common.SuggestedReviewerInfo) Objects(java.util.Objects) Timer0(com.google.gerrit.metrics.Timer0) FillOptions(com.google.gerrit.server.account.AccountDirectory.FillOptions)

Aggregations

AccountLoader (com.google.gerrit.server.account.AccountLoader)24 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)13 ArrayList (java.util.ArrayList)10 Account (com.google.gerrit.entities.Account)7 Inject (com.google.inject.Inject)6 Singleton (com.google.inject.Singleton)6 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)5 Set (java.util.Set)5 AuthException (com.google.gerrit.extensions.restapi.AuthException)4 List (java.util.List)4 ImmutableList (com.google.common.collect.ImmutableList)3 Lists (com.google.common.collect.Lists)3 FluentLogger (com.google.common.flogger.FluentLogger)3 Nullable (com.google.gerrit.common.Nullable)3 ChangeMessage (com.google.gerrit.entities.ChangeMessage)3 PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)3 SubmitRecord (com.google.gerrit.entities.SubmitRecord)3 ApprovalInfo (com.google.gerrit.extensions.common.ApprovalInfo)3 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)3 Url (com.google.gerrit.extensions.restapi.Url)3