Search in sources :

Example 46 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 47 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)

Example 48 with ICalTimeZone

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

the class SearchParams method parseTimeZonePart.

private static TimeZone parseTimeZonePart(Element tzElt) throws ServiceException {
    String id = tzElt.getAttribute(MailConstants.A_ID);
    // is it a well-known timezone?  if so then we're done here
    ICalTimeZone knownTZ = WellKnownTimeZones.getTimeZoneById(id);
    if (knownTZ != null) {
        return knownTZ;
    }
    // custom timezone!
    String test = tzElt.getAttribute(MailConstants.A_CAL_TZ_STDOFFSET, null);
    if (test == null) {
        throw ServiceException.INVALID_REQUEST("Unknown TZ: \"" + id + "\" and no " + MailConstants.A_CAL_TZ_STDOFFSET + " specified", null);
    }
    return CalendarUtils.parseTzElement(tzElt);
}
Also used : ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone)

Example 49 with ICalTimeZone

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

the class CreateInvite method serializeData.

@Override
protected void serializeData(RedoLogOutput out) throws IOException {
    out.writeInt(mCalendarItemId);
    if (getVersion().atLeast(1, 1))
        out.writeUTF(mCalendarItemPartStat);
    out.writeInt(mFolderId);
    if (getVersion().atLeast(1, 0))
        out.writeShort((short) -1);
    // keep this for backward compatibility when there was mForce field
    out.writeBoolean(true);
    // in this class
    int dataLen = mData != null ? mData.length : 0;
    out.writeInt(dataLen);
    if (dataLen > 0) {
        out.write(mData);
    }
    ICalTimeZone localTz = mInvite.getTimeZoneMap().getLocalTimeZone();
    out.writeUTF(Util.encodeAsMetadata(localTz).toString());
    out.writeUTF(Invite.encodeMetadata(mInvite).toString());
    if (getVersion().atLeast(1, 22)) {
        out.writeBoolean(mPreserveExistingAlarms);
        out.writeBoolean(mDiscardExistingInvites);
    }
    if (getVersion().atLeast(1, 23))
        out.writeBoolean(mAddRevision);
}
Also used : ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone)

Example 50 with ICalTimeZone

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

the class CreateInvite method deserializeData.

@Override
protected void deserializeData(RedoLogInput in) throws IOException {
    mCalendarItemId = in.readInt();
    if (getVersion().atLeast(1, 1))
        mCalendarItemPartStat = in.readUTF();
    mFolderId = in.readInt();
    if (getVersion().atLeast(1, 0))
        in.readShort();
    // keep this for backward compatibility when there was mForce field
    in.readBoolean();
    // in this class
    int dataLen = in.readInt();
    if (dataLen > 0) {
        mData = new byte[dataLen];
        in.readFully(mData);
    }
    try {
        ICalTimeZone localTz = Util.decodeTimeZoneFromMetadata(new Metadata(in.readUTF()));
        mInvite = Invite.decodeMetadata(getMailboxId(), new Metadata(in.readUTF()), null, localTz);
    } catch (ServiceException ex) {
        ex.printStackTrace();
        throw new IOException("Cannot read serialized entry for CreateInvite " + ex.toString());
    }
    if (getVersion().atLeast(1, 22)) {
        mPreserveExistingAlarms = in.readBoolean();
        mDiscardExistingInvites = in.readBoolean();
    } else {
        mPreserveExistingAlarms = false;
        mDiscardExistingInvites = false;
    }
    if (getVersion().atLeast(1, 23))
        mAddRevision = in.readBoolean();
    else
        mAddRevision = false;
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) Metadata(com.zimbra.cs.mailbox.Metadata) IOException(java.io.IOException) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone)

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