Search in sources :

Example 31 with ZComponent

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

the class TestCalDav method makeFreeBusyRequestIcal.

public String makeFreeBusyRequestIcal(Account organizer, List<Account> attendees, Date start, Date end) throws IOException {
    ZVCalendar vcal = new ZVCalendar();
    vcal.addVersionAndProdId();
    vcal.addProperty(new ZProperty(ICalTok.METHOD, ICalTok.REQUEST.toString()));
    ZComponent vfreebusy = new ZComponent(ICalTok.VFREEBUSY);
    ParsedDateTime dtstart = ParsedDateTime.fromUTCTime(start.getTime());
    vfreebusy.addProperty(dtstart.toProperty(ICalTok.DTSTART, false));
    ParsedDateTime dtend = ParsedDateTime.fromUTCTime(end.getTime());
    vfreebusy.addProperty(dtend.toProperty(ICalTok.DTEND, false));
    vfreebusy.addProperty(new ZProperty(ICalTok.DTSTAMP, "20140108T224700Z"));
    vfreebusy.addProperty(new ZProperty(ICalTok.UID, "d123f102-42a7-4283-b025-3376dabe53b3"));
    vfreebusy.addProperty(organizer(organizer));
    for (Account attendee : attendees) {
        vfreebusy.addProperty(new ZProperty(ICalTok.ATTENDEE, "mailto:" + attendee.getName()));
    }
    vcal.addComponent(vfreebusy);
    StringWriter calWriter = new StringWriter();
    vcal.toICalendar(calWriter);
    String icalString = calWriter.toString();
    Closeables.closeQuietly(calWriter);
    return icalString;
}
Also used : ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) Account(com.zimbra.cs.account.Account) ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) StringWriter(java.io.StringWriter) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime)

Example 32 with ZComponent

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

the class TestCalDav method exampleCancelIcal.

public String exampleCancelIcal(Account organizer, Account attendee1, Account attendee2) throws IOException {
    ZVCalendar vcal = new ZVCalendar();
    vcal.addVersionAndProdId();
    vcal.addProperty(new ZProperty(ICalTok.METHOD, ICalTok.CANCEL.toString()));
    ICalTimeZone tz = ICalTimeZone.lookupByTZID("Africa/Harare");
    vcal.addComponent(tz.newToVTimeZone());
    ZComponent vevent = new ZComponent(ICalTok.VEVENT);
    ParsedDateTime dtstart = parsedDateTime(2020, java.util.Calendar.APRIL, 1, 9, 0, tz);
    vevent.addProperty(dtstart.toProperty(ICalTok.DTSTART, false));
    ParsedDateTime dtend = parsedDateTime(2020, java.util.Calendar.APRIL, 1, 13, 0, tz);
    vevent.addProperty(dtend.toProperty(ICalTok.DTEND, false));
    vevent.addProperty(new ZProperty(ICalTok.DTSTAMP, "20140108T224700Z"));
    vevent.addProperty(new ZProperty(ICalTok.SUMMARY, "Meeting for fun"));
    vevent.addProperty(new ZProperty(ICalTok.UID, "d123f102-42a7-4283-b025-3376dabe53b3"));
    vevent.addProperty(new ZProperty(ICalTok.STATUS, ICalTok.CANCELLED.toString()));
    vevent.addProperty(new ZProperty(ICalTok.SEQUENCE, "1"));
    vevent.addProperty(organizer(organizer));
    vevent.addProperty(attendee(attendee1, ICalTok.REQ_PARTICIPANT, ICalTok.INDIVIDUAL, ICalTok.NEEDS_ACTION));
    vevent.addProperty(attendee(attendee2, ICalTok.REQ_PARTICIPANT, ICalTok.INDIVIDUAL, ICalTok.NEEDS_ACTION));
    vcal.addComponent(vevent);
    StringWriter calWriter = new StringWriter();
    vcal.toICalendar(calWriter);
    String icalString = calWriter.toString();
    Closeables.closeQuietly(calWriter);
    return icalString;
}
Also used : ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) StringWriter(java.io.StringWriter) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone)

Example 33 with ZComponent

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

the class TestCalDav method simpleMeeting.

public ZVCalendar simpleMeeting(Account organizer, List<MailTarget> attendees, String uid, String seq, int startHour) throws IOException {
    ZVCalendar vcal = new ZVCalendar();
    vcal.addVersionAndProdId();
    vcal.addProperty(new ZProperty(ICalTok.METHOD, ICalTok.PUBLISH.toString()));
    ICalTimeZone tz = ICalTimeZone.lookupByTZID("Africa/Harare");
    vcal.addComponent(tz.newToVTimeZone());
    ZComponent vevent = new ZComponent(ICalTok.VEVENT);
    ParsedDateTime dtstart = parsedDateTime(2020, java.util.Calendar.APRIL, 1, startHour, 0, tz);
    vevent.addProperty(dtstart.toProperty(ICalTok.DTSTART, false));
    ParsedDateTime dtend = parsedDateTime(2020, java.util.Calendar.APRIL, 1, startHour + 4, 0, tz);
    vevent.addProperty(dtend.toProperty(ICalTok.DTEND, false));
    vevent.addProperty(new ZProperty(ICalTok.DTSTAMP, "20150108T224700Z"));
    vevent.addProperty(new ZProperty(ICalTok.SUMMARY, "Simple Meeting"));
    vevent.addProperty(new ZProperty(ICalTok.UID, uid));
    vevent.addProperty(new ZProperty(ICalTok.STATUS, ICalTok.CONFIRMED.toString()));
    vevent.addProperty(new ZProperty(ICalTok.SEQUENCE, seq));
    vevent.addProperty(organizer(organizer));
    for (MailTarget att : attendees) {
        if (att.getId().equals(organizer.getId())) {
            vevent.addProperty(attendee(att, ICalTok.REQ_PARTICIPANT, ICalTok.INDIVIDUAL, ICalTok.ACCEPTED));
        } else {
            vevent.addProperty(attendee(att, ICalTok.REQ_PARTICIPANT, ICalTok.INDIVIDUAL, ICalTok.NEEDS_ACTION));
        }
    }
    vcal.addComponent(vevent);
    return vcal;
}
Also used : ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) MailTarget(com.zimbra.cs.account.MailTarget) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone)

Example 34 with ZComponent

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

the class Invite method toVComponents.

public static ZComponent[] toVComponents(Invite[] invites, boolean includePrivateData, boolean useOutlookCompatAllDayEvents, boolean convertCanceledInstancesToExdates, boolean includeAttaches) throws ServiceException {
    List<ZComponent> comps = new ArrayList<ZComponent>(invites.length);
    if (!convertCanceledInstancesToExdates || invites.length <= 1) {
        for (Invite inv : invites) {
            ZComponent comp = inv.newToVComponent(useOutlookCompatAllDayEvents, includePrivateData, includeAttaches);
            comps.add(comp);
        }
    } else {
        // Activate the hack that converts standalone VEVENT/VTODO components with STATUS:CANCELLED
        // into EXDATEs on the series component. (bug 36434)
        Invite seriesInv = null;
        ZComponent seriesComp = null;
        // Find the series invite.
        for (Invite inv : invites) {
            if (inv.isRecurrence()) {
                ZComponent comp = inv.newToVComponent(useOutlookCompatAllDayEvents, includePrivateData, includeAttaches);
                seriesComp = comp;
                comps.add(seriesComp);
                seriesInv = inv;
                break;
            }
        }
        for (Invite inv : invites) {
            if (inv != seriesInv) {
                // We already handled the series invite in the previous loop.
                if (inv.hasRecurId() && inv.isCancel()) {
                    // as a standalone component.
                    if (seriesComp != null) {
                        RecurId rid = inv.getRecurId();
                        ZProperty ridProp = rid.toProperty(false);
                        // EXDATE and RECURRENCE-ID have same value types and parameter list.  Just copy over.
                        ZProperty exdateProp = new ZProperty(ICalTok.EXDATE, ridProp.getValue());
                        for (Iterator<ZParameter> paramsIter = ridProp.parameterIterator(); paramsIter.hasNext(); ) {
                            ZParameter param = paramsIter.next();
                            exdateProp.addParameter(param);
                        }
                        seriesComp.addProperty(exdateProp);
                    } else {
                        // But if there is no series component, let the canceled instance be a component.
                        ZComponent comp = inv.newToVComponent(useOutlookCompatAllDayEvents, includePrivateData, includeAttaches);
                        if (comp != null)
                            comps.add(comp);
                    }
                } else {
                    // Modified instances are added as standalone components.
                    ZComponent comp = inv.newToVComponent(useOutlookCompatAllDayEvents, includePrivateData, includeAttaches);
                    if (comp != null)
                        comps.add(comp);
                }
            }
        }
    }
    return comps.toArray(new ZComponent[0]);
}
Also used : ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) ArrayList(java.util.ArrayList) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter)

Example 35 with ZComponent

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

the class Invite method createFromCalendar.

private static void createFromCalendar(List<Invite> toAdd, Account account, String fragment, ZVCalendar cal, boolean sentByMe, Mailbox mbx, int mailItemId, boolean continueOnError, InviteVisitor visitor) throws ServiceException {
    String method = cal.getPropVal(ICalTok.METHOD, ICalTok.PUBLISH.toString());
    // process the TIMEZONE's first: everything depends on them being there...
    TimeZoneMap tzmap = new TimeZoneMap(Util.getAccountTimeZone(account));
    Map<String, String> tzidRenames = Maps.newHashMap();
    List<ZComponent> components = Lists.newArrayList(cal.getComponentIterator());
    for (ZComponent comp : components) {
        if (ICalTok.VTIMEZONE.equals(comp.getTok())) {
            ICalTimeZone tz = ICalTimeZone.fromVTimeZone(comp, false, /* skipLookup */
            ICalTimeZone.TZID_NAME_ASSIGNMENT_BEHAVIOR.KEEP_IF_DOESNT_CLASH);
            tzmap.add(tz);
            String origTZID = comp.getPropVal(ICalTok.TZID, null);
            if ((null != origTZID) && (origTZID != tz.getID())) {
                tzidRenames.put(origTZID, tz.getID());
            }
        }
    }
    adjustTZIDnames(components, tzidRenames);
    createFromCalendar(toAdd, account, fragment, method, tzmap, cal.getComponentIterator(), sentByMe, mbx, mailItemId, continueOnError, visitor);
}
Also used : ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone)

Aggregations

ZComponent (com.zimbra.common.calendar.ZCalendar.ZComponent)35 ZProperty (com.zimbra.common.calendar.ZCalendar.ZProperty)18 ZVCalendar (com.zimbra.common.calendar.ZCalendar.ZVCalendar)16 ICalTimeZone (com.zimbra.common.calendar.ICalTimeZone)14 ArrayList (java.util.ArrayList)10 ICalTok (com.zimbra.common.calendar.ZCalendar.ICalTok)9 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)7 ZParameter (com.zimbra.common.calendar.ZCalendar.ZParameter)7 Account (com.zimbra.cs.account.Account)7 Invite (com.zimbra.cs.mailbox.calendar.Invite)7 IOException (java.io.IOException)7 TimeZoneMap (com.zimbra.common.calendar.TimeZoneMap)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Test (org.junit.Test)5 ServiceException (com.zimbra.common.service.ServiceException)4 InputStream (java.io.InputStream)4 MessagingException (javax.mail.MessagingException)4 MimeMessage (javax.mail.internet.MimeMessage)4 StringWriter (java.io.StringWriter)3 Address (javax.mail.Address)3