Search in sources :

Example 6 with BaseComponentType

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

the class BwUpdates method applyUpdate.

private UpdateResult applyUpdate(final EventInfo ei, final ComponentSelectionType selPar) throws WebdavException {
    /* First two selects just get us in to the events */
    ComponentSelectionType sel = selPar;
    // Top level must be "vcalendar"
    if ((sel == null) || (sel.getVcalendar() == null)) {
        return new UpdateResult("Not \"vcalendar\"");
    }
    // Next - expect "components"
    ComponentsSelectionType csel = sel.getComponents();
    if (csel == null) {
        return new UpdateResult("Not \"component\"");
    }
    for (ComponentReferenceType c : csel.getRemove()) {
        UpdateResult ur = removeOverride(ei, c);
        if (!ur.getOk()) {
            return ur;
        }
    }
    for (ComponentReferenceType c : csel.getAdd()) {
        UpdateResult ur = addOverride(ei, c);
        if (!ur.getOk()) {
            return ur;
        }
    }
    /* Updates may be applied to the master or any overrides selected by uid and
     * recurrence-id
     */
    for (ComponentSelectionType cs : csel.getComponent()) {
        BaseComponentType ent = cs.getBaseComponent().getValue();
        // Must be a component matching the current one.
        if (ent == null) {
            return new UpdateResult("Missing component to match");
        }
        Integer entType = entTypes.get(ent.getClass());
        if (entType == null) {
            return new UpdateResult("Unknown entity type: " + ent.getClass());
        }
        if (entType != ei.getEvent().getEntityType()) {
            return new UpdateResult("No matching entity");
        }
        List<EventInfo> entities = new ArrayList<EventInfo>();
        entities.add(ei);
        entities.addAll(ei.getOverrides());
        entities = match(// sel,
        entities, ent);
        if ((entities == null) || (entities.size() == 0)) {
            return new UpdateResult("No matching entity");
        }
        if ((cs.getProperties() == null) && (cs.getComponents() == null)) {
            // No properties or components - error
            return new UpdateResult("Must select \"components\" and/or \"properties\"");
        }
        /* At this point we either select properties to change or nested components
       */
        if (cs.getComponents() != null) {
            UpdateResult ur = applySubCompUpdates(ei, cs.getComponents());
            if (!ur.getOk()) {
                return ur;
            }
        }
        if (cs.getProperties() != null) {
            // Updating properties
            UpdateResult ur = updateEventsProperties(entities, cs.getProperties());
            if (!ur.getOk()) {
                return ur;
            }
        }
    }
    return UpdateResult.getOkResult();
}
Also used : BaseComponentType(ietf.params.xml.ns.icalendar_2.BaseComponentType) ComponentSelectionType(org.oasis_open.docs.ws_calendar.ns.soap.ComponentSelectionType) EventInfo(org.bedework.calfacade.svc.EventInfo) ComponentsSelectionType(org.oasis_open.docs.ws_calendar.ns.soap.ComponentsSelectionType) ArrayList(java.util.ArrayList) ComponentReferenceType(org.oasis_open.docs.ws_calendar.ns.soap.ComponentReferenceType) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)

Example 7 with BaseComponentType

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

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

the class BwUpdates method getCompSelector.

private CompSelector getCompSelector(final BaseComponentType selComp) throws WebdavException {
    CompSelector cs = new CompSelector();
    for (JAXBElement<? extends BasePropertyType> prop : selComp.getProperties().getBasePropertyOrTzid()) {
        if (prop.getName().equals(XcalTags.uid)) {
            cs.uid = ((UidPropType) prop.getValue()).getText();
            if ((cs.uid != null) && (cs.recurrenceId != null)) {
                return cs;
            }
            continue;
        }
        if (prop.getName().equals(XcalTags.recurrenceId)) {
            RecurrenceIdPropType rid = (RecurrenceIdPropType) prop.getValue();
            XcalUtil.DtTzid dtTzid = XcalUtil.getDtTzid(rid);
            try {
                cs.recurrenceId = BwDateTime.makeBwDateTime(dtTzid.dateOnly, dtTzid.dt, dtTzid.tzid);
            } catch (CalFacadeException cfe) {
                throw new WebdavException(cfe);
            }
            if ((cs.uid != null) && (cs.recurrenceId != null)) {
                return cs;
            }
            continue;
        }
    }
    return cs;
}
Also used : RecurrenceIdPropType(ietf.params.xml.ns.icalendar_2.RecurrenceIdPropType) XcalUtil(org.bedework.util.calendar.XcalUtil) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 9 with BaseComponentType

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

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

CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)6 BaseComponentType (ietf.params.xml.ns.icalendar_2.BaseComponentType)4 ArrayOfParameters (ietf.params.xml.ns.icalendar_2.ArrayOfParameters)3 ArrayOfProperties (ietf.params.xml.ns.icalendar_2.ArrayOfProperties)3 BasePropertyType (ietf.params.xml.ns.icalendar_2.BasePropertyType)3 ValarmType (ietf.params.xml.ns.icalendar_2.ValarmType)3 JAXBElement (javax.xml.bind.JAXBElement)3 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)3 ArrayOfComponents (ietf.params.xml.ns.icalendar_2.ArrayOfComponents)2 DescriptionPropType (ietf.params.xml.ns.icalendar_2.DescriptionPropType)2 DurationPropType (ietf.params.xml.ns.icalendar_2.DurationPropType)2 RecurrenceIdPropType (ietf.params.xml.ns.icalendar_2.RecurrenceIdPropType)2 VeventType (ietf.params.xml.ns.icalendar_2.VeventType)2 VtodoType (ietf.params.xml.ns.icalendar_2.VtodoType)2 BwAlarm (org.bedework.calfacade.BwAlarm)2 BwEvent (org.bedework.calfacade.BwEvent)2 BwString (org.bedework.calfacade.BwString)2 EventInfo (org.bedework.calfacade.svc.EventInfo)2 ActionPropType (ietf.params.xml.ns.icalendar_2.ActionPropType)1 AttachPropType (ietf.params.xml.ns.icalendar_2.AttachPropType)1