Search in sources :

Example 1 with TriggerVal

use of org.bedework.calfacade.BwAlarm.TriggerVal in project bw-calendar-engine by Bedework.

the class VAlarmUtil method processComponentAlarms.

/**
 * If there are any alarms for this component add them to the events alarm
 * collection
 *
 * @param cb          IcalCallback object
 * @param val
 * @param ev
 * @param currentPrincipal - href for current authenticated user
 * @param chg
 * @throws CalFacadeException
 */
public static void processComponentAlarms(final IcalCallback cb, final Component val, final BwEvent ev, final String currentPrincipal, final ChangeTable chg) throws CalFacadeException {
    try {
        ComponentList als = null;
        if (val instanceof VEvent) {
            als = ((VEvent) val).getAlarms();
        } else if (val instanceof VToDo) {
            als = ((VToDo) val).getAlarms();
        } else if (val instanceof VPoll) {
            als = ((VPoll) val).getAlarms();
        } else {
            return;
        }
        if ((als == null) || als.isEmpty()) {
            return;
        }
        for (Object o : als) {
            if (!(o instanceof VAlarm)) {
                throw new IcalMalformedException("Invalid alarm list");
            }
            VAlarm va = (VAlarm) o;
            PropertyList pl = va.getProperties();
            if (pl == null) {
                // Empty VAlarm
                throw new IcalMalformedException("Invalid alarm list");
            }
            Property prop;
            BwAlarm al;
            /* XXX Handle mozilla alarm stuff in a way that might work better with other clients.
         *
         */
            prop = pl.getProperty("X-MOZ-LASTACK");
            boolean mozlastAck = prop != null;
            String mozSnoozeTime = null;
            if (mozlastAck) {
                prop = pl.getProperty("X-MOZ-SNOOZE-TIME");
                if (prop == null) {
                    // lastack and no snooze - presume dismiss so delete alarm
                    continue;
                }
                // UTC time
                mozSnoozeTime = prop.getValue();
            }
            // All alarm types require action and trigger
            prop = pl.getProperty(Property.ACTION);
            if (prop == null) {
                throw new IcalMalformedException("Invalid alarm");
            }
            String actionStr = prop.getValue();
            TriggerVal tr = getTrigger(pl, "NONE".equals(actionStr));
            if (mozSnoozeTime != null) {
                tr.trigger = mozSnoozeTime;
                tr.triggerDateTime = true;
                tr.triggerStart = false;
            }
            DurationRepeat dr = getDurationRepeat(pl);
            if ("EMAIL".equals(actionStr)) {
                al = BwAlarm.emailAlarm(ev, ev.getCreatorHref(), tr, dr.duration, dr.repeat, getOptStr(pl, "ATTACH"), getReqStr(pl, "DESCRIPTION"), getReqStr(pl, "SUMMARY"), null);
                Iterator<?> atts = getReqStrs(pl, "ATTENDEE");
                while (atts.hasNext()) {
                    al.addAttendee(getAttendee(cb, (Attendee) atts.next()));
                }
            } else if ("AUDIO".equals(actionStr)) {
                al = BwAlarm.audioAlarm(ev, ev.getCreatorHref(), tr, dr.duration, dr.repeat, getOptStr(pl, "ATTACH"));
            } else if ("DISPLAY".equals(actionStr)) {
                al = BwAlarm.displayAlarm(ev, ev.getCreatorHref(), tr, dr.duration, dr.repeat, getReqStr(pl, "DESCRIPTION"));
            } else if ("PROCEDURE".equals(actionStr)) {
                al = BwAlarm.procedureAlarm(ev, ev.getCreatorHref(), tr, dr.duration, dr.repeat, getReqStr(pl, "ATTACH"), getOptStr(pl, "DESCRIPTION"));
            } else if ("NONE".equals(actionStr)) {
                al = BwAlarm.noneAlarm(ev, ev.getCreatorHref(), tr, dr.duration, dr.repeat, getOptStr(pl, "DESCRIPTION"));
            } else {
                al = BwAlarm.otherAlarm(ev, ev.getCreatorHref(), actionStr, tr, dr.duration, dr.repeat, getOptStr(pl, "DESCRIPTION"));
            }
            /* Mozilla is add xprops to the containing event to set the snooze time.
         * Seems wrong - there could be multiple alarms.
         *
         * We possibly want to try this sort of trick..

        prop = pl.getProperty("X-MOZ-LASTACK");
        boolean mozlastAck = prop != null;

        String mozSnoozeTime = null;
        if (mozlastAck) {
          prop = pl.getProperty("X-MOZ-SNOOZE-TIME");

          if (prop == null) {
            // lastack and no snooze - presume dismiss so delete alarm
            continue;
          }

          mozSnoozeTime = prop.getValue(); // UTC time
        }
        ...

        TriggerVal tr = getTrigger(pl);

        if (mozSnoozeTime != null) {
          tr.trigger = mozSnoozeTime;
          tr.triggerDateTime = true;
          tr.triggerStart = false;
        }

         */
            Iterator it = pl.iterator();
            while (it.hasNext()) {
                prop = (Property) it.next();
                if (prop instanceof XProperty) {
                    /* ------------------------- x-property --------------------------- */
                    XProperty xp = (XProperty) prop;
                    al.addXproperty(new BwXproperty(xp.getName(), xp.getParameters().toString(), xp.getValue()));
                    continue;
                }
                if (prop instanceof Uid) {
                    Uid p = (Uid) prop;
                    al.addXproperty(BwXproperty.makeIcalProperty(p.getName(), p.getParameters().toString(), p.getValue()));
                    continue;
                }
            }
            al.setEvent(ev);
            al.setOwnerHref(currentPrincipal);
            chg.addValue(PropertyInfoIndex.VALARM, al);
        }
    } catch (CalFacadeException cfe) {
        throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) XProperty(net.fortuna.ical4j.model.property.XProperty) ComponentList(net.fortuna.ical4j.model.ComponentList) BwAlarm(org.bedework.calfacade.BwAlarm) BwAttendee(org.bedework.calfacade.BwAttendee) Attendee(net.fortuna.ical4j.model.property.Attendee) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) Uid(net.fortuna.ical4j.model.property.Uid) PropertyList(net.fortuna.ical4j.model.PropertyList) VPoll(net.fortuna.ical4j.model.component.VPoll) BwXproperty(org.bedework.calfacade.BwXproperty) Iterator(java.util.Iterator) VAlarm(net.fortuna.ical4j.model.component.VAlarm) Property(net.fortuna.ical4j.model.Property) XProperty(net.fortuna.ical4j.model.property.XProperty) TriggerVal(org.bedework.calfacade.BwAlarm.TriggerVal) VToDo(net.fortuna.ical4j.model.component.VToDo)

Example 2 with TriggerVal

use of org.bedework.calfacade.BwAlarm.TriggerVal in project bw-calendar-engine by Bedework.

the class IcalUtil method getTrigger.

/**
 * @param pl
 * @param absentOk - if true and absent returns an empty result.
 * @return TriggerVal
 * @throws Throwable
 */
public static TriggerVal getTrigger(final PropertyList pl, final boolean absentOk) throws Throwable {
    Trigger prop = (Trigger) pl.getProperty(Property.TRIGGER);
    TriggerVal tr = new TriggerVal();
    if (prop == null) {
        if (!absentOk) {
            throw new IcalMalformedException("Invalid alarm - no trigger");
        }
        return tr;
    }
    tr.trigger = prop.getValue();
    if (prop.getDateTime() != null) {
        tr.triggerDateTime = true;
        return tr;
    }
    ParameterList pars = prop.getParameters();
    if (pars == null) {
        tr.triggerStart = true;
        return tr;
    }
    Parameter par = pars.getParameter("RELATED");
    if (par == null) {
        tr.triggerStart = true;
        return tr;
    }
    tr.triggerStart = "START".equals(par.getValue());
    return tr;
}
Also used : Trigger(net.fortuna.ical4j.model.property.Trigger) ParameterList(net.fortuna.ical4j.model.ParameterList) Parameter(net.fortuna.ical4j.model.Parameter) TriggerVal(org.bedework.calfacade.BwAlarm.TriggerVal)

Aggregations

TriggerVal (org.bedework.calfacade.BwAlarm.TriggerVal)2 Iterator (java.util.Iterator)1 ComponentList (net.fortuna.ical4j.model.ComponentList)1 Parameter (net.fortuna.ical4j.model.Parameter)1 ParameterList (net.fortuna.ical4j.model.ParameterList)1 Property (net.fortuna.ical4j.model.Property)1 PropertyList (net.fortuna.ical4j.model.PropertyList)1 VAlarm (net.fortuna.ical4j.model.component.VAlarm)1 VEvent (net.fortuna.ical4j.model.component.VEvent)1 VPoll (net.fortuna.ical4j.model.component.VPoll)1 VToDo (net.fortuna.ical4j.model.component.VToDo)1 Attendee (net.fortuna.ical4j.model.property.Attendee)1 Trigger (net.fortuna.ical4j.model.property.Trigger)1 Uid (net.fortuna.ical4j.model.property.Uid)1 XProperty (net.fortuna.ical4j.model.property.XProperty)1 BwAlarm (org.bedework.calfacade.BwAlarm)1 BwAttendee (org.bedework.calfacade.BwAttendee)1 BwXproperty (org.bedework.calfacade.BwXproperty)1 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)1