Search in sources :

Example 6 with ContactGroup

use of com.zimbra.cs.mailbox.ContactGroup in project zm-mailbox by Zimbra.

the class ContactFolderFormatter method printContactGroup.

private void printContactGroup(String encodedContactGroup, OutputStream out) throws IOException {
    ContactGroup contactGroup = null;
    try {
        contactGroup = ContactGroup.init(encodedContactGroup);
    } catch (ServiceException e) {
        ZimbraLog.contact.warn("unable to init contact group", e);
    }
    if (contactGroup == null) {
        return;
    }
    for (ContactGroup.Member member : contactGroup.getMembers()) {
        ContactGroup.Member.Type type = member.getType();
        out.write(FIELD_DELIMITER);
        out.write(type.getDelimittedFieldsEncoded().getBytes("UTF-8"));
        out.write(FIELD_DELIMITER);
        out.write(member.getValue().getBytes("UTF-8"));
    }
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) ContactGroup(com.zimbra.cs.mailbox.ContactGroup)

Example 7 with ContactGroup

use of com.zimbra.cs.mailbox.ContactGroup in project zm-mailbox by Zimbra.

the class TestContactGroup method membersIterator.

@Test
public void membersIterator() 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) });
    boolean caughtException = false;
    try {
        for (Iterator<Member> iter = contactGroup.getMembers().iterator(); iter.hasNext(); ) {
            Member member = iter.next();
            if (member.getType() == Member.Type.GAL_REF || member.getType() == Member.Type.INLINE) {
                // not allowed
                iter.remove();
            }
        }
    } catch (UnsupportedOperationException e) {
        caughtException = true;
    }
    assertTrue(caughtException);
}
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 8 with ContactGroup

use of com.zimbra.cs.mailbox.ContactGroup in project zm-mailbox by Zimbra.

the class TestContactGroup method unmodifiableList.

@Test
public void unmodifiableList() 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) });
    boolean caughtException = false;
    try {
        List<Member> members = contactGroup.getMembers();
        for (Member member : members) {
            // not allowed
            members.remove(member);
        }
    } catch (UnsupportedOperationException e) {
        caughtException = true;
    }
    assertTrue(caughtException);
}
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 9 with ContactGroup

use of com.zimbra.cs.mailbox.ContactGroup 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 10 with ContactGroup

use of com.zimbra.cs.mailbox.ContactGroup 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)

Aggregations

ContactGroup (com.zimbra.cs.mailbox.ContactGroup)25 Member (com.zimbra.cs.mailbox.ContactGroup.Member)16 Test (org.junit.Test)13 ContactRefMember (com.zimbra.cs.mailbox.ContactGroup.ContactRefMember)12 GalRefMember (com.zimbra.cs.mailbox.ContactGroup.GalRefMember)12 InlineMember (com.zimbra.cs.mailbox.ContactGroup.InlineMember)12 Contact (com.zimbra.cs.mailbox.Contact)9 HashMap (java.util.HashMap)8 ServiceException (com.zimbra.common.service.ServiceException)7 Account (com.zimbra.cs.account.Account)5 Mailbox (com.zimbra.cs.mailbox.Mailbox)5 ItemId (com.zimbra.cs.service.util.ItemId)5 ArrayList (java.util.ArrayList)5 ZMailbox (com.zimbra.client.ZMailbox)4 Element (com.zimbra.common.soap.Element)4 OperationContext (com.zimbra.cs.mailbox.OperationContext)4 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)3 Attachment (com.zimbra.cs.mailbox.Contact.Attachment)3 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)2 VCardParamsAndValue (com.zimbra.cs.mailbox.VCardParamsAndValue)2