Search in sources :

Example 1 with ActionPropType

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

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

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 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)2 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 BasePropertyType (ietf.params.xml.ns.icalendar_2.BasePropertyType)1 ValarmType (ietf.params.xml.ns.icalendar_2.ValarmType)1 JAXBElement (javax.xml.bind.JAXBElement)1 BwAlarm (org.bedework.calfacade.BwAlarm)1