use of com.zimbra.cs.account.Provisioning.GroupMemberEmailAddrs in project zm-mailbox by Zimbra.
the class SendShareNotification method sendNotificationEmailToGroupGrantees.
private void sendNotificationEmailToGroupGrantees(OperationContext octxt, Mailbox mbox, Account authAccount, Account ownerAccount, Collection<ShareInfoData> sids, String notes, Action action) throws ServiceException, MessagingException {
Provisioning prov = Provisioning.getInstance();
for (ShareInfoData sid : sids) {
String granteeId = sid.getGranteeId();
Group group = prov.getGroupBasic(DistributionListBy.id, granteeId);
if (group == null) {
// huh? grantee type is GROUP but the group cannot be found by id.
// just log a warning and do not send.
// This is not likely to happen because validateRequest had already
// checked existance of the grantee.
sLog.warn("Group not found for sending share notificaiton to: " + granteeId + "(" + sid.getGranteeNotifName() + ")" + ", share notification not sent");
continue;
}
/*
* send to group members
*/
GroupMemberEmailAddrs addrs = prov.getMemberAddrs(group);
if (addrs.groupAddr() != null) {
// just send to the group's address, no treatment needed for recipients
sendNotificationEmail(octxt, mbox, authAccount, ownerAccount, sid, notes, action, null, null);
} else {
// send one common notif email to all internal members,
if (addrs.internalAddrs() != null) {
sendNotificationEmail(octxt, mbox, authAccount, ownerAccount, sid, notes, action, addrs.internalAddrs(), null);
}
// send one personalized notif email to each external member
Collection<String> extMembers = addrs.externalAddrs();
if (extMembers != null) {
if (extMembers.size() <= DebugConfig.sendGroupShareNotificationSynchronouslyThreshold) {
// send synchronously
sendNotificationEmailToGroupExternalMembers(octxt, mbox, authAccount, ownerAccount, sid, notes, action, extMembers);
} else {
// send asynchronously in a separate thread to avoid holding up the request
sendNotificationEmailToGroupExternalMembersAsync(octxt, mbox, authAccount, ownerAccount, sid, notes, action, extMembers);
}
}
}
}
}
use of com.zimbra.cs.account.Provisioning.GroupMemberEmailAddrs in project zm-mailbox by Zimbra.
the class TestLdapProvDynamicGroup method testGetMemberAddrs.
private void testGetMemberAddrs(boolean dynamic) throws Exception {
/*
* group has both internal and external members
*/
Group group = provUtil.createGroup(genGroupNameLocalPart(seq), domain, dynamic);
Account acct1 = provUtil.createAccount(genAcctNameLocalPart(seq), domain);
Account acct2 = provUtil.createAccount(genAcctNameLocalPart(seq), domain);
String externalAddr1 = "user1@external.com";
String externalAddr2 = "user2@external.com";
prov.addGroupMembers(group, new String[] { acct1.getName(), acct2.getName(), externalAddr1, externalAddr2 });
GroupMemberEmailAddrs addrs = prov.getMemberAddrs(group);
assertNull(addrs.groupAddr());
Verify.verifyEquals(Sets.newHashSet(acct1.getName(), acct2.getName()), addrs.internalAddrs());
Verify.verifyEquals(Sets.newHashSet(externalAddr1, externalAddr2), addrs.externalAddrs());
/*
* group has only internal members
*/
group = provUtil.createGroup(genGroupNameLocalPart(seq), domain, dynamic);
prov.addGroupMembers(group, new String[] { acct1.getName(), acct2.getName() });
addrs = prov.getMemberAddrs(group);
assertEquals(group.getName(), addrs.groupAddr());
assertNull(addrs.internalAddrs());
assertNull(addrs.externalAddrs());
/*
* group has only external members
*/
group = provUtil.createGroup(genGroupNameLocalPart(seq), domain, dynamic);
prov.addGroupMembers(group, new String[] { externalAddr1, externalAddr2 });
addrs = prov.getMemberAddrs(group);
assertNull(addrs.groupAddr());
assertNull(addrs.internalAddrs());
Verify.verifyEquals(Sets.newHashSet(externalAddr1, externalAddr2), addrs.externalAddrs());
/*
* group has no member
*/
group = provUtil.createGroup(genGroupNameLocalPart(seq), domain, dynamic);
addrs = prov.getMemberAddrs(group);
assertEquals(group.getName(), addrs.groupAddr());
assertNull(addrs.internalAddrs());
assertNull(addrs.externalAddrs());
}
Aggregations