Search in sources :

Example 1 with AvatarProvider

use of com.google.gerrit.server.avatar.AvatarProvider in project gerrit by GerritCodeReview.

the class InternalAccountDirectory method fill.

private void fill(AccountInfo info, Account account, @Nullable Collection<ExternalId> externalIds, Set<FillOptions> options) {
    if (options.contains(FillOptions.ID)) {
        info._accountId = account.getId().get();
    } else {
        // Was previously set to look up account for filling.
        info._accountId = null;
    }
    if (options.contains(FillOptions.NAME)) {
        info.name = Strings.emptyToNull(account.getFullName());
        if (info.name == null) {
            info.name = account.getUserName();
        }
    }
    if (options.contains(FillOptions.EMAIL)) {
        info.email = account.getPreferredEmail();
    }
    if (options.contains(FillOptions.SECONDARY_EMAILS)) {
        info.secondaryEmails = externalIds != null ? getSecondaryEmails(account, externalIds) : null;
    }
    if (options.contains(FillOptions.USERNAME)) {
        info.username = externalIds != null ? AccountState.getUserName(externalIds) : null;
    }
    if (options.contains(FillOptions.STATUS)) {
        info.status = account.getStatus();
    }
    if (options.contains(FillOptions.AVATARS)) {
        AvatarProvider ap = avatar.get();
        if (ap != null) {
            info.avatars = new ArrayList<>(3);
            IdentifiedUser user = userFactory.create(account.getId());
            // GWT UI uses DEFAULT_SIZE (26px).
            addAvatar(ap, info, user, AvatarInfo.DEFAULT_SIZE);
            // PolyGerrit UI prefers 32px and 100px.
            if (!info.avatars.isEmpty()) {
                if (32 != AvatarInfo.DEFAULT_SIZE) {
                    addAvatar(ap, info, user, 32);
                }
                if (100 != AvatarInfo.DEFAULT_SIZE) {
                    addAvatar(ap, info, user, 100);
                }
            }
        }
    }
}
Also used : AvatarProvider(com.google.gerrit.server.avatar.AvatarProvider) IdentifiedUser(com.google.gerrit.server.IdentifiedUser)

Example 2 with AvatarProvider

use of com.google.gerrit.server.avatar.AvatarProvider in project gerrit by GerritCodeReview.

the class GetAvatar method apply.

@Override
public Response.Redirect apply(AccountResource rsrc) throws ResourceNotFoundException {
    AvatarProvider impl = avatarProvider.get();
    if (impl == null) {
        throw (new ResourceNotFoundException()).caching(CacheControl.PUBLIC(1, TimeUnit.DAYS));
    }
    String url = impl.getUrl(rsrc.getUser(), size);
    if (Strings.isNullOrEmpty(url)) {
        throw (new ResourceNotFoundException()).caching(CacheControl.PUBLIC(1, TimeUnit.HOURS));
    }
    return Response.redirect(url);
}
Also used : AvatarProvider(com.google.gerrit.server.avatar.AvatarProvider) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Example 3 with AvatarProvider

use of com.google.gerrit.server.avatar.AvatarProvider in project gerrit by GerritCodeReview.

the class GetAvatarChangeUrl method apply.

@Override
public String apply(AccountResource rsrc) throws ResourceNotFoundException {
    AvatarProvider impl = avatarProvider.get();
    if (impl == null) {
        throw new ResourceNotFoundException();
    }
    String url = impl.getChangeAvatarUrl(rsrc.getUser());
    if (Strings.isNullOrEmpty(url)) {
        throw new ResourceNotFoundException();
    }
    return url;
}
Also used : AvatarProvider(com.google.gerrit.server.avatar.AvatarProvider) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Aggregations

AvatarProvider (com.google.gerrit.server.avatar.AvatarProvider)3 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)2 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)1