Search in sources :

Example 11 with BwAlarm

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

the class AlarmRule method end.

public void end(String ns, String name) throws Exception {
    BwAlarm entity = (BwAlarm) pop();
    globals.counts[globals.valarms]++;
    if (!(top() instanceof EventInfo)) {
        warn("Expected an event info object: found " + top());
        return;
    }
    BwEvent ev = ((EventInfo) top()).getEvent();
    if (entity.getOwnerHref() == null) {
        entity.setOwnerHref(ev.getOwnerHref());
    }
    entity.setEvent(ev);
    ev.addAlarm(entity);
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) BwEvent(org.bedework.calfacade.BwEvent) BwAlarm(org.bedework.calfacade.BwAlarm)

Example 12 with BwAlarm

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

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

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

the class RepeatPropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    BwAlarm alarm = ui.getSubComponent().getAlarm();
    RepeatPropType pr = (RepeatPropType) ui.getProp();
    if (ui.isRemove()) {
        alarm.setRepeat(0);
        flagChange(alarm, ui);
        return UpdateResult.getOkResult();
    }
    if (ui.isAdd()) {
        if (alarm.getRepeat() != 0) {
            return new UpdateResult("Entity already has repeat - cannot add");
        }
        alarm.setRepeat(pr.getInteger().intValue());
        flagChange(alarm, ui);
        return UpdateResult.getOkResult();
    }
    if (!ui.isChange()) {
        return new UpdateResult("No update specified for " + ui.getPropName());
    }
    /* Ensure the old value matches */
    if (pr.getInteger().intValue() != alarm.getRepeat()) {
        return new UpdateResult("Values don't match for update to " + ui.getPropName());
    }
    pr = (RepeatPropType) ui.getUpdprop();
    alarm.setRepeat(pr.getInteger().intValue());
    flagChange(alarm, ui);
    return UpdateResult.getOkResult();
}
Also used : RepeatPropType(ietf.params.xml.ns.icalendar_2.RepeatPropType) BwAlarm(org.bedework.calfacade.BwAlarm) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)

Example 15 with BwAlarm

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

the class TriggerPropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    BwAlarm alarm = ui.getSubComponent().getAlarm();
    TriggerPropType pr = (TriggerPropType) ui.getProp();
    if (ui.isRemove()) {
        return new UpdateResult("Cannot remove " + ui.getPropName());
    }
    if (ui.isAdd()) {
        return new UpdateResult("Cannot add " + ui.getPropName());
    }
    if (!ui.isChange()) {
        return new UpdateResult("No update specified for " + ui.getPropName());
    }
    /* Ensure the old value matches */
    if (pr.getDateTime() != null) {
        if (!alarm.getTriggerDateTime()) {
            return new UpdateResult("Values don't match for update to " + ui.getPropName());
        }
    } else {
        if (alarm.getTriggerDateTime()) {
            return new UpdateResult("Values don't match for update to " + ui.getPropName());
        }
    }
    pr = (TriggerPropType) ui.getUpdprop();
    if (pr.getDateTime() != null) {
        alarm.setTrigger(XcalUtil.getIcalFormatDateTime(pr.getDateTime()));
        alarm.setTriggerDateTime(true);
    } else {
        alarm.setTrigger(pr.getDuration());
        RelatedParamType r = (RelatedParamType) XcalUtil.findParam(pr, XcalTags.related);
        alarm.setTriggerStart((r == null) || (r.getText().toUpperCase().equals("START")));
    }
    flagChange(alarm, ui);
    return UpdateResult.getOkResult();
}
Also used : TriggerPropType(ietf.params.xml.ns.icalendar_2.TriggerPropType) BwAlarm(org.bedework.calfacade.BwAlarm) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) RelatedParamType(ietf.params.xml.ns.icalendar_2.RelatedParamType)

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