Search in sources :

Example 6 with Attach

use of com.zimbra.common.calendar.Attach in project zm-mailbox by Zimbra.

the class Alarm method decodeMetadata.

/**
     * Create an Alarm from Metadata.  Return value may be null.
     * @param meta
     * @return
     * @throws ServiceException
     * @throws ParseException
     */
public static Alarm decodeMetadata(Metadata meta) throws ServiceException {
    Action action = expandAction(meta.get(FN_ACTION));
    if (!actionAllowed(action))
        return null;
    TriggerType tt = expandTriggerType(meta.get(FN_TRIGGER_TYPE));
    TriggerRelated triggerRelated = null;
    ParsedDuration triggerRelative = null;
    ParsedDateTime triggerAbsolute = null;
    if (TriggerType.ABSOLUTE.equals(tt)) {
        try {
            triggerAbsolute = ParsedDateTime.parseUtcOnly(meta.get(FN_TRIGGER_ABSOLUTE));
        } catch (ParseException e) {
            throw ServiceException.FAILURE("Error parsing metadata for alarm", e);
        }
    } else {
        triggerRelative = ParsedDuration.parse(meta.get(FN_TRIGGER_RELATIVE));
        triggerRelated = expandTriggerRelated(meta.get(FN_TRIGGER_RELATED, null));
    }
    ParsedDuration repeatDuration = null;
    int repeatCount = 0;
    String val = meta.get(FN_REPEAT_DURATION, null);
    if (val != null) {
        repeatDuration = ParsedDuration.parse(val);
        repeatCount = (int) meta.getLong(FN_REPEAT_COUNT, 0);
    }
    String description = meta.get(FN_DESCRIPTION, null);
    String summary = meta.get(FN_SUMMARY, null);
    Attach attach = null;
    Metadata metaAttach = meta.getMap(FN_ATTACH, true);
    if (metaAttach != null)
        attach = Util.decodeAttachFromMetadata(metaAttach);
    int numAts = (int) meta.getLong(FN_NUM_ATTENDEES, 0);
    List<ZAttendee> attendees = new ArrayList<ZAttendee>(numAts);
    for (int i = 0; i < numAts; i++) {
        try {
            Metadata metaAttendee = meta.getMap(FN_ATTENDEE + i, true);
            if (metaAttendee != null)
                attendees.add(new ZAttendee(metaAttendee));
        } catch (ServiceException e) {
            ZimbraLog.calendar.warn("Problem decoding attendee " + i + " in ALARM ");
        }
    }
    Alarm alarm = new Alarm(action, tt, triggerRelated, triggerRelative, triggerAbsolute, repeatDuration, repeatCount, description, summary, attach, attendees, Util.decodeXPropsFromMetadata(meta));
    return alarm;
}
Also used : ParsedDuration(com.zimbra.common.calendar.ParsedDuration) Attach(com.zimbra.common.calendar.Attach) CalendarAttach(com.zimbra.soap.mail.type.CalendarAttach) Metadata(com.zimbra.cs.mailbox.Metadata) ArrayList(java.util.ArrayList) ServiceException(com.zimbra.common.service.ServiceException) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) ParseException(java.text.ParseException)

Aggregations

Attach (com.zimbra.common.calendar.Attach)6 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)4 ParsedDuration (com.zimbra.common.calendar.ParsedDuration)4 ParseException (java.text.ParseException)4 ArrayList (java.util.ArrayList)4 ServiceException (com.zimbra.common.service.ServiceException)3 CalendarAttach (com.zimbra.soap.mail.type.CalendarAttach)3 ICalTok (com.zimbra.common.calendar.ZCalendar.ICalTok)2 ZParameter (com.zimbra.common.calendar.ZCalendar.ZParameter)2 ZProperty (com.zimbra.common.calendar.ZCalendar.ZProperty)2 MessagingException (javax.mail.MessagingException)2 ContentType (javax.mail.internet.ContentType)2 MimeMessage (javax.mail.internet.MimeMessage)2 ImmutableList (com.google.common.collect.ImmutableList)1 Geo (com.zimbra.common.calendar.Geo)1 ZComponent (com.zimbra.common.calendar.ZCalendar.ZComponent)1 ContentDisposition (com.zimbra.common.mime.ContentDisposition)1 JavaMailInternetAddress (com.zimbra.common.mime.shim.JavaMailInternetAddress)1 Element (com.zimbra.common.soap.Element)1 ZMimeBodyPart (com.zimbra.common.zmime.ZMimeBodyPart)1