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"));
}
}
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);
}
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);
}
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());
}
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);
}
Aggregations