use of com.zimbra.cs.gal.GalGroupMembers.ContactDLMembers in project zm-mailbox by Zimbra.
the class ToXML method encodeContact.
public static Element encodeContact(Element parent, ItemIdFormatter ifmt, OperationContext octxt, Contact contact, ContactGroup contactGroup, Collection<String> memberAttrFilter, boolean summary, Collection<String> attrFilter, int fields, String migratedDlist, boolean returnHiddenAttrs, long maxMembers, boolean returnCertInfo) throws ServiceException {
Element el = parent.addElement(MailConstants.E_CONTACT);
el.addAttribute(MailConstants.A_ID, ifmt.formatItemId(contact));
if (needToOutput(fields, Change.FOLDER)) {
el.addAttribute(MailConstants.A_FOLDER, ifmt.formatItemId(new ItemId(contact.getMailbox().getAccountId(), contact.getFolderId())));
}
recordItemTags(el, contact, octxt, fields);
if (needToOutput(fields, Change.CONFLICT)) {
el.addAttribute(MailConstants.A_CHANGE_DATE, contact.getChangeDate() / 1000);
el.addAttribute(MailConstants.A_MODIFIED_SEQUENCE, contact.getModifiedSequence());
el.addAttribute(MailConstants.A_DATE, contact.getDate());
el.addAttribute(MailConstants.A_REVISION, contact.getSavedSequence());
} else if (needToOutput(fields, Change.CONTENT)) {
el.addAttribute(MailConstants.A_DATE, contact.getDate());
el.addAttribute(MailConstants.A_REVISION, contact.getSavedSequence());
}
if (needToOutput(fields, Change.METADATA)) {
encodeAllCustomMetadata(el, contact, fields);
}
if (!needToOutput(fields, Change.CONTENT)) {
if (summary) {
try {
el.addAttribute(MailConstants.A_FILE_AS_STR, contact.getFileAsString());
} catch (ServiceException e) {
}
el.addAttribute(ContactConstants.A_email, contact.get(ContactConstants.A_email));
el.addAttribute(ContactConstants.A_email2, contact.get(ContactConstants.A_email2));
el.addAttribute(ContactConstants.A_email3, contact.get(ContactConstants.A_email3));
String type = contact.get(ContactConstants.A_type);
el.addAttribute(ContactConstants.A_type, type);
// send back date with summary via search results
el.addAttribute(MailConstants.A_CHANGE_DATE, contact.getChangeDate() / 1000);
}
// stop here if we're not returning the actual contact content
return el;
}
try {
el.addAttribute(MailConstants.A_FILE_AS_STR, contact.getFileAsString());
} catch (ServiceException e) {
}
List<Attachment> attachments = contact.getAttachments();
// encode contact group members (not derefed) if we don't have a
// already derefed contactGroup, and we don't have a migrated dlist
boolean encodeContactGroupMembersBasic = (contactGroup == null) && (migratedDlist == null);
if (attrFilter != null) {
for (String name : attrFilter) {
// XXX: How to distinguish between a non-existent attribute and
// an existing attribute with null or empty string value?
String value = contact.get(name);
if (!Strings.isNullOrEmpty(value)) {
encodeContactAttr(el, name, value, contact, encodeContactGroupMembersBasic, octxt, returnCertInfo);
} else if (attachments != null) {
for (Attachment attach : attachments) {
if (attach.getName().equals(name)) {
encodeContactAttachment(el, attach);
}
}
}
}
} else {
Map<String, String> contactFields = returnHiddenAttrs ? contact.getAllFields() : contact.getFields();
for (Map.Entry<String, String> me : contactFields.entrySet()) {
String name = me.getKey();
String value = me.getValue();
// can be configured as a hidden or non-hidden field
if (ContactConstants.A_member.equals(name) && maxMembers != GetContacts.NO_LIMIT_MAX_MEMBERS) {
// there is a limit on the max number of members to return
ContactDLMembers dlMembers = new ContactDLMembers(contact);
if (dlMembers.getTotal() > maxMembers) {
el.addAttribute(MailConstants.A_TOO_MANY_MEMBERS, true);
continue;
}
}
if (name != null && !name.trim().isEmpty() && !Strings.isNullOrEmpty(value)) {
encodeContactAttr(el, name, value, contact, encodeContactGroupMembersBasic, octxt, returnCertInfo);
}
}
if (attachments != null) {
for (Attachment attach : attachments) {
encodeContactAttachment(el, attach);
}
}
}
if (migratedDlist != null) {
encodeContactAttr(el, ContactConstants.A_dlist, migratedDlist, contact, false, octxt, returnCertInfo);
} else if (contactGroup != null) {
encodeContactGroup(el, contactGroup, memberAttrFilter, ifmt, octxt, summary, fields);
}
return el;
}
Aggregations