Search in sources :

Example 21 with Address

use of com.google.gerrit.server.mail.Address in project gerrit by GerritCodeReview.

the class ProjectWatch method deliverToMembers.

private void deliverToMembers(Watchers.List matching, AccountGroup.UUID startUUID) throws OrmException {
    ReviewDb db = args.db.get();
    Set<AccountGroup.UUID> seen = new HashSet<>();
    List<AccountGroup.UUID> q = new ArrayList<>();
    seen.add(startUUID);
    q.add(startUUID);
    while (!q.isEmpty()) {
        AccountGroup.UUID uuid = q.remove(q.size() - 1);
        GroupDescription.Basic group = args.groupBackend.get(uuid);
        if (!Strings.isNullOrEmpty(group.getEmailAddress())) {
            // If the group has an email address, do not expand membership.
            matching.emails.add(new Address(group.getEmailAddress()));
            continue;
        }
        AccountGroup ig = GroupDescriptions.toAccountGroup(group);
        if (ig == null) {
            // Non-internal groups cannot be expanded by the server.
            continue;
        }
        for (AccountGroupMember m : db.accountGroupMembers().byGroup(ig.getId())) {
            matching.accounts.add(m.getAccountId());
        }
        for (AccountGroup.UUID m : args.groupIncludes.subgroupsOf(uuid)) {
            if (seen.add(m)) {
                q.add(m);
            }
        }
    }
}
Also used : GroupDescription(com.google.gerrit.common.data.GroupDescription) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) Address(com.google.gerrit.server.mail.Address) AccountGroupMember(com.google.gerrit.reviewdb.client.AccountGroupMember) ArrayList(java.util.ArrayList) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) HashSet(java.util.HashSet)

Example 22 with Address

use of com.google.gerrit.server.mail.Address in project gerrit by GerritCodeReview.

the class ChangeField method parseReviewerByEmailFieldValues.

public static ReviewerByEmailSet parseReviewerByEmailFieldValues(Iterable<String> values) {
    ImmutableTable.Builder<ReviewerStateInternal, Address, Timestamp> b = ImmutableTable.builder();
    for (String v : values) {
        int f = v.indexOf(',');
        if (f < 0) {
            continue;
        }
        int l = v.lastIndexOf(',');
        if (l == f) {
            continue;
        }
        b.put(ReviewerStateInternal.valueOf(v.substring(0, f)), Address.parse(v.substring(f + 1, l)), new Timestamp(Long.valueOf(v.substring(l + 1, v.length()))));
    }
    return ReviewerByEmailSet.fromTable(b.build());
}
Also used : Address(com.google.gerrit.server.mail.Address) ReviewerStateInternal(com.google.gerrit.server.notedb.ReviewerStateInternal) ImmutableTable(com.google.common.collect.ImmutableTable) Timestamp(java.sql.Timestamp)

Example 23 with Address

use of com.google.gerrit.server.mail.Address in project gerrit by GerritCodeReview.

the class ProjectConfig method saveNotifySections.

private void saveNotifySections(Config rc, Set<AccountGroup.UUID> keepGroups) {
    for (NotifyConfig nc : sort(notifySections.values())) {
        List<String> email = new ArrayList<>();
        for (GroupReference gr : nc.getGroups()) {
            if (gr.getUUID() != null) {
                keepGroups.add(gr.getUUID());
            }
            email.add(new PermissionRule(gr).asString(false));
        }
        Collections.sort(email);
        List<String> addrs = new ArrayList<>();
        for (Address addr : nc.getAddresses()) {
            addrs.add(addr.toString());
        }
        Collections.sort(addrs);
        email.addAll(addrs);
        set(rc, NOTIFY, nc.getName(), KEY_HEADER, nc.getHeader(), NotifyConfig.Header.BCC);
        if (email.isEmpty()) {
            rc.unset(NOTIFY, nc.getName(), KEY_EMAIL);
        } else {
            rc.setStringList(NOTIFY, nc.getName(), KEY_EMAIL, email);
        }
        if (nc.getNotify().equals(EnumSet.of(NotifyType.ALL))) {
            rc.unset(NOTIFY, nc.getName(), KEY_TYPE);
        } else {
            List<String> types = Lists.newArrayListWithCapacity(4);
            for (NotifyType t : NotifyType.values()) {
                if (nc.isNotify(t)) {
                    types.add(StringUtils.toLowerCase(t.name()));
                }
            }
            rc.setStringList(NOTIFY, nc.getName(), KEY_TYPE, types);
        }
        set(rc, NOTIFY, nc.getName(), KEY_FILTER, nc.getFilter());
    }
}
Also used : NotifyType(com.google.gerrit.server.account.WatchConfig.NotifyType) Address(com.google.gerrit.server.mail.Address) PermissionRule(com.google.gerrit.common.data.PermissionRule) ArrayList(java.util.ArrayList) GroupReference(com.google.gerrit.common.data.GroupReference)

Aggregations

Address (com.google.gerrit.server.mail.Address)23 DateTime (org.joda.time.DateTime)11 MailMessage (com.google.gerrit.server.mail.receive.MailMessage)6 Account (com.google.gerrit.reviewdb.client.Account)5 Test (org.junit.Test)5 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)3 LinkedHashMap (java.util.LinkedHashMap)3 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)2 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)2 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)2 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)2 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)2 NotifyConfig (com.google.gerrit.server.git.NotifyConfig)2 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableTable (com.google.common.collect.ImmutableTable)1