use of com.zimbra.cs.mailbox.ContactGroup.Member in project zm-mailbox by Zimbra.
the class TestContactGroup method replaceMembersWithDlist.
@Test
public void replaceMembersWithDlist() throws Exception {
ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(Member.Type.CONTACT_REF, CONTACT_REF_VALUE), new MemberData(Member.Type.GAL_REF, GAL_REF_VALUE) });
String dlist = "\"Ballard, Martha\" <martha34@aol.com>, \"Davidson, Ross\" <rossd@example.zimbra.com>, user1@test.com";
contactGroup.migrateFromDlist(dlist);
contactGroup = reEncode(contactGroup);
List<Member> members = contactGroup.getMembers();
assertEquals(3, members.size());
Member member = members.get(0);
assertEquals(Member.Type.INLINE, member.getType());
assertEquals("\"Ballard, Martha\" <martha34@aol.com>", member.getValue());
member = members.get(1);
assertEquals(Member.Type.INLINE, member.getType());
assertEquals("\"Davidson, Ross\" <rossd@example.zimbra.com>", member.getValue());
member = members.get(2);
assertEquals(Member.Type.INLINE, member.getType());
assertEquals("user1@test.com", member.getValue());
}
use of com.zimbra.cs.mailbox.ContactGroup.Member in project zm-mailbox by Zimbra.
the class TestContactGroup method derefContact.
@Test
public void derefContact() throws Exception {
Account account = Provisioning.getInstance().get(AccountBy.name, TestUtil.getAddress("user1"));
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
// TODO
OperationContext octxt = null;
Map<String, Object> fields = new HashMap<String, Object>();
fields.put(ContactConstants.A_fileAs, ContactConstants.FA_FIRST_LAST);
fields.put(ContactConstants.A_firstName, "test");
fields.put(ContactConstants.A_email, "test1@zimbra.com");
fields.put(ContactConstants.A_workEmail1, "test2@zimbra.com");
Contact contact = mbox.createContact(octxt, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null);
ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(Member.Type.CONTACT_REF, "" + contact.getId()), new MemberData(Member.Type.INLINE, "aaa@test.com"), new MemberData(Member.Type.INLINE, "zzz@test.com") });
contactGroup.derefAllMembers(mbox, octxt);
boolean gotContactRefMember = false;
String prevMemberKey = null;
for (Member member : contactGroup.getDerefedMembers()) {
String memberKey = member.getDerefedKey();
if (prevMemberKey != null) {
assertTrue(prevMemberKey.compareTo(memberKey) < 0);
}
prevMemberKey = memberKey;
Member.Type type = member.getType();
if (type == Member.Type.CONTACT_REF) {
assertEquals("test", memberKey);
gotContactRefMember = true;
}
// System.out.println(memberKey);
}
List<String> emailAddrs = contactGroup.getEmailAddresses(false, mbox, octxt, false);
assertEquals(4, emailAddrs.size());
assertTrue(emailAddrs.contains("test1@zimbra.com"));
assertTrue(emailAddrs.contains("test2@zimbra.com"));
assertTrue(emailAddrs.contains("aaa@test.com"));
assertTrue(emailAddrs.contains("zzz@test.com"));
assertTrue(gotContactRefMember);
}
use of com.zimbra.cs.mailbox.ContactGroup.Member in project zm-mailbox by Zimbra.
the class TestContactGroup method returnMembersAsDlist.
@Test
public void returnMembersAsDlist() throws Exception {
Account account = Provisioning.getInstance().get(AccountBy.name, TestUtil.getAddress("user1"));
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
// TODO
OperationContext octxt = null;
Map<String, Object> fields = new HashMap<String, Object>();
fields.put(ContactConstants.A_fileAs, ContactConstants.FA_FIRST_LAST);
fields.put(ContactConstants.A_firstName, "test");
fields.put(ContactConstants.A_email, "test1@zimbra.com");
fields.put(ContactConstants.A_workEmail1, "test2@zimbra.com");
Contact contact = mbox.createContact(octxt, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null);
Account galMember = Provisioning.getInstance().get(AccountBy.name, TestUtil.getAddress("user2"));
LdapAccount ldapAccount = (LdapAccount) galMember;
String dn = ldapAccount.getDN();
String galEntryEmail = galMember.getName();
ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(Member.Type.CONTACT_REF, "" + contact.getId()), new MemberData(Member.Type.GAL_REF, dn), new MemberData(Member.Type.INLINE, "aaa@test.com"), new MemberData(Member.Type.INLINE, "zzz@test.com") });
contactGroup.derefAllMembers(mbox, octxt);
for (Member member : contactGroup.getDerefedMembers()) {
String memberKey = member.getDerefedKey();
System.out.println(memberKey);
}
String dlist = contactGroup.migrateToDlist(mbox, octxt);
// should be in member order
assertEquals("test1@zimbra.com, test2@zimbra.com, " + galEntryEmail + ", aaa@test.com, zzz@test.com", dlist);
}
use of com.zimbra.cs.mailbox.ContactGroup.Member in project zm-mailbox by Zimbra.
the class TestContactGroup method removeMember.
@Test
public void removeMember() throws Exception {
ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(Member.Type.CONTACT_REF, CONTACT_REF_VALUE), new MemberData(Member.Type.GAL_REF, GAL_REF_VALUE), new MemberData(Member.Type.INLINE, INLINE_VALUE) });
Member memberToRemove = contactGroup.getMembers().get(0);
contactGroup.removeMember(memberToRemove.getType(), memberToRemove.getValue());
contactGroup = reEncode(contactGroup);
List<Member> members = contactGroup.getMembers();
assertEquals(2, members.size());
}
use of com.zimbra.cs.mailbox.ContactGroup.Member in project zm-mailbox by Zimbra.
the class AddressObject method populateContactGroupAppleXProps.
private static void populateContactGroupAppleXProps(DavContext ctxt, Contact contact) {
if (contact.isContactGroup() == false) {
return;
}
ContactGroup contactGroup = null;
try {
contactGroup = ContactGroup.init(contact.get(ContactConstants.A_groupMember));
} catch (ServiceException e) {
ZimbraLog.dav.warn("can't get group members for Contact %d", contact.getId(), e);
}
ListMultimap<String, VCardParamsAndValue> xprops = contact.getUnknownVCardProps();
xprops.put(XABSKIND, new VCardParamsAndValue("group"));
if (contactGroup != null) {
try {
for (Member member : contactGroup.getMembers()) {
if (member.getType().equals(Member.Type.CONTACT_REF)) {
ItemId itemId = new ItemId(member.getValue(), contact.getAccount().getId());
if (itemId.belongsTo(contact.getAccount())) {
// make sure member belongs to the same collection as the group.
Contact c = getContactByUID(ctxt, itemId.toString(), contact.getAccount(), contact.getFolderId());
if (c != null) {
xprops.put(XABSMEMBER, new VCardParamsAndValue("urn:uuid:" + VCard.getUid(c)));
}
}
}
}
} catch (ServiceException e) {
ZimbraLog.dav.warn("can't create group members xprops for Contact %d", contact.getId(), e);
}
}
contact.setUnknownVCardProps(xprops);
}
Aggregations