use of com.zimbra.cs.mailbox.ContactGroup in project zm-mailbox by Zimbra.
the class ToXML method encodeContactGroup.
private static void encodeContactGroup(Element elem, ContactGroup contactGroup, Collection<String> memberAttrFilter, ItemIdFormatter ifmt, OperationContext octxt, boolean summary, int fields) throws ServiceException {
for (ContactGroup.Member member : contactGroup.getMembers(true)) {
Element eMember = elem.addNonUniqueElement(MailConstants.E_CONTACT_GROUP_MEMBER);
encodeContactGroupMemberBasic(eMember, member);
Object derefedMember = member.getDerefedObj();
if (derefedMember != null) {
if (derefedMember instanceof String) {
// inline member, do nothing
} else if (derefedMember instanceof Contact) {
// only expand one level for now.
// If this member is a group, do not create/pass down a ContactGroup object from the member.
encodeContact(eMember, ifmt, octxt, (Contact) derefedMember, summary, memberAttrFilter, fields);
} else if (derefedMember instanceof GalContact) {
encodeGalContact(eMember, (GalContact) derefedMember, memberAttrFilter);
} else if (derefedMember instanceof Element) {
// proxied GAL or Contact entry
Element eContact = (Element) derefedMember;
if (memberAttrFilter != null) {
for (Element eAttr : eContact.listElements()) {
String name = eAttr.getAttribute(MailConstants.A_ATTRIBUTE_NAME, null);
if (!memberAttrFilter.contains(name)) {
eAttr.detach();
}
}
}
eMember.addNonUniqueElement(eContact);
}
}
}
}
use of com.zimbra.cs.mailbox.ContactGroup in project zm-mailbox by Zimbra.
the class UserServletUtil method populateContactFields.
public static void populateContactFields(Iterator<? extends MailItem> contacts, Mailbox mbox, OperationContext octxt, ArrayList<Map<String, String>> allContacts, HashSet<String> fields) throws ServiceException {
while (contacts.hasNext()) {
Object obj = contacts.next();
if (obj instanceof Contact) {
Contact c = (Contact) obj;
if (c.isContactGroup()) {
HashMap<String, String> nContacts = new HashMap<String, String>();
// first add all the fields and values
nContacts.putAll(c.getFields());
// remove groupMemeber
nContacts.remove(ContactConstants.A_groupMember);
// then re-calculate the dlist as in 7.X
ContactGroup cg = ContactGroup.init(c, false);
String strs = cg.migrateToDlist(mbox, octxt);
nContacts.put(ContactConstants.A_dlist, strs);
allContacts.add(nContacts);
fields.addAll(nContacts.keySet());
} else {
allContacts.add(c.getFields());
fields.addAll(c.getFields().keySet());
}
}
}
}
use of com.zimbra.cs.mailbox.ContactGroup in project zm-mailbox by Zimbra.
the class CreateContact method migrateFromDlist.
static void migrateFromDlist(ParsedContact pc) throws ServiceException {
/*
* replace groupMember with dlist data
*
* Note: if the user had also used new clients to manipulate group members
* all ref members will be lost, since all dlist members will be
* migrated as INLINE members.
* if dlist is an empty string, the group will become an empty group.
*
* This is the expected behavior.
*/
Map<String, String> fields = pc.getFields();
String dlist = fields.get(ContactConstants.A_dlist);
if (dlist != null) {
try {
ContactGroup contactGroup = ContactGroup.init();
contactGroup.migrateFromDlist(dlist);
fields.put(ContactConstants.A_groupMember, contactGroup.encode());
fields.remove(ContactConstants.A_dlist);
} catch (Exception e) {
ZimbraLog.contact.info("skipped migrating contact group, dlist=[%s]", dlist, e);
}
}
}
use of com.zimbra.cs.mailbox.ContactGroup in project zm-mailbox by Zimbra.
the class GetContacts method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
Account mRequestedAcct = getRequestedAccount(zsc);
Account mAuthedAcct = getAuthenticatedAccount(zsc);
GetContactsRequest req = zsc.elementToJaxb(request);
boolean sync = req.getSync() == null ? false : req.getSync();
boolean derefContactGroupMember = req.getDerefGroupMember();
String folderIdStr = req.getFolderId();
int folderId = ALL_FOLDERS;
if (folderIdStr != null) {
ItemId iidFolder = new ItemId(folderIdStr, zsc);
if (iidFolder.belongsTo(mbox))
folderId = iidFolder.getId();
else
throw ServiceException.FAILURE("Got remote folderId: " + folderIdStr + " but did not proxy", null);
}
SortBy sort = SortBy.of(req.getSortBy());
if (sort == null) {
sort = SortBy.NONE;
}
ArrayList<String> attrs = null;
ArrayList<String> memberAttrs = null;
ArrayList<ItemId> ids = null;
// MailConstants.A_ATTRIBUTE_NAME
List<AttributeName> reqAttrs = req.getAttributes();
if (reqAttrs != null && reqAttrs.size() > 0) {
attrs = new ArrayList<String>();
for (AttributeName attrName : reqAttrs) {
attrs.add(attrName.getName());
}
}
// MailConstants.E_CONTACT_GROUP_MEMBER_ATTRIBUTE
reqAttrs = req.getMemberAttributes();
if (reqAttrs != null && reqAttrs.size() > 0) {
memberAttrs = new ArrayList<String>();
for (AttributeName attrName : reqAttrs) {
memberAttrs.add(attrName.getName());
}
}
// MailConstants.E_CONTACT
List<Id> contactIds = req.getContacts();
if (contactIds != null && contactIds.size() > 0) {
ids = new ArrayList<ItemId>();
for (Id target : contactIds) {
String idStr = target.getId();
if (idStr.indexOf(",") > 0) {
// comma-separated IDs. TODO: deprecate this use-case
String[] toks = idStr.split(",");
for (int i = 0; i < toks.length; i++) {
ids.add(new ItemId(toks[i], zsc));
}
} else {
ids.add(new ItemId(idStr, zsc));
}
}
}
long maxMembers = DEFAULT_MAX_MEMBERS;
boolean returnHiddenAttrs = false;
if (attrs == null) {
returnHiddenAttrs = req.getReturnHiddenAttrs();
maxMembers = (req.getMaxMembers() == null) ? DEFAULT_MAX_MEMBERS : req.getMaxMembers();
}
boolean returnCertInfo = req.getReturnCertInfo();
Map<String, Set<String>> memberOfMap = null;
if (req.getIncludeMemberOf()) {
memberOfMap = ContactMemberOfMap.getMemberOfMap(mbox, octxt);
}
Element response = zsc.createElement(MailConstants.GET_CONTACTS_RESPONSE);
// want to return modified date only on sync-related requests
int fields = ToXML.NOTIFY_FIELDS;
if (sync) {
fields |= Change.CONFLICT;
}
if (req.getWantImapUid()) {
fields |= Change.IMAP_UID;
}
// for perf reason, derefContactGroupMember is not supported in this mode
if (derefContactGroupMember) {
if (ids == null) {
throw ServiceException.INVALID_REQUEST(MailConstants.A_DEREF_CONTACT_GROUP_MEMBER + " is supported only when specific contact ids are specified", null);
}
}
if (ids != null) {
ArrayList<Integer> local = new ArrayList<Integer>();
HashMap<String, StringBuffer> remote = new HashMap<String, StringBuffer>();
partitionItems(zsc, ids, local, remote);
if (remote.size() > 0) {
if (folderId > 0)
throw ServiceException.INVALID_REQUEST("Cannot specify a folder with mixed-mailbox items", null);
List<Element> responses = proxyRemote(request, remote, context);
for (Element e : responses) response.addNonUniqueElement(e);
}
if (local.size() > 0) {
boolean migrateDlist = CreateContact.needToMigrateDlist(zsc);
for (int id : local) {
Contact con = mbox.getContactById(octxt, id);
if (con != null && (folderId == ALL_FOLDERS || folderId == con.getFolderId())) {
ContactGroup contactGroup = null;
String migratedDlist = null;
if (migrateDlist) {
ContactGroup cg = ContactGroup.init(con, false);
if (cg != null) {
migratedDlist = cg.migrateToDlist(con.getMailbox(), octxt);
}
} else if (derefContactGroupMember) {
contactGroup = ContactGroup.init(con, false);
if (contactGroup != null) {
contactGroup.derefAllMembers(con.getMailbox(), octxt, zsc.getResponseProtocol());
}
}
ToXML.encodeContact(response, ifmt, octxt, con, contactGroup, memberAttrs, false, /* summary */
attrs, fields, migratedDlist, returnHiddenAttrs, maxMembers, returnCertInfo, ContactMemberOfMap.setOfMemberOf(zsc.getRequestedAccountId(), id, memberOfMap), mRequestedAcct, mAuthedAcct);
}
}
}
} else {
for (Contact con : mbox.getContactList(octxt, folderId, sort)) {
if (con != null) {
ToXML.encodeContact(response, ifmt, octxt, con, null, null, false, /* summary */
attrs, fields, null, returnHiddenAttrs, maxMembers, returnCertInfo, ContactMemberOfMap.setOfMemberOf(zsc.getRequestedAccountId(), con.getId(), memberOfMap));
}
}
}
return response;
}
use of com.zimbra.cs.mailbox.ContactGroup in project zm-mailbox by Zimbra.
the class TestContactGroup method getMembers.
@Test
public void getMembers() 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) });
List<Member> members = contactGroup.getMembers();
assertEquals(3, members.size());
assertTrue(members.get(0) instanceof ContactRefMember);
assertEquals(CONTACT_REF_VALUE, members.get(0).getValue());
assertTrue(members.get(1) instanceof GalRefMember);
assertEquals(GAL_REF_VALUE, members.get(1).getValue());
assertTrue(members.get(2) instanceof InlineMember);
assertEquals(INLINE_VALUE, members.get(2).getValue());
}
Aggregations