Search in sources :

Example 6 with Nullable

use of com.google.gerrit.common.Nullable in project gerrit by GerritCodeReview.

the class PostReviewers method addByAccountId.

@Nullable
private Addition addByAccountId(String reviewer, ChangeResource rsrc, ReviewerState state, NotifyHandling notify, ListMultimap<RecipientType, Account.Id> accountsToNotify, boolean allowGroup, boolean allowByEmail) throws OrmException, PermissionBackendException {
    Account.Id accountId = null;
    try {
        accountId = accounts.parse(reviewer).getAccountId();
    } catch (UnprocessableEntityException | AuthException e) {
        // AuthException won't occur since the user is authenticated at this point.
        if (!allowGroup && !allowByEmail) {
            // Only return failure if we aren't going to try other interpretations.
            return fail(reviewer, MessageFormat.format(ChangeMessages.get().reviewerNotFoundUser, reviewer));
        }
        return null;
    }
    ReviewerResource rrsrc = reviewerFactory.create(rsrc, accountId);
    Account member = rrsrc.getReviewerUser().getAccount();
    PermissionBackend.ForRef perm = permissionBackend.user(rrsrc.getReviewerUser()).ref(rrsrc.getChange().getDest());
    if (isValidReviewer(member, perm)) {
        return new Addition(reviewer, rsrc, ImmutableSet.of(member.getId()), null, state, notify, accountsToNotify);
    }
    if (!member.isActive()) {
        if (allowByEmail && state == CC) {
            return null;
        }
        return fail(reviewer, MessageFormat.format(ChangeMessages.get().reviewerInactive, reviewer));
    }
    return fail(reviewer, MessageFormat.format(ChangeMessages.get().reviewerCantSeeChange, reviewer));
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) AuthException(com.google.gerrit.extensions.restapi.AuthException) Nullable(com.google.gerrit.common.Nullable)

Aggregations

Nullable (com.google.gerrit.common.Nullable)6 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)2 Account (com.google.gerrit.reviewdb.client.Account)2 PermissionBackend (com.google.gerrit.server.permissions.PermissionBackend)2 HashSet (java.util.HashSet)2 GroupDescription (com.google.gerrit.common.data.GroupDescription)1 NoSuchGroupException (com.google.gerrit.common.errors.NoSuchGroupException)1 RootRelative (com.google.gerrit.extensions.annotations.RootRelative)1 DynamicMap (com.google.gerrit.extensions.registration.DynamicMap)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 Timer1 (com.google.gerrit.metrics.Timer1)1 ChangeControl (com.google.gerrit.server.project.ChangeControl)1 NoSuchProjectException (com.google.gerrit.server.project.NoSuchProjectException)1 OrmException (com.google.gwtorm.server.OrmException)1 AbstractModule (com.google.inject.AbstractModule)1 Binding (com.google.inject.Binding)1 Injector (com.google.inject.Injector)1 Key (com.google.inject.Key)1 TypeLiteral (com.google.inject.TypeLiteral)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1