Search in sources :

Example 11 with ZProperty

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

the class FreeBusy method parse.

/**
     * Create a FreeBusy object from VFREEBUSY ZComponent.
     * @param comp
     * @return
     * @throws ServiceException
     */
public static FreeBusy parse(ZComponent comp) throws ServiceException {
    String name = null;
    ParsedDateTime dtStart = null;
    ParsedDateTime dtEnd = null;
    List<Interval> intervals = new ArrayList<Interval>();
    TimeZoneMap tzmap = new TimeZoneMap(ICalTimeZone.getUTC());
    Iterator<ZProperty> propIter = comp.getPropertyIterator();
    while (propIter.hasNext()) {
        ZProperty prop = propIter.next();
        ICalTok tok = prop.getToken();
        if (tok == null)
            continue;
        switch(tok) {
            case DTSTART:
                try {
                    dtStart = ParsedDateTime.parse(prop, tzmap);
                } catch (ParseException e) {
                    throw ServiceException.INVALID_REQUEST("bad DTSTART: " + prop.toString(), e);
                }
                break;
            case DTEND:
                try {
                    dtEnd = ParsedDateTime.parse(prop, tzmap);
                } catch (ParseException e) {
                    throw ServiceException.INVALID_REQUEST("bad DTEND: " + prop.toString(), e);
                }
                break;
            case ORGANIZER:
                ZOrganizer att = new ZOrganizer(prop);
                name = att.getAddress();
                break;
            case FREEBUSY:
                String fbStatus = IcalXmlStrMap.FBTYPE_FREE;
                ZParameter fbType = prop.getParameter(ICalTok.FBTYPE);
                if (fbType != null)
                    fbStatus = IcalXmlStrMap.sFreeBusyMap.toXml(fbType.getValue());
                List<String> vals = prop.getValueList();
                for (String fbVal : vals) {
                    Period period;
                    try {
                        period = Period.parse(fbVal, ICalTimeZone.getUTC(), tzmap);
                    } catch (ParseException e) {
                        throw ServiceException.INVALID_REQUEST("bad period value: " + fbVal, e);
                    }
                    intervals.add(new Interval(period.getStart().getUtcTime(), period.getEnd().getUtcTime(), fbStatus));
                }
                break;
        }
    }
    if (name == null)
        throw ServiceException.INVALID_REQUEST("VFREEBUSY missing ORGANIZER", null);
    if (dtStart == null || dtEnd == null)
        throw ServiceException.INVALID_REQUEST("VFREEBUSY missing DTSTART/DTEND", null);
    IntervalList ivalList = new IntervalList(dtStart.getUtcTime(), dtEnd.getUtcTime());
    for (Interval ival : intervals) {
        ivalList.addInterval(ival);
    }
    return new FreeBusy(name, ivalList, dtStart.getUtcTime(), dtEnd.getUtcTime());
}
Also used : ZOrganizer(com.zimbra.cs.mailbox.calendar.ZOrganizer) Period(com.zimbra.cs.mailbox.calendar.Period) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter) ICalTok(com.zimbra.common.calendar.ZCalendar.ICalTok) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) ParseException(java.text.ParseException)

Example 12 with ZProperty

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

the class Mailbox method writeICalendarForCalendarItems.

public void writeICalendarForCalendarItems(Writer writer, OperationContext octxt, Collection<CalendarItem> calItems, Folder f, boolean useOutlookCompatMode, boolean ignoreErrors, boolean needAppleICalHacks, boolean trimCalItemsList, boolean escapeHtmlTags, boolean includeAttaches) throws ServiceException {
    lock.lock();
    try {
        writer.write("BEGIN:VCALENDAR\r\n");
        if (f != null) {
            writer.write("X-WR-CALNAME:");
            writer.write(f.getName());
            writer.write("\r\n");
            writer.write("X-WR-CALID:");
            writer.write(new ItemId(f).toString());
            writer.write("\r\n");
        }
        ZProperty prop;
        prop = new ZProperty(ICalTok.PRODID, ZCalendar.sZimbraProdID);
        prop.toICalendar(writer, needAppleICalHacks);
        prop = new ZProperty(ICalTok.VERSION, ZCalendar.sIcalVersion);
        prop.toICalendar(writer, needAppleICalHacks);
        prop = new ZProperty(ICalTok.METHOD, ICalTok.PUBLISH.toString());
        prop.toICalendar(writer, needAppleICalHacks);
        // timezones
        ICalTimeZone localTz = Util.getAccountTimeZone(getAccount());
        TimeZoneMap tzmap = new TimeZoneMap(localTz);
        for (CalendarItem calItem : calItems) {
            tzmap.add(calItem.getTimeZoneMap());
        }
        // iterate the tzmap and add all the VTimeZone's
        for (Iterator<ICalTimeZone> iter = tzmap.tzIterator(); iter.hasNext(); ) {
            ICalTimeZone tz = iter.next();
            tz.newToVTimeZone().toICalendar(writer, needAppleICalHacks);
        }
        // help keep memory consumption low
        tzmap = null;
        // build all the event components and add them to the Calendar
        for (Iterator<CalendarItem> iter = calItems.iterator(); iter.hasNext(); ) {
            CalendarItem calItem = iter.next();
            boolean allowPrivateAccess = calItem.isPublic() || calItem.allowPrivateAccess(octxt.getAuthenticatedUser(), octxt.isUsingAdminPrivileges());
            if (trimCalItemsList) {
                // help keep memory consumption low
                iter.remove();
            }
            Invite[] invites = calItem.getInvites();
            if (invites != null && invites.length > 0) {
                boolean appleICalExdateHack = LC.calendar_apple_ical_compatible_canceled_instances.booleanValue();
                ZComponent[] comps = null;
                try {
                    comps = Invite.toVComponents(invites, allowPrivateAccess, useOutlookCompatMode, appleICalExdateHack, includeAttaches);
                } catch (ServiceException e) {
                    if (ignoreErrors) {
                        ZimbraLog.calendar.warn("Error retrieving iCalendar data for item %s: %s", calItem.getId(), e.getMessage(), e);
                    } else {
                        throw e;
                    }
                }
                if (comps != null) {
                    for (ZComponent comp : comps) {
                        comp.toICalendar(writer, needAppleICalHacks, escapeHtmlTags);
                    }
                }
            }
        }
        writer.write("END:VCALENDAR\r\n");
    } catch (IOException e) {
        throw ServiceException.FAILURE("Error writing iCalendar", e);
    } finally {
        lock.release();
    }
}
Also used : IOException(java.io.IOException) ItemId(com.zimbra.cs.service.util.ItemId) SetCalendarItem(com.zimbra.cs.redolog.op.SetCalendarItem) ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone) CreateInvite(com.zimbra.cs.redolog.op.CreateInvite) Invite(com.zimbra.cs.mailbox.calendar.Invite)

Example 13 with ZProperty

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

the class TestCalDav method testCreateModifyDeleteAttendeeModifyAndCancel.

/** Mostly checking that if attendees cease to exist (even via DLs) then modification and cancel iTip
     * messages still work to the remaining attendees.
     */
@Test
public void testCreateModifyDeleteAttendeeModifyAndCancel() throws ServiceException, IOException {
    Account dav1 = users[1].create();
    Account dav2 = users[2].create();
    Account dav3 = users[3].create();
    Account dav4 = users[4].create();
    DistributionList dl = TestUtil.createDistributionList(DL1);
    String[] members = { dav4.getName() };
    prov.addMembers(dl, members);
    List<MailTarget> attendees = Lists.newArrayList();
    attendees.add(dav1);
    attendees.add(dav2);
    attendees.add(dav3);
    attendees.add(dl);
    ZVCalendar vCal = simpleMeeting(dav1, attendees, "1", 8);
    ZProperty uidProp = vCal.getComponent(ICalTok.VEVENT).getProperty(ICalTok.UID);
    String uid = uidProp.getValue();
    String davBaseName = uid + ".ics";
    String url = String.format("%s%s", getFolderUrl(dav1, "Calendar"), davBaseName);
    doIcalPut(url, dav1, zvcalendarToBytes(vCal), HttpStatus.SC_CREATED);
    String inboxhref = TestCalDav.waitForNewSchedulingRequestByUID(dav2, uid);
    assertTrue("Found meeting request for newly created item", inboxhref.contains(uid));
    doDeleteMethod(getLocalServerRoot().append(inboxhref).toString(), dav2, HttpStatus.SC_NO_CONTENT);
    // attendee via DL
    inboxhref = TestCalDav.waitForNewSchedulingRequestByUID(dav4, uid);
    assertTrue("Found meeting request for newly created item", inboxhref.contains(uid));
    doDeleteMethod(getLocalServerRoot().append(inboxhref).toString(), dav4, HttpStatus.SC_NO_CONTENT);
    vCal = simpleMeeting(dav1, attendees, uid, "2", 9);
    doIcalPut(url, dav1, zvcalendarToBytes(vCal), HttpStatus.SC_CREATED);
    inboxhref = TestCalDav.waitForNewSchedulingRequestByUID(dav2, uid);
    assertTrue("Found meeting request for newly created item", inboxhref.contains(uid));
    doDeleteMethod(getLocalServerRoot().append(inboxhref).toString(), dav2, HttpStatus.SC_NO_CONTENT);
    // attendee via DL
    inboxhref = TestCalDav.waitForNewSchedulingRequestByUID(dav4, uid);
    assertTrue("Found meeting request for newly created item", inboxhref.contains(uid));
    doDeleteMethod(getLocalServerRoot().append(inboxhref).toString(), dav4, HttpStatus.SC_NO_CONTENT);
    // Test that iTip handling still happens when some of the attendees no longer exist.
    users[3].cleanup();
    // attendee via DL
    users[4].cleanup();
    vCal = simpleMeeting(dav1, attendees, uid, "3", 10);
    doIcalPut(url, dav1, zvcalendarToBytes(vCal), HttpStatus.SC_CREATED);
    inboxhref = TestCalDav.waitForNewSchedulingRequestByUID(dav2, uid);
    assertTrue("Found meeting request for newly created item", inboxhref.contains(uid));
    doDeleteMethod(getLocalServerRoot().append(inboxhref).toString(), dav2, HttpStatus.SC_NO_CONTENT);
    String dav2Url = String.format("%s%s", getFolderUrl(dav2, "Calendar"), davBaseName);
    doGetMethod(dav2Url, dav2, HttpStatus.SC_OK);
    // Cancel meeting by deleting it
    doDeleteMethod(url, dav1, HttpStatus.SC_NO_CONTENT);
    inboxhref = TestCalDav.waitForNewSchedulingRequestByUID(dav2, uid);
    assertTrue("Found meeting request for newly created item", inboxhref.contains(uid));
    doDeleteMethod(getLocalServerRoot().append(inboxhref).toString(), dav2, HttpStatus.SC_NO_CONTENT);
    // The associated calendar item should have been deleted as a result of the Cancel
    doGetMethod(dav2Url, dav2, HttpStatus.SC_NOT_FOUND);
}
Also used : Account(com.zimbra.cs.account.Account) ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) MailTarget(com.zimbra.cs.account.MailTarget) DistributionList(com.zimbra.cs.account.DistributionList) Test(org.junit.Test)

Example 14 with ZProperty

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

the class TestCalDav method attendee.

public static ZProperty attendee(MailTarget mailTarget, ICalTok role, ICalTok cutype, ICalTok partstat) {
    ZProperty att = new ZProperty(ICalTok.ATTENDEE, "mailto:" + mailTarget.getName());
    String displayName = mailTarget.getAttr(Provisioning.A_displayName);
    if (Strings.isNullOrEmpty(displayName)) {
        displayName = mailTarget.getName().substring(0, mailTarget.getName().indexOf("@"));
    }
    att.addParameter(new ZParameter(ICalTok.CN, displayName));
    att.addParameter(new ZParameter(ICalTok.ROLE, role.toString()));
    att.addParameter(new ZParameter(ICalTok.CUTYPE, cutype.toString()));
    att.addParameter(new ZParameter(ICalTok.PARTSTAT, partstat.toString()));
    return att;
}
Also used : ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter)

Example 15 with ZProperty

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

the class TestCalDav method simpleEvent.

public byte[] simpleEvent(Account organizer) 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, 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, "Simple Event"));
    vevent.addProperty(new ZProperty(ICalTok.UID, "d1102-42a7-4283-b025-3376dabe53b3"));
    vevent.addProperty(new ZProperty(ICalTok.STATUS, ICalTok.CONFIRMED.toString()));
    vevent.addProperty(new ZProperty(ICalTok.SEQUENCE, "1"));
    // vevent.addProperty(organizer(organizer));
    vcal.addComponent(vevent);
    return zvcalendarToBytes(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) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone)

Aggregations

ZProperty (com.zimbra.common.calendar.ZCalendar.ZProperty)49 ZParameter (com.zimbra.common.calendar.ZCalendar.ZParameter)19 ZComponent (com.zimbra.common.calendar.ZCalendar.ZComponent)18 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)13 ArrayList (java.util.ArrayList)12 Account (com.zimbra.cs.account.Account)10 ICalTok (com.zimbra.common.calendar.ZCalendar.ICalTok)9 ZVCalendar (com.zimbra.common.calendar.ZCalendar.ZVCalendar)9 ICalTimeZone (com.zimbra.common.calendar.ICalTimeZone)8 Invite (com.zimbra.cs.mailbox.calendar.Invite)8 ParsedDuration (com.zimbra.common.calendar.ParsedDuration)7 ZOrganizer (com.zimbra.cs.mailbox.calendar.ZOrganizer)7 TimeZoneMap (com.zimbra.common.calendar.TimeZoneMap)6 ServiceException (com.zimbra.common.service.ServiceException)6 ParseException (java.text.ParseException)6 IRecurrence (com.zimbra.cs.mailbox.calendar.Recurrence.IRecurrence)5 AccountAddressMatcher (com.zimbra.cs.util.AccountUtil.AccountAddressMatcher)5 Element (com.zimbra.common.soap.Element)4 IOException (java.io.IOException)4 Geo (com.zimbra.common.calendar.Geo)3