use of com.zimbra.cs.redolog.op.CreateInvite in project zm-mailbox by Zimbra.
the class Mailbox method addInvite.
/**
* Directly add an Invite into the system...this process also gets triggered when we add a Message
* that has a text/calendar Mime part: but this API is useful when you don't want to add a corresponding
* message.
* @param octxt
* @param inv
* @param pm NULL is OK here
* @param preserveExistingAlarms
* @param discardExistingInvites
* @param addRevision if true and revisioning is enabled and calendar item exists already, add a revision
* with current snapshot of the calendar item
*
* @return AddInviteData
* @throws ServiceException
*/
public AddInviteData addInvite(OperationContext octxt, Invite inv, int folderId, ParsedMessage pm, boolean preserveExistingAlarms, boolean discardExistingInvites, boolean addRevision) throws ServiceException {
if (pm == null) {
// the MimeMessage is fake, so we don't need to index it
inv.setDontIndexMimeMessage(true);
String desc = inv.getDescription();
if (inv.hasAttachment() || (desc != null && (desc.length() > Invite.getMaxDescInMeta()))) {
MimeMessage mm = CalendarMailSender.createCalendarMessage(inv);
pm = new ParsedMessage(mm, octxt == null ? System.currentTimeMillis() : octxt.getTimestamp(), true);
}
}
byte[] data = null;
try {
if (pm != null) {
data = pm.getRawData();
}
} catch (IOException ioe) {
throw ServiceException.FAILURE("Caught IOException", ioe);
}
CreateInvite redoRecorder = new CreateInvite(mId, inv, folderId, data, preserveExistingAlarms, discardExistingInvites, addRevision);
boolean success = false;
try {
beginTransaction("addInvite", octxt, redoRecorder);
CreateInvite redoPlayer = (octxt == null ? null : (CreateInvite) octxt.getPlayer());
if (redoPlayer == null || redoPlayer.getCalendarItemId() == 0) {
int currId = inv.getMailItemId();
if (currId <= 0) {
inv.setInviteId(getNextItemId(Mailbox.ID_AUTO_INCREMENT));
} else {
inv.setInviteId(currId);
}
}
CalendarItem calItem = getCalendarItemByUid(octxt, inv.getUid());
boolean processed = true;
if (calItem == null) {
// ONLY create an calendar item if this is a REQUEST method...otherwise don't.
if (inv.getMethod().equals("REQUEST") || inv.getMethod().equals("PUBLISH")) {
calItem = createCalendarItem(folderId, 0, null, inv.getUid(), pm, inv, null);
} else {
// for now, just ignore this Invitation
return null;
}
} else {
if (!checkItemChangeID(calItem)) {
throw MailServiceException.MODIFY_CONFLICT();
}
if (inv.getMethod().equals("REQUEST") || inv.getMethod().equals("PUBLISH")) {
// Preserve invId. (bug 19868)
Invite currInv = calItem.getInvite(inv.getRecurId());
if (currInv != null) {
inv.setInviteId(currInv.getMailItemId());
}
}
if (addRevision) {
calItem.snapshotRevision();
}
processed = calItem.processNewInvite(pm, inv, folderId, CalendarItem.NEXT_ALARM_KEEP_CURRENT, preserveExistingAlarms, discardExistingInvites);
}
if (Invite.isOrganizerMethod(inv.getMethod())) {
// Don't update the index for replies. (bug 55317)
index.add(calItem);
}
redoRecorder.setCalendarItemAttrs(calItem.getId(), calItem.getFolderId());
success = true;
if (processed) {
return new AddInviteData(calItem.getId(), inv.getMailItemId(), inv.getComponentNum(), calItem.getModifiedSequence(), calItem.getSavedSequence());
} else {
return null;
}
} finally {
endTransaction(success);
}
}
Aggregations