Search in sources :

Example 6 with BwAlarm

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

the class ChangeTableEntry method diff.

/**
 * Compare the original and new collections. Update the removed and added
 * collections to reflect the changes that need to be made.
 *
 * <p>Alarms are the only peruser class we have to deal with.
 *
 * @param originalVals
 * @return true if collection set changed - that is, members were added or
 *              removed.
 */
@SuppressWarnings("unchecked")
public boolean diff(final Collection originalVals) {
    boolean alarms = index == PropertyInfoIndex.VALARM;
    Collection newVals = getNewValues();
    boolean collectionSetChanged = false;
    if (!Util.isEmpty(originalVals)) {
        if (!alarms && (newVals == null)) {
            // Remove everything
            setRemovedValues(getCollection(originalVals));
            getRemovedValues().addAll(originalVals);
            changed = true;
            collectionSetChanged = true;
        } else {
            for (Object o : originalVals) {
                if (alarms) {
                    BwAlarm al = (BwAlarm) o;
                    if (!al.getOwnerHref().equals(chg.getUserHref())) {
                        continue;
                    }
                }
                if ((newVals == null) || !newVals.contains(o)) {
                    if (getRemovedValues() == null) {
                        setRemovedValues(getCollection(originalVals));
                    }
                    getRemovedValues().add(o);
                    changed = true;
                    collectionSetChanged = true;
                }
            }
        }
    }
    if (newVals == null) {
        return collectionSetChanged;
    }
    if (Util.isEmpty(originalVals)) {
        // Add everything
        setAddedValues(getCollection(newVals));
        getAddedValues().addAll(newVals);
        added = true;
        changed = true;
        return true;
    }
    /* Here we also look for entries that have equals return true but are
     * in fact different in some way. These can be tested for if they
     * implement the Differable interface
     */
    List<Differable> differList = null;
    for (Object o : newVals) {
        if ((o instanceof Differable) && (differList == null)) {
            differList = new ArrayList<Differable>(originalVals);
        }
        if (!originalVals.contains(o)) {
            if (getAddedValues() == null) {
                setAddedValues(getCollection(newVals));
            }
            getAddedValues().add(o);
            changed = true;
            collectionSetChanged = true;
        } else if (differList != null) {
            // See if it changed
            Differable orig = differList.get(differList.indexOf(o));
            if (orig.differsFrom(o)) {
                if (getChangedValues() == null) {
                    setChangedValues(getCollection(newVals));
                }
                getChangedValues().add(o);
                changed = true;
            }
        }
    }
    return collectionSetChanged;
}
Also used : Differable(org.bedework.calfacade.base.Differable) Collection(java.util.Collection) BwAlarm(org.bedework.calfacade.BwAlarm)

Example 7 with BwAlarm

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

the class AlarmDurationPropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    BwAlarm alarm = ui.getSubComponent().getAlarm();
    DurationPropType dur = (DurationPropType) ui.getProp();
    if (ui.isRemove()) {
        if (alarm.getDuration() == null) {
            return new UpdateResult("Entity has no duration - cannot remove");
        }
        alarm.setDuration(null);
        flagChange(alarm, ui);
        return UpdateResult.getOkResult();
    }
    if (ui.isAdd()) {
        if (alarm.getDuration() != null) {
            return new UpdateResult("Entity already has duration - cannot add");
        }
        alarm.setDuration(dur.getDuration());
        flagChange(alarm, ui);
        return UpdateResult.getOkResult();
    }
    /* Changing duration */
    dur = (DurationPropType) ui.getUpdprop();
    if (!dur.getDuration().equals(alarm.getDuration())) {
        alarm.setDuration(dur.getDuration());
        flagChange(alarm, ui);
    }
    return UpdateResult.getOkResult();
}
Also used : DurationPropType(ietf.params.xml.ns.icalendar_2.DurationPropType) BwAlarm(org.bedework.calfacade.BwAlarm) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)

Example 8 with BwAlarm

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

the class DocBuilder method indexAlarms.

private void indexAlarms(final BwDateTime start, final Set<BwAlarm> alarms) throws CalFacadeException {
    try {
        if (Util.isEmpty(alarms)) {
            return;
        }
        startArray(getJname(PropertyInfoIndex.VALARM));
        for (final BwAlarm al : alarms) {
            startObject();
            makeField(PropertyInfoIndex.OWNER, al.getOwnerHref());
            makeField(PropertyInfoIndex.PUBLIC, al.getPublick());
            final int atype = al.getAlarmType();
            final String action;
            if (atype != BwAlarm.alarmTypeOther) {
                action = BwAlarm.alarmTypes[atype];
            } else {
                final List<BwXproperty> xps = al.getXicalProperties("ACTION");
                action = xps.get(0).getValue();
            }
            makeField(PropertyInfoIndex.ACTION, action);
            try {
                final Set<String> triggerTimes = new TreeSet<>();
                Date dt = null;
                for (int i = 0; i < 100; i++) {
                    // Arb limit
                    dt = al.getNextTriggerDate(start, dt);
                    if (dt == null) {
                        break;
                    }
                    triggerTimes.add(DateTimeUtil.isoDateTimeUTC(dt));
                }
                if (!Util.isEmpty(triggerTimes)) {
                    makeField(PropertyInfoIndex.NEXT_TRIGGER_DATE_TIME, triggerTimes);
                }
            } catch (final Throwable t) {
                error("Exception calculating next trigger");
                error(t);
            }
            makeField(PropertyInfoIndex.TRIGGER, al.getTrigger());
            if (al.getTriggerDateTime()) {
                makeField(PropertyInfoIndex.TRIGGER_DATE_TIME, true);
            } else if (!al.getTriggerStart()) {
                makeField(ParameterInfoIndex.RELATED.getJname(), Related.END.getValue());
            }
            if (al.getDuration() != null) {
                makeField(PropertyInfoIndex.DURATION, al.getDuration());
                makeField(PropertyInfoIndex.REPEAT, al.getRepeat());
            }
            if (atype == BwAlarm.alarmTypeAudio) {
                makeField(PropertyInfoIndex.ATTACH, al.getAttach());
            } else if (atype == BwAlarm.alarmTypeDisplay) {
                /* This is required but somehow we got a bunch of alarms with no description
           * Is it possibly because of the rollback issue I (partially) fixed?
           */
                makeField(PropertyInfoIndex.DESCRIPTION, al.getDescription());
            } else if (atype == BwAlarm.alarmTypeEmail) {
                makeField(PropertyInfoIndex.ATTACH, al.getAttach());
                makeField(PropertyInfoIndex.DESCRIPTION, al.getDescription());
                makeField(PropertyInfoIndex.SUMMARY, al.getSummary());
                if (al.getNumAttendees() > 0) {
                    indexAttendees(al.getAttendees(), false);
                }
            } else if (atype == BwAlarm.alarmTypeProcedure) {
                makeField(PropertyInfoIndex.ATTACH, al.getAttach());
                makeField(PropertyInfoIndex.DESCRIPTION, al.getDescription());
            } else {
                makeField(PropertyInfoIndex.DESCRIPTION, al.getDescription());
            }
            indexXprops(al);
            endObject();
        }
        endArray();
    } catch (final IndexException e) {
        throw new CalFacadeException(e);
    }
}
Also used : IndexException(org.bedework.util.indexing.IndexException) BwXproperty(org.bedework.calfacade.BwXproperty) TreeSet(java.util.TreeSet) BwAlarm(org.bedework.calfacade.BwAlarm) Date(java.util.Date) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 9 with BwAlarm

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

the class EntityBuilder method restoreAlarms.

private Set<BwAlarm> restoreAlarms() throws CalFacadeException {
    final List<Object> vals = getFieldValues(PropertyInfoIndex.VALARM);
    if (Util.isEmpty(vals)) {
        return null;
    }
    final Set<BwAlarm> alarms = new TreeSet<>();
    for (final Object o : vals) {
        try {
            pushFields(o);
            final BwAlarm alarm = new BwAlarm();
            alarm.setOwnerHref(getString(PropertyInfoIndex.OWNER));
            alarm.setPublick(getBooleanNotNull(PropertyInfoIndex.PUBLIC));
            final String action = getString(PropertyInfoIndex.ACTION);
            final String actionVal = action.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) {
                alarm.setAlarmType(BwAlarm.alarmTypeOther);
                alarm.addXproperty(BwXproperty.makeIcalProperty("ACTION", null, action));
            } else {
                alarm.setAlarmType(atype);
            }
            alarm.setTrigger(getString(PropertyInfoIndex.TRIGGER));
            alarm.setTriggerDateTime(getBool(PropertyInfoIndex.TRIGGER_DATE_TIME));
            final String rel = getString(ParameterInfoIndex.RELATED);
            alarm.setTriggerStart(rel == null);
            alarm.setDuration(getString(PropertyInfoIndex.DURATION));
            alarm.setRepeat(getInt(PropertyInfoIndex.REPEAT));
            if (atype == BwAlarm.alarmTypeAudio) {
                alarm.setAttach(getString(PropertyInfoIndex.ATTACH));
            } else if (atype == BwAlarm.alarmTypeDisplay) {
                alarm.setDescription(getString(PropertyInfoIndex.DESCRIPTION));
            } else if (atype == BwAlarm.alarmTypeEmail) {
                alarm.setAttach(getString(PropertyInfoIndex.ATTACH));
                alarm.setDescription(getString(PropertyInfoIndex.DESCRIPTION));
                alarm.setSummary(getString(PropertyInfoIndex.SUMMARY));
                alarm.setAttendees(restoreAttendees(false));
            } else if (atype == BwAlarm.alarmTypeProcedure) {
                alarm.setAttach(getString(PropertyInfoIndex.ATTACH));
                alarm.setDescription(getString(PropertyInfoIndex.DESCRIPTION));
            } else {
                alarm.setDescription(getString(PropertyInfoIndex.DESCRIPTION));
            }
            alarm.setXproperties(restoreXprops());
            alarms.add(alarm);
        } catch (final IndexException ie) {
            throw new CalFacadeException(ie);
        } finally {
            popFields();
        }
    }
    return alarms;
}
Also used : IndexException(org.bedework.util.indexing.IndexException) TreeSet(java.util.TreeSet) BwString(org.bedework.calfacade.BwString) BwLongString(org.bedework.calfacade.BwLongString) BwAlarm(org.bedework.calfacade.BwAlarm) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 10 with BwAlarm

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

the class BwStringRule method end.

@Override
public void end(final String ns, final String name) throws Exception {
    if (name.equals("bwstring")) {
        // 3.5 onwards we wrapped with a tag. Do nothing
        return;
    }
    BwString entity = (BwString) pop();
    if (top() instanceof BwRequestStatus) {
        BwRequestStatus rs = (BwRequestStatus) top();
        rs.setDescription(entity);
        return;
    }
    if (top() instanceof BwCategory) {
        BwCategory cat = (BwCategory) top();
        if (name.equals("keyword")) {
            cat.setWord(entity);
        } else if (name.equals("desc")) {
            cat.setDescription(entity);
        } else {
            unknownTag(name);
        }
        return;
    }
    if (top() instanceof BwContact) {
        BwContact ent = (BwContact) top();
        if (name.equals("value")) {
            ent.setCn(entity);
        } else {
            unknownTag(name);
        }
        return;
    }
    if (top() instanceof BwLocation) {
        BwLocation loc = (BwLocation) top();
        if (name.equals("addr")) {
            loc.setAddress(entity);
        } else if (name.equals("subaddr")) {
            loc.setSubaddress(entity);
        } else {
            unknownTag(name);
        }
        return;
    }
    if (top() instanceof BwFilterDef) {
        BwFilterDef f = (BwFilterDef) top();
        if (name.equals("display-name")) {
            f.addDisplayName(entity);
        } else if (name.equals("subaddr")) {
            f.addDescription(new BwLongString(entity.getLang(), entity.getValue()));
        } else {
            unknownTag(name);
        }
        return;
    }
    if (top() instanceof BwAlarm) {
        BwAlarm a = (BwAlarm) top();
        if (name.equals("description")) {
            a.addDescription(entity);
            if (entity.getLang() != null) {
                a.addXproperty(new BwXproperty(entity.getLang(), null, entity.getValue()));
            } else {
                a.addDescription(entity);
            }
            return;
        }
        if (name.equals("summary")) {
            a.addSummary(entity);
        } else {
            unknownTag(name);
        }
        return;
    }
    EventInfo ei = (EventInfo) top();
    BwEvent e = ei.getEvent();
    if (e instanceof BwEventProxy) {
        e = ((BwEventProxy) e).getRef();
    }
    if (name.equals("comment")) {
        e.addComment(entity);
    } else if (name.equals("description")) {
        e.addDescription(new BwLongString(entity.getLang(), entity.getValue()));
    } else if (name.equals("resource")) {
        e.addResource(entity);
    } else if (name.equals("summary")) {
        e.addSummary(entity);
    } else {
        unknownTag(name);
    }
}
Also used : BwLongString(org.bedework.calfacade.BwLongString) BwLocation(org.bedework.calfacade.BwLocation) BwRequestStatus(org.bedework.calfacade.BwRequestStatus) EventInfo(org.bedework.calfacade.svc.EventInfo) BwXproperty(org.bedework.calfacade.BwXproperty) BwCategory(org.bedework.calfacade.BwCategory) BwFilterDef(org.bedework.calfacade.BwFilterDef) BwEvent(org.bedework.calfacade.BwEvent) BwString(org.bedework.calfacade.BwString) BwContact(org.bedework.calfacade.BwContact) BwEventProxy(org.bedework.calfacade.BwEventProxy) BwAlarm(org.bedework.calfacade.BwAlarm)

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