use of com.zimbra.cs.mailbox.Appointment in project zm-mailbox by Zimbra.
the class DismissCalendarItemAlarm method handle.
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
String acctId = mbox.getAccountId();
Account authAcct = getAuthenticatedAccount(zsc);
OperationContext octxt = getOperationContext(zsc, context);
Element response = getResponseElement(zsc);
for (String calItemElement : sCalItemElems) {
for (Iterator<Element> iter = request.elementIterator(calItemElement); iter.hasNext(); ) {
Element calItemElem = iter.next();
ItemId iid = new ItemId(calItemElem.getAttribute(MailConstants.A_ID), zsc);
long dismissedAt = calItemElem.getAttributeLong(MailConstants.A_CAL_ALARM_DISMISSED_AT);
// trace logging
ZimbraLog.calendar.info("<DismissCalendarItemAlarm> id=%s, at=%d", iid.toString(), dismissedAt);
// mailbox for this calendar item; not necessarily same as requested mailbox
Mailbox ciMbox = null;
String ciAcctId = iid.getAccountId();
if (ciAcctId == null || ciAcctId.equals(acctId)) {
ciMbox = mbox;
} else {
// Let's see if the account is a Desktop account.
if (AccountUtil.isZDesktopLocalAccount(zsc.getAuthtokenAccountId()))
ciMbox = MailboxManager.getInstance().getMailboxByAccountId(ciAcctId, false);
if (ciMbox == null)
throw MailServiceException.PERM_DENIED("cannot dismiss alarms of a shared calendar");
}
int calItemId = iid.getId();
ItemIdFormatter ifmt = new ItemIdFormatter(authAcct.getId(), acctId, false);
try {
ciMbox.dismissCalendarItemAlarm(octxt, calItemId, dismissedAt);
CalendarItem calItem = ciMbox.getCalendarItemById(octxt, calItemId);
Element calItemRespElem;
if (calItem instanceof Appointment)
calItemRespElem = response.addElement(MailConstants.E_APPOINTMENT);
else
calItemRespElem = response.addElement(MailConstants.E_TASK);
calItemRespElem.addAttribute(MailConstants.A_CAL_ID, iid.toString(ifmt));
boolean hidePrivate = !calItem.allowPrivateAccess(authAcct, zsc.isUsingAdminPrivileges());
boolean showAll = !hidePrivate || calItem.isPublic();
if (showAll) {
AlarmData alarmData = calItem.getAlarmData();
if (alarmData != null)
ToXML.encodeAlarmData(calItemRespElem, calItem, alarmData);
}
} catch (NoSuchItemException nsie) {
//item must not exist in db anymore.
//this can happen if an alarm is dismissed while a big sync is happening which deletes the item (e.g. bug 48560)
//since item is not in db, it has effectively been dismissed; return ok and no further alarms
Element calItemRespElem = response.addElement(calItemElement);
calItemRespElem.addAttribute(MailConstants.A_CAL_ID, iid.toString(ifmt));
}
}
}
return response;
}
use of com.zimbra.cs.mailbox.Appointment in project zm-mailbox by Zimbra.
the class GetCalendarItemSummaries method encodeCalendarItemInstances.
/**
* Encodes a calendar item
*
* @param parent
* @param elementName
* name of element to add (MailConstants .E_APPOINTMENT or MailConstants.E_TASK)
* @param rangeStart
* start period to expand instances (or -1 for no start time constraint)
* @param rangeEnd
* end period to expand instances (or -1 for no end time constraint)
* @param newFormat
* temporary HACK - true: SearchRequest, false: GetAppointmentSummaries
* @return
*/
static EncodeCalendarItemResult encodeCalendarItemInstances(ZimbraSoapContext lc, OperationContext octxt, CalendarItem calItem, Account acct, long rangeStart, long rangeEnd, boolean newFormat) throws ServiceException {
EncodeCalendarItemResult toRet = new EncodeCalendarItemResult();
ItemIdFormatter ifmt = new ItemIdFormatter(lc);
Account authAccount = getAuthenticatedAccount(lc);
boolean hidePrivate = !calItem.allowPrivateAccess(authAccount, lc.isUsingAdminPrivileges());
try {
boolean expandRanges;
if (calItem instanceof Task) {
expandRanges = true;
if (rangeStart == -1 && rangeEnd == -1) {
rangeStart = Long.MIN_VALUE;
rangeEnd = Long.MAX_VALUE;
}
} else {
expandRanges = (rangeStart != -1 && rangeEnd != -1 && rangeStart < rangeEnd);
}
boolean isAppointment = calItem instanceof Appointment;
// Use the marshalling code in calendar summary cache for uniform output, when we can.
if (isAppointment && expandRanges) {
CalendarItemData calItemData = CalSummaryCache.reloadCalendarItemOverRange(calItem, rangeStart, rangeEnd);
if (calItemData != null) {
int numInstances = calItemData.getNumInstances();
if (numInstances > 0) {
Element calItemElem = CacheToXML.encodeCalendarItemData(lc, ifmt, calItemData, !hidePrivate, !newFormat);
toRet.element = calItemElem;
toRet.numInstancesExpanded = numInstances;
}
}
return toRet;
}
// But there are other cases (e.g. tasks, no time range) that require the legacy code below.
// don't initialize until we find at least one valid instance
Element calItemElem = null;
Invite defaultInvite = calItem.getDefaultInviteOrNull();
if (defaultInvite == null) {
mLog.info("Could not load defaultinfo for calendar item with id=" + calItem.getId() + " SKIPPING");
return toRet;
}
ParsedDuration defDuration = defaultInvite.getEffectiveDuration();
// events and 1 second for non all-day. (bug 28615)
if (defDuration == null && !defaultInvite.isTodo()) {
if (defaultInvite.isAllDayEvent()) {
defDuration = ParsedDuration.ONE_DAY;
} else {
defDuration = ParsedDuration.ONE_SECOND;
}
}
long defDurationMsecs = 0;
if (defaultInvite.getStartTime() != null && defDuration != null) {
ParsedDateTime s = defaultInvite.getStartTime();
long et = s.add(defDuration).getUtcTime();
defDurationMsecs = et - s.getUtcTime();
}
String defaultFba = null;
if (calItem instanceof Appointment) {
defaultFba = ((Appointment) calItem).getEffectiveFreeBusyActual(defaultInvite, null);
}
String defaultPtSt = calItem.getEffectivePartStat(defaultInvite, null);
AlarmData alarmData = calItem.getAlarmData();
// add all the instances:
int numInRange = 0;
if (expandRanges) {
Collection<CalendarItem.Instance> instances = calItem.expandInstances(rangeStart, rangeEnd, true);
long alarmTime = 0;
long alarmInst = 0;
if (alarmData != null) {
alarmTime = alarmData.getNextAt();
alarmInst = alarmData.getNextInstanceStart();
}
for (CalendarItem.Instance inst : instances) {
try {
InviteInfo invId = inst.getInviteInfo();
Invite inv = calItem.getInvite(invId.getMsgId(), invId.getComponentId());
boolean showAll = !hidePrivate || inv.isPublic();
// figure out which fields are different from the default and put their data here...
ParsedDuration invDuration = inv.getEffectiveDuration();
long instStart = inst.getStart();
// For an instance whose alarm time is within the time range, we must
// include it even if its start time is after the range.
long startOrAlarm = instStart == alarmInst ? alarmTime : instStart;
// events and 1 second for non all-day. (bug 28615)
if (invDuration == null) {
if (inv.isAllDayEvent())
invDuration = ParsedDuration.ONE_DAY;
else
invDuration = ParsedDuration.ONE_SECOND;
}
if (!inst.hasStart() || (startOrAlarm < rangeEnd && invDuration.addToTime(instStart) > rangeStart)) {
numInRange++;
} else {
continue;
}
if (calItemElem == null) {
calItemElem = lc.createElement(isAppointment ? MailConstants.E_APPOINTMENT : MailConstants.E_TASK);
if (showAll) {
// flags and tags
ToXML.recordItemTags(calItemElem, calItem, octxt);
}
// Organizer
if (inv.hasOrganizer()) {
ZOrganizer org = inv.getOrganizer();
org.toXml(calItemElem);
}
calItemElem.addAttribute("x_uid", calItem.getUid());
calItemElem.addAttribute(MailConstants.A_UID, calItem.getUid());
}
Element instElt = calItemElem.addElement(MailConstants.E_INSTANCE);
if (showAll) {
if (isAppointment && inv.isEvent()) {
String instFba = ((Appointment) calItem).getEffectiveFreeBusyActual(inv, inst);
if (instFba != null && (!instFba.equals(defaultFba) || inst.isException()))
instElt.addAttribute(MailConstants.A_APPT_FREEBUSY_ACTUAL, instFba);
}
String instPtSt = calItem.getEffectivePartStat(inv, inst);
if (!defaultPtSt.equals(instPtSt) || inst.isException())
instElt.addAttribute(MailConstants.A_CAL_PARTSTAT, instPtSt);
}
if (inst.hasStart()) {
instElt.addAttribute(MailConstants.A_CAL_START_TIME, instStart);
if (inv.isAllDayEvent())
instElt.addAttribute(MailConstants.A_CAL_TZ_OFFSET, inst.getStartTzOffset());
}
if (inst.isException() && inv.hasRecurId()) {
RecurId rid = inv.getRecurId();
instElt.addAttribute(MailConstants.A_CAL_RECURRENCE_ID_Z, rid.getDtZ());
} else {
instElt.addAttribute(MailConstants.A_CAL_RECURRENCE_ID_Z, inst.getRecurIdZ());
}
if (inst.isException()) {
instElt.addAttribute(MailConstants.A_CAL_IS_EXCEPTION, true);
instElt.addAttribute(MailConstants.A_CAL_INV_ID, ifmt.formatItemId(calItem, inst.getMailItemId()));
instElt.addAttribute(MailConstants.A_CAL_COMPONENT_NUM, inst.getComponentNum());
if (showAll) {
// fragment has already been sanitized...
String frag = inv.getFragment();
if (frag != null && !frag.equals(""))
instElt.addAttribute(MailConstants.E_FRAG, frag, Element.Disposition.CONTENT);
if (inv.getPriority() != null)
instElt.addAttribute(MailConstants.A_CAL_PRIORITY, inv.getPriority());
if (inv.isEvent()) {
if (inv.getFreeBusy() != null)
instElt.addAttribute(MailConstants.A_APPT_FREEBUSY, inv.getFreeBusy());
if (inv.getTransparency() != null)
instElt.addAttribute(MailConstants.A_APPT_TRANSPARENCY, inv.getTransparency());
}
if (inv.isTodo()) {
if (inv.getPercentComplete() != null)
instElt.addAttribute(MailConstants.A_TASK_PERCENT_COMPLETE, inv.getPercentComplete());
}
if (inv.getName() != null)
instElt.addAttribute(MailConstants.A_NAME, inv.getName());
if (inv.getLocation() != null)
instElt.addAttribute(MailConstants.A_CAL_LOCATION, inv.getLocation());
List<String> categories = inv.getCategories();
if (categories != null) {
for (String cat : categories) {
instElt.addElement(MailConstants.E_CAL_CATEGORY).setText(cat);
}
}
Geo geo = inv.getGeo();
if (geo != null)
geo.toXml(instElt);
if (inv.hasOtherAttendees())
instElt.addAttribute(MailConstants.A_CAL_OTHER_ATTENDEES, true);
if (inv.hasAlarm())
instElt.addAttribute(MailConstants.A_CAL_ALARM, true);
}
instElt.addAttribute(MailConstants.A_CAL_ISORG, inv.isOrganizer());
if (inv.isTodo()) {
if (inst.hasEnd()) {
instElt.addAttribute(MailConstants.A_TASK_DUE_DATE, inst.getEnd());
if (inv.isAllDayEvent())
instElt.addAttribute(MailConstants.A_CAL_TZ_OFFSET_DUE, inst.getEndTzOffset());
}
} else {
if (inst.hasStart() && inst.hasEnd()) {
instElt.addAttribute(newFormat ? MailConstants.A_CAL_NEW_DURATION : MailConstants.A_CAL_DURATION, inst.getEnd() - inst.getStart());
}
}
if (inv.getStatus() != null)
instElt.addAttribute(MailConstants.A_CAL_STATUS, inv.getStatus());
if (inv.getClassProp() != null)
instElt.addAttribute(MailConstants.A_CAL_CLASS, inv.getClassProp());
if (inv.isAllDayEvent())
instElt.addAttribute(MailConstants.A_CAL_ALLDAY, true);
if (inv.isDraft())
instElt.addAttribute(MailConstants.A_CAL_DRAFT, true);
if (inv.isNeverSent())
instElt.addAttribute(MailConstants.A_CAL_NEVER_SENT, true);
if (inv.isRecurrence())
instElt.addAttribute(MailConstants.A_CAL_RECUR, true);
} else {
if (inv.isTodo()) {
if (inst.hasEnd()) {
instElt.addAttribute(MailConstants.A_TASK_DUE_DATE, inst.getEnd());
if (inv.isAllDayEvent())
instElt.addAttribute(MailConstants.A_CAL_TZ_OFFSET_DUE, inst.getEndTzOffset());
}
} else {
// the default duration due to daylight savings time transitions.
if (inst.hasStart() && inst.hasEnd() && defDurationMsecs != inst.getEnd() - inst.getStart()) {
instElt.addAttribute(newFormat ? MailConstants.A_CAL_NEW_DURATION : MailConstants.A_CAL_DURATION, inst.getEnd() - inst.getStart());
}
}
}
} catch (MailServiceException.NoSuchItemException e) {
mLog.info("Error could not get instance " + inst.getMailItemId() + "-" + inst.getComponentNum() + " for appt " + calItem.getId(), e);
}
}
// iterate all the instances
}
if (!expandRanges || numInRange > 0) {
// if we found any calItems at all, we have to encode the "Default" data here
boolean showAll = !hidePrivate || defaultInvite.isPublic();
if (calItemElem == null) {
calItemElem = lc.createElement(isAppointment ? MailConstants.E_APPOINTMENT : MailConstants.E_TASK);
calItemElem.addAttribute("x_uid", calItem.getUid());
calItemElem.addAttribute(MailConstants.A_UID, calItem.getUid());
if (showAll) {
// flags and tags
ToXML.recordItemTags(calItemElem, calItem, octxt);
}
// Organizer
if (defaultInvite.hasOrganizer()) {
ZOrganizer org = defaultInvite.getOrganizer();
org.toXml(calItemElem);
}
}
if (showAll) {
if (alarmData != null)
ToXML.encodeAlarmData(calItemElem, calItem, alarmData);
String defaultPriority = defaultInvite.getPriority();
if (defaultPriority != null)
calItemElem.addAttribute(MailConstants.A_CAL_PRIORITY, defaultPriority);
calItemElem.addAttribute(MailConstants.A_CAL_PARTSTAT, defaultPtSt);
if (defaultInvite.isEvent()) {
calItemElem.addAttribute(MailConstants.A_APPT_FREEBUSY, defaultInvite.getFreeBusy());
calItemElem.addAttribute(MailConstants.A_APPT_FREEBUSY_ACTUAL, defaultFba);
calItemElem.addAttribute(MailConstants.A_APPT_TRANSPARENCY, defaultInvite.getTransparency());
}
if (defaultInvite.isTodo()) {
String pctComplete = defaultInvite.getPercentComplete();
if (pctComplete != null)
calItemElem.addAttribute(MailConstants.A_TASK_PERCENT_COMPLETE, pctComplete);
}
calItemElem.addAttribute(MailConstants.A_NAME, defaultInvite.getName());
calItemElem.addAttribute(MailConstants.A_CAL_LOCATION, defaultInvite.getLocation());
List<String> categories = defaultInvite.getCategories();
if (categories != null) {
for (String cat : categories) {
calItemElem.addElement(MailConstants.E_CAL_CATEGORY).setText(cat);
}
}
Geo geo = defaultInvite.getGeo();
if (geo != null)
geo.toXml(calItemElem);
// fragment has already been sanitized...
String fragment = defaultInvite.getFragment();
if (!fragment.equals(""))
calItemElem.addAttribute(MailConstants.E_FRAG, fragment, Element.Disposition.CONTENT);
if (defaultInvite.hasOtherAttendees()) {
calItemElem.addAttribute(MailConstants.A_CAL_OTHER_ATTENDEES, defaultInvite.hasOtherAttendees());
}
if (defaultInvite.hasAlarm()) {
calItemElem.addAttribute(MailConstants.A_CAL_ALARM, defaultInvite.hasAlarm());
}
}
calItemElem.addAttribute(MailConstants.A_CAL_ISORG, defaultInvite.isOrganizer());
calItemElem.addAttribute(MailConstants.A_ID, ifmt.formatItemId(calItem));
calItemElem.addAttribute(MailConstants.A_CAL_INV_ID, ifmt.formatItemId(calItem, defaultInvite.getMailItemId()));
calItemElem.addAttribute(MailConstants.A_CAL_COMPONENT_NUM, defaultInvite.getComponentNum());
calItemElem.addAttribute(MailConstants.A_FOLDER, ifmt.formatItemId(new ItemId(calItem.getMailbox().getAccountId(), calItem.getFolderId())));
calItemElem.addAttribute(MailConstants.A_CAL_STATUS, defaultInvite.getStatus());
calItemElem.addAttribute(MailConstants.A_CAL_CLASS, defaultInvite.getClassProp());
if (!defaultInvite.isTodo())
calItemElem.addAttribute(newFormat ? MailConstants.A_CAL_NEW_DURATION : MailConstants.A_CAL_DURATION, defDurationMsecs);
if (defaultInvite.isAllDayEvent())
calItemElem.addAttribute(MailConstants.A_CAL_ALLDAY, defaultInvite.isAllDayEvent());
if (defaultInvite.isDraft())
calItemElem.addAttribute(MailConstants.A_CAL_DRAFT, defaultInvite.isDraft());
if (defaultInvite.isNeverSent())
calItemElem.addAttribute(MailConstants.A_CAL_NEVER_SENT, defaultInvite.isNeverSent());
if (defaultInvite.isRecurrence())
calItemElem.addAttribute(MailConstants.A_CAL_RECUR, defaultInvite.isRecurrence());
if (calItem.hasExceptions()) {
calItemElem.addAttribute(MailConstants.A_CAL_HAS_EXCEPTIONS, true);
}
toRet.element = calItemElem;
}
toRet.numInstancesExpanded = numInRange;
} catch (MailServiceException.NoSuchItemException e) {
mLog.info("Error could not get default invite for calendar item: " + calItem.getId(), e);
} catch (RuntimeException e) {
mLog.info("Caught Exception " + e + " while getting summary info for calendar item: " + calItem.getId(), e);
}
return toRet;
}
use of com.zimbra.cs.mailbox.Appointment in project zm-mailbox by Zimbra.
the class CalSummaryCache method reloadCalendarItemOverRange.
// mSummaryCache
//
// key = "accountId:folderId"
// value = CalendarData type
//
// CalendarData = {
// folderId, range start, range end,
// // list of CalendarItemData objects (one for each appointment in range)
// [
// CalendarItemData {
// calItemId, folderId, flags, tags, item type,
// last modified,
// actual range start, actual range end,
// uid, isRecurring, isPublic, alarm,
// default instance data (FullInstanceData type),
// // list of instances (FullInstanceData if an exception, InstanceData if not)
// [
// InstanceData/FullInstanceData, ...
// ]
// },
// CalendarItemData, ...
// ]
public static CalendarItemData reloadCalendarItemOverRange(CalendarItem calItem, long rangeStart, long rangeEnd) throws ServiceException {
CalendarItemData calItemData = null;
try {
boolean rangeValid = (rangeStart >= CalendarUtils.MICROSOFT_EPOC_START_MS_SINCE_EPOC && rangeEnd > CalendarUtils.MICROSOFT_EPOC_START_MS_SINCE_EPOC && rangeStart < rangeEnd);
if (!rangeValid) {
return null;
}
Invite defaultInvite = calItem.getDefaultInviteOrNull();
if (defaultInvite == null) {
ZimbraLog.calendar.info("Could not load defaultinfo for calendar item with id=" + calItem.getId() + "; SKIPPING");
return null;
}
String defaultFba = null;
if (calItem instanceof Appointment)
defaultFba = ((Appointment) calItem).getEffectiveFreeBusyActual(defaultInvite, null);
AlarmData alarm = null;
CalendarItem.AlarmData calItemAlarmData = calItem.getAlarmData();
long alarmTime = 0;
long alarmInst = 0;
if (calItemAlarmData != null) {
alarmTime = calItemAlarmData.getNextAt();
alarmInst = calItemAlarmData.getNextInstanceStart();
int alarmInvId = calItemAlarmData.getInvId();
int alarmCompNum = calItemAlarmData.getCompNum();
String summary = null, location = null;
Invite alarmInv = calItem.getInvite(alarmInvId, alarmCompNum);
if (alarmInv != null) {
summary = alarmInv.getName();
location = alarmInv.getLocation();
}
alarm = new AlarmData(calItemAlarmData.getNextAt(), calItemAlarmData.getNextInstanceStart(), alarmInvId, alarmCompNum, summary, location, calItemAlarmData.getAlarm());
}
Long defDtStartLong = null;
Long defDurationLong = null;
ParsedDateTime defDtStart = defaultInvite.getStartTime();
if (defDtStart != null) {
defDtStartLong = Long.valueOf(defDtStart.getUtcTime());
ParsedDateTime defDtEnd = defaultInvite.getEffectiveEndTime();
if (defDtEnd != null)
defDurationLong = Long.valueOf(defDtEnd.getUtcTime() - defDtStartLong.longValue());
}
String defaultEffectivePartStat = calItem.getEffectivePartStat(defaultInvite, null);
FullInstanceData defaultData = new FullInstanceData(defaultInvite, null, defDtStartLong, defDurationLong, defaultEffectivePartStat, defaultFba, null);
calItemData = new CalendarItemData(calItem.getType(), calItem.getFolderId(), calItem.getId(), calItem.getFlagString(), calItem.getTags(), TagUtil.getTagIdString(calItem), calItem.getModifiedSequence(), calItem.getSavedSequence(), calItem.getDate(), calItem.getChangeDate(), calItem.getSize(), defaultInvite.getUid(), defaultInvite.isRecurrence(), calItem.hasExceptions(), calItem.isPublic(), alarm, defaultData);
long actualRangeStart = 0;
long actualRangeEnd = 0;
int numInstances = 0;
Collection<CalendarItem.Instance> instances = calItem.expandInstances(rangeStart, rangeEnd, true);
for (CalendarItem.Instance inst : instances) {
try {
long instStart = inst.getStart();
long duration = inst.getEnd() - instStart;
// 0 means "no DTSTART", however, note that negative numbers are valid
Long instStartLong = instStart != 0 ? Long.valueOf(instStart) : null;
Long durationLong = duration > 0 ? Long.valueOf(duration) : null;
// For an instance whose alarm time is within the time range, we must
// include it even if its start time is after the range.
long startOrAlarm = instStart == alarmInst ? alarmTime : instStart;
boolean hasTimes = inst.hasStart() && inst.hasEnd();
if (hasTimes && (startOrAlarm >= rangeEnd || inst.getEnd() <= rangeStart)) {
continue;
}
numInstances++;
if (hasTimes) {
if (actualRangeStart == 0 || startOrAlarm < actualRangeStart)
actualRangeStart = startOrAlarm;
if (inst.getEnd() > actualRangeEnd)
actualRangeEnd = inst.getEnd();
}
InviteInfo invId = inst.getInviteInfo();
Invite inv = calItem.getInvite(invId.getMsgId(), invId.getComponentId());
Long alarmAt = instStart == alarmInst ? Long.valueOf(alarmTime) : null;
String fba = inv.getFreeBusyActual();
if (calItem instanceof Appointment)
fba = ((Appointment) calItem).getEffectiveFreeBusyActual(inv, inst);
String effectivePartStat = calItem.getEffectivePartStat(inv, inst);
InstanceData instData;
if (!inst.isException()) {
String ridZ = inst.getRecurIdZ();
Long tzOffset = instStartLong != null && inst.isAllDay() ? Long.valueOf(inst.getStartTzOffset()) : null;
instData = new InstanceData(ridZ, instStartLong, durationLong, alarmAt, tzOffset, effectivePartStat, fba, inv.getPercentComplete(), defaultData);
} else {
String ridZ = null;
if (inv.hasRecurId())
ridZ = inv.getRecurId().getDtZ();
instData = new FullInstanceData(inv, ridZ, instStartLong, durationLong, effectivePartStat, fba, alarmAt);
}
calItemData.addInstance(instData);
} catch (MailServiceException.NoSuchItemException e) {
ZimbraLog.calendar.info("Error could not get instance " + inst.getMailItemId() + "-" + inst.getComponentNum() + " for appt " + calItem.getId(), e);
}
}
if (numInstances < 1)
return null;
calItemData.setActualRange(actualRangeStart, actualRangeEnd);
} catch (MailServiceException.NoSuchItemException e) {
ZimbraLog.calendar.info("Error could not get default invite for calendar item: " + calItem.getId(), e);
} catch (RuntimeException e) {
ZimbraLog.calendar.info("Caught Exception " + e + " while getting summary info for calendar item: " + calItem.getId(), e);
}
return calItemData;
}
use of com.zimbra.cs.mailbox.Appointment in project zm-mailbox by Zimbra.
the class ToXML method encodeInviteComponent.
public static Element encodeInviteComponent(Element parent, ItemIdFormatter ifmt, OperationContext octxt, CalendarItem calItem, /* may be null */
ItemId calId, /* may be null */
Invite invite, int fields, boolean neuter) throws ServiceException {
boolean allFields = true;
if (fields != NOTIFY_FIELDS) {
allFields = false;
if (!needToOutput(fields, Change.INVITE)) {
return parent;
}
}
Element e = parent.addElement(MailConstants.E_INVITE_COMPONENT);
e.addAttribute(MailConstants.A_CAL_METHOD, invite.getMethod());
e.addAttribute(MailConstants.A_CAL_COMPONENT_NUM, invite.getComponentNum());
e.addAttribute(MailConstants.A_CAL_RSVP, invite.getRsvp());
boolean allowPrivateAccess = calItem != null ? allowPrivateAccess(octxt, calItem) : true;
if (allFields) {
if (invite.isPublic() || allowPrivateAccess) {
String priority = invite.getPriority();
if (priority != null) {
e.addAttribute(MailConstants.A_CAL_PRIORITY, priority);
}
e.addAttribute(MailConstants.A_NAME, invite.getName());
e.addAttribute(MailConstants.A_CAL_LOCATION, invite.getLocation());
List<String> categories = invite.getCategories();
if (categories != null) {
for (String cat : categories) {
e.addElement(MailConstants.E_CAL_CATEGORY).setText(cat);
}
}
List<String> comments = invite.getComments();
if (comments != null) {
for (String cmt : comments) {
e.addElement(MailConstants.E_CAL_COMMENT).setText(cmt);
}
}
List<String> contacts = invite.getContacts();
if (contacts != null) {
for (String contact : contacts) {
e.addElement(MailConstants.E_CAL_CONTACT).setText(contact);
}
}
Geo geo = invite.getGeo();
if (geo != null) {
geo.toXml(e);
}
// Percent Complete (VTODO)
if (invite.isTodo()) {
String pct = invite.getPercentComplete();
if (pct != null)
e.addAttribute(MailConstants.A_TASK_PERCENT_COMPLETE, pct);
long completed = invite.getCompleted();
if (completed != 0) {
ParsedDateTime c = ParsedDateTime.fromUTCTime(completed);
e.addAttribute(MailConstants.A_TASK_COMPLETED, c.getDateTimePartString());
}
}
// Attendee(s)
List<ZAttendee> attendees = invite.getAttendees();
for (ZAttendee at : attendees) {
at.toXml(e);
}
// Alarms
Iterator<Alarm> alarmsIter = invite.alarmsIterator();
while (alarmsIter.hasNext()) {
Alarm alarm = alarmsIter.next();
alarm.toXml(e);
}
// x-prop
encodeXProps(e, invite.xpropsIterator());
// fragment
String fragment = invite.getFragment();
if (!Strings.isNullOrEmpty(fragment)) {
e.addAttribute(MailConstants.E_FRAG, fragment, Element.Disposition.CONTENT);
}
if (!invite.hasBlobPart()) {
e.addAttribute(MailConstants.A_CAL_NO_BLOB, true);
}
// Description (plain and html)
String desc = invite.getDescription();
if (desc != null) {
Element descElem = e.addElement(MailConstants.E_CAL_DESCRIPTION);
descElem.setText(desc);
}
String descHtml = invite.getDescriptionHtml();
BrowserDefang defanger = DefangFactory.getDefanger(MimeConstants.CT_TEXT_HTML);
if (descHtml != null) {
try {
descHtml = StringUtil.stripControlCharacters(descHtml);
descHtml = defanger.defang(descHtml, neuter);
Element descHtmlElem = e.addElement(MailConstants.E_CAL_DESC_HTML);
descHtmlElem.setText(descHtml);
} catch (IOException ex) {
ZimbraLog.calendar.warn("Unable to defang HTML for SetAppointmentRequest", ex);
}
}
if (invite.isEvent()) {
if (calItem != null && calItem instanceof Appointment) {
Instance inst = Instance.fromInvite(calItem.getId(), invite);
Appointment appt = (Appointment) calItem;
e.addAttribute(MailConstants.A_APPT_FREEBUSY_ACTUAL, appt.getEffectiveFreeBusyActual(invite, inst));
}
e.addAttribute(MailConstants.A_APPT_FREEBUSY, invite.getFreeBusy());
e.addAttribute(MailConstants.A_APPT_TRANSPARENCY, invite.getTransparency());
}
// Organizer
if (invite.hasOrganizer()) {
ZOrganizer org = invite.getOrganizer();
org.toXml(e);
}
e.addAttribute(MailConstants.A_CAL_URL, invite.getUrl());
}
if (invite.isOrganizer()) {
e.addAttribute(MailConstants.A_CAL_ISORG, true);
}
boolean isRecurring = false;
e.addAttribute("x_uid", invite.getUid());
e.addAttribute(MailConstants.A_UID, invite.getUid());
e.addAttribute(MailConstants.A_CAL_SEQUENCE, invite.getSeqNo());
//zdsync
e.addAttribute(MailConstants.A_CAL_DATETIME, invite.getDTStamp());
String itemId = null;
if (calId != null) {
itemId = calId.toString(ifmt);
} else if (calItem != null) {
itemId = ifmt.formatItemId(calItem);
}
if ((itemId != null) && !("0".equals(itemId))) {
e.addAttribute(MailConstants.A_CAL_ID, /* calItemId */
itemId);
if (invite.isEvent()) {
// for backward compat
e.addAttribute(MailConstants.A_APPT_ID_DEPRECATE_ME, /* apptId */
itemId);
}
if (calItem != null) {
ItemId ciFolderId = new ItemId(calItem.getMailbox(), calItem.getFolderId());
e.addAttribute(MailConstants.A_CAL_ITEM_FOLDER, /* ciFolder */
ifmt.formatItemId(ciFolderId));
}
}
Recurrence.IRecurrence recur = invite.getRecurrence();
if (recur != null) {
isRecurring = true;
Element recurElt = e.addElement(MailConstants.E_CAL_RECUR);
recur.toXml(recurElt);
}
e.addAttribute(MailConstants.A_CAL_STATUS, invite.getStatus());
e.addAttribute(MailConstants.A_CAL_CLASS, invite.getClassProp());
boolean allDay = invite.isAllDayEvent();
boolean isException = invite.hasRecurId();
if (isException) {
e.addAttribute(MailConstants.A_CAL_IS_EXCEPTION, true);
RecurId rid = invite.getRecurId();
e.addAttribute(MailConstants.A_CAL_RECURRENCE_ID_Z, rid.getDtZ());
encodeRecurId(e, rid, allDay);
}
boolean forceUTC = DebugConfig.calendarForceUTC && !isRecurring && !isException && !allDay;
ParsedDateTime dtStart = invite.getStartTime();
if (dtStart != null) {
encodeDtStart(e, dtStart, allDay, forceUTC);
}
ParsedDateTime dtEnd = invite.getEndTime();
if (dtEnd != null) {
encodeDtEnd(e, dtEnd, allDay, invite.isTodo(), forceUTC);
}
ParsedDuration dur = invite.getDuration();
if (dur != null) {
dur.toXml(e);
}
if (allDay) {
e.addAttribute(MailConstants.A_CAL_ALLDAY, true);
}
if (invite.isDraft()) {
e.addAttribute(MailConstants.A_CAL_DRAFT, true);
}
if (invite.isNeverSent()) {
e.addAttribute(MailConstants.A_CAL_NEVER_SENT, true);
}
}
return e;
}
use of com.zimbra.cs.mailbox.Appointment in project zm-mailbox by Zimbra.
the class IfbFormatter method formatCallback.
@Override
public void formatCallback(UserServletContext context) throws IOException, ServiceException, UserServletException {
context.resp.setCharacterEncoding("UTF-8");
context.resp.setContentType(MimeConstants.CT_TEXT_CALENDAR);
long rangeStart = context.getStartTime();
long rangeEnd = context.getEndTime();
if (rangeEnd < rangeStart)
throw new UserServletException(HttpServletResponse.SC_BAD_REQUEST, "End time must be after Start time");
long days = (rangeEnd - rangeStart) / Constants.MILLIS_PER_DAY;
long maxDays = LC.calendar_freebusy_max_days.longValueWithinRange(0, 36600);
if (days > maxDays)
throw new UserServletException(HttpServletResponse.SC_BAD_REQUEST, "Requested range is too large (Maximum " + maxDays + " days)");
String acctName = null;
FreeBusy fb = null;
if (context.targetMailbox != null) {
String exuid = context.params.get(UserServlet.QP_EXUID);
Appointment exAppt = null;
if (exuid != null) {
CalendarItem ci = context.targetMailbox.getCalendarItemByUid(context.opContext, exuid);
if (ci instanceof Appointment)
exAppt = (Appointment) ci;
}
acctName = context.targetMailbox.getAccount().getName();
fb = context.targetMailbox.getFreeBusy(context.opContext, acctName, rangeStart, rangeEnd, context.getFreeBusyCalendar(), exAppt);
} else {
// Unknown mailbox. Fake an always-free response, to avoid harvest attacks.
acctName = fixupAccountName(context.accountPath);
fb = FreeBusy.emptyFreeBusy(acctName, rangeStart, rangeEnd);
}
String fbFormat = context.params.get(UserServlet.QP_FBFORMAT);
String fbMsg;
if ("event".equalsIgnoreCase(fbFormat)) {
fbMsg = fb.toVCalendarAsVEvents();
} else {
String url = context.req.getRequestURL() + "?" + context.req.getQueryString();
fbMsg = fb.toVCalendar(FreeBusy.Method.PUBLISH, acctName, null, url);
}
context.resp.getOutputStream().write(fbMsg.getBytes("UTF-8"));
}
Aggregations