use of org.bedework.calfacade.exc.CalFacadeStaleStateException in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method close.
private void close(CalSvcI svci) throws WebdavException {
if ((svci == null) || !svci.isOpen()) {
return;
}
try {
svci.endTransaction();
long reqTime = System.currentTimeMillis() - reqInTime;
svci.postNotification(new HttpOutEvent(SysCode.CALDAV_OUT, reqTime));
} catch (Throwable t) {
try {
svci.close();
} catch (Throwable t1) {
}
svci = null;
if (t instanceof CalFacadeStaleStateException) {
throw new WebdavException(HttpServletResponse.SC_CONFLICT);
}
throw new WebdavException(t);
}
try {
svci.close();
} catch (Throwable t) {
svci = null;
throw new WebdavException(t);
}
}
use of org.bedework.calfacade.exc.CalFacadeStaleStateException in project bw-calendar-engine by Bedework.
the class Notifier method processSuggested.
private ProcessMessageResult processSuggested(final SysEvent msg) {
try {
final SysCode sysCode = msg.getSysCode();
String targetPrincipal = null;
SuggestBaseNotificationType sbnt = null;
if (sysCode == SysCode.SUGGESTED) {
final EntitySuggestedEvent ese = (EntitySuggestedEvent) msg;
final SuggestNotificationType snt = new SuggestNotificationType();
snt.setUid(Uid.getUid());
snt.setHref(ese.getHref());
snt.setSuggesterHref(ese.getAuthPrincipalHref());
snt.setSuggesteeHref(ese.getTargetPrincipalHref());
targetPrincipal = ese.getTargetPrincipalHref();
sbnt = snt;
} else if (sysCode == SysCode.SUGGESTED_RESPONSE) {
final EntitySuggestedResponseEvent esre = (EntitySuggestedResponseEvent) msg;
final SuggestResponseNotificationType srnt = new SuggestResponseNotificationType();
srnt.setUid(Uid.getUid());
srnt.setHref(esre.getHref());
srnt.setSuggesteeHref(esre.getAuthPrincipalHref());
srnt.setSuggesterHref(esre.getTargetPrincipalHref());
srnt.setAccepted(esre.getAccepted());
targetPrincipal = srnt.getSuggesterHref();
sbnt = srnt;
}
if (sbnt == null) {
return ProcessMessageResult.IGNORED;
}
try {
getSvci(targetPrincipal);
/* See if we have any notifications for this entity
*
* SCHEMA: If we could store the entire encoded path in the name we
* could just do a get
*/
NotificationType storedNote = null;
for (final NotificationType n : getNotes().getMatching(sbnt.getElementName())) {
if ((n == null) || (n.getNotification() == null)) {
// Bad notiifcation?
continue;
}
final SuggestBaseNotificationType ns = (SuggestBaseNotificationType) n.getNotification();
if (sbnt.getHref().equals(ns.getHref())) {
// Suggested resource
storedNote = n;
break;
}
}
if (storedNote == null) {
// save this one
sbnt.setName(getEncodedUuid());
final NotificationType n = new NotificationType();
n.setNotification(sbnt);
getNotes().add(n);
return ProcessMessageResult.PROCESSED;
}
return ProcessMessageResult.IGNORED;
} finally {
closeSvci(getSvc());
}
} catch (final CalFacadeStaleStateException csse) {
if (debug) {
trace("Stale state exception");
}
return ProcessMessageResult.STALE_STATE;
} catch (final Throwable t) {
rollback(getSvc());
error(t);
} finally {
try {
closeSvci(getSvc());
} catch (final Throwable ignored) {
}
}
return ProcessMessageResult.FAILED;
}
use of org.bedework.calfacade.exc.CalFacadeStaleStateException in project bw-calendar-engine by Bedework.
the class InScheduler method processScheduleUpdateEvent.
private ProcessMessageResult processScheduleUpdateEvent(final ScheduleUpdateEvent msg) {
try (final CalSvcI svci = getSvci(msg.getOwnerHref())) {
if (debug) {
trace("ScheduleUpdateEvent for principal " + msg.getOwnerHref());
}
final EventInfo ei = svci.getEventsHandler().get(getParentPath(msg.getHref()), getName(msg.getHref()));
if (ei == null) {
// Event deleted?.
if (debug) {
trace("InSchedule event deleted?");
}
return ProcessMessageResult.NO_ACTION;
}
final BwEvent ev = ei.getEvent();
SchedProcessor proc = null;
switch(msg.getChange()) {
case attendeeChange:
{
proc = new SchedAttendeeUpdate(svci);
break;
}
default:
warn("InSchedule: unhandled change type for " + ev.getOwnerHref() + " " + msg.getChange());
}
if (proc == null) {
return ProcessMessageResult.PROCESSED;
}
final SchedProcResult pr = proc.process(ei);
if (debug) {
trace("InSchedule " + pr.sr);
}
return ProcessMessageResult.PROCESSED;
} catch (final CalFacadeStaleStateException csse) {
if (debug) {
trace("Stale state exception");
}
rollback(getSvc());
return ProcessMessageResult.STALE_STATE;
} catch (final Throwable t) {
rollback(getSvc());
error(t);
}
return ProcessMessageResult.FAILED;
}
use of org.bedework.calfacade.exc.CalFacadeStaleStateException in project bw-calendar-engine by Bedework.
the class InScheduler method processEntityQueuedEvent.
private ProcessMessageResult processEntityQueuedEvent(final EntityQueuedEvent msg) {
/* These are events that are placed in the inbox.
*/
EventInfo ei = null;
try (final CalSvcI svci = getSvci(msg.getOwnerHref())) {
if (debug) {
trace("InSchedule inbox entry for principal " + msg.getOwnerHref());
}
ei = getInboxEvent(svci, msg.getName());
if (ei == null) {
// Event deleted from inbox.
if (debug) {
trace("InSchedule event deleted from inbox");
}
return ProcessMessageResult.NO_ACTION;
}
final BwEvent ev = ei.getEvent();
final int method = ev.getScheduleMethod();
if (debug) {
trace("InSchedule event for " + msg.getOwnerHref() + " " + msg.getName() + " with method " + ScheduleMethods.methods[method] + "\n" + ev);
if (ev.getSuppressed()) {
for (final EventInfo oei : ei.getOverrides()) {
trace("Override: " + oei.getEvent());
}
}
}
InProcessor proc = null;
switch(method) {
case Icalendar.methodTypeCancel:
proc = new InCancel(svci);
break;
case Icalendar.methodTypeRequest:
case Icalendar.methodTypePollStatus:
proc = new InRequest(svci);
break;
case Icalendar.methodTypeReply:
proc = new InReply(svci);
break;
case Icalendar.methodTypeRefresh:
proc = new InRefresh(svci);
break;
default:
warn("InSchedule: unhandled method for " + ev.getOwnerHref() + " " + method);
}
if (proc == null) {
deleteEvent(ei, false, false);
return ProcessMessageResult.PROCESSED;
}
final ProcessResult pr = proc.process(ei);
if (debug) {
trace("InSchedule " + pr.sr);
}
if (!pr.noInboxChange) {
proc.pendingToInbox(ei, ev.getOwnerHref(), pr.attendeeAccepting, pr.removeInboxEntry);
}
deleteEvent(ei, false, false);
return ProcessMessageResult.PROCESSED;
} catch (final CalFacadeForbidden cff) {
if (debug) {
trace("Forbidden exception" + cff);
}
if (ei != null) {
try {
deleteEvent(ei, false, false);
} catch (final Throwable ignored) {
}
}
return ProcessMessageResult.FAILED_NORETRIES;
} catch (final CalFacadeStaleStateException csse) {
if (debug) {
trace("Stale state exception");
}
rollback(getSvc());
return ProcessMessageResult.STALE_STATE;
} catch (final Throwable t) {
rollback(getSvc());
error(t);
}
return ProcessMessageResult.FAILED;
}
Aggregations