Search in sources :

Example 1 with CalFacadeStaleStateException

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);
    }
}
Also used : CalFacadeStaleStateException(org.bedework.calfacade.exc.CalFacadeStaleStateException) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) HttpOutEvent(org.bedework.sysevents.events.HttpOutEvent)

Example 2 with CalFacadeStaleStateException

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;
}
Also used : CalFacadeStaleStateException(org.bedework.calfacade.exc.CalFacadeStaleStateException) EntitySuggestedEvent(org.bedework.sysevents.events.publicAdmin.EntitySuggestedEvent) AdminNotificationType(org.bedework.caldav.util.notifications.admin.AdminNotificationType) BaseNotificationType(org.bedework.caldav.util.notifications.BaseNotificationType) SuggestResponseNotificationType(org.bedework.caldav.util.notifications.suggest.SuggestResponseNotificationType) NotificationType(org.bedework.caldav.util.notifications.NotificationType) ApprovalResponseNotificationType(org.bedework.caldav.util.notifications.admin.ApprovalResponseNotificationType) SuggestNotificationType(org.bedework.caldav.util.notifications.suggest.SuggestNotificationType) AwaitingApprovalNotificationType(org.bedework.caldav.util.notifications.admin.AwaitingApprovalNotificationType) SuggestBaseNotificationType(org.bedework.caldav.util.notifications.suggest.SuggestBaseNotificationType) SuggestResponseNotificationType(org.bedework.caldav.util.notifications.suggest.SuggestResponseNotificationType) SuggestBaseNotificationType(org.bedework.caldav.util.notifications.suggest.SuggestBaseNotificationType) SysCode(org.bedework.sysevents.events.SysEventBase.SysCode) SuggestNotificationType(org.bedework.caldav.util.notifications.suggest.SuggestNotificationType) EntitySuggestedResponseEvent(org.bedework.sysevents.events.publicAdmin.EntitySuggestedResponseEvent)

Example 3 with CalFacadeStaleStateException

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;
}
Also used : SchedProcessor(org.bedework.inoutsched.processors.SchedProcessor) CalFacadeStaleStateException(org.bedework.calfacade.exc.CalFacadeStaleStateException) SchedProcResult(org.bedework.inoutsched.processors.SchedProcessor.SchedProcResult) EventInfo(org.bedework.calfacade.svc.EventInfo) CalSvcI(org.bedework.calsvci.CalSvcI) BwEvent(org.bedework.calfacade.BwEvent) SchedAttendeeUpdate(org.bedework.inoutsched.processors.SchedAttendeeUpdate)

Example 4 with CalFacadeStaleStateException

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;
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) InRequest(org.bedework.inoutsched.processors.InRequest) InRefresh(org.bedework.inoutsched.processors.InRefresh) ProcessResult(org.bedework.inoutsched.processors.InProcessor.ProcessResult) CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) BwEvent(org.bedework.calfacade.BwEvent) InReply(org.bedework.inoutsched.processors.InReply) CalFacadeStaleStateException(org.bedework.calfacade.exc.CalFacadeStaleStateException) CalSvcI(org.bedework.calsvci.CalSvcI) InProcessor(org.bedework.inoutsched.processors.InProcessor) InCancel(org.bedework.inoutsched.processors.InCancel)

Aggregations

CalFacadeStaleStateException (org.bedework.calfacade.exc.CalFacadeStaleStateException)4 BwEvent (org.bedework.calfacade.BwEvent)2 EventInfo (org.bedework.calfacade.svc.EventInfo)2 CalSvcI (org.bedework.calsvci.CalSvcI)2 BaseNotificationType (org.bedework.caldav.util.notifications.BaseNotificationType)1 NotificationType (org.bedework.caldav.util.notifications.NotificationType)1 AdminNotificationType (org.bedework.caldav.util.notifications.admin.AdminNotificationType)1 ApprovalResponseNotificationType (org.bedework.caldav.util.notifications.admin.ApprovalResponseNotificationType)1 AwaitingApprovalNotificationType (org.bedework.caldav.util.notifications.admin.AwaitingApprovalNotificationType)1 SuggestBaseNotificationType (org.bedework.caldav.util.notifications.suggest.SuggestBaseNotificationType)1 SuggestNotificationType (org.bedework.caldav.util.notifications.suggest.SuggestNotificationType)1 SuggestResponseNotificationType (org.bedework.caldav.util.notifications.suggest.SuggestResponseNotificationType)1 CalFacadeForbidden (org.bedework.calfacade.exc.CalFacadeForbidden)1 InCancel (org.bedework.inoutsched.processors.InCancel)1 InProcessor (org.bedework.inoutsched.processors.InProcessor)1 ProcessResult (org.bedework.inoutsched.processors.InProcessor.ProcessResult)1 InRefresh (org.bedework.inoutsched.processors.InRefresh)1 InReply (org.bedework.inoutsched.processors.InReply)1 InRequest (org.bedework.inoutsched.processors.InRequest)1 SchedAttendeeUpdate (org.bedework.inoutsched.processors.SchedAttendeeUpdate)1