Search in sources :

Example 1 with BwAlarm

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

the class ToXEvent method processEventAlarm.

/**
 * Process any alarms.
 *
 * @param ev
 * @param comp
 * @param pattern
 * @param masterClass
 * @throws CalFacadeException
 */
public static void processEventAlarm(final BwEvent ev, final BaseComponentType comp, final BaseComponentType pattern, final Class masterClass) throws CalFacadeException {
    if (!emit(pattern, masterClass, ValarmType.class)) {
        return;
    }
    Set<BwAlarm> als = ev.getAlarms();
    if ((als == null) || als.isEmpty()) {
        return;
    }
    if (!(comp instanceof VeventType) && !(comp instanceof VtodoType)) {
        warn("Entity of class " + ev.getClass() + " has alarms but not allowed by entity of type " + comp.getClass());
    }
    ArrayOfComponents aoc = comp.getComponents();
    if (aoc == null) {
        aoc = new ArrayOfComponents();
        comp.setComponents(aoc);
    }
    for (BwAlarm alarm : als) {
        ValarmType va = Xalarms.toXAlarm(ev, alarm, pattern, masterClass);
        aoc.getBaseComponent().add(of.createValarm(va));
    }
}
Also used : ValarmType(ietf.params.xml.ns.icalendar_2.ValarmType) VtodoType(ietf.params.xml.ns.icalendar_2.VtodoType) VeventType(ietf.params.xml.ns.icalendar_2.VeventType) ArrayOfComponents(ietf.params.xml.ns.icalendar_2.ArrayOfComponents) BwAlarm(org.bedework.calfacade.BwAlarm)

Example 2 with BwAlarm

use of org.bedework.calfacade.BwAlarm 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 3 with BwAlarm

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

the class VAlarmUtil method processEventAlarm.

/**
 * Process any alarms.
 *
 * @param ev
 * @param comp
 * @param currentPrincipal - href for current authenticated user
 * @throws CalFacadeException
 */
public static void processEventAlarm(final BwEvent ev, final Component comp, final String currentPrincipal) throws CalFacadeException {
    if (currentPrincipal == null) {
        // No alarms for unauthenticated users.
        return;
    }
    Collection<BwAlarm> als = ev.getAlarms();
    if ((als == null) || als.isEmpty()) {
        return;
    }
    ComponentList vals = null;
    if (comp instanceof VEvent) {
        vals = ((VEvent) comp).getAlarms();
    } else if (comp instanceof VToDo) {
        vals = ((VToDo) comp).getAlarms();
    } else {
        throw new CalFacadeException("org.bedework.invalid.component.type", comp.getName());
    }
    for (BwAlarm alarm : als) {
        /* Only add alarms for the current authenticated user */
        if (!currentPrincipal.equals(alarm.getOwnerHref())) {
            continue;
        }
        vals.add(setAlarm(ev, alarm));
    }
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) ComponentList(net.fortuna.ical4j.model.ComponentList) BwAlarm(org.bedework.calfacade.BwAlarm) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) VToDo(net.fortuna.ical4j.model.component.VToDo)

Example 4 with BwAlarm

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

the class Xalarms method toBwAlarm.

/**
 * The generated alarm may not be a valid alarm if it is being used as a
 * selector. It must have at least the action as a selector.
 *
 * @param alarm
 * @param validate - true if alarm must be valid and complete
 * @return ValarmType
 * @throws CalFacadeException
 */
public static BwAlarm toBwAlarm(final ValarmType alarm, final boolean validate) throws CalFacadeException {
    BwAlarm ba = new BwAlarm();
    /* ============ Action =================== */
    ActionPropType action = (ActionPropType) XcalUtil.findProperty(alarm, XcalTags.action);
    if (action == null) {
        throw new CalFacadeException("Invalid alarm - no action");
    }
    String actionVal = action.getText().toUpperCase();
    int atype = -1;
    for (int i = 0; i < BwAlarm.alarmTypes.length; i++) {
        if (actionVal.equals(BwAlarm.alarmTypes[i])) {
            atype = i;
            break;
        }
    }
    if (atype < 0) {
        throw new CalFacadeException("Unhandled alarm action");
    }
    ba.setAlarmType(atype);
    /* ============ Trigger =================== */
    TriggerPropType tr = (TriggerPropType) XcalUtil.findProperty(alarm, XcalTags.trigger);
    if (tr == null) {
        if (validate) {
            throw new CalFacadeException("Invalid alarm - no action");
        }
    } else {
        if (tr.getDateTime() != null) {
            ba.setTrigger(XcalUtil.getIcalFormatDateTime(tr.getDateTime()));
            ba.setTriggerDateTime(true);
        } else {
            ba.setTrigger(tr.getDuration());
            RelatedParamType r = (RelatedParamType) XcalUtil.findParam(tr, XcalTags.related);
            ba.setTriggerStart((r == null) || (r.getText().toUpperCase().equals("START")));
        }
    }
    /* ============ Duration =================== */
    DurationPropType dur = (DurationPropType) XcalUtil.findProperty(alarm, XcalTags.duration);
    if (dur != null) {
        // MUST have repeat
        RepeatPropType rep = (RepeatPropType) XcalUtil.findProperty(alarm, XcalTags.repeat);
        ba.setDuration(dur.getDuration());
        if (rep == null) {
            if (validate) {
                throw new CalFacadeException("Invalid alarm - no repeat");
            }
        } else {
            ba.setRepeat(rep.getInteger().intValue());
        }
    }
    /* ============ Description ============ */
    if ((atype == BwAlarm.alarmTypeDisplay) || (atype == BwAlarm.alarmTypeEmail) || (atype == BwAlarm.alarmTypeProcedure)) {
        DescriptionPropType desc = (DescriptionPropType) XcalUtil.findProperty(alarm, XcalTags.description);
        if (desc != null) {
            ba.setDescription(desc.getText());
        }
    }
    /* ============ Summary ============ */
    if (atype == BwAlarm.alarmTypeEmail) {
        SummaryPropType s = (SummaryPropType) XcalUtil.findProperty(alarm, XcalTags.summary);
        if (s != null) {
            ba.setSummary(s.getText());
        }
    }
    if ((atype == BwAlarm.alarmTypeAudio) || (atype == BwAlarm.alarmTypeEmail) || (atype == BwAlarm.alarmTypeProcedure)) {
        AttachPropType a = (AttachPropType) XcalUtil.findProperty(alarm, XcalTags.attach);
        // XXX Onl handle 1 attachment
        if ((a != null) && (a.getUri() != null)) {
            ba.setAttach(a.getUri());
        }
    }
    if (atype == BwAlarm.alarmTypeEmail) {
        for (JAXBElement<? extends BasePropertyType> bpel : alarm.getProperties().getBasePropertyOrTzid()) {
            if (!bpel.getName().equals(XcalTags.attendee)) {
                continue;
            }
            AttendeePropType attp = (AttendeePropType) bpel.getValue();
            BwAttendee batt = new BwAttendee();
            batt.setAttendeeUri(attp.getCalAddress());
            ba.addAttendee(batt);
        }
    }
    return ba;
}
Also used : SummaryPropType(ietf.params.xml.ns.icalendar_2.SummaryPropType) TriggerPropType(ietf.params.xml.ns.icalendar_2.TriggerPropType) AttachPropType(ietf.params.xml.ns.icalendar_2.AttachPropType) DurationPropType(ietf.params.xml.ns.icalendar_2.DurationPropType) DescriptionPropType(ietf.params.xml.ns.icalendar_2.DescriptionPropType) BwAlarm(org.bedework.calfacade.BwAlarm) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) RelatedParamType(ietf.params.xml.ns.icalendar_2.RelatedParamType) ActionPropType(ietf.params.xml.ns.icalendar_2.ActionPropType) AttendeePropType(ietf.params.xml.ns.icalendar_2.AttendeePropType) RepeatPropType(ietf.params.xml.ns.icalendar_2.RepeatPropType) BwAttendee(org.bedework.calfacade.BwAttendee)

Example 5 with BwAlarm

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

the class Events method compileAlarms.

/**
 * Compile an alarm component
 *
 * @param val
 * @return alarms or null
 * @throws CalFacadeException
 */
public Set<BwAlarm> compileAlarms(final String val) throws CalFacadeException {
    try {
        StringReader sr = new StringReader(ValidateAlarmPrefix + val + ValidateAlarmSuffix);
        IcalTranslator trans = new IcalTranslator(getSvc().getIcalCallback());
        Icalendar ic = trans.fromIcal(null, sr);
        if ((ic == null) || (ic.getEventInfo() == null)) {
            if (debug) {
                trace("Not single event");
            }
            return null;
        }
        /* There should be alarms in the Calendar object
       */
        EventInfo ei = ic.getEventInfo();
        BwEvent ev = ei.getEvent();
        Set<BwAlarm> alarms = ev.getAlarms();
        if (Util.isEmpty(alarms)) {
            return null;
        }
        return alarms;
    } catch (CalFacadeException cfe) {
        if (debug) {
            error(cfe);
        }
        return null;
    }
}
Also used : CoreEventInfo(org.bedework.calcorei.CoreEventInfo) EventInfo(org.bedework.calfacade.svc.EventInfo) Icalendar(org.bedework.icalendar.Icalendar) StringReader(java.io.StringReader) BwEvent(org.bedework.calfacade.BwEvent) IcalTranslator(org.bedework.icalendar.IcalTranslator) BwAlarm(org.bedework.calfacade.BwAlarm) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

BwAlarm (org.bedework.calfacade.BwAlarm)20 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)8 BwEvent (org.bedework.calfacade.BwEvent)6 BwXproperty (org.bedework.calfacade.BwXproperty)5 UpdateResult (org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)4 ValarmType (ietf.params.xml.ns.icalendar_2.ValarmType)3 TreeSet (java.util.TreeSet)3 BwString (org.bedework.calfacade.BwString)3 EventInfo (org.bedework.calfacade.svc.EventInfo)3 DurationPropType (ietf.params.xml.ns.icalendar_2.DurationPropType)2 RelatedParamType (ietf.params.xml.ns.icalendar_2.RelatedParamType)2 RepeatPropType (ietf.params.xml.ns.icalendar_2.RepeatPropType)2 TriggerPropType (ietf.params.xml.ns.icalendar_2.TriggerPropType)2 ComponentList (net.fortuna.ical4j.model.ComponentList)2 VEvent (net.fortuna.ical4j.model.component.VEvent)2 VToDo (net.fortuna.ical4j.model.component.VToDo)2 BwAttendee (org.bedework.calfacade.BwAttendee)2 BwLongString (org.bedework.calfacade.BwLongString)2 IndexException (org.bedework.util.indexing.IndexException)2 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)2