Search in sources :

Example 6 with Member

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());
}
Also used : ContactGroup(com.zimbra.cs.mailbox.ContactGroup) ContactRefMember(com.zimbra.cs.mailbox.ContactGroup.ContactRefMember) GalRefMember(com.zimbra.cs.mailbox.ContactGroup.GalRefMember) Member(com.zimbra.cs.mailbox.ContactGroup.Member) InlineMember(com.zimbra.cs.mailbox.ContactGroup.InlineMember) Test(org.junit.Test)

Example 7 with Member

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);
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) Contact(com.zimbra.cs.mailbox.Contact) ParsedContact(com.zimbra.cs.mime.ParsedContact) ParsedContact(com.zimbra.cs.mime.ParsedContact) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ContactGroup(com.zimbra.cs.mailbox.ContactGroup) ContactRefMember(com.zimbra.cs.mailbox.ContactGroup.ContactRefMember) GalRefMember(com.zimbra.cs.mailbox.ContactGroup.GalRefMember) Member(com.zimbra.cs.mailbox.ContactGroup.Member) InlineMember(com.zimbra.cs.mailbox.ContactGroup.InlineMember) Test(org.junit.Test)

Example 8 with Member

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);
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) Contact(com.zimbra.cs.mailbox.Contact) ParsedContact(com.zimbra.cs.mime.ParsedContact) ParsedContact(com.zimbra.cs.mime.ParsedContact) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) ContactGroup(com.zimbra.cs.mailbox.ContactGroup) ContactRefMember(com.zimbra.cs.mailbox.ContactGroup.ContactRefMember) GalRefMember(com.zimbra.cs.mailbox.ContactGroup.GalRefMember) Member(com.zimbra.cs.mailbox.ContactGroup.Member) InlineMember(com.zimbra.cs.mailbox.ContactGroup.InlineMember) Test(org.junit.Test)

Example 9 with Member

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());
}
Also used : ContactGroup(com.zimbra.cs.mailbox.ContactGroup) ContactRefMember(com.zimbra.cs.mailbox.ContactGroup.ContactRefMember) GalRefMember(com.zimbra.cs.mailbox.ContactGroup.GalRefMember) Member(com.zimbra.cs.mailbox.ContactGroup.Member) InlineMember(com.zimbra.cs.mailbox.ContactGroup.InlineMember) Test(org.junit.Test)

Example 10 with Member

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);
}
Also used : VCardParamsAndValue(com.zimbra.cs.mailbox.VCardParamsAndValue) ServiceException(com.zimbra.common.service.ServiceException) ContactGroup(com.zimbra.cs.mailbox.ContactGroup) Member(com.zimbra.cs.mailbox.ContactGroup.Member) ItemId(com.zimbra.cs.service.util.ItemId) Contact(com.zimbra.cs.mailbox.Contact)

Aggregations

Member (com.zimbra.cs.mailbox.ContactGroup.Member)17 ContactGroup (com.zimbra.cs.mailbox.ContactGroup)15 ContactRefMember (com.zimbra.cs.mailbox.ContactGroup.ContactRefMember)12 GalRefMember (com.zimbra.cs.mailbox.ContactGroup.GalRefMember)12 InlineMember (com.zimbra.cs.mailbox.ContactGroup.InlineMember)12 Test (org.junit.Test)12 ServiceException (com.zimbra.common.service.ServiceException)5 Contact (com.zimbra.cs.mailbox.Contact)5 ZMailbox (com.zimbra.client.ZMailbox)4 Account (com.zimbra.cs.account.Account)4 Mailbox (com.zimbra.cs.mailbox.Mailbox)4 ItemId (com.zimbra.cs.service.util.ItemId)4 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)3 OperationContext (com.zimbra.cs.mailbox.OperationContext)3 ParsedContact (com.zimbra.cs.mime.ParsedContact)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Element (com.zimbra.common.soap.Element)2 VCardParamsAndValue (com.zimbra.cs.mailbox.VCardParamsAndValue)2 ZContact (com.zimbra.client.ZContact)1