Search in sources :

Example 1 with ContactDLMembers

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;
}
Also used : ContactDLMembers(com.zimbra.cs.gal.GalGroupMembers.ContactDLMembers) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) Element(com.zimbra.common.soap.Element) Attachment(com.zimbra.cs.mailbox.Contact.Attachment) ItemId(com.zimbra.cs.service.util.ItemId) Map(java.util.Map) IcalXmlStrMap(com.zimbra.cs.mailbox.calendar.IcalXmlStrMap) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap)

Aggregations

TimeZoneMap (com.zimbra.common.calendar.TimeZoneMap)1 ServiceException (com.zimbra.common.service.ServiceException)1 Element (com.zimbra.common.soap.Element)1 ContactDLMembers (com.zimbra.cs.gal.GalGroupMembers.ContactDLMembers)1 Attachment (com.zimbra.cs.mailbox.Contact.Attachment)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 IcalXmlStrMap (com.zimbra.cs.mailbox.calendar.IcalXmlStrMap)1 ItemId (com.zimbra.cs.service.util.ItemId)1 Map (java.util.Map)1