Search in sources :

Example 1 with SysCode

use of org.bedework.sysevents.events.SysEventBase.SysCode in project bw-calendar-engine by Bedework.

the class Notifier method processApproved.

private ProcessMessageResult processApproved(final SysEvent msg) {
    try {
        String targetPrincipal = null;
        final SysCode sysCode = msg.getSysCode();
        AdminNotificationType ant = null;
        if (sysCode == SysCode.APPROVAL_STATUS) {
            final EntityApprovalResponseEvent eare = (EntityApprovalResponseEvent) msg;
            final ApprovalResponseNotificationType arnt = new ApprovalResponseNotificationType();
            arnt.setUid(Uid.getUid());
            arnt.setHref(eare.getHref());
            arnt.setPrincipalHref(eare.getOwnerHref());
            arnt.setAccepted(eare.getApproved());
            arnt.setComment(eare.getComment());
            arnt.setCalsuiteHref(eare.getCalsuiteHref());
            targetPrincipal = eare.getCalsuiteHref();
            ant = arnt;
        } else if (sysCode == SysCode.APPROVAL_NEEDED) {
            final EntityApprovalNeededEvent eane = (EntityApprovalNeededEvent) msg;
            final AwaitingApprovalNotificationType aant = new AwaitingApprovalNotificationType();
            aant.setUid(Uid.getUid());
            aant.setHref(eane.getHref());
            aant.setPrincipalHref(eane.getOwnerHref());
            aant.setComment(eane.getComment());
            aant.setCalsuiteHref(eane.getCalsuiteHref());
            targetPrincipal = eane.getCalsuiteHref();
            ant = aant;
        }
        if (ant == 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(ant.getElementName())) {
                if ((n == null) || (n.getNotification() == null)) {
                    // Bad notiifcation?
                    continue;
                }
                final AdminNotificationType ns = (AdminNotificationType) n.getNotification();
                if (ant.getHref().equals(ns.getHref())) {
                    // Already have a notification for resource
                    storedNote = n;
                    break;
                }
            }
            if (storedNote != null) {
                getNotes().remove(storedNote);
            }
            // save this one
            ant.setName(getEncodedUuid());
            final NotificationType n = new NotificationType();
            n.setNotification(ant);
            getNotes().add(n);
            return ProcessMessageResult.PROCESSED;
        } finally {
            closeSvci(getSvc());
        }
    } catch (final Throwable t) {
        rollback(getSvc());
        error(t);
    } finally {
        try {
            closeSvci(getSvc());
        } catch (final Throwable ignored) {
        }
    }
    return ProcessMessageResult.FAILED;
}
Also used : EntityApprovalResponseEvent(org.bedework.sysevents.events.publicAdmin.EntityApprovalResponseEvent) EntityApprovalNeededEvent(org.bedework.sysevents.events.publicAdmin.EntityApprovalNeededEvent) 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) ApprovalResponseNotificationType(org.bedework.caldav.util.notifications.admin.ApprovalResponseNotificationType) AwaitingApprovalNotificationType(org.bedework.caldav.util.notifications.admin.AwaitingApprovalNotificationType) AdminNotificationType(org.bedework.caldav.util.notifications.admin.AdminNotificationType) SysCode(org.bedework.sysevents.events.SysEventBase.SysCode)

Example 2 with SysCode

use of org.bedework.sysevents.events.SysEventBase.SysCode 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 SysCode

use of org.bedework.sysevents.events.SysEventBase.SysCode in project bw-calendar-engine by Bedework.

the class DataCounts method update.

/**
 * @param ev
 */
public void update(final SysEvent ev) {
    SysCode sc = ev.getSysCode();
    DataValue dl = dlMap.get(sc);
    if (dl != null) {
        dl.inc();
    }
}
Also used : SysCode(org.bedework.sysevents.events.SysEventBase.SysCode)

Example 4 with SysCode

use of org.bedework.sysevents.events.SysEventBase.SysCode in project bw-calendar-engine by Bedework.

the class DataValues method update.

/**
 * @param ev
 */
public void update(final SysEvent ev) {
    SysCode sc = ev.getSysCode();
    if (ev instanceof TimedEvent) {
        TimedEvent te = (TimedEvent) ev;
        String lbl = te.getLabel();
        DataAvg dv = timedValuesMap.get(lbl);
        if (dv == null) {
            dv = new DataAvg(lbl, ev.getSysCode());
            timedValuesMap.put(lbl, dv);
        }
        dv.inc(te.getMillis());
        return;
    }
    if (ev instanceof MillisecsEvent) {
        DataAvg dv = dvMap.get(sc);
        if (dv != null) {
            dv.inc(((MillisecsEvent) ev).getMillis());
        }
        return;
    }
    if (sc == SysCode.STATS) {
        StatsEvent se = (StatsEvent) ev;
        String sname = se.getName();
        DataAvg da = statMap.get(sname);
        if (da == null) {
            da = new DataAvg(sname, sc);
            statMap.put(sname, da);
        }
        StatType st = StatsEvent.getStatType(sname);
        if (st != StatType.lnum) {
            da.inc(1);
        } else if (se.getLongValue() != null) {
            da.inc(se.getLongValue());
        }
        return;
    }
}
Also used : MillisecsEvent(org.bedework.sysevents.events.MillisecsEvent) TimedEvent(org.bedework.sysevents.events.TimedEvent) StatType(org.bedework.sysevents.events.StatsEvent.StatType) StatsEvent(org.bedework.sysevents.events.StatsEvent) SysCode(org.bedework.sysevents.events.SysEventBase.SysCode)

Example 5 with SysCode

use of org.bedework.sysevents.events.SysEventBase.SysCode in project bw-calendar-engine by Bedework.

the class DataCounts method addDl.

private DataValue addDl(final String name, final SysCode scode) {
    DataValue dl = new DataValue(name, scode);
    dls.add(dl);
    SysCode s = dl.getSysCode();
    if (s != null) {
        dlMap.put(s, dl);
    }
    return dl;
}
Also used : SysCode(org.bedework.sysevents.events.SysEventBase.SysCode)

Aggregations

SysCode (org.bedework.sysevents.events.SysEventBase.SysCode)5 BaseNotificationType (org.bedework.caldav.util.notifications.BaseNotificationType)2 NotificationType (org.bedework.caldav.util.notifications.NotificationType)2 AdminNotificationType (org.bedework.caldav.util.notifications.admin.AdminNotificationType)2 ApprovalResponseNotificationType (org.bedework.caldav.util.notifications.admin.ApprovalResponseNotificationType)2 AwaitingApprovalNotificationType (org.bedework.caldav.util.notifications.admin.AwaitingApprovalNotificationType)2 SuggestBaseNotificationType (org.bedework.caldav.util.notifications.suggest.SuggestBaseNotificationType)2 SuggestNotificationType (org.bedework.caldav.util.notifications.suggest.SuggestNotificationType)2 SuggestResponseNotificationType (org.bedework.caldav.util.notifications.suggest.SuggestResponseNotificationType)2 CalFacadeStaleStateException (org.bedework.calfacade.exc.CalFacadeStaleStateException)1 MillisecsEvent (org.bedework.sysevents.events.MillisecsEvent)1 StatsEvent (org.bedework.sysevents.events.StatsEvent)1 StatType (org.bedework.sysevents.events.StatsEvent.StatType)1 TimedEvent (org.bedework.sysevents.events.TimedEvent)1 EntityApprovalNeededEvent (org.bedework.sysevents.events.publicAdmin.EntityApprovalNeededEvent)1 EntityApprovalResponseEvent (org.bedework.sysevents.events.publicAdmin.EntityApprovalResponseEvent)1 EntitySuggestedEvent (org.bedework.sysevents.events.publicAdmin.EntitySuggestedEvent)1 EntitySuggestedResponseEvent (org.bedework.sysevents.events.publicAdmin.EntitySuggestedResponseEvent)1