Search in sources :

Example 26 with ICalTimeZone

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

the class ToXML method encodeTimeZoneMap.

private static void encodeTimeZoneMap(Element parent, TimeZoneMap tzmap) {
    assert (tzmap != null);
    for (Iterator<ICalTimeZone> iter = tzmap.tzIterator(); iter.hasNext(); ) {
        ICalTimeZone tz = iter.next();
        Element e = parent.addElement(MailConstants.E_CAL_TZ);
        e.addAttribute(MailConstants.A_ID, tz.getID());
        e.addAttribute(MailConstants.A_CAL_TZ_STDOFFSET, tz.getStandardOffset() / 60 / 1000);
        e.addAttribute(MailConstants.A_CAL_TZ_STDNAME, tz.getStandardTzname());
        if (tz.useDaylightTime()) {
            SimpleOnset standard = tz.getStandardOnset();
            SimpleOnset daylight = tz.getDaylightOnset();
            if (standard != null && daylight != null) {
                e.addAttribute(MailConstants.A_CAL_TZ_DAYOFFSET, tz.getDaylightOffset() / 60 / 1000);
                e.addAttribute(MailConstants.A_CAL_TZ_DAYNAME, tz.getDaylightTzname());
                Element std = e.addElement(MailConstants.E_CAL_TZ_STANDARD);
                int standardWeek = standard.getWeek();
                if (standardWeek != 0) {
                    std.addAttribute(MailConstants.A_CAL_TZ_WEEK, standardWeek);
                    std.addAttribute(MailConstants.A_CAL_TZ_DAYOFWEEK, standard.getDayOfWeek());
                } else {
                    std.addAttribute(MailConstants.A_CAL_TZ_DAYOFMONTH, standard.getDayOfMonth());
                }
                std.addAttribute(MailConstants.A_CAL_TZ_MONTH, standard.getMonth());
                std.addAttribute(MailConstants.A_CAL_TZ_HOUR, standard.getHour());
                std.addAttribute(MailConstants.A_CAL_TZ_MINUTE, standard.getMinute());
                std.addAttribute(MailConstants.A_CAL_TZ_SECOND, standard.getSecond());
                Element day = e.addElement(MailConstants.E_CAL_TZ_DAYLIGHT);
                int daylightWeek = daylight.getWeek();
                if (daylightWeek != 0) {
                    day.addAttribute(MailConstants.A_CAL_TZ_WEEK, daylightWeek);
                    day.addAttribute(MailConstants.A_CAL_TZ_DAYOFWEEK, daylight.getDayOfWeek());
                } else {
                    day.addAttribute(MailConstants.A_CAL_TZ_DAYOFMONTH, daylight.getDayOfMonth());
                }
                day.addAttribute(MailConstants.A_CAL_TZ_MONTH, daylight.getMonth());
                day.addAttribute(MailConstants.A_CAL_TZ_HOUR, daylight.getHour());
                day.addAttribute(MailConstants.A_CAL_TZ_MINUTE, daylight.getMinute());
                day.addAttribute(MailConstants.A_CAL_TZ_SECOND, daylight.getSecond());
            }
        }
    }
}
Also used : SimpleOnset(com.zimbra.common.calendar.ICalTimeZone.SimpleOnset) Element(com.zimbra.common.soap.Element) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone) Mountpoint(com.zimbra.cs.mailbox.Mountpoint)

Example 27 with ICalTimeZone

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

the class CreateInvite method getPrintableData.

@Override
protected String getPrintableData() {
    StringBuilder sb = new StringBuilder("calItemId=").append(mCalendarItemId);
    sb.append(", calItemPartStat=").append(mCalendarItemPartStat);
    sb.append(", folder=").append(mFolderId);
    sb.append(", dataLen=").append(mData != null ? mData.length : 0);
    ICalTimeZone localTz = mInvite.getTimeZoneMap().getLocalTimeZone();
    sb.append(", localTZ=").append(Util.encodeAsMetadata(localTz).toString());
    sb.append(", inv=").append(Invite.encodeMetadata(mInvite).toString());
    sb.append(", preserveExistingAlarms=").append(mPreserveExistingAlarms);
    sb.append(", discardExistingInvites=").append(mDiscardExistingInvites);
    sb.append(", addRevision=").append(mAddRevision);
    return sb.toString();
}
Also used : ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone)

Example 28 with ICalTimeZone

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

the class ForwardCalendarItem method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account senderAcct = getZDesktopSafeAuthenticatedAccount(zsc);
    Mailbox mbox = getRequestedMailbox(zsc);
    OperationContext octxt = getOperationContext(zsc, context);
    // proxy handling
    ItemId iid = new ItemId(request.getAttribute(MailConstants.A_ID), zsc);
    if (!iid.belongsTo(getRequestedAccount(zsc))) {
        // Proxy it.
        return proxyRequest(request, context, iid.getAccountId());
    }
    Element msgElem = request.getElement(MailConstants.E_MSG);
    ParseMimeMessage.MimeMessageData parsedMessageData = new ParseMimeMessage.MimeMessageData();
    MimeMessage mm = ParseMimeMessage.parseMimeMsgSoap(zsc, octxt, mbox, msgElem, null, ParseMimeMessage.NO_INV_ALLOWED_PARSER, parsedMessageData);
    Element exc = request.getOptionalElement(MailConstants.E_CAL_EXCEPTION_ID);
    Element tzElem = request.getOptionalElement(MailConstants.E_CAL_TZ);
    CalendarItem calItem = mbox.getCalendarItemById(octxt, iid.getId());
    if (calItem == null) {
        throw MailServiceException.NO_SUCH_CALITEM(iid.toString(), "Could not find calendar item");
    }
    RecurId rid = null;
    if (exc != null) {
        TimeZoneMap tzmap = calItem.getTimeZoneMap();
        ICalTimeZone tz = null;
        if (tzElem != null) {
            tz = CalendarUtils.parseTzElement(tzElem);
            tzmap.add(tz);
        }
        ParsedDateTime exceptDt = CalendarUtils.parseDateTime(exc, tzmap);
        rid = new RecurId(exceptDt, RecurId.RANGE_NONE);
    }
    Pair<List<MimeMessage>, List<MimeMessage>> mimePair = forwardCalItem(mbox, octxt, calItem, rid, mm, senderAcct);
    sendForwardMessages(mbox, octxt, mimePair);
    Element response = getResponseElement(zsc);
    return response;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Element(com.zimbra.common.soap.Element) RecurId(com.zimbra.cs.mailbox.calendar.RecurId) ItemId(com.zimbra.cs.service.util.ItemId) CalendarItem(com.zimbra.cs.mailbox.CalendarItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone)

Example 29 with ICalTimeZone

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

the class GetMsgTest method testHandle.

@Test
public void testHandle() throws Exception {
    Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
    Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, "test2@zimbra.com");
    Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(acct1);
    Folder calendarFolder = mbox1.getCalendarFolders(null, SortBy.NONE).get(0);
    String fragment = "Some message";
    ZVCalendar calendar = new ZVCalendar();
    calendar.addDescription(desc, null);
    ZComponent comp = new ZComponent("VEVENT");
    calendar.addComponent(comp);
    Invite invite = MailboxTestUtil.generateInvite(acct1, fragment, calendar);
    ICalTimeZone ical = invite.getTimeZoneMap().getLocalTimeZone();
    long utc = 5 * 60 * 60 * 1000;
    ParsedDateTime s = ParsedDateTime.fromUTCTime(System.currentTimeMillis() + utc, ical);
    ParsedDateTime e = ParsedDateTime.fromUTCTime(System.currentTimeMillis() + (30 * 60 * 1000) + utc, ical);
    invite.setDtStart(s);
    invite.setDtEnd(e);
    invite.setPriority("5");
    invite.setClassProp("PRI");
    invite.setOrganizer(new ZOrganizer("test@zimbra.com", null));
    invite.setUid(UUID.randomUUID().toString());
    invite.setMethod("REQUEST");
    invite.setName("Testing");
    invite.setFreeBusy("B");
    invite.setIsOrganizer(true);
    invite.setItemType(MailItem.Type.APPOINTMENT);
    invite.setUid(UUID.randomUUID().toString());
    AddInviteData inviteData = mbox1.addInvite(null, invite, calendarFolder.getId());
    calendarFolder = mbox1.getCalendarFolders(null, SortBy.NONE).get(0);
    Element request = new Element.XMLElement("GetCalendarItem");
    Element action = request.addElement(MailConstants.E_MSG);
    action.addAttribute(MailConstants.A_ID, acct1.getId() + ":" + inviteData.calItemId + "-" + inviteData.invId);
    action.addAttribute(MailConstants.A_WANT_HTML, "1");
    action.addAttribute(MailConstants.A_NEED_EXP, "1");
    Element response = new GetMsg().handle(request, ServiceTestUtil.getRequestContext(acct1));
    Element organizer = response.getElement("m").getElement("inv").getElement("comp").getElement("or");
    String organizerString = organizer.prettyPrint();
    assertTrue(organizerString.contains("a=\"test@zimbra.com\" url=\"test@zimbra.com\""));
    mbox1.grantAccess(null, 10, acct2.getId(), ACL.GRANTEE_USER, ACL.RIGHT_READ, null);
    request = new Element.XMLElement("CreateMountPoint");
    Element link = request.addElement("link");
    link.addAttribute("f", "#");
    link.addAttribute("reminder", 0);
    link.addAttribute("name", "sharedcal");
    link.addAttribute("path", "/Calendar");
    link.addAttribute("owner", "test@zimbra.com");
    link.addAttribute("l", 10);
    link.addAttribute("view", "appoinment");
    response = new CreateMountpoint().handle(request, ServiceTestUtil.getRequestContext(acct2));
    String mptId = response.getElement("link").getAttribute("id");
    request = new Element.XMLElement("GetMsgRequest");
    action = request.addElement(MailConstants.E_MSG);
    action.addAttribute(MailConstants.A_ID, acct1.getId() + ":" + inviteData.calItemId + "-" + mptId);
    action.addAttribute(MailConstants.A_WANT_HTML, "1");
    action.addAttribute(MailConstants.A_NEED_EXP, "1");
    response = new GetMsg().handle(request, ServiceTestUtil.getRequestContext(acct2, acct1));
    organizerString = response.getElement("m").prettyPrint();
    assertTrue(!organizerString.contains("a=\"test@zimbra.com\" url=\"test@zimbra.com\""));
    request = new Element.XMLElement("FolderAction");
    action = request.addElement("action");
    action.addAttribute("id", mptId);
    action.addAttribute("op", "delete");
    response = new FolderAction().handle(request, ServiceTestUtil.getRequestContext(acct2));
    mbox1.revokeAccess(null, 10, acct2.getId());
}
Also used : Account(com.zimbra.cs.account.Account) AddInviteData(com.zimbra.cs.mailbox.Mailbox.AddInviteData) Element(com.zimbra.common.soap.Element) ZOrganizer(com.zimbra.cs.mailbox.calendar.ZOrganizer) Folder(com.zimbra.cs.mailbox.Folder) ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) Mailbox(com.zimbra.cs.mailbox.Mailbox) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) Invite(com.zimbra.cs.mailbox.calendar.Invite) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone) Test(org.junit.Test)

Example 30 with ICalTimeZone

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

the class WorkingHours method getWorkingHours.

public static FreeBusy getWorkingHours(Account authAcct, boolean asAdmin, Account account, String name, long start, long end) throws ServiceException {
    // If free/busy viewing is blocked, so is viewing working hours.
    AccessManager accessMgr = AccessManager.getInstance();
    boolean accountAceAllowed = accessMgr.canDo(authAcct, account, User.R_viewFreeBusy, asAdmin);
    if (!accountAceAllowed)
        return FreeBusy.nodataFreeBusy(account.getName(), start, end);
    // Get the working hours preference and parse it.
    String workingHoursPref = account.getPrefCalendarWorkingHours();
    HoursByDay workingHoursByDay = new HoursByDay(workingHoursPref);
    // Build a recurrence rule for each day of the week and expand over the time range.
    IntervalList intervals = new IntervalList(start, end);
    ICalTimeZone tz = Util.getAccountTimeZone(account);
    TimeZoneMap tzmap = new TimeZoneMap(tz);
    StartSpec startSpec = new StartSpec(start, tz);
    for (int day = 1; day <= 7; ++day) {
        TimeRange timeRange = workingHoursByDay.getHoursForDay(day);
        if (timeRange.enabled) {
            IRecurrence rrule = getRecurrenceForDay(day, startSpec, timeRange, tz, tzmap);
            List<Instance> instances = rrule.expandInstances(0, start, end);
            for (Instance inst : instances) {
                Interval ival = new Interval(inst.getStart(), inst.getEnd(), IcalXmlStrMap.FBTYPE_BUSY_UNAVAILABLE);
                intervals.addInterval(ival);
            }
        }
    }
    // hours are shown as out-of-office.
    for (Iterator<Interval> iter = intervals.iterator(); iter.hasNext(); ) {
        Interval interval = iter.next();
        String status = interval.getStatus();
        interval.setStatus(invertStatus(status));
    }
    return new FreeBusy(name, intervals, start, end);
}
Also used : AccessManager(com.zimbra.cs.account.AccessManager) Instance(com.zimbra.cs.mailbox.CalendarItem.Instance) IRecurrence(com.zimbra.cs.mailbox.calendar.Recurrence.IRecurrence) IntervalList(com.zimbra.cs.fb.FreeBusy.IntervalList) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone) Interval(com.zimbra.cs.fb.FreeBusy.Interval)

Aggregations

ICalTimeZone (com.zimbra.common.calendar.ICalTimeZone)62 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)17 ZComponent (com.zimbra.common.calendar.ZCalendar.ZComponent)14 TimeZoneMap (com.zimbra.common.calendar.TimeZoneMap)12 Element (com.zimbra.common.soap.Element)11 ZVCalendar (com.zimbra.common.calendar.ZCalendar.ZVCalendar)10 ServiceException (com.zimbra.common.service.ServiceException)10 ArrayList (java.util.ArrayList)10 ZProperty (com.zimbra.common.calendar.ZCalendar.ZProperty)8 Account (com.zimbra.cs.account.Account)8 Invite (com.zimbra.cs.mailbox.calendar.Invite)8 Mailbox (com.zimbra.cs.mailbox.Mailbox)7 IOException (java.io.IOException)7 Metadata (com.zimbra.cs.mailbox.Metadata)6 ItemId (com.zimbra.cs.service.util.ItemId)6 ParseException (java.text.ParseException)6 OperationContext (com.zimbra.cs.mailbox.OperationContext)5 RecurId (com.zimbra.cs.mailbox.calendar.RecurId)5 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)5 GregorianCalendar (java.util.GregorianCalendar)5