Search in sources :

Example 1 with ValarmType

use of ietf.params.xml.ns.icalendar_2.ValarmType 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 ValarmType

use of ietf.params.xml.ns.icalendar_2.ValarmType 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 3 with ValarmType

use of ietf.params.xml.ns.icalendar_2.ValarmType in project bw-calendar-engine by Bedework.

the class BwUpdates method findSubComponent.

private Component findSubComponent(final EventInfo ei, final BaseComponentType bc) throws WebdavException {
    try {
        BwEvent ev = ei.getEvent();
        int etype = ev.getEntityType();
        if (bc instanceof ValarmType) {
            if ((etype != IcalDefs.entityTypeEvent) || (etype != IcalDefs.entityTypeTodo)) {
                return null;
            }
            /* Look for the alarm - we match on the whole component */
            BwAlarm matched = null;
            BwAlarm pattern = Xalarms.toBwAlarm((ValarmType) bc, false);
            if ((pattern == null) || (ev.getNumAlarms() == 0)) {
                return null;
            }
            for (BwAlarm al : ev.getAlarms()) {
                if (al.matches(pattern)) {
                    if (matched != null) {
                        // Multiple matches - bad
                        return null;
                    }
                    matched = al;
                }
            }
            return new PropertyUpdateComponent(ei, matched);
        }
        return null;
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : ValarmType(ietf.params.xml.ns.icalendar_2.ValarmType) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) BwAlarm(org.bedework.calfacade.BwAlarm) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 4 with ValarmType

use of ietf.params.xml.ns.icalendar_2.ValarmType in project bw-calendar-engine by Bedework.

the class BwUpdates method addSubComp.

private UpdateResult addSubComp(final EventInfo ei, final ComponentReferenceType sel) throws WebdavException {
    try {
        BwEvent ev = ei.getEvent();
        int etype = ev.getEntityType();
        BaseComponentType bc = sel.getBaseComponent().getValue();
        if (bc instanceof ValarmType) {
            if ((etype != IcalDefs.entityTypeEvent) || (etype != IcalDefs.entityTypeTodo)) {
                return new UpdateResult("Invalid entity type for alarm add");
            }
            BwAlarm al = Xalarms.toBwAlarm((ValarmType) bc, false);
            if (al == null) {
                return new UpdateResult("Invalid alarm for add");
            }
            ev.addAlarm(al);
            return UpdateResult.getOkResult();
        }
        return new UpdateResult("Invalid entity type for add");
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : ValarmType(ietf.params.xml.ns.icalendar_2.ValarmType) BaseComponentType(ietf.params.xml.ns.icalendar_2.BaseComponentType) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) BwAlarm(org.bedework.calfacade.BwAlarm) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 5 with ValarmType

use of ietf.params.xml.ns.icalendar_2.ValarmType in project bw-calendar-engine by Bedework.

the class Xalarms method toXAlarm.

/**
 * @param ev
 * @param val
 * @param pattern
 * @param masterClass
 * @return ValarmType
 * @throws CalFacadeException
 */
public static ValarmType toXAlarm(final BwEvent ev, final BwAlarm val, final BaseComponentType pattern, final Class masterClass) throws CalFacadeException {
    try {
        ValarmType alarm = new ValarmType();
        int atype = val.getAlarmType();
        alarm.setProperties(new ArrayOfProperties());
        List<JAXBElement<? extends BasePropertyType>> pl = alarm.getProperties().getBasePropertyOrTzid();
        if (emit(pattern, masterClass, ValarmType.class, ActionPropType.class)) {
            ActionPropType a = new ActionPropType();
            a.setText(BwAlarm.alarmTypes[val.getAlarmType()]);
            pl.add(of.createAction(a));
        }
        if (emit(pattern, masterClass, ValarmType.class, TriggerPropType.class)) {
            TriggerPropType t = new TriggerPropType();
            if (val.getTriggerDateTime()) {
                // t.setDateTime(val.getTrigger());
                t.setDateTime(XcalUtil.getXMlUTCCal(val.getTrigger()));
            } else {
                t.setDuration(val.getTrigger());
                if (!val.getTriggerStart()) {
                    ArrayOfParameters pars = getAop(t);
                    RelatedParamType r = new RelatedParamType();
                    r.setText(IcalDefs.alarmTriggerRelatedEnd);
                    JAXBElement<RelatedParamType> param = of.createRelated(r);
                    pars.getBaseParameter().add(param);
                }
            }
            pl.add(of.createTrigger(t));
        }
        if (emit(pattern, masterClass, ValarmType.class, DurationPropType.class)) {
            if (val.getDuration() != null) {
                DurationPropType dur = new DurationPropType();
                dur.setDuration(val.getDuration());
                pl.add(of.createDuration(dur));
                RepeatPropType rep = new RepeatPropType();
                rep.setInteger(BigInteger.valueOf(val.getRepeat()));
                pl.add(of.createRepeat(rep));
            }
        }
        /* Description */
        if ((atype == BwAlarm.alarmTypeDisplay) || (atype == BwAlarm.alarmTypeEmail) || (atype == BwAlarm.alarmTypeProcedure)) {
            // Both require description
            String desc = val.getDescription();
            if (desc == null) {
                if (ev != null) {
                    if (ev.getDescription() != null) {
                        desc = ev.getDescription();
                    } else {
                        desc = ev.getSummary();
                    }
                }
            }
            if (desc == null) {
                desc = " ";
            }
            DescriptionPropType d = new DescriptionPropType();
            d.setText(desc);
            pl.add(of.createDescription(d));
        }
        /* Summary */
        if (atype == BwAlarm.alarmTypeEmail) {
            SummaryPropType s = new SummaryPropType();
            s.setText(val.getSummary());
            pl.add(of.createSummary(s));
        }
        if ((atype == BwAlarm.alarmTypeAudio) || (atype == BwAlarm.alarmTypeEmail) || (atype == BwAlarm.alarmTypeProcedure)) {
            if (val.getAttach() != null) {
                AttachPropType a = new AttachPropType();
                a.setUri(val.getAttach());
                pl.add(of.createAttach(a));
            }
        }
        /* Attendees */
        if (atype == BwAlarm.alarmTypeEmail) {
            if (val.getNumAttendees() > 0) {
                for (BwAttendee att : val.getAttendees()) {
                    pl.add(of.createAttendee(ToXEvent.makeAttendee(att)));
                }
            }
        }
        if (val.getNumXproperties() > 0) {
        /* This alarm has x-props */
        }
        return alarm;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : SummaryPropType(ietf.params.xml.ns.icalendar_2.SummaryPropType) TriggerPropType(ietf.params.xml.ns.icalendar_2.TriggerPropType) ArrayOfParameters(ietf.params.xml.ns.icalendar_2.ArrayOfParameters) AttachPropType(ietf.params.xml.ns.icalendar_2.AttachPropType) JAXBElement(javax.xml.bind.JAXBElement) DurationPropType(ietf.params.xml.ns.icalendar_2.DurationPropType) DescriptionPropType(ietf.params.xml.ns.icalendar_2.DescriptionPropType) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) RelatedParamType(ietf.params.xml.ns.icalendar_2.RelatedParamType) ValarmType(ietf.params.xml.ns.icalendar_2.ValarmType) ArrayOfProperties(ietf.params.xml.ns.icalendar_2.ArrayOfProperties) BasePropertyType(ietf.params.xml.ns.icalendar_2.BasePropertyType) ActionPropType(ietf.params.xml.ns.icalendar_2.ActionPropType) RepeatPropType(ietf.params.xml.ns.icalendar_2.RepeatPropType) BwAttendee(org.bedework.calfacade.BwAttendee)

Aggregations

ValarmType (ietf.params.xml.ns.icalendar_2.ValarmType)4 BwAlarm (org.bedework.calfacade.BwAlarm)4 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)4 ActionPropType (ietf.params.xml.ns.icalendar_2.ActionPropType)2 AttachPropType (ietf.params.xml.ns.icalendar_2.AttachPropType)2 DescriptionPropType (ietf.params.xml.ns.icalendar_2.DescriptionPropType)2 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 SummaryPropType (ietf.params.xml.ns.icalendar_2.SummaryPropType)2 TriggerPropType (ietf.params.xml.ns.icalendar_2.TriggerPropType)2 BwAttendee (org.bedework.calfacade.BwAttendee)2 BwEvent (org.bedework.calfacade.BwEvent)2 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)2 ArrayOfComponents (ietf.params.xml.ns.icalendar_2.ArrayOfComponents)1 ArrayOfParameters (ietf.params.xml.ns.icalendar_2.ArrayOfParameters)1 ArrayOfProperties (ietf.params.xml.ns.icalendar_2.ArrayOfProperties)1 AttendeePropType (ietf.params.xml.ns.icalendar_2.AttendeePropType)1 BaseComponentType (ietf.params.xml.ns.icalendar_2.BaseComponentType)1 BasePropertyType (ietf.params.xml.ns.icalendar_2.BasePropertyType)1